Skip to content

Commit

Permalink
Merge pull request #79 from nismod/fix/adapation_options_kludge
Browse files Browse the repository at this point in the history
Fix adaptation options no. of days < 15
  • Loading branch information
tomalrussell authored May 24, 2022
2 parents b584277 + c0b973d commit c5ee7f2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
13 changes: 12 additions & 1 deletion backend/backend/app/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
from typing import Any, Generic, Literal, TypeVar
from pydantic import BaseModel, conint, root_validator
from pydantic import BaseModel, conint, validator
from pydantic.generics import GenericModel


Expand Down Expand Up @@ -119,6 +119,17 @@ class AdaptationVariables(DataVariables):
class AdaptationCostBenefitRatioParameters(DataParameters):
eael_days: conint(ge=1, le=30)

@validator('eael_days')
def fix_eael_days(cls, eael_days) -> float:
"""
The data for `AdaptationCostBenefit.avoided_eael_mean` is erroneous and
should be modified in the meantime. This validator adds a fudge factor
to account for the multiplicative error in the data.
TODO: fix the data so we don't need this function.
"""
return eael_days / 15


class Adaptation(AdaptationDimensions, AdaptationVariables):
class Config:
Expand Down
1 change: 1 addition & 0 deletions src/details/features/adaptation/AdaptationSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function makeAdaptationCsv(options: Adaptation[]) {
).join('\n');
}

// TODO: remove factor when data is updated
const HORRIBLE_HACK_FACTOR = 1/15;
export const AdaptationSection = ({ fd }) => {
const options : Adaptation[] = fd?.adaptation.map(
Expand Down
9 changes: 4 additions & 5 deletions src/sidebar/networks/AdaptationControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ function makeOptions(values, labelFn = (x) => x) {
label: labelFn(val),
}));
}
const HORRIBLE_HACK_FACTOR = 1/15;
const EAEL_DAYS_MARKS = [1, 5, 10, 15, 20, 25, 30].map((x) => ({ value: x * HORRIBLE_HACK_FACTOR, label: x }));
const EAEL_DAYS_MARKS = [1, 5, 10, 15, 20, 25, 30].map((x) => ({ value: x, label: x }));
const CostBenefitRatioInputs: FC = () => {
const [eaelDays, setEaelDays] = useRecoilState(adaptationCostBenefitRatioEaelDaysState);

Expand All @@ -52,9 +51,9 @@ const CostBenefitRatioInputs: FC = () => {
id="adaptation-cost-benefit-eael-days"
value={eaelDays}
onChange={(e, value: number) => setEaelDays(value)}
min={1*HORRIBLE_HACK_FACTOR}
max={30*HORRIBLE_HACK_FACTOR}
step={1*HORRIBLE_HACK_FACTOR}
min={1}
max={30}
step={1}
marks={EAEL_DAYS_MARKS}
valueLabelDisplay="auto"
/>
Expand Down
3 changes: 1 addition & 2 deletions src/state/layers/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ export const adaptationFieldState = atom<
default: 'avoided_ead_mean',
});

const HORRIBLE_HACK_FACTOR = 1/15;
export const adaptationCostBenefitRatioEaelDaysState = atom<number>({
key: 'adaptationCostBenefitRatioEaelDaysState',
default: 15 * HORRIBLE_HACK_FACTOR,
default: 15,
});

export const adaptationDataParamsStateEffect: StateEffect<AdaptationOptionParams> = (
Expand Down

0 comments on commit c5ee7f2

Please sign in to comment.