Skip to content

Commit

Permalink
refactor: fallback to country default.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Sep 18, 2024
1 parent 11a3b5e commit 90948a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
34 changes: 19 additions & 15 deletions src/Data/Textile/Simulator.elm
Original file line number Diff line number Diff line change
Expand Up @@ -214,26 +214,30 @@ computeDurability ({ inputs } as simulator) =


computeMakingAirTransportRatio : Simulator -> Simulator
computeMakingAirTransportRatio ({ inputs } as simulator) =
computeMakingAirTransportRatio ({ durability, inputs } as simulator) =
simulator
|> updateLifeCycleStep Label.Making
(\({ country } as step) ->
{ step
| airTransportRatio =
if inputs.airTransportRatio /= Nothing then
-- User-provided value always takes precedence
step.airTransportRatio

else if Country.isEuropeOrTurkey country then
-- If Making country is Europe or Turquey, airTransportRatio is always 0
Split.zero

else if Unit.floatDurabilityFromHolistic simulator.durability >= 1 then
-- Durable garments outside of Europe and Turquey
Split.third

else
Split.full
case inputs.airTransportRatio of
Just airTransportRatio ->
-- User-provided value always takes precedence
airTransportRatio

Nothing ->
if Country.isEuropeOrTurkey country then
-- If Making country is Europe or Turkey, airTransportRatio is always 0
Split.zero

else if Unit.floatDurabilityFromHolistic durability >= 1 then
-- Durable garments outside of Europe and Turkey
Split.third

else
-- FIXME: how about faling back to coutry default?
-- Spli.full ?
country.airTransportRatio
}
)

Expand Down
6 changes: 2 additions & 4 deletions src/Data/Textile/Step.elm
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ getTransportedMass inputs { label, outputMass } =
updateFromInputs : Textile.Db -> Inputs -> Step -> Step
updateFromInputs { wellKnown } inputs ({ label, country, complementsImpacts } as step) =
let
{ airTransportRatio, dyeingMedium, makingComplexity, makingDeadStock, makingWaste, printing, surfaceMass, yarnSize } =
{ dyeingMedium, makingComplexity, makingDeadStock, makingWaste, printing, surfaceMass, yarnSize } =
inputs
in
case label of
Expand Down Expand Up @@ -348,9 +348,7 @@ updateFromInputs { wellKnown } inputs ({ label, country, complementsImpacts } as

Label.Making ->
{ step
| airTransportRatio =
airTransportRatio |> Maybe.withDefault country.airTransportRatio
, makingComplexity = makingComplexity
| makingComplexity = makingComplexity
, makingDeadStock = makingDeadStock
, makingWaste = makingWaste
, processInfo =
Expand Down

0 comments on commit 90948a1

Please sign in to comment.