Skip to content

Commit

Permalink
Harmonize ecosystemic services values in the API. (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 authored Apr 10, 2024
1 parent b29e598 commit 3a50b65
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 30 deletions.
69 changes: 40 additions & 29 deletions src/Data/Impact.elm
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,39 @@ divideComplementsImpactsBy n =
mapComplementsImpacts (Quantity.divideBy n)


encodeComplementsImpacts : ComplementsImpacts -> Encode.Value
encodeComplementsImpacts complementsImpact =
let
negated =
negateComplementsImpacts complementsImpact
in
Encode.object
-- Ecosystemic services
[ ( "hedges", Unit.encodeImpact negated.hedges )
, ( "plotSize", Unit.encodeImpact negated.plotSize )
, ( "cropDiversity", Unit.encodeImpact negated.cropDiversity )
, ( "permanentPasture", Unit.encodeImpact negated.permanentPasture )
, ( "livestockDensity", Unit.encodeImpact negated.livestockDensity )

-- Textile complements
, ( "microfibers", Unit.encodeImpact negated.microfibers )
, ( "outOfEuropeEOL", Unit.encodeImpact negated.outOfEuropeEOL )
]


getTotalComplementsImpacts : ComplementsImpacts -> Unit.Impact
getTotalComplementsImpacts complementsImpacts =
Quantity.sum
[ complementsImpacts.hedges
, complementsImpacts.plotSize
, complementsImpacts.cropDiversity
, complementsImpacts.permanentPasture
, complementsImpacts.livestockDensity
, complementsImpacts.microfibers
, complementsImpacts.outOfEuropeEOL
]


mapComplementsImpacts : (Unit.Impact -> Unit.Impact) -> ComplementsImpacts -> ComplementsImpacts
mapComplementsImpacts fn ci =
{ hedges = fn ci.hedges
Expand All @@ -113,6 +146,11 @@ mapComplementsImpacts fn ci =
}


negateComplementsImpacts : ComplementsImpacts -> ComplementsImpacts
negateComplementsImpacts =
mapComplementsImpacts (Unit.impactToFloat >> negate >> Unit.impact)


noComplementsImpacts : ComplementsImpacts
noComplementsImpacts =
{ hedges = Unit.impact 0
Expand All @@ -125,19 +163,6 @@ noComplementsImpacts =
}


getTotalComplementsImpacts : ComplementsImpacts -> Unit.Impact
getTotalComplementsImpacts complementsImpacts =
Quantity.sum
[ complementsImpacts.hedges
, complementsImpacts.plotSize
, complementsImpacts.cropDiversity
, complementsImpacts.permanentPasture
, complementsImpacts.livestockDensity
, complementsImpacts.microfibers
, complementsImpacts.outOfEuropeEOL
]


impactsWithComplements : ComplementsImpacts -> Impacts -> Impacts
impactsWithComplements complementsImpacts impacts =
let
Expand Down Expand Up @@ -408,24 +433,10 @@ decodeWithoutAggregated =
|> Decode.map Impacts


encodeComplementsImpacts : ComplementsImpacts -> Encode.Value
encodeComplementsImpacts c =
Encode.object
[ ( "hedges", Unit.encodeImpact c.hedges )
, ( "plotSize", Unit.encodeImpact c.plotSize )
, ( "cropDiversity", Unit.encodeImpact c.cropDiversity )
, ( "permanentPasture", Unit.encodeImpact c.permanentPasture )
, ( "livestockDensity", Unit.encodeImpact c.livestockDensity )
, ( "microfibers", Unit.encodeImpact c.microfibers )
, ( "outOfEuropeEOL", Unit.encodeImpact c.outOfEuropeEOL )
]


encode : Impacts -> Encode.Value
encode (Impacts impacts) =
Definition.encodeBase
Unit.encodeImpact
impacts
impacts
|> Definition.encodeBase Unit.encodeImpact


encodeSingleImpact : Impacts -> Trigram -> Encode.Value
Expand Down
12 changes: 11 additions & 1 deletion src/Page/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ getApiServerUrl { clientUrl } =

changelog : List News
changelog =
[ { date = "9 avril 2024"
[ { date = "10 avril 2024"
, level = "minor"
, domains = [ "Textile" ]
, md =
"""Les compléments sont désormais exposés de façon à mieux matérialiser leurs
effets\u{00A0}; une dégradation est désormais exprimée par un nombre positif
(qui additionnée au coût le fait augmenter), tandis qu'une amélioration
s'exprime par une valeur négative (qui additionnée au coût le fait baisser).
"""
}
, { date = "9 avril 2024"
, level = "minor"
, domains = [ "Textile" ]
, md =
Expand Down

0 comments on commit 3a50b65

Please sign in to comment.