diff --git a/src/Data/Textile/Simulator.elm b/src/Data/Textile/Simulator.elm index 1a881f0bc..438328813 100644 --- a/src/Data/Textile/Simulator.elm +++ b/src/Data/Textile/Simulator.elm @@ -3,6 +3,7 @@ module Data.Textile.Simulator exposing , compute , encode , getTotalImpactsWithoutComplements + , getTotalImpactsWithoutDurability , stepMaterialImpacts , toStepsImpacts ) @@ -55,6 +56,7 @@ encode v = , ( "daysOfWear", v.daysOfWear |> Duration.inDays |> round |> Encode.int ) , ( "durability", v.durability |> Unit.floatDurabilityFromHolistic |> Encode.float ) , ( "impacts", Impact.encode v.impacts ) + , ( "impactsWithoutDurability", Impact.encode (getTotalImpactsWithoutDurability v.lifeCycle) ) , ( "inputs", Inputs.encode v.inputs ) , ( "lifeCycle", LifeCycle.encode v.lifeCycle ) , ( "transport", Transport.encode v.transport ) @@ -751,6 +753,19 @@ getTotalImpactsWithoutComplements { durability, lifeCycle } = |> Impact.divideBy (Unit.floatDurabilityFromHolistic durability) +getTotalImpactsWithoutDurability : LifeCycle -> 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 } diff --git a/src/Page/Api.elm b/src/Page/Api.elm index 7d4acd6eb..b3f1297d9 100644 --- a/src/Page/Api.elm +++ b/src/Page/Api.elm @@ -55,7 +55,12 @@ getApiServerUrl { clientUrl } = changelog : List News changelog = - [ { date = "5 septembre 2024" + [ { date = "29 octobre 2024" + , level = "minor" + , domains = [ "Textile" ] + , md = "Ajout du champ `impactsWithoutDurability` dans la réponse des calculs détaillés. Ce champ a le même format que le champ `impacts` mais contient les scores avant application du coefficient de durabilité." + } + , { date = "5 septembre 2024" , level = "minor" , domains = [ "Textile" ] , md = "Ajout du champ `physicalDurability` qui permet de préciser la durabilité physique d'un vêtement." diff --git a/src/Page/Food.elm b/src/Page/Food.elm index 2fea0f9c7..f569e8933 100644 --- a/src/Page/Food.elm +++ b/src/Page/Food.elm @@ -1408,6 +1408,7 @@ sidebarView session model results = , customScoreInfo = Nothing , productMass = results.preparedMass , totalImpacts = results.total + , totalImpactsWithoutDurability = Nothing -- Impacts tabs , impactTabsConfig = diff --git a/src/Page/Object.elm b/src/Page/Object.elm index 90c3c6c30..7c7f620c8 100644 --- a/src/Page/Object.elm +++ b/src/Page/Object.elm @@ -424,6 +424,7 @@ simulatorView session model = , customScoreInfo = Nothing , productMass = Simulator.extractMass model.results , totalImpacts = Simulator.extractImpacts model.results + , totalImpactsWithoutDurability = Nothing -- Impacts tabs , impactTabsConfig = diff --git a/src/Page/Textile.elm b/src/Page/Textile.elm index 0c0acb91b..0f0d3efea 100644 --- a/src/Page/Textile.elm +++ b/src/Page/Textile.elm @@ -1122,6 +1122,7 @@ simulatorView session model ({ inputs, impacts } as simulator) = ) , productMass = inputs.mass , totalImpacts = impacts + , totalImpactsWithoutDurability = Just <| Simulator.getTotalImpactsWithoutDurability simulator.lifeCycle -- Impacts tabs , impactTabsConfig = diff --git a/src/Views/Score.elm b/src/Views/Score.elm index cc6da3fd3..779e56a94 100644 --- a/src/Views/Score.elm +++ b/src/Views/Score.elm @@ -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 diff --git a/src/Views/Sidebar.elm b/src/Views/Sidebar.elm index 68d94edde..3ce98d311 100644 --- a/src/Views/Sidebar.elm +++ b/src/Views/Sidebar.elm @@ -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 } @@ -58,6 +59,7 @@ view config = , impactDefinition = config.selectedImpact , mass = config.productMass , score = config.totalImpacts + , scoreWithoutDurability = config.totalImpactsWithoutDurability } , case config.impactTabsConfig of Just impactTabsConfig -> diff --git a/tests/server.spec.js b/tests/server.spec.js index c3e1fbdd4..0e5226532 100644 --- a/tests/server.spec.js +++ b/tests/server.spec.js @@ -320,6 +320,14 @@ describe("API", () => { expectStatus(response, 200); expect(response.body.lifeCycle).toHaveLength(8); }); + + it("should expose impacts without durability", async () => { + const response = await makeRequest("/api/textile/simulator/detailed", successQuery); + + expectStatus(response, 200); + expect(response.body.impacts.ecs).toBeCloseTo(1619.93, 1); + expect(response.body.impactsWithoutDurability.ecs).toBeCloseTo(1085.35, 1); + }); }); describe("End to end textile simulations", () => {