Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display score without durability #815

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Data/Textile/Simulator.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Data.Textile.Simulator exposing
, compute
, encode
, getTotalImpactsWithoutComplements
, getTotalImpactsWithoutDurability
, stepMaterialImpacts
, toStepsImpacts
)
Expand Down Expand Up @@ -751,6 +752,19 @@ getTotalImpactsWithoutComplements { durability, lifeCycle } =
|> Impact.divideBy (Unit.floatDurabilityFromHolistic durability)


getTotalImpactsWithoutDurability : Simulator -> Impacts
getTotalImpactsWithoutDurability { lifeCycle } =
let
complementsImpactsWithoutDurability =
lifeCycle
|> Array.filter .enabled
|> LifeCycle.sumComplementsImpacts
in
lifeCycle
|> LifeCycle.computeFinalImpacts
|> Impact.impactsWithComplements complementsImpactsWithoutDurability


updateLifeCycle : (LifeCycle -> LifeCycle) -> Simulator -> Simulator
updateLifeCycle update simulator =
{ simulator | lifeCycle = update simulator.lifeCycle }
Expand Down
1 change: 1 addition & 0 deletions src/Page/Food.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ sidebarView session model results =
, customScoreInfo = Nothing
, productMass = results.preparedMass
, totalImpacts = results.total
, totalImpactsWithoutDurability = Nothing

-- Impacts tabs
, impactTabsConfig =
Expand Down
1 change: 1 addition & 0 deletions src/Page/Object.elm
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ simulatorView session model =
, customScoreInfo = Nothing
, productMass = Simulator.extractMass model.results
, totalImpacts = Simulator.extractImpacts model.results
, totalImpactsWithoutDurability = Nothing

-- Impacts tabs
, impactTabsConfig =
Expand Down
1 change: 1 addition & 0 deletions src/Page/Textile.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ simulatorView session model ({ inputs, impacts } as simulator) =
)
, productMass = inputs.mass
, totalImpacts = impacts
, totalImpactsWithoutDurability = Just <| Simulator.getTotalImpactsWithoutDurability simulator

-- Impacts tabs
, impactTabsConfig =
Expand Down
8 changes: 7 additions & 1 deletion src/Views/Score.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ type alias Config msg =
, impactDefinition : Definition
, mass : Mass
, score : Impacts
, scoreWithoutDurability : Maybe Impacts
}


view : Config msg -> Html msg
view { customInfo, impactDefinition, mass, score } =
view { customInfo, impactDefinition, mass, score, scoreWithoutDurability } =
div [ class "card bg-secondary shadow-sm" ]
[ div [ class "card-body text-center text-nowrap text-white" ]
[ div [ class "display-3 lh-1" ] [ Format.formatImpact impactDefinition score ]
, div []
[ scoreWithoutDurability
|> Maybe.map (\s -> span [] [ Format.formatImpact impactDefinition s, text " hors durabilité" ])
|> Maybe.withDefault (text "")
]
, small [] [ text "Pour ", Format.kg mass ]
]
, case customInfo of
Expand Down
2 changes: 2 additions & 0 deletions src/Views/Sidebar.elm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type alias Config msg =
, switchBookmarkTab : BookmarkView.ActiveTab -> msg
, switchImpact : Result String Trigram -> msg
, totalImpacts : Impacts
, totalImpactsWithoutDurability : Maybe Impacts
, updateBookmarkName : String -> msg
}

Expand Down Expand Up @@ -58,6 +59,7 @@ view config =
, impactDefinition = config.selectedImpact
, mass = config.productMass
, score = config.totalImpacts
, scoreWithoutDurability = config.totalImpactsWithoutDurability
}
, case config.impactTabsConfig of
Just impactTabsConfig ->
Expand Down