diff --git a/bin/build-db b/bin/build-db index b397693611..dfc0a93f34 100755 --- a/bin/build-db +++ b/bin/build-db @@ -44,7 +44,7 @@ const targetDbFile = "src/Static/Json.elm"; const elmTemplate = fs.readFileSync(`${targetDbFile}-template`).toString(); const elmWithFixtures = elmTemplate // Transverse JSON data - .replace("%countriesJson%", parseAndValidate("public/data/countries.json", "code")) + .replace("%geozonesJson%", parseAndValidate("public/data/geozones.json", "code")) .replace("%impactsJson%", parseAndValidate("public/data/impacts.json")) .replace( "%processesJson%", diff --git a/bin/score_history/create_table_score_history.sql b/bin/score_history/create_table_score_history.sql index daa209dfd7..aee9ed92fa 100644 --- a/bin/score_history/create_table_score_history.sql +++ b/bin/score_history/create_table_score_history.sql @@ -9,7 +9,7 @@ CREATE TABLE score_history ( mass numeric NOT NULL, elements text NOT NULL, lifecycle_step text NOT NULL, - lifecycle_step_country text NOT NULL, + lifecycle_step_geozone text NOT NULL, impact text NOT NULL, value numeric NOT NULL, norm_value_ecs numeric NOT NULL diff --git a/bin/score_history/score_history.py b/bin/score_history/score_history.py index d205eda57e..aa72eff683 100755 --- a/bin/score_history/score_history.py +++ b/bin/score_history/score_history.py @@ -208,7 +208,7 @@ def create_df_textile( "mass": query["mass"], "elements": json.dumps(query["materials"]), "lifecycle_step": step_label, - "lifecycle_step_country": step.get("country", {}).get("code", ""), + "lifecycle_step_geozone": step.get("geozone", {}).get("code", ""), "impact": impacts.index.tolist(), "value": impacts.values.tolist(), } @@ -229,7 +229,7 @@ def create_df_textile( "mass": query["mass"], "elements": json.dumps(query["materials"]), "lifecycle_step": step_label, - "lifecycle_step_country": step.get("country", {}).get("code", ""), + "lifecycle_step_geozone": step.get("geozone", {}).get("code", ""), "impact": complementsImpacts.index.tolist(), "value": 0, "norm_value_ecs": complementsImpacts.values.tolist(), @@ -316,7 +316,7 @@ def create_df_food( Returns: - pd.DataFrame: A DataFrame with columns for datetime, branch, commit, domain, product name, product ID, - query, mass, elements, lifecycle step and country, impact indices, values, + query, mass, elements, lifecycle step and geozone, impact indices, values, and normalized impact values expressed in 'ecs' units. """ if lifecycle_step == "ingredients": @@ -335,7 +335,7 @@ def create_df_food( "mass": example["response"]["results"]["preparedMass"], "elements": json.dumps(example["query"]["ingredients"]), "lifecycle_step": lifecycle_step, - "lifecycle_step_country": "", + "lifecycle_step_geozone": "", "impact": impacts_sr.index.tolist(), "value": impacts_sr.values.tolist(), } @@ -356,7 +356,7 @@ def create_df_food( "mass": example["response"]["results"]["preparedMass"], "elements": json.dumps(example["query"]["ingredients"]), "lifecycle_step": lifecycle_step, - "lifecycle_step_country": "", + "lifecycle_step_geozone": "", "impact": complementsImpacts.index.tolist(), "value": 0, "norm_value_ecs": complementsImpacts.values.tolist(), @@ -398,7 +398,7 @@ def are_df_different(df1, df2, tolerance=0.0001): "product_name", "query", "lifecycle_step", - "lifecycle_step_country", + "lifecycle_step_geozone", "impact", ] diff --git a/docker/server-simple.js b/docker/server-simple.js index 72b62e018f..6ae1a1f8ea 100644 --- a/docker/server-simple.js +++ b/docker/server-simple.js @@ -109,7 +109,7 @@ api.get("/", async (req, res) => { }); // Redirects: API -api.get(/^\/countries$/, (_, res) => res.redirect("textile/countries")); +api.get(/^\/geozones$/, (_, res) => res.redirect("textile/geozones")); api.get(/^\/materials$/, (_, res) => res.redirect("textile/materials")); api.get(/^\/products$/, (_, res) => res.redirect("textile/products")); const cleanRedirect = (url) => (url.startsWith("/") ? url : ""); diff --git a/openapi.yaml b/openapi.yaml index 4e662293ac..114496ecdd 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -39,18 +39,18 @@ paths: responses: 200: description: Documentation de l'API au format OpenAPI. - /textile/countries: + /textile/geozones: get: tags: - Textile - summary: Liste des pays utilisables pour les simulations textiles. + summary: Liste des zones géographiques utilisables pour les simulations textiles. responses: 200: description: Opération réussie content: application/json: schema: - $ref: "#/components/schemas/CountryListResponse" + $ref: "#/components/schemas/GeozoneListResponse" /textile/materials: get: tags: @@ -179,18 +179,18 @@ paths: application/json: schema: $ref: "#/components/schemas/TrimListResponse" - /food/countries: + /food/geozones: get: tags: - Alimentaire - summary: Liste des pays utilisables pour les simulations alimentairess. + summary: Liste des zones géographiques utilisables pour les simulations alimentaires. responses: 200: description: Opération réussie content: application/json: schema: - $ref: "#/components/schemas/CountryListResponse" + $ref: "#/components/schemas/GeozoneListResponse" /food/ingredients: get: tags: @@ -267,16 +267,16 @@ paths: ingredients: - id: cfd4a437-aa49-49ff-818e-353421f2fc09 mass: 120 - country: ES + geozone: ES - id: a98b8776-a96d-48e9-b218-976f5452907a mass: 140 - country: ES + geozone: ES - id: 2bf307e8-8cb0-400b-a4f1-cf615d9e96f4 mass: 60 - country: ES + geozone: ES - id: 9042b6d0-c309-4757-a03f-ba802f0c8c01 mass: 225 - country: ES + geozone: ES transform: id: a2836bb8-7f45-5cfa-bb00-8b38046291cf mass: 545 @@ -292,7 +292,7 @@ paths: ingredients: - id: db0e5f44-34b4-4160-b003-77c828d75e60 mass: 500 - country: BR + geozone: BR transform: null packaging: [] distribution: ambient @@ -327,12 +327,12 @@ components: materials: - id: "62a4d6fb-3276-4ba5-93a3-889ecd3bff84" share: 1 - country: "FR" + geozone: "FR" product: "tshirt" - countrySpinning: "FR" - countryFabric: "FR" - countryDyeing: "FR" - countryMaking: "FR" + geozoneSpinning: "FR" + geozoneFabric: "FR" + geozoneDyeing: "FR" + geozoneMaking: "FR" fabricProcess: "knitting-mix" tShirtChina: summary: "T-Shirt Chine, low-cost, 100% Coton" @@ -342,10 +342,10 @@ components: - id: "62a4d6fb-3276-4ba5-93a3-889ecd3bff84" share: 1 product: "tshirt" - countrySpinning: "CN" - countryFabric: "CN" - countryDyeing: "CN" - countryMaking: "CN" + geozoneSpinning: "CN" + geozoneFabric: "CN" + geozoneDyeing: "CN" + geozoneMaking: "CN" airTransportRatio: 0.33 makingWaste: null makingDeadStock: null @@ -501,29 +501,29 @@ components: - small-business - large-business-with-services - large-business-without-services - countryDyeing: + geozoneDyeing: type: string description: | - Code pays pour l'étape de **Teinture** (liste disponible sur le point d'entrée `textile/countries`) + Code de zone géographique pour l'étape de **Teinture** (liste disponible sur le point d'entrée `textile/geozones`) minLength: 2 maxLength: 3 - countryFabric: + geozoneFabric: type: string description: | - Code pays pour l'étape de **Tissage/Tricotage** (liste disponible sur le point d'entrée `textile/countries`) + Code de zone géographique pour l'étape de **Tissage/Tricotage** (liste disponible sur le point d'entrée `textile/geozones`) minLength: 2 maxLength: 3 - countryMaking: + geozoneMaking: type: string description: | - Code pays pour l'étape de **Confection** (liste disponible sur le point d'entrée `textile/countries`) + Code de zone géographique pour l'étape de **Confection** (liste disponible sur le point d'entrée `textile/geozones`) minLength: 2 maxLength: 3 - countrySpinning: + geozoneSpinning: type: string description: | - Code pays pour l'étape de **Filature** (liste disponible sur le point d'entrée `textile/countries`). - Si non spécifié, le pays de filature pris en considération est celui de production de + Code de zone géographique pour l'étape de **Filature** (liste disponible sur le point d'entrée `textile/geozones`). + Si non spécifié, la zone géographique de filature prise en considération est celle de production de la matière la plus représentée dans le mix. minLength: 2 maxLength: 3 @@ -731,9 +731,9 @@ components: - ConventionalSpinning - UnconventionalSpinning - SyntheticSpinning - country: + geozone: type: string - description: Code du pays d'origine de la matière (liste disponible sur le point d'entrée `/textile/countries`). + description: Code de la zone géographique d'origine de la matière (liste disponible sur le point d'entrée `/textile/geozones`). minLength: 2 maxLength: 3 FoodQuery: @@ -796,7 +796,7 @@ components: - l'identifiant de la matière (pour avoir la liste, utiliser l'API de liste d'ingrédients) - sa masse **exprimée en grammes** - - un éventuel code de pays d'origine (ex: `BR` pour le Brésil) + - un éventuel code de zone géographique d'origine (ex: `BR` pour le Brésil) - un éventuel transport par avion *uniquement si c'est un [ingrédient de catégorie "HORS EUROPE-MAGHREB (AVION)"](https://fabrique-numerique.gitbook.io/ecobalyse/alimentaire/transport#circuits-consideres)* (valeurs possible: ``, `byPlane`, `noPlane`) @@ -811,9 +811,9 @@ components: mass: type: number description: Masse de l'ingrédient, **en grammes** - country: + geozone: type: string - description: Code du pays d'origine (liste disponible sur le point d'entrée `/food/countries`). + description: Code de la zone géographique d'origine (liste disponible sur le point d'entrée `/food/geozones`). byPlane: type: string description: Transport par avion @@ -869,9 +869,9 @@ components: type: string description: | Lien hypertexte vers la documentation de l'API - CountryListResponse: + GeozoneListResponse: type: array - description: Liste des pays. + description: Liste des zones géographiques. items: type: object properties: diff --git a/public/data/food/examples.json b/public/data/food/examples.json index 002e29731c..e61ec2ea3e 100644 --- a/public/data/food/examples.json +++ b/public/data/food/examples.json @@ -16,7 +16,7 @@ "distribution": "ambient", "ingredients": [ { - "country": "FR", + "geozone": "FR", "id": "db791ac8-02b9-41b0-bc2b-2913e745bd19", "mass": 1000 } @@ -38,7 +38,7 @@ "distribution": "ambient", "ingredients": [ { - "country": "FR", + "geozone": "FR", "id": "a2e25aca-1f42-4bc8-bc0e-4d7c751775aa", "mass": 1000 } @@ -81,7 +81,7 @@ "distribution": "frozen", "ingredients": [ { - "country": "FR", + "geozone": "FR", "id": "a360871c-fc35-4cb3-af2c-5eeb8bd6f984", "mass": 250 } @@ -104,7 +104,7 @@ "distribution": "frozen", "ingredients": [ { - "country": "BR", + "geozone": "BR", "id": "8fb5024c-ceec-4201-b069-ea253c537ad6", "mass": 250 } @@ -193,57 +193,57 @@ "distribution": "frozen", "ingredients": [ { - "country": "FR", + "geozone": "FR", "id": "a2e25aca-1f42-4bc8-bc0e-4d7c751775aa", "mass": 148 }, { - "country": "FR", + "geozone": "FR", "id": "6523c72b-2c28-474d-9bf8-45e018bbd0be", "mass": 100 }, { - "country": "FR", + "geozone": "FR", "id": "faa513ae-9c32-4e6c-874e-58c13309339e", "mass": 19 }, { - "country": "FR", + "geozone": "FR", "id": "41d65ed4-230f-4a47-a67c-9a8015f50420", "mass": 43 }, { - "country": "FR", + "geozone": "FR", "id": "5fc8032f-ca1c-4497-844b-f9213075eab3", "mass": 3 }, { - "country": "FR", + "geozone": "FR", "id": "96b301d9-d21b-4cea-8903-bd7917e95a30", "mass": 5 }, { - "country": "FR", + "geozone": "FR", "id": "36b3ffec-51e7-4e26-b1b5-7d52554e0aa6", "mass": 33 }, { - "country": "FR", + "geozone": "FR", "id": "74314f2e-aa88-4ac1-aa78-bb29dceebf0b", "mass": 19 }, { - "country": "FR", + "geozone": "FR", "id": "3cfab110-363e-442a-9170-1af337fe9ea3", "mass": 2 }, { - "country": "FR", + "geozone": "FR", "id": "97cde31b-e46e-472d-836d-9b217c3845df", "mass": 14 }, { - "country": "FR", + "geozone": "FR", "id": "4d5198e7-413a-4ae2-8448-535aa3b302ae", "mass": 6 } @@ -270,57 +270,57 @@ "distribution": "frozen", "ingredients": [ { - "country": "FR", + "geozone": "FR", "id": "db791ac8-02b9-41b0-bc2b-2913e745bd19", "mass": 148 }, { - "country": "FR", + "geozone": "FR", "id": "6523c72b-2c28-474d-9bf8-45e018bbd0be", "mass": 100 }, { - "country": "FR", + "geozone": "FR", "id": "faa513ae-9c32-4e6c-874e-58c13309339e", "mass": 19 }, { - "country": "FR", + "geozone": "FR", "id": "4e3009f3-1b33-41d7-b6f3-dc7230331da0", "mass": 43 }, { - "country": "FR", + "geozone": "FR", "id": "5fc8032f-ca1c-4497-844b-f9213075eab3", "mass": 3 }, { - "country": "FR", + "geozone": "FR", "id": "51f8e8d2-13c0-446c-bf0a-9272fc46edde", "mass": 5 }, { - "country": "FR", + "geozone": "FR", "id": "36b3ffec-51e7-4e26-b1b5-7d52554e0aa6", "mass": 33 }, { - "country": "FR", + "geozone": "FR", "id": "74314f2e-aa88-4ac1-aa78-bb29dceebf0b", "mass": 19 }, { - "country": "FR", + "geozone": "FR", "id": "64fb23f2-0cac-403c-bbfa-1973c9a0ea40", "mass": 2 }, { - "country": "FR", + "geozone": "FR", "id": "97cde31b-e46e-472d-836d-9b217c3845df", "mass": 14 }, { - "country": "FR", + "geozone": "FR", "id": "9042b6d0-c309-4757-a03f-ba802f0c8c01", "mass": 6 } @@ -405,37 +405,37 @@ "distribution": "frozen", "ingredients": [ { - "country": "FR", + "geozone": "FR", "id": "a2e25aca-1f42-4bc8-bc0e-4d7c751775aa", "mass": 97 }, { - "country": "FR", + "geozone": "FR", "id": "6523c72b-2c28-474d-9bf8-45e018bbd0be", "mass": 89 }, { - "country": "FR", + "geozone": "FR", "id": "faa513ae-9c32-4e6c-874e-58c13309339e", "mass": 70 }, { - "country": "FR", + "geozone": "FR", "id": "755225f1-f0c5-497f-b8a9-263828a84a22", "mass": 16 }, { - "country": "FR", + "geozone": "FR", "id": "5fc8032f-ca1c-4497-844b-f9213075eab3", "mass": 5 }, { - "country": "FR", + "geozone": "FR", "id": "5d22559d-c16d-4545-94b9-be2ff51e2879", "mass": 31 }, { - "country": "FR", + "geozone": "FR", "id": "96b301d9-d21b-4cea-8903-bd7917e95a30", "mass": 16 }, @@ -444,7 +444,7 @@ "mass": 1 }, { - "country": "FR", + "geozone": "FR", "id": "36b3ffec-51e7-4e26-b1b5-7d52554e0aa6", "mass": 22 } @@ -537,27 +537,27 @@ "distribution": "frozen", "ingredients": [ { - "country": "FR", + "geozone": "FR", "id": "a2e25aca-1f42-4bc8-bc0e-4d7c751775aa", "mass": 113 }, { - "country": "FR", + "geozone": "FR", "id": "6523c72b-2c28-474d-9bf8-45e018bbd0be", "mass": 76 }, { - "country": "FR", + "geozone": "FR", "id": "faa513ae-9c32-4e6c-874e-58c13309339e", "mass": 36.00000000000001 }, { - "country": "FR", + "geozone": "FR", "id": "5fc8032f-ca1c-4497-844b-f9213075eab3", "mass": 4 }, { - "country": "FR", + "geozone": "FR", "id": "96b301d9-d21b-4cea-8903-bd7917e95a30", "mass": 21 }, @@ -566,27 +566,27 @@ "mass": 2 }, { - "country": "FR", + "geozone": "FR", "id": "74314f2e-aa88-4ac1-aa78-bb29dceebf0b", "mass": 12 }, { - "country": "FR", + "geozone": "FR", "id": "16caaefa-40f5-4d29-a3e6-26349846f2c9", "mass": 36.00000000000001 }, { - "country": "FR", + "geozone": "FR", "id": "361139ac-1028-4cc8-9c0e-4955c5fa39d3", "mass": 36.00000000000001 }, { - "country": "FR", + "geozone": "FR", "id": "97cde31b-e46e-472d-836d-9b217c3845df", "mass": 12 }, { - "country": "FR", + "geozone": "FR", "id": "36b3ffec-51e7-4e26-b1b5-7d52554e0aa6", "mass": 22 } @@ -613,7 +613,7 @@ "distribution": "frozen", "ingredients": [ { - "country": "BR", + "geozone": "BR", "id": "ce073919-1aff-4892-a1f5-b25ee94bccd8", "mass": 200 } @@ -636,7 +636,7 @@ "distribution": "frozen", "ingredients": [ { - "country": "FR", + "geozone": "FR", "id": "41d65ed4-230f-4a47-a67c-9a8015f50420", "mass": 250 } @@ -659,7 +659,7 @@ "distribution": "frozen", "ingredients": [ { - "country": "FR", + "geozone": "FR", "id": "4e3009f3-1b33-41d7-b6f3-dc7230331da0", "mass": 200 } diff --git a/public/data/countries.json b/public/data/geozones.json similarity index 89% rename from public/data/countries.json rename to public/data/geozones.json index e813208fc2..7a7ab40b0e 100644 --- a/public/data/countries.json +++ b/public/data/geozones.json @@ -4,9 +4,9 @@ "code": "---", "electricityProcessId": "ed6d177e-44bb-5ba4-beec-d683dc21be9f", "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", - "name": "Pays inconnu (par défaut)", + "name": "Zone inconnue (par défaut)", "scopes": ["textile"], - "zone": "Asia" + "worldRegion": "Asia" }, { "aquaticPollutionScenario": "Best", @@ -15,7 +15,7 @@ "heatProcessId": "f6ea2983-e024-5de2-b323-273f2436deba", "name": "Région - Europe de l'Ouest", "scopes": ["textile", "object", "veli"], - "zone": "Europe" + "worldRegion": "Europe" }, { "aquaticPollutionScenario": "Best", @@ -24,7 +24,7 @@ "heatProcessId": "f6ea2983-e024-5de2-b323-273f2436deba", "name": "Région - Europe de l'Est", "scopes": ["textile", "object", "veli"], - "zone": "Europe" + "worldRegion": "Europe" }, { "aquaticPollutionScenario": "Worst", @@ -33,7 +33,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Région - Asie", "scopes": ["textile", "object", "veli"], - "zone": "Asia" + "worldRegion": "Asia" }, { "aquaticPollutionScenario": "Worst", @@ -42,7 +42,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Région - Afrique", "scopes": ["textile", "object", "veli"], - "zone": "Africa" + "worldRegion": "Africa" }, { "aquaticPollutionScenario": "Average", @@ -51,7 +51,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Région - Moyen-Orient", "scopes": ["textile", "object", "veli"], - "zone": "Middle_East" + "worldRegion": "Middle_East" }, { "aquaticPollutionScenario": "Average", @@ -60,7 +60,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Région - Amérique Latine", "scopes": ["textile", "object", "veli"], - "zone": "South_America" + "worldRegion": "South_America" }, { "aquaticPollutionScenario": "Worst", @@ -69,7 +69,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Région - Amérique du nord", "scopes": ["textile", "object", "veli"], - "zone": "North_America" + "worldRegion": "North_America" }, { "aquaticPollutionScenario": "Worst", @@ -78,7 +78,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Région - Océanie", "scopes": ["textile", "object", "veli"], - "zone": "Oceania" + "worldRegion": "Oceania" }, { "aquaticPollutionScenario": "Worst", @@ -87,7 +87,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Myanmar", "scopes": ["textile", "object"], - "zone": "Asia" + "worldRegion": "Asia" }, { "aquaticPollutionScenario": "Worst", @@ -96,7 +96,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Bangladesh", "scopes": ["textile", "object"], - "zone": "Asia" + "worldRegion": "Asia" }, { "aquaticPollutionScenario": "Worst", @@ -105,7 +105,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Brésil", "scopes": ["food"], - "zone": "South_America" + "worldRegion": "South_America" }, { "aquaticPollutionScenario": "Average", @@ -114,7 +114,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Chine", "scopes": ["food", "textile", "object", "veli"], - "zone": "Asia" + "worldRegion": "Asia" }, { "aquaticPollutionScenario": "Best", @@ -123,7 +123,7 @@ "heatProcessId": "f6ea2983-e024-5de2-b323-273f2436deba", "name": "Allemagne", "scopes": ["object", "veli"], - "zone": "Europe" + "worldRegion": "Europe" }, { "aquaticPollutionScenario": "Best", @@ -132,7 +132,7 @@ "heatProcessId": "f6ea2983-e024-5de2-b323-273f2436deba", "name": "Espagne", "scopes": ["food"], - "zone": "Europe" + "worldRegion": "Europe" }, { "aquaticPollutionScenario": "Best", @@ -141,7 +141,7 @@ "heatProcessId": "f6ea2983-e024-5de2-b323-273f2436deba", "name": "France", "scopes": ["food", "textile", "object", "veli"], - "zone": "Europe" + "worldRegion": "Europe" }, { "aquaticPollutionScenario": "Worst", @@ -150,7 +150,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Inde", "scopes": ["textile", "object", "veli"], - "zone": "Asia" + "worldRegion": "Asia" }, { "aquaticPollutionScenario": "Best", @@ -159,7 +159,7 @@ "heatProcessId": "f6ea2983-e024-5de2-b323-273f2436deba", "name": "Italie", "scopes": ["food", "object", "veli"], - "zone": "Europe" + "worldRegion": "Europe" }, { "aquaticPollutionScenario": "Average", @@ -168,7 +168,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Kenya", "scopes": ["food"], - "zone": "Africa" + "worldRegion": "Africa" }, { "aquaticPollutionScenario": "Average", @@ -177,7 +177,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Cambodge", "scopes": ["textile", "object"], - "zone": "Asia" + "worldRegion": "Asia" }, { "aquaticPollutionScenario": "Average", @@ -186,7 +186,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Maroc", "scopes": ["food", "textile", "object", "veli"], - "zone": "Africa" + "worldRegion": "Africa" }, { "aquaticPollutionScenario": "Best", @@ -195,7 +195,7 @@ "heatProcessId": "f6ea2983-e024-5de2-b323-273f2436deba", "name": "Pays-bas", "scopes": ["veli"], - "zone": "Europe" + "worldRegion": "Europe" }, { "aquaticPollutionScenario": "Best", @@ -204,7 +204,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Nouvelle-Zélande", "scopes": ["food"], - "zone": "Oceania" + "worldRegion": "Oceania" }, { "aquaticPollutionScenario": "Worst", @@ -213,7 +213,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Pérou", "scopes": ["food"], - "zone": "South_America" + "worldRegion": "South_America" }, { "aquaticPollutionScenario": "Worst", @@ -222,7 +222,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Pakistan", "scopes": ["textile", "object"], - "zone": "Asia" + "worldRegion": "Asia" }, { "aquaticPollutionScenario": "Best", @@ -231,7 +231,7 @@ "heatProcessId": "f6ea2983-e024-5de2-b323-273f2436deba", "name": "Pologne", "scopes": ["object", "veli"], - "zone": "Europe" + "worldRegion": "Europe" }, { "aquaticPollutionScenario": "Best", @@ -240,7 +240,7 @@ "heatProcessId": "f6ea2983-e024-5de2-b323-273f2436deba", "name": "Portugal", "scopes": ["object", "veli"], - "zone": "Europe" + "worldRegion": "Europe" }, { "aquaticPollutionScenario": "Average", @@ -249,7 +249,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Tunisie", "scopes": ["textile", "object", "veli"], - "zone": "Africa" + "worldRegion": "Africa" }, { "aquaticPollutionScenario": "Average", @@ -258,7 +258,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Turquie", "scopes": ["textile", "object", "veli"], - "zone": "Middle_East" + "worldRegion": "Middle_East" }, { "aquaticPollutionScenario": "Best", @@ -267,7 +267,7 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Etats-Unis", "scopes": ["food"], - "zone": "North_America" + "worldRegion": "North_America" }, { "aquaticPollutionScenario": "Average", @@ -276,6 +276,6 @@ "heatProcessId": "3561ace1-f710-50ce-a69c-9cf842e729e4", "name": "Vietnam", "scopes": ["textile", "object", "veli"], - "zone": "Asia" + "worldRegion": "Asia" } ] diff --git a/public/data/textile/examples.json b/public/data/textile/examples.json index 75342ce0c1..29b79514b4 100644 --- a/public/data/textile/examples.json +++ b/public/data/textile/examples.json @@ -5,10 +5,10 @@ "name": "Tshirt lin (150g) - France - Mode \"éthique\"", "query": { "business": "small-business", - "countryDyeing": "FR", - "countryFabric": "FR", - "countryMaking": "FR", - "countrySpinning": "TR", + "geozoneDyeing": "FR", + "geozoneFabric": "FR", + "geozoneMaking": "FR", + "geozoneSpinning": "TR", "mass": 0.15, "materials": [ { @@ -28,10 +28,10 @@ "name": "Tshirt coton bio (150g) - France - Mode \"éthique\"", "query": { "business": "small-business", - "countryDyeing": "FR", - "countryFabric": "FR", - "countryMaking": "FR", - "countrySpinning": "TR", + "geozoneDyeing": "FR", + "geozoneFabric": "FR", + "geozoneMaking": "FR", + "geozoneSpinning": "TR", "mass": 0.15, "materials": [ { @@ -51,10 +51,10 @@ "name": "Pull polyester (550g) - Asie - Mode \"ultra fast fashion\"", "query": { "business": "large-business-without-services", - "countryDyeing": "RAS", - "countryFabric": "RAS", - "countryMaking": "RAS", - "countrySpinning": "RAS", + "geozoneDyeing": "RAS", + "geozoneFabric": "RAS", + "geozoneMaking": "RAS", + "geozoneSpinning": "RAS", "mass": 0.55, "materials": [ { @@ -74,10 +74,10 @@ "name": "Pull coton (550g) - Chine - Mode \"fast fashion\"", "query": { "business": "large-business-without-services", - "countryDyeing": "CN", - "countryFabric": "CN", - "countryMaking": "CN", - "countrySpinning": "CN", + "geozoneDyeing": "CN", + "geozoneFabric": "CN", + "geozoneMaking": "CN", + "geozoneSpinning": "CN", "mass": 0.55, "materials": [ { @@ -97,10 +97,10 @@ "name": "Pull viscose (550g) - Chine - Mode \"fast fashion\"", "query": { "business": "large-business-without-services", - "countryDyeing": "CN", - "countryFabric": "CN", - "countryMaking": "CN", - "countrySpinning": "CN", + "geozoneDyeing": "CN", + "geozoneFabric": "CN", + "geozoneMaking": "CN", + "geozoneSpinning": "CN", "mass": 0.55, "materials": [ { @@ -124,10 +124,10 @@ "name": "Pull coton (550g) - Pakistan - Mode \"traditionnelle\"", "query": { "business": "large-business-without-services", - "countryDyeing": "PK", - "countryFabric": "PK", - "countryMaking": "PK", - "countrySpinning": "PK", + "geozoneDyeing": "PK", + "geozoneFabric": "PK", + "geozoneMaking": "PK", + "geozoneSpinning": "PK", "mass": 0.55, "materials": [ { @@ -147,10 +147,10 @@ "name": "Pull coton bio (550g) - France - Mode \"traditionnelle\"", "query": { "business": "large-business-with-services", - "countryDyeing": "FR", - "countryFabric": "FR", - "countryMaking": "FR", - "countrySpinning": "IN", + "geozoneDyeing": "FR", + "geozoneFabric": "FR", + "geozoneMaking": "FR", + "geozoneSpinning": "IN", "mass": 0.55, "materials": [ { @@ -170,10 +170,10 @@ "name": "Pull laine (550g) - France - Mode \"éthique\"", "query": { "business": "small-business", - "countryDyeing": "FR", - "countryFabric": "FR", - "countryMaking": "FR", - "countrySpinning": "CN", + "geozoneDyeing": "FR", + "geozoneFabric": "FR", + "geozoneMaking": "FR", + "geozoneSpinning": "CN", "mass": 0.55, "materials": [ { @@ -193,14 +193,14 @@ "name": "Pull laine paysanne (550g) - France - Mode \"éthique\"", "query": { "business": "small-business", - "countryDyeing": "FR", - "countryFabric": "FR", - "countryMaking": "FR", - "countrySpinning": "FR", + "geozoneDyeing": "FR", + "geozoneFabric": "FR", + "geozoneMaking": "FR", + "geozoneSpinning": "FR", "mass": 0.55, "materials": [ { - "country": "FR", + "geozone": "FR", "id": "72e29a61-52a9-4eb5-b3fc-5fb87edea041", "share": 1 } @@ -217,10 +217,10 @@ "name": "Tshirt synthétique (150g) - Asie - Mode \"ultra fast fashion\"", "query": { "business": "large-business-without-services", - "countryDyeing": "RAS", - "countryFabric": "RAS", - "countryMaking": "RAS", - "countrySpinning": "RAS", + "geozoneDyeing": "RAS", + "geozoneFabric": "RAS", + "geozoneMaking": "RAS", + "geozoneSpinning": "RAS", "mass": 0.15, "materials": [ { @@ -244,10 +244,10 @@ "name": "Tshirt coton (150g) - Chine - Mode \"fast fashion\"", "query": { "business": "large-business-without-services", - "countryDyeing": "CN", - "countryFabric": "CN", - "countryMaking": "CN", - "countrySpinning": "CN", + "geozoneDyeing": "CN", + "geozoneFabric": "CN", + "geozoneMaking": "CN", + "geozoneSpinning": "CN", "mass": 0.15, "materials": [ { @@ -271,10 +271,10 @@ "name": "Tshirt coton (150g) - Pakistan - Mode \"traditionnelle\"", "query": { "business": "large-business-with-services", - "countryDyeing": "PK", - "countryFabric": "PK", - "countryMaking": "PK", - "countrySpinning": "PK", + "geozoneDyeing": "PK", + "geozoneFabric": "PK", + "geozoneMaking": "PK", + "geozoneSpinning": "PK", "mass": 0.15, "materials": [ { @@ -294,10 +294,10 @@ "name": "Tshirt coton (150g) - France - Mode \"traditionnelle\"", "query": { "business": "large-business-with-services", - "countryDyeing": "FR", - "countryFabric": "FR", - "countryMaking": "FR", - "countrySpinning": "TR", + "geozoneDyeing": "FR", + "geozoneFabric": "FR", + "geozoneMaking": "FR", + "geozoneSpinning": "TR", "mass": 0.15, "materials": [ { @@ -316,7 +316,7 @@ "id": "307b3586-41f4-4d93-833a-e03b5be137cc", "name": "Jupe coton (300g) - Majorant par défaut", "query": { - "countrySpinning": "CN", + "geozoneSpinning": "CN", "mass": 0.3, "materials": [ { @@ -345,7 +345,7 @@ "id": "536e3785-039a-49d6-a119-3cfce485420c", "name": "Chemise coton (250g) - Majorant par défaut", "query": { - "countrySpinning": "CN", + "geozoneSpinning": "CN", "mass": 0.25, "materials": [ { @@ -370,8 +370,8 @@ "id": "bf24fd40-9a2a-4489-935b-d82c339e5abe", "name": "Jean coton (450g) - Majorant par défaut", "query": { - "countrySpinning": "CN", "fading": true, + "geozoneSpinning": "CN", "mass": 0.45, "materials": [ { @@ -400,7 +400,7 @@ "id": "f86835d3-7018-40fa-8144-2d1f6aa264b9", "name": "Pantalon coton (450g) - Majorant par défaut", "query": { - "countrySpinning": "CN", + "geozoneSpinning": "CN", "mass": 0.45, "materials": [ { @@ -429,7 +429,7 @@ "id": "32c8973b-864f-4060-977d-a0738f6414c4", "name": "Manteau coton (950g) - Majorant par défaut", "query": { - "countrySpinning": "CN", + "geozoneSpinning": "CN", "mass": 0.95, "materials": [ { @@ -459,7 +459,7 @@ "name": "Tshirt coton (150g) - Majorant par défaut", "query": { "business": "large-business-without-services", - "countrySpinning": "CN", + "geozoneSpinning": "CN", "mass": 0.15, "materials": [ { @@ -499,7 +499,7 @@ "name": "Pull coton (550g) - Majorant par défaut", "query": { "business": "large-business-without-services", - "countrySpinning": "CN", + "geozoneSpinning": "CN", "mass": 0.55, "materials": [ { @@ -519,7 +519,7 @@ "name": "Chaussettes coton (40g) - Majorant par défaut", "query": { "business": "large-business-without-services", - "countrySpinning": "CN", + "geozoneSpinning": "CN", "mass": 0.04, "materials": [ { @@ -539,7 +539,7 @@ "name": "Caleçon coton (40g) - Majorant par défaut", "query": { "business": "large-business-without-services", - "countrySpinning": "CN", + "geozoneSpinning": "CN", "mass": 0.04, "materials": [ { @@ -559,7 +559,7 @@ "name": "Slip coton (30g) - Majorant par défaut", "query": { "business": "large-business-without-services", - "countrySpinning": "CN", + "geozoneSpinning": "CN", "mass": 0.03, "materials": [ { @@ -579,7 +579,7 @@ "name": "Maillot de bain polyester (100g) - Majorant par défaut", "query": { "business": "large-business-without-services", - "countrySpinning": "CN", + "geozoneSpinning": "CN", "mass": 0.1, "materials": [ { diff --git a/public/data/textile/materials.json b/public/data/textile/materials.json index 005cd3c710..1086e508ba 100644 --- a/public/data/textile/materials.json +++ b/public/data/textile/materials.json @@ -2,7 +2,7 @@ { "alias": "ei-chanvre", "cff": null, - "defaultCountry": "CN", + "defaultGeozone": "CN", "geographicOrigin": "Asie - Pacifique", "id": "0c1a4654-b030-4fe1-86b7-d96ce0b85bb8", "name": "Chanvre", @@ -14,7 +14,7 @@ { "alias": "ei-laine-par-defaut", "cff": null, - "defaultCountry": "CN", + "defaultGeozone": "CN", "geographicOrigin": "Asie - Pacifique", "id": "1fc3e17d-5661-429d-a150-7986eae16d9d", "name": "Laine par défaut", @@ -29,7 +29,7 @@ "manufacturerAllocation": 0.8, "recycledQualityRatio": 0.5 }, - "defaultCountry": "FR", + "defaultGeozone": "FR", "geographicOrigin": "France", "id": "457e9b0d-9eda-4dca-b199-deeb0a154fa9", "name": "Coton recyclé (déchets post-consommation)", @@ -41,7 +41,7 @@ { "alias": "ei-acrylique", "cff": null, - "defaultCountry": "CN", + "defaultGeozone": "CN", "geographicOrigin": "Asie - Pacifique", "id": "49a0bec0-f9f3-42db-a514-a9dcf06a8969", "name": "Acrylique", @@ -53,7 +53,7 @@ { "alias": "ei-coton", "cff": null, - "defaultCountry": "CN", + "defaultGeozone": "CN", "geographicOrigin": "Asie - Pacifique", "id": "62a4d6fb-3276-4ba5-93a3-889ecd3bff84", "name": "Coton", @@ -65,7 +65,7 @@ { "alias": "ei-laine-nouvelle-filiere", "cff": null, - "defaultCountry": "CN", + "defaultGeozone": "CN", "geographicOrigin": "Asie - Pacifique", "id": "72e29a61-52a9-4eb5-b3fc-5fb87edea041", "name": "Laine nouvelle filière", @@ -77,7 +77,7 @@ { "alias": "ei-pp", "cff": null, - "defaultCountry": "FR", + "defaultGeozone": "FR", "geographicOrigin": "Europe", "id": "73ef624d-250e-4a9a-af5d-43505b21b527", "name": "Polypropylène", @@ -92,7 +92,7 @@ "manufacturerAllocation": 0.5, "recycledQualityRatio": 1.0 }, - "defaultCountry": "CN", + "defaultGeozone": "CN", "geographicOrigin": "Asie - Pacifique", "id": "8f44c680-1263-4588-b79b-a9e4dc3d8de4", "name": "Polyester recyclé", @@ -104,7 +104,7 @@ { "alias": "elasthane", "cff": null, - "defaultCountry": "CN", + "defaultGeozone": "CN", "geographicOrigin": "Asie - Pacifique", "id": "9973088b-c929-4cc5-894a-1e4d28c161d4", "name": "Elasthane (Lycra)", @@ -116,7 +116,7 @@ { "alias": "ei-pet", "cff": null, - "defaultCountry": "CN", + "defaultGeozone": "CN", "geographicOrigin": "Asie - Pacifique", "id": "9dba0e95-0c35-4f8b-9267-62ddf47d4984", "name": "Polyester", @@ -128,7 +128,7 @@ { "alias": "ei-jute-kenaf", "cff": null, - "defaultCountry": "CN", + "defaultGeozone": "CN", "geographicOrigin": "Asie - Pacifique", "id": "a09b2677-2900-4417-a202-e5f9a1abcce1", "name": "Jute", @@ -140,7 +140,7 @@ { "alias": "ei-coton-organic", "cff": null, - "defaultCountry": "CN", + "defaultGeozone": "CN", "geographicOrigin": "Asie - Pacifique", "id": "a1c1c2ec-33b1-49d6-bf8e-139e2eb7f097", "name": "Coton biologique", @@ -152,7 +152,7 @@ { "alias": "ei-lin", "cff": null, - "defaultCountry": "FR", + "defaultGeozone": "FR", "geographicOrigin": "Europe", "id": "a52e486c-b67e-40af-8337-e8143cbf9076", "name": "Lin", @@ -164,7 +164,7 @@ { "alias": "ei-viscose", "cff": null, - "defaultCountry": "CN", + "defaultGeozone": "CN", "geographicOrigin": "Asie - Pacifique", "id": "c087d394-5901-4b03-ba7a-7d4b0db0490c", "name": "Viscose", @@ -176,7 +176,7 @@ { "alias": "ei-pa", "cff": null, - "defaultCountry": "FR", + "defaultGeozone": "FR", "geographicOrigin": "Europe", "id": "c84280ff-e921-4d5c-92d6-51030bf4f74e", "name": "Nylon", @@ -191,7 +191,7 @@ "manufacturerAllocation": 0.8, "recycledQualityRatio": 0.5 }, - "defaultCountry": "FR", + "defaultGeozone": "FR", "geographicOrigin": "Espagne & France", "id": "d3d20384-88fb-4c75-ac12-c647365ac6c5", "name": "Coton recyclé (déchets de production)", diff --git a/server.js b/server.js index 3f7019976e..a7adc33bb2 100644 --- a/server.js +++ b/server.js @@ -237,7 +237,7 @@ api.get("/", async (req, res) => { }); // Redirects: API -api.get(/^\/countries$/, (_, res) => res.redirect("textile/countries")); +api.get(/^\/geozones$/, (_, res) => res.redirect("textile/geozones")); api.get(/^\/materials$/, (_, res) => res.redirect("textile/materials")); api.get(/^\/products$/, (_, res) => res.redirect("textile/products")); const cleanRedirect = (url) => (url.startsWith("/") ? url : ""); diff --git a/src/Data/Common/Db.elm b/src/Data/Common/Db.elm index 3693745371..a9898cb26e 100644 --- a/src/Data/Common/Db.elm +++ b/src/Data/Common/Db.elm @@ -1,10 +1,10 @@ module Data.Common.Db exposing - ( countriesFromJson + ( geozonesFromJson , impactsFromJson , transportsFromJson ) -import Data.Country as Country exposing (Country) +import Data.Geozone as Geozone exposing (Geozone) import Data.Impact.Definition as Definition exposing (Definitions) import Data.Process exposing (Process) import Data.Transport as Transport exposing (Distances) @@ -17,9 +17,9 @@ impactsFromJson = >> Result.mapError Decode.errorToString -countriesFromJson : List Process -> String -> Result String (List Country) -countriesFromJson processes = - Decode.decodeString (Country.decodeList processes) +geozonesFromJson : List Process -> String -> Result String (List Geozone) +geozonesFromJson processes = + Decode.decodeString (Geozone.decodeList processes) >> Result.mapError Decode.errorToString diff --git a/src/Data/Component.elm b/src/Data/Component.elm index d3e32ddafd..21ecc0d3d1 100644 --- a/src/Data/Component.elm +++ b/src/Data/Component.elm @@ -79,7 +79,7 @@ module Data.Component exposing import Data.Common.DecodeUtils as DU import Data.Common.EncodeUtils as EU import Data.Component.Config as Config exposing (EndOfLifeStrategies, EndOfLifeStrategy) -import Data.Country as Country exposing (Country) +import Data.Geozone as Geozone exposing (Geozone) import Data.Impact as Impact exposing (Impacts) import Data.Impact.Definition exposing (Trigram) import Data.Process as Process exposing (Process) @@ -131,8 +131,8 @@ type alias EnergyMixes = and optional overrides, typically used for queries -} type alias Item = - { country : Maybe Country.Code - , custom : Maybe Custom + { custom : Maybe Custom + , geozone : Maybe Geozone.Code , id : Id , quantity : Quantity } @@ -140,8 +140,8 @@ type alias Item = type alias ExpandedItem = { component : Component - , country : Maybe Country , elements : List ExpandedElement + , geozone : Maybe Geozone , quantity : Quantity } @@ -158,7 +158,7 @@ type alias Custom = type alias DataContainer db = { db | components : List Component - , countries : List Country + , geozones : List Geozone , processes : List Process } @@ -176,7 +176,7 @@ type alias Element = -} type alias ExpandedElement = { amount : Amount - , country : Maybe Country + , geozone : Maybe Geozone , material : Process , transforms : List Process } @@ -388,13 +388,13 @@ applyTransform { elec, heat } transform (Results { amount, label, impacts, items {-| Sequencially apply transforms to existing Results (typically, material ones). Note: for now we use average elec and heat mixes, but we might want to allow -specifying specific country mixes in the future. +specifying specific geographical zones mixes in the future. -} -applyTransforms : List Process -> Maybe Country -> Process.Unit -> List Process -> Results -> Result String Results -applyTransforms processes maybeCountry unit transforms materialResults = +applyTransforms : List Process -> Maybe Geozone -> Process.Unit -> List Process -> Results -> Result String Results +applyTransforms processes maybeGeozone unit transforms materialResults = checkTransformsUnit unit transforms - |> Result.andThen (\_ -> loadEnergyMixes processes maybeCountry) + |> Result.andThen (\_ -> loadEnergyMixes processes maybeGeozone) |> Result.map (\energyMixes -> transforms @@ -436,18 +436,18 @@ compute requirements items = |> Result.map (computeEndOfLifeResults requirements) -computeElementResults : DataContainer db -> Maybe Country.Code -> Element -> Result String Results -computeElementResults db maybeCountry = - expandElement db maybeCountry +computeElementResults : DataContainer db -> Maybe Geozone.Code -> Element -> Result String Results +computeElementResults db maybeGeozone = + expandElement db maybeGeozone >> Result.andThen - (\{ amount, country, material, transforms } -> + (\{ amount, geozone, material, transforms } -> amount |> computeInitialAmount (List.map .waste transforms) |> Result.andThen (\initialAmount -> material |> computeMaterialResults initialAmount - |> applyTransforms db.processes country material.unit transforms + |> applyTransforms db.processes geozone material.unit transforms ) ) @@ -489,7 +489,7 @@ computeImpacts db = computeItemResults : DataContainer db -> Item -> Result String Results -computeItemResults db { country, custom, id, quantity } = +computeItemResults db { custom, geozone, id, quantity } = let component_ = findById id db.components @@ -499,7 +499,7 @@ computeItemResults db { country, custom, id, quantity } = (\component -> custom |> customElements component - |> List.map (computeElementResults db country) + |> List.map (computeElementResults db geozone) |> RE.combine ) |> Result.map (List.foldr addResults emptyResults) @@ -596,8 +596,8 @@ computeShareImpacts mass { process, split } = createItem : Id -> Item createItem id = - { country = Nothing - , custom = Nothing + { custom = Nothing + , geozone = Nothing , id = id , quantity = quantityFromInt 1 } @@ -648,8 +648,8 @@ decodeElement = decodeItem : Decoder Item decodeItem = Decode.succeed Item - |> DU.strictOptional "country" Country.decodeCode |> DU.strictOptional "custom" decodeCustom + |> DU.strictOptional "geozone" Geozone.decodeCode |> Decode.required "id" (Decode.map Id Uuid.decoder) |> Decode.required "quantity" decodeQuantity @@ -784,7 +784,7 @@ encodeItem item = EU.optionalPropertiesObject [ ( "id", item.id |> idToString |> Encode.string |> Just ) , ( "quantity", item.quantity |> quantityToInt |> Encode.int |> Just ) - , ( "country", item.country |> Maybe.map Country.encodeCode ) + , ( "geozone", item.geozone |> Maybe.map Geozone.encodeCode ) , ( "custom", item.custom |> Maybe.map encodeCustom ) ] @@ -838,10 +838,10 @@ encodeResults maybeTrigram (Results results) = {-| Turn an Element to an ExpandedElement -} -expandElement : DataContainer db -> Maybe Country.Code -> Element -> Result String ExpandedElement -expandElement { countries, processes } maybeCountry { amount, material, transforms } = +expandElement : DataContainer db -> Maybe Geozone.Code -> Element -> Result String ExpandedElement +expandElement { geozones, processes } maybeGeozone { amount, material, transforms } = Ok (ExpandedElement amount) - |> RE.andMap (resolveCountry countries maybeCountry) + |> RE.andMap (resolveGeozone geozones maybeGeozone) |> RE.andMap (Process.findById material processes) |> RE.andMap (transforms @@ -852,28 +852,28 @@ expandElement { countries, processes } maybeCountry { amount, material, transfor {-| Take a list of elements and resolve them with fully qualified processes -} -expandElements : DataContainer db -> Maybe Country.Code -> List Element -> Result String (List ExpandedElement) -expandElements db maybeCountry = - RE.combineMap (expandElement db maybeCountry) +expandElements : DataContainer db -> Maybe Geozone.Code -> List Element -> Result String (List ExpandedElement) +expandElements db maybeGeozone = + RE.combineMap (expandElement db maybeGeozone) expandItem : DataContainer a -> Item -> Result String ExpandedItem -expandItem ({ components, countries } as db) { country, custom, id, quantity } = +expandItem ({ components, geozones } as db) { custom, geozone, id, quantity } = findById id components |> Result.andThen (\component -> - country - |> resolveCountry countries + geozone + |> resolveGeozone geozones |> Result.andThen - (\maybeCountry -> + (\maybeGeozone -> custom |> customElements component - |> expandElements db country + |> expandElements db geozone |> Result.map (\expandedElements -> { component = component - , country = maybeCountry , elements = expandedElements + , geozone = maybeGeozone , quantity = quantity } ) @@ -881,11 +881,11 @@ expandItem ({ components, countries } as db) { country, custom, id, quantity } = ) -resolveCountry : List Country -> Maybe Country.Code -> Result String (Maybe Country) -resolveCountry countries maybeCode = +resolveGeozone : List Geozone -> Maybe Geozone.Code -> Result String (Maybe Geozone) +resolveGeozone geozones maybeCode = case maybeCode of Just code -> - countries |> Country.findByCode code |> Result.map Just + geozones |> Geozone.findByCode code |> Result.map Just Nothing -> Ok Nothing @@ -1126,7 +1126,7 @@ loadDefaultEnergyMixes processes = (fromIdString "3561ace1-f710-50ce-a69c-9cf842e729e4") -loadEnergyMixes : List Process -> Maybe Country -> Result String EnergyMixes +loadEnergyMixes : List Process -> Maybe Geozone -> Result String EnergyMixes loadEnergyMixes processes = Maybe.map (\{ electricityProcess, heatProcess } -> Ok <| EnergyMixes electricityProcess heatProcess) >> Maybe.withDefault (loadDefaultEnergyMixes processes) diff --git a/src/Data/Dataset.elm b/src/Data/Dataset.elm index 73fb7cc098..1ea0a5196a 100644 --- a/src/Data/Dataset.elm +++ b/src/Data/Dataset.elm @@ -12,8 +12,8 @@ module Data.Dataset exposing ) import Data.Component as Component -import Data.Country as Country import Data.Food.Ingredient as Ingredient +import Data.Geozone as Geozone import Data.Impact.Definition as Definition import Data.Process as Process import Data.Scope as Scope exposing (Scope) @@ -30,9 +30,9 @@ It's used by Page.Explore and related routes. -} type Dataset = Components Scope (Maybe Component.Id) - | Countries (Maybe Country.Code) | FoodExamples (Maybe Uuid) | FoodIngredients (Maybe Ingredient.Id) + | Geozones (Maybe Geozone.Code) | Impacts (Maybe Definition.Trigram) | ObjectExamples (Maybe Uuid) | Processes Scope (Maybe Process.Id) @@ -49,7 +49,7 @@ datasets scope = [ FoodExamples Nothing , Impacts Nothing , FoodIngredients Nothing - , Countries Nothing + , Geozones Nothing , Processes Scope.Food Nothing ] @@ -65,7 +65,7 @@ datasets scope = , Components Scope.Textile Nothing , Impacts Nothing , TextileMaterials Nothing - , Countries Nothing + , Geozones Nothing , Processes Scope.Textile Nothing , TextileProducts Nothing ] @@ -97,8 +97,8 @@ defaultDatasetFor scope = fromSlug : String -> Dataset fromSlug string = case string of - "countries" -> - Countries Nothing + "geozones" -> + Geozones Nothing "food-examples" -> FoodExamples Nothing @@ -155,15 +155,15 @@ isDetailed dataset = Components _ (Just _) -> True - Countries (Just _) -> - True - FoodExamples (Just _) -> True FoodIngredients (Just _) -> True + Geozones (Just _) -> + True + Impacts (Just _) -> True @@ -205,15 +205,15 @@ reset dataset = Components scope _ -> Components scope Nothing - Countries _ -> - Countries Nothing - FoodExamples _ -> FoodExamples Nothing FoodIngredients _ -> FoodIngredients Nothing + Geozones _ -> + Geozones Nothing + Impacts _ -> Impacts Nothing @@ -239,7 +239,7 @@ reset dataset = same : Dataset -> Dataset -> Bool same a b = case ( a, b ) of - ( Countries _, Countries _ ) -> + ( Geozones _, Geozones _ ) -> True ( FoodExamples _, FoodExamples _ ) -> @@ -282,15 +282,15 @@ setIdFromString idString dataset = Components scope _ -> Components scope (Component.idFromString idString |> Result.toMaybe) - Countries _ -> - Countries (Just (Country.codeFromString idString)) - FoodExamples _ -> FoodExamples (idString |> Uuid.fromString |> Result.toMaybe) FoodIngredients _ -> FoodIngredients (idString |> Ingredient.idFromString |> Result.toMaybe) + Geozones _ -> + Geozones (Just (Geozone.codeFromString idString)) + Impacts _ -> Impacts (Definition.toTrigram idString |> Result.toMaybe) @@ -324,15 +324,15 @@ strings dataset = Components scope _ -> { label = "Composants", slug = Scope.toString scope ++ "-components" } - Countries _ -> - { label = "Pays", slug = "countries" } - FoodExamples _ -> { label = "Exemples", slug = "food-examples" } FoodIngredients _ -> { label = "Ingrédients", slug = "ingredients" } + Geozones _ -> + { label = "Zone", slug = "geozones" } + Impacts _ -> { label = "Impacts", slug = "impacts" } @@ -364,12 +364,6 @@ toRoutePath dataset = Components _ Nothing -> [ slug dataset ] - Countries (Just code) -> - [ slug dataset, Country.codeToString code ] - - Countries Nothing -> - [ slug dataset ] - FoodExamples (Just id) -> [ slug dataset, Uuid.toString id ] @@ -382,6 +376,12 @@ toRoutePath dataset = FoodIngredients Nothing -> [ slug dataset ] + Geozones (Just code) -> + [ slug dataset, Geozone.codeToString code ] + + Geozones Nothing -> + [ slug dataset ] + Impacts (Just trigram) -> [ slug dataset, Definition.toString trigram ] diff --git a/src/Data/Food/Query.elm b/src/Data/Food/Query.elm index fb7fa8940f..adb929a7c8 100644 --- a/src/Data/Food/Query.elm +++ b/src/Data/Food/Query.elm @@ -26,10 +26,10 @@ module Data.Food.Query exposing import Base64 import Data.Common.DecodeUtils as DU import Data.Common.EncodeUtils as EU -import Data.Country as Country import Data.Food.Ingredient as Ingredient import Data.Food.Preparation as Preparation import Data.Food.Retail as Retail +import Data.Geozone as Geozone import Data.Process as Process import Json.Decode as Decode exposing (Decoder) import Json.Decode.Pipeline as Pipe @@ -40,7 +40,7 @@ import Url.Parser as Parser exposing (Parser) type alias IngredientQuery = - { country : Maybe Country.Code + { geozone : Maybe Geozone.Code , id : Ingredient.Id , mass : Mass , planeTransport : Ingredient.PlaneTransport @@ -144,7 +144,7 @@ decodeProcess = decodeIngredient : Decoder IngredientQuery decodeIngredient = Decode.succeed IngredientQuery - |> DU.strictOptional "country" Country.decodeCode + |> DU.strictOptional "geozone" Geozone.decodeCode |> Pipe.required "id" Ingredient.decodeId |> Pipe.required "mass" decodeMassInGrams |> DU.strictOptionalWithDefault "byPlane" decodePlaneTransport Ingredient.PlaneNotApplicable @@ -212,7 +212,7 @@ encodeIngredient v = EU.optionalPropertiesObject [ ( "id", Ingredient.encodeId v.id |> Just ) , ( "mass", encodeMassAsGrams v.mass |> Just ) - , ( "country", v.country |> Maybe.map Country.encodeCode ) + , ( "geozone", v.geozone |> Maybe.map Geozone.encodeCode ) , ( "byPlane", v.planeTransport |> Ingredient.encodePlaneTransport ) ] diff --git a/src/Data/Food/Recipe.elm b/src/Data/Food/Recipe.elm index 9bb4210a67..f2112c8984 100644 --- a/src/Data/Food/Recipe.elm +++ b/src/Data/Food/Recipe.elm @@ -23,7 +23,6 @@ module Data.Food.Recipe exposing , toString ) -import Data.Country as Country exposing (Country) import Data.Food.EcosystemicServices as EcosystemicServices exposing (EcosystemicServices) import Data.Food.Ingredient as Ingredient exposing (Ingredient) import Data.Food.Origin as Origin @@ -31,6 +30,7 @@ import Data.Food.Preparation as Preparation exposing (Preparation) import Data.Food.Query as BuilderQuery exposing (Query) import Data.Food.Retail as Retail import Data.Food.WellKnown exposing (WellKnown) +import Data.Geozone as Geozone exposing (Geozone) import Data.Impact as Impact exposing (Impacts) import Data.Impact.Definition as Definition import Data.Process as Process exposing (Process) @@ -51,9 +51,9 @@ import String.Extra as SE import Volume exposing (Volume) -france : Country.Code +france : Geozone.Code france = - Country.codeFromString "FR" + Geozone.codeFromString "FR" type alias Packaging = @@ -63,7 +63,7 @@ type alias Packaging = type alias RecipeIngredient = - { country : Maybe Country + { geozone : Maybe Geozone , ingredient : Ingredient , mass : Mass , planeTransport : Ingredient.PlaneTransport @@ -320,7 +320,7 @@ computeIngredientsTotalComplements = computeIngredientTransport : Db -> RecipeIngredient -> Transport -computeIngredientTransport db { country, ingredient, mass, planeTransport } = +computeIngredientTransport db { geozone, ingredient, mass, planeTransport } = let emptyImpacts = Impact.empty @@ -337,8 +337,8 @@ computeIngredientTransport db { country, ingredient, mass, planeTransport } = baseTransport = let base = - case country of - -- In case a custom country is provided, compute the distances to it from France + case geozone of + -- In case a custom geographical zone is provided, compute the distances to it from France Just { code } -> db.distances |> Transport.getTransportBetween emptyImpacts code france @@ -371,9 +371,9 @@ computeIngredientTransport db { country, ingredient, mass, planeTransport } = -- 500km of road transport are added for every ingredient that are not coming from France. -- This corresponds to the step "2. RECETTE" in the -- [transport documentation](https://fabrique-numerique.gitbook.io/ecobalyse/alimentaire/transport#circuits-consideres) - case country of + case geozone of Just { code } -> - if code /= Country.codeFromString "FR" then + if code /= Geozone.codeFromString "FR" then Transport.addRoadWithCooling (Length.kilometers 500) (ingredient.transportCooling == Ingredient.AlwaysCool) t else @@ -556,16 +556,16 @@ ingredientListFromQuery db = ingredientFromQuery : Db -> BuilderQuery.IngredientQuery -> Result String RecipeIngredient -ingredientFromQuery db { country, id, mass, planeTransport } = +ingredientFromQuery db { geozone, id, mass, planeTransport } = let ingredientResult = Ingredient.findById id db.food.ingredients in Ok RecipeIngredient |> RE.andMap - (case Maybe.map (\c -> Country.findByCode c db.countries) country of - Just (Ok country_) -> - Ok (Just country_) + (case Maybe.map (\c -> Geozone.findByCode c db.geozones) geozone of + Just (Ok geozone_) -> + Ok (Just geozone_) Just (Err error) -> Err error @@ -583,7 +583,7 @@ ingredientFromQuery db { country, id, mass, planeTransport } = ingredientQueryFromIngredient : Ingredient -> BuilderQuery.IngredientQuery ingredientQueryFromIngredient ingredient = - { country = Nothing + { geozone = Nothing , id = ingredient.id , mass = Mass.grams 100 , planeTransport = Ingredient.byPlaneByDefault ingredient diff --git a/src/Data/Food/Validation.elm b/src/Data/Food/Validation.elm index a24e95c8f0..244557f634 100644 --- a/src/Data/Food/Validation.elm +++ b/src/Data/Food/Validation.elm @@ -1,9 +1,9 @@ module Data.Food.Validation exposing (validate) -import Data.Country as Country import Data.Food.Ingredient as Ingredient import Data.Food.Preparation as Preparation import Data.Food.Query exposing (IngredientQuery, ProcessQuery, Query) +import Data.Geozone as Geozone import Data.Process as Process import Data.Scope as Scope import Data.Validation as Validation @@ -28,8 +28,8 @@ validateIngredient : Db -> IngredientQuery -> Result String IngredientQuery validateIngredient db ingredientQuery = Ok IngredientQuery |> RE.andMap - (ingredientQuery.country - |> validateMaybe (Country.validateForScope Scope.Food db.countries) + (ingredientQuery.geozone + |> validateMaybe (Geozone.validateForScope Scope.Food db.geozones) ) |> RE.andMap (db.food.ingredients diff --git a/src/Data/Country.elm b/src/Data/Geozone.elm similarity index 79% rename from src/Data/Country.elm rename to src/Data/Geozone.elm index 530d4c1f2c..46fbd6b463 100644 --- a/src/Data/Country.elm +++ b/src/Data/Geozone.elm @@ -1,7 +1,7 @@ -module Data.Country exposing +module Data.Geozone exposing ( AquaticPollutionScenario(..) , Code(..) - , Country + , Geozone , codeFromString , codeToString , decodeCode @@ -11,14 +11,14 @@ module Data.Country exposing , findByCode , getAquaticPollutionRatio , isEuropeOrTurkey - , unknownCountryCode + , unknownGeozoneCode , validateForScope ) import Data.Process as Process exposing (Process) import Data.Scope as Scope exposing (Scope) import Data.Split as Split exposing (Split) -import Data.Zone as Zone exposing (Zone) +import Data.WorldRegion as WorldRegion exposing (WorldRegion) import Json.Decode as Decode exposing (Decoder) import Json.Decode.Extra as DE import Json.Decode.Pipeline as Pipe @@ -35,14 +35,14 @@ type AquaticPollutionScenario | Worst -type alias Country = +type alias Geozone = { aquaticPollutionScenario : AquaticPollutionScenario , code : Code , electricityProcess : Process , heatProcess : Process , name : String , scopes : List Scope - , zone : Zone + , worldRegion : WorldRegion } @@ -56,23 +56,23 @@ codeToString (Code string) = string -findByCode : Code -> List Country -> Result String Country +findByCode : Code -> List Geozone -> Result String Geozone findByCode code = List.filter (.code >> (==) code) >> List.head - >> Result.fromMaybe ("Code pays invalide: " ++ codeToString code ++ ".") + >> Result.fromMaybe ("Code de zone géographique invalide: " ++ codeToString code ++ ".") -decode : List Process -> Decoder Country +decode : List Process -> Decoder Geozone decode processes = - Decode.succeed Country + Decode.succeed Geozone |> Pipe.required "aquaticPollutionScenario" decodeAquaticPollutionScenario |> Pipe.required "code" decodeCode |> Pipe.required "electricityProcessId" (Process.decodeFromId processes) |> Pipe.required "heatProcessId" (Process.decodeFromId processes) |> Pipe.required "name" Decode.string |> Pipe.optional "scopes" (Decode.list Scope.decode) [ Scope.Food, Scope.Textile ] - |> Pipe.required "zone" Zone.decode + |> Pipe.required "worldRegion" WorldRegion.decode decodeCode : Decoder Code @@ -80,12 +80,12 @@ decodeCode = Decode.map Code Decode.string -decodeList : List Process -> Decoder (List Country) +decodeList : List Process -> Decoder (List Geozone) decodeList processes = Decode.list (decode processes) -encode : Country -> Encode.Value +encode : Geozone -> Encode.Value encode v = Encode.object [ ( "aquaticPollutionScenario", v.aquaticPollutionScenario |> aquaticPollutionScenarioToString |> Encode.string ) @@ -152,28 +152,28 @@ getAquaticPollutionRatio scenario = Split.fromPercent 37 -isEuropeOrTurkey : Country -> Bool -isEuropeOrTurkey country = - country.zone == Zone.Europe || country.code == codeFromString "TR" +isEuropeOrTurkey : Geozone -> Bool +isEuropeOrTurkey geozone = + geozone.worldRegion == WorldRegion.Europe || geozone.code == codeFromString "TR" -unknownCountryCode : Code -unknownCountryCode = +unknownGeozoneCode : Code +unknownGeozoneCode = Code "---" -validateForScope : Scope -> List Country -> Code -> Result String Code -validateForScope scope countries countryCode = - countries - |> findByCode countryCode +validateForScope : Scope -> List Geozone -> Code -> Result String Code +validateForScope scope geozones geozoneCode = + geozones + |> findByCode geozoneCode |> Result.andThen (\{ code, scopes } -> if List.member scope scopes then Ok code else - "Le code pays " - ++ codeToString countryCode + "Le code de zone géographique " + ++ codeToString geozoneCode ++ " n'est pas utilisable dans un contexte " ++ Scope.toLabel scope ++ "." diff --git a/src/Data/Textile/Formula.elm b/src/Data/Textile/Formula.elm index 304a60bfd4..234b532bcc 100644 --- a/src/Data/Textile/Formula.elm +++ b/src/Data/Textile/Formula.elm @@ -20,7 +20,7 @@ module Data.Textile.Formula exposing ) import Area exposing (Area) -import Data.Country as Country +import Data.Geozone as Geozone import Data.Impact as Impact exposing (Impacts) import Data.Process as Process exposing (Process) import Data.Split as Split exposing (Split) @@ -122,15 +122,15 @@ recycledMaterialImpacts impacts { cffData, nonRecycledProcess, recycledProcess } spinningImpacts : Impacts - -> { countryElecProcess : Process, spinningKwh : Energy } + -> { geozoneElecProcess : Process, spinningKwh : Energy } -> StepValues -spinningImpacts impacts { countryElecProcess, spinningKwh } = +spinningImpacts impacts { geozoneElecProcess, spinningKwh } = { heat = Quantity.zero , impacts = impacts |> Impact.mapImpacts (\trigram _ -> - spinningKwh |> Unit.forKWh (Process.getImpact trigram countryElecProcess) + spinningKwh |> Unit.forKWh (Process.getImpact trigram geozoneElecProcess) ) , kwh = spinningKwh } @@ -139,8 +139,8 @@ spinningImpacts impacts { countryElecProcess, spinningKwh } = dyeingImpacts : Impacts -> Process -- Inbound: Dyeing process - -> Process -- Outbound: country heat impact - -> Process -- Outbound: country electricity impact + -> Process -- Outbound: geozone heat impact + -> Process -- Outbound: geozone electricity impact -> Mass -> StepValues dyeingImpacts impacts dyeingProcess heatProcess elecProcess baseMass = @@ -173,8 +173,8 @@ dyeingImpacts impacts dyeingProcess heatProcess elecProcess baseMass = printingImpacts : Impacts -> - { elecProcess : Process -- Outbound: country electricity impact - , heatProcess : Process -- Outbound: country heat impact + { elecProcess : Process -- Outbound: geozone electricity impact + , heatProcess : Process -- Outbound: geozone heat impact , printingProcess : Process -- Inbound: Printing process , ratio : Split , surfaceMass : Unit.SurfaceMass @@ -215,9 +215,9 @@ printingImpacts impacts { elecProcess, heatProcess, printingProcess, ratio, surf finishingImpacts : Impacts -> - { elecProcess : Process -- Outbound: country electricity impact + { elecProcess : Process -- Outbound: geozone electricity impact , finishingProcess : Process -- Inbound: Printing process - , heatProcess : Process -- Outbound: country heat impact + , heatProcess : Process -- Outbound: geozone heat impact } -> Mass -> StepValues @@ -246,7 +246,7 @@ finishingImpacts impacts { elecProcess, finishingProcess, heatProcess } baseMass materialDyeingToxicityImpacts : Impacts -> - { aquaticPollutionScenario : Country.AquaticPollutionScenario + { aquaticPollutionScenario : Geozone.AquaticPollutionScenario , dyeingToxicityProcess : Process -- Inbound: dyeing process } -> Mass @@ -260,7 +260,7 @@ materialDyeingToxicityImpacts impacts { aquaticPollutionScenario, dyeingToxicity |> Unit.forKg (Process.getImpact trigram dyeingToxicityProcess) |> Quantity.multiplyBy (aquaticPollutionScenario - |> Country.getAquaticPollutionRatio + |> Geozone.getAquaticPollutionRatio |> Split.toFloat ) |> (\impact -> Split.applyToQuantity impact split) @@ -270,7 +270,7 @@ materialDyeingToxicityImpacts impacts { aquaticPollutionScenario, dyeingToxicity materialPrintingToxicityImpacts : Impacts -> - { aquaticPollutionScenario : Country.AquaticPollutionScenario + { aquaticPollutionScenario : Geozone.AquaticPollutionScenario , printingToxicityProcess : Process -- Inbound: printing process , surfaceMass : Unit.SurfaceMass } @@ -286,7 +286,7 @@ materialPrintingToxicityImpacts impacts { aquaticPollutionScenario, printingToxi |> Unit.forSquareMeter (Process.getImpact trigram printingToxicityProcess) |> Quantity.multiplyBy (aquaticPollutionScenario - |> Country.getAquaticPollutionRatio + |> Geozone.getAquaticPollutionRatio |> Split.toFloat ) |> (\impact -> Split.applyToQuantity impact split) @@ -296,14 +296,14 @@ materialPrintingToxicityImpacts impacts { aquaticPollutionScenario, printingToxi makingImpacts : Impacts -> - { countryElecProcess : Process - , countryHeatProcess : Process - , fadingProcess : Maybe Process + { fadingProcess : Maybe Process + , geozoneElecProcess : Process + , geozoneHeatProcess : Process , makingComplexity : MakingComplexity } -> Mass -> StepValues -makingImpacts impacts { countryElecProcess, countryHeatProcess, fadingProcess, makingComplexity } outputMass = +makingImpacts impacts { fadingProcess, geozoneElecProcess, geozoneHeatProcess, makingComplexity } outputMass = -- Note: Fading, when enabled, is applied at the Making step because -- it can only be applied on finished products (using step output mass). -- Also: @@ -336,7 +336,7 @@ makingImpacts impacts { countryElecProcess, countryHeatProcess, fadingProcess, m Quantity.sum [ -- Making process (per-item) elec - |> Unit.forKWh (Process.getImpact trigram countryElecProcess) + |> Unit.forKWh (Process.getImpact trigram geozoneElecProcess) -- Fading process (mass-dependent) , outputMass @@ -346,9 +346,9 @@ makingImpacts impacts { countryElecProcess, countryHeatProcess, fadingProcess, m |> Maybe.withDefault Quantity.zero ) , fadingElec - |> Unit.forKWh (Process.getImpact trigram countryElecProcess) + |> Unit.forKWh (Process.getImpact trigram geozoneElecProcess) , fadingHeat - |> Unit.forMJ (Process.getImpact trigram countryHeatProcess) + |> Unit.forMJ (Process.getImpact trigram geozoneHeatProcess) ] ) , kwh = Quantity.sum [ elec, fadingElec ] @@ -357,7 +357,7 @@ makingImpacts impacts { countryElecProcess, countryHeatProcess, fadingProcess, m knittingImpacts : Impacts - -> { countryElecProcess : Process, elec : Energy } + -> { elec : Energy, geozoneElecProcess : Process } -> Mass -> { impacts : Impacts @@ -365,7 +365,7 @@ knittingImpacts : , picking : Maybe Unit.PickPerMeter , threadDensity : Maybe Unit.ThreadDensity } -knittingImpacts impacts { countryElecProcess, elec } baseMass = +knittingImpacts impacts { elec, geozoneElecProcess } baseMass = let electricityKWh = Energy.kilowattHours @@ -377,7 +377,7 @@ knittingImpacts impacts { countryElecProcess, elec } baseMass = |> Impact.mapImpacts (\trigram _ -> electricityKWh - |> Unit.forKWh (Process.getImpact trigram countryElecProcess) + |> Unit.forKWh (Process.getImpact trigram geozoneElecProcess) ) , kwh = electricityKWh , picking = Nothing @@ -388,7 +388,7 @@ knittingImpacts impacts { countryElecProcess, elec } baseMass = weavingImpacts : Impacts -> - { countryElecProcess : Process + { geozoneElecProcess : Process , outputMass : Mass , pickingElec : Float , surfaceMass : Unit.SurfaceMass @@ -400,7 +400,7 @@ weavingImpacts : , picking : Maybe Unit.PickPerMeter , threadDensity : Maybe Unit.ThreadDensity } -weavingImpacts impacts { countryElecProcess, outputMass, pickingElec, surfaceMass, yarnSize } = +weavingImpacts impacts { geozoneElecProcess, outputMass, pickingElec, surfaceMass, yarnSize } = -- Methodology: https://fabrique-numerique.gitbook.io/ecobalyse/textile/etapes-du-cycle-de-vie/tricotage-tissage let outputSurface = @@ -423,7 +423,7 @@ weavingImpacts impacts { countryElecProcess, outputMass, pickingElec, surfaceMas |> Impact.mapImpacts (\trigram _ -> electricityKWh - |> Unit.forKWh (Process.getImpact trigram countryElecProcess) + |> Unit.forKWh (Process.getImpact trigram geozoneElecProcess) ) , kwh = electricityKWh , picking = Just picking @@ -463,14 +463,14 @@ computePicking threadDensity outputSurface = useImpacts : Impacts -> - { countryElecProcess : Process + { geozoneElecProcess : Process , ironingElec : Energy , nonIroningProcess : Process , useNbCycles : Int } -> Mass -> StepValues -useImpacts impacts { countryElecProcess, ironingElec, nonIroningProcess, useNbCycles } baseMass = +useImpacts impacts { geozoneElecProcess, ironingElec, nonIroningProcess, useNbCycles } baseMass = let totalEnergy = -- Note: Ironing is expressed per-item, non-ironing is mass-depdendent @@ -488,7 +488,7 @@ useImpacts impacts { countryElecProcess, ironingElec, nonIroningProcess, useNbCy (\trigram _ -> Quantity.sum [ totalEnergy - |> Unit.forKWh (Process.getImpact trigram countryElecProcess) + |> Unit.forKWh (Process.getImpact trigram geozoneElecProcess) , baseMass |> Unit.forKg (Process.getImpact trigram nonIroningProcess) |> Quantity.multiplyBy (toFloat useNbCycles) @@ -501,15 +501,15 @@ useImpacts impacts { countryElecProcess, ironingElec, nonIroningProcess, useNbCy endOfLifeImpacts : Impacts -> - { countryElecProcess : Process - , endOfLife : Process + { endOfLife : Process + , geozoneElecProcess : Process , heatProcess : Process , passengerCar : Process , volume : Volume } -> Mass -> StepValues -endOfLifeImpacts impacts { countryElecProcess, endOfLife, heatProcess, passengerCar, volume } baseMass = +endOfLifeImpacts impacts { endOfLife, geozoneElecProcess, heatProcess, passengerCar, volume } baseMass = -- Notes: -- - passengerCar is expressed per-item -- - endOfLife is mass-dependent @@ -544,7 +544,7 @@ endOfLifeImpacts impacts { countryElecProcess, endOfLife, heatProcess, passenger [ Process.getImpact trigram passengerCar |> Quantity.multiplyBy carTrunkAllocationRatio , elecEnergy - |> Unit.forKWh (Process.getImpact trigram countryElecProcess) + |> Unit.forKWh (Process.getImpact trigram geozoneElecProcess) , heatEnergy |> Unit.forMJ (Process.getImpact trigram heatProcess) , baseMass diff --git a/src/Data/Textile/Inputs.elm b/src/Data/Textile/Inputs.elm index 538468881c..655b4844e9 100644 --- a/src/Data/Textile/Inputs.elm +++ b/src/Data/Textile/Inputs.elm @@ -2,9 +2,9 @@ module Data.Textile.Inputs exposing ( Inputs , MaterialInput , computeMaterialTransport - , countryList , encode , fromQuery + , geozoneList , getMaterialMicrofibersComplement , getOutOfEuropeEOLComplement , getOutOfEuropeEOLProbability @@ -16,7 +16,7 @@ module Data.Textile.Inputs exposing import Data.Common.EncodeUtils as EU import Data.Component as Component exposing (Item) -import Data.Country as Country exposing (Country) +import Data.Geozone as Geozone exposing (Geozone) import Data.Impact as Impact import Data.Process as Process import Data.Split as Split exposing (Split) @@ -43,7 +43,7 @@ import Views.Format as Format type alias MaterialInput = - { country : Maybe Country + { geozone : Maybe Geozone , material : Material , share : Split , spinning : Maybe Spinning @@ -53,21 +53,21 @@ type alias MaterialInput = type alias Inputs = { airTransportRatio : Maybe Split , business : Maybe Economics.Business - , countryDistribution : Country - , countryDyeing : Country - , countryEndOfLife : Country - , countryFabric : Country - , countryMaking : Country - - -- TODO: countryMaterial isn't used anymore, but we still need it because `countryList` uses it, - -- which in turn is used to build the lifecycle, which needs a country for each step. - , countryMaterial : Country - , countrySpinning : Country - , countryUse : Country , disabledSteps : List Label , dyeingProcessType : Maybe ProcessType , fabricProcess : Maybe Fabric , fading : Maybe Bool + , geozoneDistribution : Geozone + , geozoneDyeing : Geozone + , geozoneEndOfLife : Geozone + , geozoneFabric : Geozone + , geozoneMaking : Geozone + + -- TODO: geozoneMaterial isn't used anymore, but we still need it because `geozoneList` uses it, + -- which in turn is used to build the lifecycle, which needs a geographical zone for each step. + , geozoneMaterial : Geozone + , geozoneSpinning : Geozone + , geozoneUse : Geozone , makingComplexity : Maybe MakingComplexity , makingDeadStock : Maybe Split , makingWaste : Maybe Split @@ -85,30 +85,30 @@ type alias Inputs = } -fromMaterialQuery : List Material -> List Country -> List MaterialQuery -> Result String (List MaterialInput) -fromMaterialQuery materials countries = +fromMaterialQuery : List Material -> List Geozone -> List MaterialQuery -> Result String (List MaterialInput) +fromMaterialQuery materials geozones = List.map - (\{ country, id, share, spinning } -> + (\{ geozone, id, share, spinning } -> let - countryResult = - case country of - Just countryCode -> - Country.findByCode countryCode countries + geozoneResult = + case geozone of + Just geozoneCode -> + Geozone.findByCode geozoneCode geozones |> Result.map Just Nothing -> Ok Nothing in Result.map2 - (\material_ country_ -> - { country = country_ + (\material_ geozone_ -> + { geozone = geozone_ , material = material_ , share = share , spinning = spinning } ) (Material.findById id materials) - countryResult + geozoneResult ) >> RE.combine @@ -116,8 +116,8 @@ fromMaterialQuery materials countries = toMaterialQuery : List MaterialInput -> List MaterialQuery toMaterialQuery = List.map - (\{ country, material, share, spinning } -> - { country = country |> Maybe.andThen (.code >> toQueryCountryCode) + (\{ geozone, material, share, spinning } -> + { geozone = geozone |> Maybe.andThen (.code >> toQueryGeozoneCode) , id = material.id , share = share , spinning = spinning @@ -134,37 +134,37 @@ getMainMaterial = >> Result.fromMaybe "La liste de matières est vide." -getMainMaterialCountry : List Country -> List MaterialInput -> Result String Country -getMainMaterialCountry countries = +getMainMaterialGeozone : List Geozone -> List MaterialInput -> Result String Geozone +getMainMaterialGeozone geozones = getMainMaterial >> Result.andThen - (\{ defaultCountry } -> - Country.findByCode defaultCountry countries + (\{ defaultGeozone } -> + Geozone.findByCode defaultGeozone geozones ) fromQuery : Db -> Query -> Result String Inputs -fromQuery { countries, textile } query = +fromQuery { geozones, textile } query = let materials_ = query.materials - |> fromMaterialQuery textile.materials countries + |> fromMaterialQuery textile.materials geozones franceResult = - Country.findByCode (Country.Code "FR") countries + Geozone.findByCode (Geozone.Code "FR") geozones - unknownCountryResult = - Country.findByCode Country.unknownCountryCode countries + unknownGeozoneResult = + Geozone.findByCode Geozone.unknownGeozoneCode geozones - mainMaterialCountry = + mainMaterialGeozone = materials_ - |> Result.andThen (getMainMaterialCountry countries) - |> RE.orElse unknownCountryResult + |> Result.andThen (getMainMaterialGeozone geozones) + |> RE.orElse unknownGeozoneResult - getCountryResult fallbackResult maybeCode = + getGeozoneResult fallbackResult maybeCode = case maybeCode of Just code -> - Country.findByCode code countries + Geozone.findByCode code geozones Nothing -> fallbackResult @@ -182,22 +182,22 @@ fromQuery { countries, textile } query = Ok Inputs |> RE.andMap (Ok query.airTransportRatio) |> RE.andMap (Ok query.business) - -- The distribution country is always France - |> RE.andMap franceResult - |> RE.andMap (getCountryResult unknownCountryResult query.countryDyeing) - -- The end of life country is always France - |> RE.andMap franceResult - |> RE.andMap (getCountryResult unknownCountryResult query.countryFabric) - |> RE.andMap (getCountryResult unknownCountryResult query.countryMaking) - -- Material country is constrained to be the first material's default country - |> RE.andMap mainMaterialCountry - |> RE.andMap (getCountryResult unknownCountryResult query.countrySpinning) - -- The use country is always France - |> RE.andMap franceResult |> RE.andMap (Ok query.disabledSteps) |> RE.andMap (Ok query.dyeingProcessType) |> RE.andMap (Ok query.fabricProcess) |> RE.andMap (Ok query.fading) + -- The distribution geographical zone is always France + |> RE.andMap franceResult + |> RE.andMap (getGeozoneResult unknownGeozoneResult query.geozoneDyeing) + -- The end of life geographical zone is always France + |> RE.andMap franceResult + |> RE.andMap (getGeozoneResult unknownGeozoneResult query.geozoneFabric) + |> RE.andMap (getGeozoneResult unknownGeozoneResult query.geozoneMaking) + -- The material geographical zone is constrained to be the first material's default geographical zone + |> RE.andMap mainMaterialGeozone + |> RE.andMap (getGeozoneResult unknownGeozoneResult query.geozoneSpinning) + -- The use geographical zone is always France + |> RE.andMap franceResult |> RE.andMap (Ok query.makingComplexity) |> RE.andMap (Ok query.makingDeadStock) |> RE.andMap (Ok query.makingWaste) @@ -218,14 +218,14 @@ toQuery : Inputs -> Query toQuery inputs = { airTransportRatio = inputs.airTransportRatio , business = inputs.business - , countryDyeing = toQueryCountryCode inputs.countryDyeing.code - , countryFabric = toQueryCountryCode inputs.countryFabric.code - , countryMaking = toQueryCountryCode inputs.countryMaking.code - , countrySpinning = toQueryCountryCode inputs.countrySpinning.code , disabledSteps = inputs.disabledSteps , dyeingProcessType = inputs.dyeingProcessType , fabricProcess = inputs.fabricProcess , fading = inputs.fading + , geozoneDyeing = toQueryGeozoneCode inputs.geozoneDyeing.code + , geozoneFabric = toQueryGeozoneCode inputs.geozoneFabric.code + , geozoneMaking = toQueryGeozoneCode inputs.geozoneMaking.code + , geozoneSpinning = toQueryGeozoneCode inputs.geozoneSpinning.code , makingComplexity = inputs.makingComplexity , makingDeadStock = inputs.makingDeadStock , makingWaste = inputs.makingWaste @@ -248,9 +248,9 @@ toQuery inputs = } -toQueryCountryCode : Country.Code -> Maybe Country.Code -toQueryCountryCode c = - if c == Country.unknownCountryCode then +toQueryGeozoneCode : Geozone.Code -> Maybe Geozone.Code +toQueryGeozoneCode c = + if c == Geozone.unknownGeozoneCode then Nothing else @@ -289,7 +289,7 @@ stepsToStrings wellKnown inputs = ] , ifStepEnabled Label.Spinning [ "filature" - , inputs.countrySpinning.name + , inputs.geozoneSpinning.name ] , case inputs.yarnSize of Just yarnSize -> @@ -301,7 +301,7 @@ stepsToStrings wellKnown inputs = [ inputs.fabricProcess |> Maybe.withDefault inputs.product.fabric |> Fabric.toLabel - , inputs.countryFabric.name + , inputs.geozoneFabric.name ] , ifStepEnabled Label.Ennobling [ "ennoblissement\u{00A0}: " @@ -309,32 +309,32 @@ stepsToStrings wellKnown inputs = |> Dyeing.toProcess wellKnown |> Process.getDisplayName ) - , inputs.countryDyeing.name + , inputs.geozoneDyeing.name ] , ifStepEnabled Label.Ennobling [ "impression" , case inputs.printing of Just printing -> - "impression " ++ Printing.toFullLabel printing ++ "\u{00A0}: " ++ inputs.countryDyeing.name + "impression " ++ Printing.toFullLabel printing ++ "\u{00A0}: " ++ inputs.geozoneDyeing.name Nothing -> "non" ] , ifStepEnabled Label.Making [ "confection" - , inputs.countryMaking.name ++ makingOptionsToString inputs + , inputs.geozoneMaking.name ++ makingOptionsToString inputs ] , ifStepEnabled Label.Distribution [ "distribution" - , inputs.countryDistribution.name + , inputs.geozoneDistribution.name ] , ifStepEnabled Label.Use [ "utilisation" - , inputs.countryUse.name + , inputs.geozoneUse.name ] , ifStepEnabled Label.EndOfLife [ "fin de vie" - , inputs.countryEndOfLife.name + , inputs.geozoneEndOfLife.name ] ] |> List.filter (not << List.isEmpty) @@ -353,10 +353,10 @@ materialsToString materials = materials |> List.filter (\{ share } -> Split.toFloat share > 0) |> List.map - (\{ country, material, share } -> + (\{ geozone, material, share } -> let - countryName = - country + geozoneName = + geozone |> Maybe.map .name |> Maybe.withDefault (" par défaut (" ++ material.geographicOrigin ++ ")") in @@ -364,7 +364,7 @@ materialsToString materials = ++ "% " ++ material.name ++ " provenance " - ++ countryName + ++ geozoneName ) |> String.join ", " @@ -403,16 +403,16 @@ makingOptionsToString { airTransportRatio, fading, makingComplexity, makingDeadS ) -countryList : Inputs -> List Country -countryList inputs = - [ inputs.countryMaterial - , inputs.countrySpinning - , inputs.countryFabric - , inputs.countryDyeing - , inputs.countryMaking - , inputs.countryDistribution - , inputs.countryUse - , inputs.countryEndOfLife +geozoneList : Inputs -> List Geozone +geozoneList inputs = + [ inputs.geozoneMaterial + , inputs.geozoneSpinning + , inputs.geozoneFabric + , inputs.geozoneDyeing + , inputs.geozoneMaking + , inputs.geozoneDistribution + , inputs.geozoneUse + , inputs.geozoneEndOfLife ] @@ -481,20 +481,20 @@ getOutOfEuropeEOLComplement { mass, materials } = ) -computeMaterialTransport : Distances -> Country.Code -> MaterialInput -> Transport -computeMaterialTransport distances nextCountryCode { country, material, share } = +computeMaterialTransport : Distances -> Geozone.Code -> MaterialInput -> Transport +computeMaterialTransport distances nextGeozoneCode { geozone, material, share } = if share /= Split.zero then let emptyImpacts = Impact.empty - countryCode = - country + geozoneCode = + geozone |> Maybe.map .code - |> Maybe.withDefault material.defaultCountry + |> Maybe.withDefault material.defaultGeozone in distances - |> Transport.getTransportBetween emptyImpacts countryCode nextCountryCode + |> Transport.getTransportBetween emptyImpacts geozoneCode nextGeozoneCode else Transport.default Impact.empty @@ -510,9 +510,9 @@ encode inputs = Encode.object [ ( "airTransportRatio", inputs.airTransportRatio |> Maybe.map Split.encodeFloat |> Maybe.withDefault Encode.null ) , ( "business", inputs.business |> Maybe.map Economics.encodeBusiness |> Maybe.withDefault Encode.null ) - , ( "countryDyeing", Country.encode inputs.countryDyeing ) - , ( "countryFabric", Country.encode inputs.countryFabric ) - , ( "countryMaking", Country.encode inputs.countryMaking ) + , ( "geozoneDyeing", Geozone.encode inputs.geozoneDyeing ) + , ( "geozoneFabric", Geozone.encode inputs.geozoneFabric ) + , ( "geozoneMaking", Geozone.encode inputs.geozoneMaking ) , ( "disabledSteps", Encode.list Label.encode inputs.disabledSteps ) , ( "dyeingProcessType", inputs.dyeingProcessType |> Maybe.map Dyeing.encode |> Maybe.withDefault Encode.null ) , ( "fabricProcess", inputs.fabricProcess |> Maybe.map Fabric.encode |> Maybe.withDefault Encode.null ) @@ -537,7 +537,7 @@ encode inputs = encodeMaterialInput : MaterialInput -> Encode.Value encodeMaterialInput v = EU.optionalPropertiesObject - [ ( "country", v.country |> Maybe.map (.code >> Country.encodeCode) ) + [ ( "geozone", v.geozone |> Maybe.map (.code >> Geozone.encodeCode) ) , ( "material", Material.encode v.material |> Just ) , ( "share", Split.encodeFloat v.share |> Just ) , ( "spinning", v.spinning |> Maybe.map Spinning.encode ) diff --git a/src/Data/Textile/LifeCycle.elm b/src/Data/Textile/LifeCycle.elm index a2edabdf5f..2df92633bd 100644 --- a/src/Data/Textile/LifeCycle.elm +++ b/src/Data/Textile/LifeCycle.elm @@ -126,13 +126,13 @@ fromQuery db = init : Db -> Inputs -> LifeCycle init { textile } inputs = - Inputs.countryList inputs + Inputs.geozoneList inputs |> List.map2 - (\( label, editable ) country -> + (\( label, editable ) geozone -> Step.create - { country = country - , editable = editable + { editable = editable , enabled = not (List.member label inputs.disabledSteps) + , geozone = geozone , label = label } ) diff --git a/src/Data/Textile/Material.elm b/src/Data/Textile/Material.elm index 3565cc4d28..aa39cad8cb 100644 --- a/src/Data/Textile/Material.elm +++ b/src/Data/Textile/Material.elm @@ -12,7 +12,7 @@ module Data.Textile.Material exposing , idToString ) -import Data.Country as Country +import Data.Geozone as Geozone import Data.Process as Process exposing (Process) import Data.Split as Split exposing (Split) import Data.Textile.Material.Origin as Origin exposing (Origin) @@ -25,7 +25,7 @@ import Json.Encode as Encode type alias Material = { alias : String , cffData : Maybe CFFData - , defaultCountry : Country.Code -- Default country for Material and Spinning steps + , defaultGeozone : Geozone.Code -- Default geographical zone for Material and Spinning steps , geographicOrigin : String -- A textual information about the geographic origin of the material , id : Id , name : String @@ -87,6 +87,7 @@ getRecyclingData material materials = ---- Helpers + findById : Id -> List Material -> Result String Material findById id = List.filter (.id >> (==) id) @@ -99,7 +100,7 @@ decode processes = Decode.succeed Material |> JDP.required "alias" Decode.string |> JDP.required "cff" (Decode.maybe decodeCFFData) - |> JDP.required "defaultCountry" (Decode.string |> Decode.map Country.codeFromString) + |> JDP.required "defaultGeozone" (Decode.string |> Decode.map Geozone.codeFromString) |> JDP.required "geographicOrigin" Decode.string |> JDP.required "id" decodeId |> JDP.required "name" Decode.string @@ -124,7 +125,7 @@ encode : Material -> Encode.Value encode v = Encode.object [ ( "alias", Encode.string v.alias ) - , ( "defaultCountry", v.defaultCountry |> Country.codeToString |> Encode.string ) + , ( "defaultGeozone", v.defaultGeozone |> Geozone.codeToString |> Encode.string ) , ( "id", encodeId v.id ) , ( "geographicOrigin", Encode.string v.geographicOrigin ) , ( "name", v.name |> Encode.string ) diff --git a/src/Data/Textile/Query.elm b/src/Data/Textile/Query.elm index 6bd6e7a50c..b90ff0c503 100644 --- a/src/Data/Textile/Query.elm +++ b/src/Data/Textile/Query.elm @@ -17,7 +17,7 @@ module Data.Textile.Query exposing , updateMaterial , updateMaterialSpinning , updateProduct - , updateStepCountry + , updateStepGeozone , updateTrims , validateMaterials ) @@ -26,7 +26,7 @@ import Base64 import Data.Common.DecodeUtils as DU import Data.Common.EncodeUtils as EU import Data.Component as Component exposing (Item) -import Data.Country as Country +import Data.Geozone as Geozone import Data.Split as Split exposing (Split) import Data.Textile.Dyeing as Dyeing exposing (ProcessType) import Data.Textile.Economics as Economics @@ -47,7 +47,7 @@ import Url.Parser as Parser exposing (Parser) type alias MaterialQuery = - { country : Maybe Country.Code + { geozone : Maybe Geozone.Code , id : Material.Id , share : Split , spinning : Maybe Spinning @@ -57,14 +57,14 @@ type alias MaterialQuery = type alias Query = { airTransportRatio : Maybe Split , business : Maybe Economics.Business - , countryDyeing : Maybe Country.Code - , countryFabric : Maybe Country.Code - , countryMaking : Maybe Country.Code - , countrySpinning : Maybe Country.Code , disabledSteps : List Label , dyeingProcessType : Maybe ProcessType , fabricProcess : Maybe Fabric , fading : Maybe Bool + , geozoneDyeing : Maybe Geozone.Code + , geozoneFabric : Maybe Geozone.Code + , geozoneMaking : Maybe Geozone.Code + , geozoneSpinning : Maybe Geozone.Code , makingComplexity : Maybe MakingComplexity , makingDeadStock : Maybe Split , makingWaste : Maybe Split @@ -86,7 +86,7 @@ addMaterial : Material -> Query -> Query addMaterial material query = let materialQuery = - { country = Nothing + { geozone = Nothing , id = material.id , share = Split.zero , spinning = Nothing @@ -145,14 +145,14 @@ decode = Decode.succeed Query |> DU.strictOptional "airTransportRatio" Split.decodeFloat |> DU.strictOptional "business" Economics.decodeBusiness - |> DU.strictOptional "countryDyeing" Country.decodeCode - |> DU.strictOptional "countryFabric" Country.decodeCode - |> DU.strictOptional "countryMaking" Country.decodeCode - |> DU.strictOptional "countrySpinning" Country.decodeCode |> Pipe.optional "disabledSteps" (Decode.list Label.decodeFromCode) [] |> DU.strictOptional "dyeingProcessType" Dyeing.decode |> DU.strictOptional "fabricProcess" Fabric.decode |> DU.strictOptional "fading" Decode.bool + |> DU.strictOptional "geozoneDyeing" Geozone.decodeCode + |> DU.strictOptional "geozoneFabric" Geozone.decodeCode + |> DU.strictOptional "geozoneMaking" Geozone.decodeCode + |> DU.strictOptional "geozoneSpinning" Geozone.decodeCode |> DU.strictOptional "makingComplexity" MakingComplexity.decode |> DU.strictOptional "makingDeadStock" Split.decodeFloat |> DU.strictOptional "makingWaste" Split.decodeFloat @@ -172,7 +172,7 @@ decode = decodeMaterialQuery : Decoder MaterialQuery decodeMaterialQuery = Decode.succeed MaterialQuery - |> DU.strictOptional "country" Country.decodeCode + |> DU.strictOptional "geozone" Geozone.decodeCode |> Pipe.required "id" Material.decodeId |> Pipe.required "share" Split.decodeFloat |> DU.strictOptional "spinning" Spinning.decode @@ -183,10 +183,10 @@ encode query = EU.optionalPropertiesObject [ ( "airTransportRatio", query.airTransportRatio |> Maybe.map Split.encodeFloat ) , ( "business", query.business |> Maybe.map Economics.encodeBusiness ) - , ( "countryDyeing", query.countryDyeing |> Maybe.map Country.encodeCode ) - , ( "countryFabric", query.countryFabric |> Maybe.map Country.encodeCode ) - , ( "countryMaking", query.countryMaking |> Maybe.map Country.encodeCode ) - , ( "countrySpinning", query.countrySpinning |> Maybe.map Country.encodeCode ) + , ( "geozoneDyeing", query.geozoneDyeing |> Maybe.map Geozone.encodeCode ) + , ( "geozoneFabric", query.geozoneFabric |> Maybe.map Geozone.encodeCode ) + , ( "geozoneMaking", query.geozoneMaking |> Maybe.map Geozone.encodeCode ) + , ( "geozoneSpinning", query.geozoneSpinning |> Maybe.map Geozone.encodeCode ) , ( "disabledSteps" , case query.disabledSteps of [] -> @@ -218,7 +218,7 @@ encode query = encodeMaterialQuery : MaterialQuery -> Encode.Value encodeMaterialQuery v = EU.optionalPropertiesObject - [ ( "country", v.country |> Maybe.map Country.encodeCode ) + [ ( "geozone", v.geozone |> Maybe.map Geozone.encodeCode ) , ( "id", Material.encodeId v.id |> Just ) , ( "share", Split.encodeFloat v.share |> Just ) , ( "spinning", v.spinning |> Maybe.map Spinning.encode ) @@ -309,7 +309,7 @@ updateMaterial oldMaterialId newMaterial = updateMaterialQuery oldMaterialId (\materialQuery -> { materialQuery - | country = newMaterial.country + | geozone = newMaterial.geozone , id = newMaterial.id , share = newMaterial.share , spinning = Nothing @@ -366,11 +366,11 @@ updateProduct product query = query -updateStepCountry : Label -> Country.Code -> Query -> Query -updateStepCountry label code query = +updateStepGeozone : Label -> Geozone.Code -> Query -> Query +updateStepGeozone label code query = let maybeCode = - if code == Country.unknownCountryCode then + if code == Geozone.unknownGeozoneCode then Nothing else @@ -378,25 +378,25 @@ updateStepCountry label code query = in case label of Label.Ennobling -> - { query | countryDyeing = maybeCode } + { query | geozoneDyeing = maybeCode } Label.Fabric -> - { query | countryFabric = maybeCode } + { query | geozoneFabric = maybeCode } Label.Making -> { query | airTransportRatio = - if query.countryMaking /= maybeCode then - -- reset custom value as we just switched country + if query.geozoneMaking /= maybeCode then + -- reset custom value as we just switched geozone Nothing else query.airTransportRatio - , countryMaking = maybeCode + , geozoneMaking = maybeCode } Label.Spinning -> - { query | countrySpinning = maybeCode } + { query | geozoneSpinning = maybeCode } _ -> query @@ -434,14 +434,14 @@ default = -- Note: the default query doesn't have any materials { airTransportRatio = Nothing , business = Nothing - , countryDyeing = Just (Country.Code "CN") - , countryFabric = Just (Country.Code "CN") - , countryMaking = Just (Country.Code "CN") - , countrySpinning = Just (Country.Code "CN") , disabledSteps = [] , dyeingProcessType = Nothing , fabricProcess = Nothing , fading = Nothing + , geozoneDyeing = Just (Geozone.Code "CN") + , geozoneFabric = Just (Geozone.Code "CN") + , geozoneMaking = Just (Geozone.Code "CN") + , geozoneSpinning = Just (Geozone.Code "CN") , makingComplexity = Nothing , makingDeadStock = Nothing , makingWaste = Nothing diff --git a/src/Data/Textile/Simulator.elm b/src/Data/Textile/Simulator.elm index 007a44ceb4..636043ef68 100644 --- a/src/Data/Textile/Simulator.elm +++ b/src/Data/Textile/Simulator.elm @@ -11,8 +11,8 @@ module Data.Textile.Simulator exposing import Array import Data.Common.EncodeUtils as EU import Data.Component as Component -import Data.Country as Country import Data.Env as Env +import Data.Geozone as Geozone import Data.Impact as Impact exposing (Impacts) import Data.Impact.Definition as Definition import Data.Scope as Scope @@ -260,7 +260,7 @@ computeMakingAirTransportRatio : Simulator -> Simulator computeMakingAirTransportRatio ({ durability, inputs } as simulator) = simulator |> updateLifeCycleStep Label.Making - (\({ country } as step) -> + (\({ geozone } as step) -> { step | airTransportRatio = case inputs.airTransportRatio of @@ -269,8 +269,8 @@ computeMakingAirTransportRatio ({ durability, inputs } as simulator) = airTransportRatio Nothing -> - if Country.isEuropeOrTurkey country then - -- If Making country is Europe or Turkey, airTransportRatio is always 0 + if Geozone.isEuropeOrTurkey geozone then + -- If Making geozone is Europe or Turkey, airTransportRatio is always 0 Split.zero else if Unit.floatDurabilityFromHolistic durability >= 1 then @@ -278,8 +278,8 @@ computeMakingAirTransportRatio ({ durability, inputs } as simulator) = Split.third else - -- FIXME: how about falling back to country default? - -- country.airTransportRatio + -- FIXME: how about falling back to geozone default? + -- geozone.airTransportRatio Split.full } ) @@ -289,14 +289,14 @@ computeEndOfLifeImpacts : Db -> Simulator -> Simulator computeEndOfLifeImpacts { textile } simulator = simulator |> updateLifeCycleStep Label.EndOfLife - (\({ country } as step) -> + (\({ geozone } as step) -> let { heat, impacts, kwh } = step.outputMass |> Formula.endOfLifeImpacts step.impacts - { countryElecProcess = country.electricityProcess - , endOfLife = textile.wellKnown.endOfLife - , heatProcess = country.heatProcess + { endOfLife = textile.wellKnown.endOfLife + , geozoneElecProcess = geozone.electricityProcess + , heatProcess = geozone.heatProcess , passengerCar = textile.wellKnown.passengerCar , volume = simulator.inputs.product.endOfLife.volume } @@ -319,7 +319,7 @@ computeUseImpacts { textile } ({ inputs, useNbCycles } as simulator) = step.outputMass |> Formula.useImpacts step.impacts -- Note: The use step is always located in France using low voltage electricity - { countryElecProcess = textile.wellKnown.lowVoltageFranceElec + { geozoneElecProcess = textile.wellKnown.lowVoltageFranceElec , ironingElec = inputs.product.use.ironingElec , nonIroningProcess = inputs.product.use.nonIroningProcess , useNbCycles = useNbCycles @@ -333,20 +333,20 @@ computeMakingImpacts : Db -> Simulator -> Simulator computeMakingImpacts { textile } ({ inputs } as simulator) = simulator |> updateLifeCycleStep Label.Making - (\({ country } as step) -> + (\({ geozone } as step) -> let { heat, impacts, kwh } = step.outputMass |> Formula.makingImpacts step.impacts - { countryElecProcess = country.electricityProcess - , countryHeatProcess = country.heatProcess - , fadingProcess = - -- Note: in the future, we may have distinct fading processes per countries + { fadingProcess = + -- Note: in the future, we may have distinct fading processes per geographic zone if inputs.fading == Just True then Just textile.wellKnown.fading else Nothing + , geozoneElecProcess = geozone.electricityProcess + , geozoneHeatProcess = geozone.heatProcess , makingComplexity = inputs.fabricProcess |> Fabric.getMakingComplexity inputs.product.making.complexity inputs.makingComplexity @@ -360,10 +360,10 @@ computeDyeingImpacts : Db -> Simulator -> Simulator computeDyeingImpacts { textile } ({ inputs } as simulator) = simulator |> updateLifeCycleStep Label.Ennobling - (\({ country, dyeingProcessType } as step) -> + (\({ geozone, dyeingProcessType } as step) -> let heatProcess = - WellKnown.getEnnoblingHeatProcess textile.wellKnown country + WellKnown.getEnnoblingHeatProcess textile.wellKnown geozone dyeingProcess = Dyeing.toProcess textile.wellKnown dyeingProcessType @@ -373,7 +373,7 @@ computeDyeingImpacts { textile } ({ inputs } as simulator) = |> List.map (\{ material, share } -> Formula.materialDyeingToxicityImpacts step.impacts - { aquaticPollutionScenario = step.country.aquaticPollutionScenario + { aquaticPollutionScenario = step.geozone.aquaticPollutionScenario , dyeingToxicityProcess = if Origin.isSynthetic material.origin then textile.wellKnown.dyeingSynthetic @@ -394,7 +394,7 @@ computeDyeingImpacts { textile } ({ inputs } as simulator) = |> Formula.dyeingImpacts step.impacts dyeingProcess heatProcess - country.electricityProcess + geozone.electricityProcess in { step | heat = Quantity.sum [ step.heat, heat, preTreatments.heat ] @@ -409,7 +409,7 @@ computePrintingImpacts : Db -> Simulator -> Simulator computePrintingImpacts { textile } ({ inputs } as simulator) = simulator |> updateLifeCycleStep Label.Ennobling - (\({ country } as step) -> + (\({ geozone } as step) -> case step.printing of Just { kind, ratio } -> let @@ -419,8 +419,8 @@ computePrintingImpacts { textile } ({ inputs } as simulator) = { heat, impacts, kwh } = step.outputMass |> Formula.printingImpacts step.impacts - { elecProcess = country.electricityProcess - , heatProcess = WellKnown.getEnnoblingHeatProcess textile.wellKnown country + { elecProcess = geozone.electricityProcess + , heatProcess = WellKnown.getEnnoblingHeatProcess textile.wellKnown geozone , printingProcess = printingProcess , ratio = ratio , surfaceMass = inputs.surfaceMass |> Maybe.withDefault inputs.product.surfaceMass @@ -430,7 +430,7 @@ computePrintingImpacts { textile } ({ inputs } as simulator) = step.outputMass |> Formula.materialPrintingToxicityImpacts step.impacts - { aquaticPollutionScenario = step.country.aquaticPollutionScenario + { aquaticPollutionScenario = step.geozone.aquaticPollutionScenario , printingToxicityProcess = printingToxicityProcess , surfaceMass = inputs.surfaceMass |> Maybe.withDefault inputs.product.surfaceMass } @@ -451,14 +451,14 @@ computeFinishingImpacts : Db -> Simulator -> Simulator computeFinishingImpacts { textile } simulator = simulator |> updateLifeCycleStep Label.Ennobling - (\({ country } as step) -> + (\({ geozone } as step) -> let { heat, impacts, kwh } = step.outputMass |> Formula.finishingImpacts step.impacts - { elecProcess = country.electricityProcess + { elecProcess = geozone.electricityProcess , finishingProcess = textile.wellKnown.finishing - , heatProcess = WellKnown.getEnnoblingHeatProcess textile.wellKnown country + , heatProcess = WellKnown.getEnnoblingHeatProcess textile.wellKnown geozone } in { step @@ -523,7 +523,7 @@ stepSpinningImpacts material maybeSpinning product step = |> Energy.kilowattHours in Formula.spinningImpacts step.impacts - { countryElecProcess = step.country.electricityProcess + { geozoneElecProcess = step.geozone.electricityProcess , spinningKwh = kwh } @@ -567,7 +567,7 @@ computeFabricImpacts { textile } ({ inputs, lifeCycle } as simulator) = in simulator |> updateLifeCycleStep Label.Fabric - (\({ country } as step) -> + (\({ geozone } as step) -> let process = inputs.fabricProcess @@ -582,8 +582,8 @@ computeFabricImpacts { textile } ({ inputs, lifeCycle } as simulator) = then step.outputMass |> Formula.knittingImpacts step.impacts - { countryElecProcess = country.electricityProcess - , elec = process.elec + { elec = process.elec + , geozoneElecProcess = geozone.electricityProcess } else @@ -593,7 +593,7 @@ computeFabricImpacts { textile } ({ inputs, lifeCycle } as simulator) = |> Maybe.withDefault inputs.product.surfaceMass in Formula.weavingImpacts step.impacts - { countryElecProcess = country.electricityProcess + { geozoneElecProcess = geozone.electricityProcess , outputMass = fabricOutputMass , pickingElec = WellKnown.weavingElecPPPM , surfaceMass = surfaceMass diff --git a/src/Data/Textile/Step.elm b/src/Data/Textile/Step.elm index f717340d2f..4650afdfbe 100644 --- a/src/Data/Textile/Step.elm +++ b/src/Data/Textile/Step.elm @@ -23,7 +23,7 @@ module Data.Textile.Step exposing ) import Area exposing (Area) -import Data.Country as Country exposing (Country) +import Data.Geozone as Geozone exposing (Geozone) import Data.Impact as Impact exposing (Impacts) import Data.Process as Process exposing (Process) import Data.Split as Split exposing (Split) @@ -51,12 +51,12 @@ import Views.Format as Format type alias Step = { airTransportRatio : Split , complementsImpacts : Impact.ComplementsImpacts - , country : Country , deadstock : Mass , durability : Unit.NonPhysicalDurability , dyeingProcessType : Maybe ProcessType , editable : Bool , enabled : Bool + , geozone : Geozone , heat : Energy , impacts : Impacts , inputMass : Mass @@ -90,13 +90,13 @@ type alias PreTreatments = type alias ProcessInfo = { airTransport : Maybe String , airTransportRatio : Maybe String - , countryElec : Maybe String - , countryHeat : Maybe String , distribution : Maybe String , dyeing : Maybe String , endOfLife : Maybe String , fabric : Maybe String , fading : Maybe String + , geozoneElec : Maybe String + , geozoneHeat : Maybe String , making : Maybe String , passengerCar : Maybe String , printing : Maybe String @@ -107,20 +107,20 @@ type alias ProcessInfo = } -create : { country : Country, editable : Bool, enabled : Bool, label : Label } -> Step -create { country, editable, enabled, label } = +create : { editable : Bool, enabled : Bool, geozone : Geozone, label : Label } -> Step +create { editable, enabled, geozone, label } = let defaultImpacts = Impact.empty in - { airTransportRatio = Split.zero -- Note: this depends on next step country, so we can't set an accurate default value initially + { airTransportRatio = Split.zero -- Note: this depends on next step geozone, so we can't set an accurate default value initially , complementsImpacts = Impact.noComplementsImpacts - , country = country , deadstock = Quantity.zero , durability = Unit.standardDurability Unit.NonPhysicalDurability , dyeingProcessType = Nothing , editable = editable , enabled = enabled + , geozone = geozone , heat = Quantity.zero , impacts = defaultImpacts , inputMass = Quantity.zero @@ -156,13 +156,13 @@ defaultProcessInfo : ProcessInfo defaultProcessInfo = { airTransport = Nothing , airTransportRatio = Nothing - , countryElec = Nothing - , countryHeat = Nothing , distribution = Nothing , dyeing = Nothing , endOfLife = Nothing , fabric = Nothing , fading = Nothing + , geozoneElec = Nothing + , geozoneHeat = Nothing , making = Nothing , passengerCar = Nothing , printing = Nothing @@ -173,21 +173,21 @@ defaultProcessInfo = } -computeMaterialTransportAndImpact : Db -> Country -> Mass -> Inputs.MaterialInput -> Transport -computeMaterialTransportAndImpact { distances, textile } country outputMass materialInput = +computeMaterialTransportAndImpact : Db -> Geozone -> Mass -> Inputs.MaterialInput -> Transport +computeMaterialTransportAndImpact { distances, textile } geozone outputMass materialInput = let materialMass = materialInput.share |> Split.applyToQuantity outputMass in materialInput - |> Inputs.computeMaterialTransport distances country.code + |> Inputs.computeMaterialTransport distances geozone.code |> Formula.transportRatio Split.zero |> computeTransportImpacts Impact.empty textile.wellKnown textile.wellKnown.roadTransport materialMass -computePreTreatment : Country -> Mass -> Process -> PreTreatments -computePreTreatment country mass process = +computePreTreatment : Geozone -> Mass -> Process -> PreTreatments +computePreTreatment geozone mass process = let massInKg = Mass.inKilograms mass @@ -199,9 +199,9 @@ computePreTreatment country mass process = in { energy = Impact.sumImpacts - [ country.electricityProcess.impacts + [ geozone.electricityProcess.impacts |> Impact.multiplyBy (Energy.inKilowattHours consumedElec) - , country.heatProcess.impacts + , geozone.heatProcess.impacts |> Impact.multiplyBy (Energy.inMegajoules consumedHeat) ] , heat = consumedHeat @@ -210,15 +210,15 @@ computePreTreatment country mass process = , toxicity = process.impacts |> Impact.multiplyBy - (country.aquaticPollutionScenario - |> Country.getAquaticPollutionRatio + (geozone.aquaticPollutionScenario + |> Geozone.getAquaticPollutionRatio |> Split.apply massInKg ) } computePreTreatments : WellKnown -> List Inputs.MaterialInput -> Step -> PreTreatments -computePreTreatments wellKnown materials { country, inputMass } = +computePreTreatments wellKnown materials { geozone, inputMass } = materials |> List.concatMap (\{ material, share } -> @@ -227,7 +227,7 @@ computePreTreatments wellKnown materials { country, inputMass } = |> List.map (share |> Split.applyToQuantity inputMass - |> computePreTreatment country + |> computePreTreatment geozone ) ) |> List.foldl @@ -254,12 +254,12 @@ computeTransports db inputs next ({ processInfo } as current) = transport = if current.label == Label.Material then inputs.materials - |> List.map (computeMaterialTransportAndImpact db next.country current.outputMass) + |> List.map (computeMaterialTransportAndImpact db next.geozone current.outputMass) |> Transport.sum else db.distances - |> Transport.getTransportBetween current.transport.impacts current.country.code next.country.code + |> Transport.getTransportBetween current.transport.impacts current.geozone.code next.geozone.code |> computeTransportSummary current |> computeTransportImpacts current.transport.impacts db.textile.wellKnown @@ -356,7 +356,7 @@ getTransportedMass inputs { label, outputMass } = updateFromInputs : Textile.Db -> Inputs -> Step -> Step -updateFromInputs { wellKnown } inputs ({ label, country, complementsImpacts } as step) = +updateFromInputs { wellKnown } inputs ({ label, geozone, complementsImpacts } as step) = let { dyeingProcessType, makingComplexity, makingDeadStock, makingWaste, printing, surfaceMass, yarnSize } = inputs @@ -376,9 +376,9 @@ updateFromInputs { wellKnown } inputs ({ label, country, complementsImpacts } as } , processInfo = { defaultProcessInfo - | countryElec = Just <| Process.getDisplayName country.electricityProcess - , countryHeat = Just <| Process.getDisplayName country.heatProcess - , endOfLife = Just <| Process.getDisplayName wellKnown.endOfLife + | endOfLife = Just <| Process.getDisplayName wellKnown.endOfLife + , geozoneElec = Just <| Process.getDisplayName geozone.electricityProcess + , geozoneHeat = Just <| Process.getDisplayName geozone.heatProcess , passengerCar = Just "Transport en voiture vers point de collecte (1km)" } } @@ -389,9 +389,9 @@ updateFromInputs { wellKnown } inputs ({ label, country, complementsImpacts } as , printing = printing , processInfo = { defaultProcessInfo - | countryElec = Just <| Process.getDisplayName country.electricityProcess - , countryHeat = Just <| Process.getDisplayName country.heatProcess - , dyeing = Nothing + | dyeing = Nothing + , geozoneElec = Just <| Process.getDisplayName geozone.electricityProcess + , geozoneHeat = Just <| Process.getDisplayName geozone.heatProcess , printing = printing |> Maybe.map @@ -408,12 +408,12 @@ updateFromInputs { wellKnown } inputs ({ label, country, complementsImpacts } as { step | processInfo = { defaultProcessInfo - | countryElec = Just <| Process.getDisplayName country.electricityProcess - , fabric = + | fabric = inputs.product.fabric |> Fabric.getProcess wellKnown |> Process.getDisplayName |> Just + , geozoneElec = Just <| Process.getDisplayName geozone.electricityProcess } , surfaceMass = surfaceMass , yarnSize = yarnSize @@ -426,8 +426,8 @@ updateFromInputs { wellKnown } inputs ({ label, country, complementsImpacts } as , makingWaste = makingWaste , processInfo = { defaultProcessInfo - | countryElec = Just <| Process.getDisplayName country.electricityProcess - , fading = Just <| Process.getDisplayName wellKnown.fading + | fading = Just <| Process.getDisplayName wellKnown.fading + , geozoneElec = Just <| Process.getDisplayName geozone.electricityProcess } } @@ -442,7 +442,7 @@ updateFromInputs { wellKnown } inputs ({ label, country, complementsImpacts } as Label.Spinning -> { step - | processInfo = { defaultProcessInfo | countryElec = Just <| Process.getDisplayName country.electricityProcess } + | processInfo = { defaultProcessInfo | geozoneElec = Just <| Process.getDisplayName geozone.electricityProcess } , yarnSize = yarnSize } @@ -451,7 +451,7 @@ updateFromInputs { wellKnown } inputs ({ label, country, complementsImpacts } as | processInfo = { defaultProcessInfo | -- Note: French low voltage electricity process is always used at the Use step - countryElec = Just <| Process.getDisplayName wellKnown.lowVoltageFranceElec + geozoneElec = Just <| Process.getDisplayName wellKnown.lowVoltageFranceElec , useIroning = -- Note: Much better expressing electricity consumption in kWh than in MJ inputs.product.use.ironingElec @@ -491,10 +491,10 @@ updateDeadStock deadstock mass step = airTransportDisabled : Step -> Bool -airTransportDisabled { country, enabled, label } = +airTransportDisabled { enabled, geozone, label } = not enabled || -- Note: disallow air transport from France to France at the Making step - (label == Label.Making && country.code == Country.codeFromString "FR") + (label == Label.Making && geozone.code == Geozone.codeFromString "FR") airTransportRatioToString : Split -> String @@ -545,7 +545,7 @@ encode v = Encode.object [ ( "airTransportRatio", Split.encodeFloat v.airTransportRatio ) , ( "complementsImpacts", Impact.encodeComplementsImpacts v.complementsImpacts ) - , ( "country", Country.encode v.country ) + , ( "geozone", Geozone.encode v.geozone ) , ( "deadstock", Encode.float (Mass.inKilograms v.deadstock) ) , ( "durability", Unit.encodeNonPhysicalDurability v.durability ) , ( "editable", Encode.bool v.editable ) @@ -590,8 +590,8 @@ encodeProcessInfo v = Encode.object [ ( "airTransport", encodeMaybeString v.airTransport ) , ( "airTransportRatio", encodeMaybeString v.airTransportRatio ) - , ( "countryElec", encodeMaybeString v.countryElec ) - , ( "countryHeat", encodeMaybeString v.countryHeat ) + , ( "geozoneElec", encodeMaybeString v.geozoneElec ) + , ( "geozoneHeat", encodeMaybeString v.geozoneHeat ) , ( "distribution", encodeMaybeString v.distribution ) , ( "endOfLife", encodeMaybeString v.endOfLife ) , ( "fabric", encodeMaybeString v.fabric ) diff --git a/src/Data/Textile/Validation.elm b/src/Data/Textile/Validation.elm index b673163168..812436cfd8 100644 --- a/src/Data/Textile/Validation.elm +++ b/src/Data/Textile/Validation.elm @@ -1,8 +1,8 @@ module Data.Textile.Validation exposing (validate) import Data.Component as Component -import Data.Country as Country import Data.Env as Env +import Data.Geozone as Geozone import Data.Scope as Scope import Data.Split as Split exposing (Split) import Data.Textile.Economics as Economics @@ -23,14 +23,14 @@ validate db query = Ok Query |> Validation.ok "airTransportRatio" query.airTransportRatio |> Validation.ok "business" query.business - |> Validation.maybe "countryDyeing" query.countryDyeing (Country.validateForScope Scope.Textile db.countries) - |> Validation.maybe "countryFabric" query.countryFabric (Country.validateForScope Scope.Textile db.countries) - |> Validation.maybe "countryMaking" query.countryMaking (Country.validateForScope Scope.Textile db.countries) - |> Validation.maybe "countrySpinning" query.countrySpinning (Country.validateForScope Scope.Textile db.countries) |> Validation.ok "disabledSteps" query.disabledSteps |> Validation.ok "dyeingProcessType" query.dyeingProcessType |> Validation.ok "fabricProcess" query.fabricProcess |> Validation.ok "fading" query.fading + |> Validation.maybe "geozoneDyeing" query.geozoneDyeing (Geozone.validateForScope Scope.Textile db.geozones) + |> Validation.maybe "geozoneFabric" query.geozoneFabric (Geozone.validateForScope Scope.Textile db.geozones) + |> Validation.maybe "geozoneMaking" query.geozoneMaking (Geozone.validateForScope Scope.Textile db.geozones) + |> Validation.maybe "geozoneSpinning" query.geozoneSpinning (Geozone.validateForScope Scope.Textile db.geozones) |> Validation.ok "makingComplexity" query.makingComplexity |> Validation.maybe "makingDeadStock" query.makingDeadStock validateMakingDeadStock |> Validation.maybe "makingWaste" query.makingWaste validateMakingWaste @@ -80,8 +80,8 @@ validateMaterialQuery : Db -> MaterialQuery -> Result String MaterialQuery validateMaterialQuery db materialQuery = Ok MaterialQuery |> RE.andMap - (materialQuery.country - |> validateMaybe (Country.validateForScope Scope.Textile db.countries) + (materialQuery.geozone + |> validateMaybe (Geozone.validateForScope Scope.Textile db.geozones) ) |> RE.andMap (db.textile.materials diff --git a/src/Data/Textile/WellKnown.elm b/src/Data/Textile/WellKnown.elm index fecc067ca5..782eb6122a 100644 --- a/src/Data/Textile/WellKnown.elm +++ b/src/Data/Textile/WellKnown.elm @@ -7,11 +7,11 @@ module Data.Textile.WellKnown exposing , weavingElecPPPM ) -import Data.Country exposing (Country) +import Data.Geozone exposing (Geozone) import Data.Process as Process exposing (Process) import Data.Textile.Material.Origin as Origin exposing (Origin) import Data.Textile.Printing as Printing -import Data.Zone as Zone +import Data.WorldRegion as WorldRegion import Result.Extra as RE @@ -50,12 +50,12 @@ type alias WellKnown = } -getEnnoblingHeatProcess : WellKnown -> Country -> Process -getEnnoblingHeatProcess wk country = +getEnnoblingHeatProcess : WellKnown -> Geozone -> Process +getEnnoblingHeatProcess wk geozone = -- Note: As per methodology documentation, retrieve a RER heat source process -- for european countries, RSA otherwise. - case country.zone of - Zone.Europe -> + case geozone.worldRegion of + WorldRegion.Europe -> wk.heatEurope _ -> diff --git a/src/Data/Transport.elm b/src/Data/Transport.elm index 86dd2fde0e..cdb2514a98 100644 --- a/src/Data/Transport.elm +++ b/src/Data/Transport.elm @@ -14,8 +14,8 @@ module Data.Transport exposing , totalKm ) -import Data.Country as Country import Data.Food.WellKnown exposing (WellKnown) +import Data.Geozone as Geozone import Data.Impact as Impact exposing (Impacts) import Data.Split as Split exposing (Split) import Data.Unit as Unit @@ -29,11 +29,11 @@ import Quantity type alias Distance = - AnyDict String Country.Code Transport + AnyDict String Geozone.Code Transport type alias Distances = - AnyDict String Country.Code Distance + AnyDict String Geozone.Code Distance type alias Transport = @@ -172,8 +172,8 @@ roadSeaTransportRatio { road, sea } = getTransportBetween : Impacts - -> Country.Code - -> Country.Code + -> Geozone.Code + -> Geozone.Code -> Distances -> Transport getTransportBetween impacts cA cB distances = @@ -230,17 +230,17 @@ encode v = decodeDistance : Decoder Distance decodeDistance = - -- FIXME: Ideally we want to check for available country codes + -- FIXME: Ideally we want to check for available geographical zones codes Dict.decode - (\str _ -> Country.codeFromString str) - Country.codeToString + (\str _ -> Geozone.codeFromString str) + Geozone.codeToString decode decodeDistances : Decoder Distances decodeDistances = - -- FIXME: Ideally we want to check for available country codes + -- FIXME: Ideally we want to check for available geographical zones codes Dict.decode - (\str _ -> Country.codeFromString str) - Country.codeToString + (\str _ -> Geozone.codeFromString str) + Geozone.codeToString decodeDistance diff --git a/src/Data/Zone.elm b/src/Data/WorldRegion.elm similarity index 75% rename from src/Data/Zone.elm rename to src/Data/WorldRegion.elm index b509167e8f..d746c7708a 100644 --- a/src/Data/Zone.elm +++ b/src/Data/WorldRegion.elm @@ -1,5 +1,5 @@ -module Data.Zone exposing - ( Zone(..) +module Data.WorldRegion exposing + ( WorldRegion(..) , decode ) @@ -7,7 +7,7 @@ import Json.Decode as Decode exposing (Decoder) import Json.Decode.Extra as DE -type Zone +type WorldRegion = Africa | Asia | Europe @@ -17,13 +17,13 @@ type Zone | SouthAmerica -decode : Decoder Zone +decode : Decoder WorldRegion decode = Decode.string |> Decode.andThen (fromString >> DE.fromResult) -fromString : String -> Result String Zone +fromString : String -> Result String WorldRegion fromString string = case string of "Africa" -> @@ -48,4 +48,4 @@ fromString string = Ok SouthAmerica _ -> - Err <| "Zone géographique inconnue : " ++ string + Err <| "Région géographique inconnue : " ++ string diff --git a/src/Page/Admin/Component.elm b/src/Page/Admin/Component.elm index 42f92615ac..8f1b4a2e9b 100644 --- a/src/Page/Admin/Component.elm +++ b/src/Page/Admin/Component.elm @@ -576,7 +576,7 @@ modalView { componentConfig, db } modals index modal = item |> updateSingleItem (Component.updateElementAmount targetElement amount) ) >> Maybe.withDefault NoOp - , updateItemCountry = \_ _ -> NoOp + , updateItemGeozone = \_ _ -> NoOp , updateItemName = \targetItem name -> item |> updateSingleItem (Component.updateItemCustomName targetItem name) diff --git a/src/Page/Api.elm b/src/Page/Api.elm index 0e6bbaa66a..e6d412e461 100644 --- a/src/Page/Api.elm +++ b/src/Page/Api.elm @@ -54,7 +54,21 @@ getApiServerUrl { clientUrl } = changelog : List News changelog = - [ { date = "22 juillet 2025" + [ { date = "24 novembre 2025" + , level = "major" + , domains = [ "Alimentaire", "Textile" ] + , md = """Les points d’entrée `/textile/countries` et `/food/countries` on été remplacés par + `textile/geozones` et `/food/geozones`. + + De même, chaque fois que le mot `country` apparaissait dans le nom d’un paramètre, + il a été remplacé par `geozone`. + + Par exemple: +- `country` => `geozone` +- `countrySpinning` => `geozoneSpinning`. + """ + } + , { date = "22 juillet 2025" , level = "major" , domains = [ "Textile" ] , md = """Le paramétrage de la surface d'impression interdit désormais les valeurs supérieures à 80%.""" diff --git a/src/Page/Explore.elm b/src/Page/Explore.elm index a15d6a27a2..0a91d8b485 100644 --- a/src/Page/Explore.elm +++ b/src/Page/Explore.elm @@ -13,13 +13,13 @@ import App exposing (Msg, PageUpdate) import Browser.Events import Browser.Navigation as Nav import Data.Component as Component exposing (Component) -import Data.Country as Country exposing (Country) import Data.Dataset as Dataset exposing (Dataset) import Data.Example as Example exposing (Example) import Data.Food.Db as FoodDb import Data.Food.Ingredient as Ingredient exposing (Ingredient) import Data.Food.Query as FoodQuery import Data.Food.Recipe as Recipe +import Data.Geozone as Geozone exposing (Geozone) import Data.Impact as Impact import Data.Impact.Definition as Definition exposing (Definition, Definitions) import Data.Key as Key @@ -38,9 +38,9 @@ import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) import Page.Explore.Components as Components -import Page.Explore.Countries as ExploreCountries import Page.Explore.FoodExamples as FoodExamples import Page.Explore.FoodIngredients as FoodIngredients +import Page.Explore.Geozones as ExploreGeozones import Page.Explore.Impacts as ExploreImpacts import Page.Explore.ObjectExamples as ObjectExamples import Page.Explore.Processes as Processes @@ -80,15 +80,15 @@ init scope dataset session = Dataset.Components _ _ -> "Nom" - Dataset.Countries _ -> - "Nom" - Dataset.FoodExamples _ -> "Coût Environnemental" Dataset.FoodIngredients _ -> "Identifiant" + Dataset.Geozones _ -> + "Nom" + Dataset.Impacts _ -> "Code" @@ -153,8 +153,8 @@ update session msg model = |> App.withCmds [ (case model.dataset of -- Try selecting the most appropriate tab when switching scope. - Dataset.Countries _ -> - Dataset.Countries Nothing + Dataset.Geozones _ -> + Dataset.Geozones Nothing Dataset.Impacts _ -> Dataset.Impacts Nothing @@ -258,27 +258,27 @@ alert error = ] -countriesExplorer : +geozonesExplorer : Db - -> Table.Config Country Msg + -> Table.Config Geozone Msg -> SortableTable.State -> Scope - -> Maybe Country.Code + -> Maybe Geozone.Code -> List (Html Msg) -countriesExplorer { distances, countries } tableConfig tableState scope maybeCode = - [ countries +geozonesExplorer { distances, geozones } tableConfig tableState scope maybeCode = + [ geozones |> List.filter (.scopes >> List.member scope) - |> Table.viewList OpenDetail tableConfig tableState scope (ExploreCountries.table distances countries) + |> Table.viewList OpenDetail tableConfig tableState scope (ExploreGeozones.table distances geozones) , case maybeCode of Just code -> detailsModal - (case Country.findByCode code countries of + (case Geozone.findByCode code geozones of Err error -> alert error - Ok country -> - country - |> Table.viewDetails scope (ExploreCountries.table distances countries) + Ok geozone -> + geozone + |> Table.viewDetails scope (ExploreGeozones.table distances geozones) ) Nothing -> @@ -696,15 +696,15 @@ explore ({ db } as session) { scope, dataset, tableState } = Dataset.Components scope_ maybeId -> componentsExplorer db scope_ tableConfig tableState maybeId - Dataset.Countries maybeCode -> - countriesExplorer db tableConfig tableState scope maybeCode - Dataset.FoodExamples maybeId -> foodExamplesExplorer db tableConfig tableState maybeId Dataset.FoodIngredients maybeId -> foodIngredientsExplorer db tableConfig tableState maybeId + Dataset.Geozones maybeCode -> + geozonesExplorer db tableConfig tableState scope maybeCode + Dataset.Impacts maybeTrigram -> impactsExplorer db.definitions tableConfig tableState scope maybeTrigram diff --git a/src/Page/Explore/Countries.elm b/src/Page/Explore/Geozones.elm similarity index 65% rename from src/Page/Explore/Countries.elm rename to src/Page/Explore/Geozones.elm index f2dc5ab7fb..1daef2a9cc 100644 --- a/src/Page/Explore/Countries.elm +++ b/src/Page/Explore/Geozones.elm @@ -1,7 +1,7 @@ -module Page.Explore.Countries exposing (table) +module Page.Explore.Geozones exposing (table) -import Data.Country as Country exposing (Country) import Data.Dataset as Dataset +import Data.Geozone as Geozone exposing (Geozone) import Data.Gitbook as Gitbook import Data.Process as Process import Data.Scope as Scope exposing (Scope) @@ -18,25 +18,25 @@ import Views.Icon as Icon import Views.Link as Link -table : Transport.Distances -> List Country.Country -> { detailed : Bool, scope : Scope } -> Table Country String msg -table distances countries { detailed, scope } = - { filename = "countries" - , toId = .code >> Country.codeToString - , toRoute = .code >> Just >> Dataset.Countries >> Route.Explore scope +table : Transport.Distances -> List Geozone.Geozone -> { detailed : Bool, scope : Scope } -> Table Geozone String msg +table distances geozones { detailed, scope } = + { filename = "geozones" + , toId = .code >> Geozone.codeToString + , toRoute = .code >> Just >> Dataset.Geozones >> Route.Explore scope , legend = [] , columns = List.filterMap identity [ Just { label = "Code" - , toValue = Table.StringValue <| .code >> Country.codeToString + , toValue = Table.StringValue <| .code >> Geozone.codeToString , toCell = - \country -> + \geozone -> if detailed then - code [] [ text (Country.codeToString country.code) ] + code [] [ text (Geozone.codeToString geozone.code) ] else - a [ Route.href (Route.Explore scope (Dataset.Countries (Just country.code))) ] - [ code [] [ text (Country.codeToString country.code) ] ] + a [ Route.href (Route.Explore scope (Dataset.Geozones (Just geozone.code))) ] + [ code [] [ text (Geozone.codeToString geozone.code) ] ] } , Just { label = "Nom" @@ -44,7 +44,7 @@ table distances countries { detailed, scope } = , toCell = .name >> text } , Just - { label = "Mix éléctrique" + { label = "Mix électrique" , toValue = Table.StringValue <| .electricityProcess >> Process.getDisplayName , toCell = .electricityProcess >> Process.getDisplayName >> text } @@ -56,11 +56,11 @@ table distances countries { detailed, scope } = , if scope == Scope.Textile then Just { label = "Taux de pollution aquatique" - , toValue = Table.FloatValue (.aquaticPollutionScenario >> Country.getAquaticPollutionRatio >> Split.toPercent) + , toValue = Table.FloatValue (.aquaticPollutionScenario >> Geozone.getAquaticPollutionRatio >> Split.toPercent) , toCell = - \country -> + \geozone -> div [ classList [ ( "text-end", not detailed ) ] ] - [ Format.splitAsPercentage 2 (Country.getAquaticPollutionRatio country.aquaticPollutionScenario) + [ Format.splitAsPercentage 2 (Geozone.getAquaticPollutionRatio geozone.aquaticPollutionScenario) , Link.smallPillExternal [ href (Gitbook.publicUrlFromPath Gitbook.TextileEnnoblingCountriesAquaticPollution) ] [ Icon.info ] @@ -73,7 +73,7 @@ table distances countries { detailed, scope } = Just { label = "Distances" , toValue = Table.StringValue <| always "" - , toCell = displayDistances countries distances + , toCell = displayDistances geozones distances } else @@ -82,17 +82,17 @@ table distances countries { detailed, scope } = } -displayDistances : List Country.Country -> Transport.Distances -> Country -> Html msg -displayDistances countries distances country = - case Dict.get country.code distances of - Just countryDistances -> - countryDistances - |> Dict.foldl (distancesToRows countries) [] +displayDistances : List Geozone.Geozone -> Transport.Distances -> Geozone -> Html msg +displayDistances geozones distances geozone = + case Dict.get geozone.code distances of + Just geozoneDistances -> + geozoneDistances + |> Dict.foldl (distancesToRows geozones) [] |> (\rows -> Html.table [ class "table table-striped table-hover text-center w-100" ] [ thead [] [ tr [] - [ th [] [ text "Code pays" ] + [ th [] [ text "Zone" ] , th [] [ text "Aérien" ] , th [] [ text "Routier" ] , th [] [ text "Maritime" ] @@ -107,14 +107,14 @@ displayDistances countries distances country = text "" -distancesToRows : List Country.Country -> Country.Code -> Transport.Transport -> List (Html msg) -> List (Html msg) -distancesToRows countries countryCode transport rows = +distancesToRows : List Geozone.Geozone -> Geozone.Code -> Transport.Transport -> List (Html msg) -> List (Html msg) +distancesToRows geozones geozoneCode transport rows = rows - |> (::) (transportToRow countryCode countries transport) + |> (::) (transportToRow geozoneCode geozones transport) -transportToRow : Country.Code -> List Country.Country -> Transport.Transport -> Html msg -transportToRow countryCode countries transport = +transportToRow : Geozone.Code -> List Geozone.Geozone -> Transport.Transport -> Html msg +transportToRow geozoneCode geozones transport = let formatDistance length = if length == Quantity.zero then @@ -125,12 +125,12 @@ transportToRow countryCode countries transport = in tr [] [ td - [ Country.findByCode countryCode countries + [ Geozone.findByCode geozoneCode geozones |> Result.map .name |> Result.withDefault "" |> title ] - [ text <| Country.codeToString countryCode ] + [ text <| Geozone.codeToString geozoneCode ] , td [] [ formatDistance transport.air ] , td [] [ formatDistance transport.road ] , td [] [ formatDistance transport.sea ] diff --git a/src/Page/Explore/TextileMaterials.elm b/src/Page/Explore/TextileMaterials.elm index caaf7607f9..9c693e6861 100644 --- a/src/Page/Explore/TextileMaterials.elm +++ b/src/Page/Explore/TextileMaterials.elm @@ -1,7 +1,7 @@ module Page.Explore.TextileMaterials exposing (table) -import Data.Country as Country import Data.Dataset as Dataset +import Data.Geozone as Geozone import Data.Gitbook as Gitbook import Data.Process as Process import Data.Scope exposing (Scope) @@ -107,17 +107,17 @@ table db { detailed, scope } = , toValue = Table.StringValue .geographicOrigin , toCell = .geographicOrigin >> text } - , { label = "Pays de production et de filature par défaut" + , { label = "Zone géographique de production et de filature par défaut" , toValue = Table.StringValue <| - .defaultCountry - >> (\maybeCountry -> Country.findByCode maybeCountry db.countries) + .defaultGeozone + >> (\maybeGeozone -> Geozone.findByCode maybeGeozone db.geozones) >> Result.map .name >> Result.toMaybe >> Maybe.withDefault "error" , toCell = \material -> - case Country.findByCode material.defaultCountry db.countries of + case Geozone.findByCode material.defaultGeozone db.geozones of Err error -> Alert.simple { attributes = [] @@ -127,8 +127,8 @@ table db { detailed, scope } = , content = [ text error ] } - Ok country -> - text country.name + Ok geozone -> + text geozone.name } , { label = "CFF: Coefficient d'allocation" , toValue = diff --git a/src/Page/Food.elm b/src/Page/Food.elm index fb262f8056..135b42833c 100644 --- a/src/Page/Food.elm +++ b/src/Page/Food.elm @@ -525,7 +525,7 @@ updateExistingIngredient query model session oldRecipeIngredient newIngredient = ingredientQuery = { id = newIngredient.id , mass = oldRecipeIngredient.mass - , country = Nothing + , geozone = Nothing , planeTransport = Ingredient.byPlaneByDefault newIngredient } in @@ -677,20 +677,20 @@ createElementSelectorConfig db ingredientQuery { excluded, recipeIngredient, imp baseElement = { element = recipeIngredient.ingredient , quantity = recipeIngredient.mass - , country = recipeIngredient.country + , geozone = recipeIngredient.geozone } in { allowEmptyList = True , baseElement = baseElement , db = { elements = db.food.ingredients - , countries = - db.countries + , geozones = + db.geozones |> Scope.anyOf [ Scope.Food ] |> List.sortBy .name , definitions = db.definitions } - , defaultCountry = Origin.toLabel recipeIngredient.ingredient.defaultOrigin + , defaultGeozone = Origin.toLabel recipeIngredient.ingredient.defaultOrigin , delete = \element -> DeleteIngredient element.id , excluded = db.food.ingredients @@ -714,7 +714,7 @@ createElementSelectorConfig db ingredientQuery { excluded, recipeIngredient, imp { ingredientQuery | id = newElement.element.id , mass = newElement.quantity - , country = Maybe.map .code newElement.country + , geozone = Maybe.map .code newElement.geozone } } @@ -726,7 +726,7 @@ updateIngredientFormView db ({ recipeIngredient, selectedImpact, transportImpact ingredientQuery = { id = recipeIngredient.ingredient.id , mass = recipeIngredient.mass - , country = recipeIngredient.country |> Maybe.map .code + , geozone = recipeIngredient.geozone |> Maybe.map .code , planeTransport = recipeIngredient.planeTransport } diff --git a/src/Page/Object.elm b/src/Page/Object.elm index 370afc7280..f2da01ad37 100644 --- a/src/Page/Object.elm +++ b/src/Page/Object.elm @@ -14,10 +14,10 @@ import Browser.Events import Browser.Navigation as Navigation import Data.Bookmark as Bookmark exposing (Bookmark) import Data.Component as Component exposing (Component, Index, TargetElement, TargetItem) -import Data.Country as Country import Data.Dataset as Dataset import Data.Env as Env import Data.Example as Example exposing (Example) +import Data.Geozone as Geozone import Data.Impact as Impact import Data.Impact.Definition as Definition exposing (Definition) import Data.Key as Key @@ -111,7 +111,7 @@ type Msg | SwitchImpactsTab ImpactTabs.Tab | ToggleComparedSimulation Bookmark Bool | UpdateBookmarkName String - | UpdateComponentItemCountry Index (Maybe Country.Code) + | UpdateComponentItemGeozone Index (Maybe Geozone.Code) | UpdateComponentItemName TargetItem String | UpdateComponentItemQuantity Index Component.Quantity | UpdateDurability (Result String Unit.Ratio) @@ -496,12 +496,12 @@ update ({ navKey } as session) msg model = { model | bookmarkName = newName } |> App.createUpdate session - ( UpdateComponentItemCountry itemIndex country, _ ) -> + ( UpdateComponentItemGeozone itemIndex geozone, _ ) -> App.createUpdate session model |> updateQuery (query |> Query.updateComponents - (Component.updateItem itemIndex (\item -> { item | country = country })) + (Component.updateItem itemIndex (\item -> { item | geozone = geozone })) ) |> App.withCmds [ Plausible.send session <| Plausible.ComponentUpdated model.scope ] @@ -665,7 +665,7 @@ simulatorView session model = , setDetailed = SetDetailedComponents , title = "Production des composants" , updateElementAmount = UpdateElementAmount - , updateItemCountry = UpdateComponentItemCountry + , updateItemGeozone = UpdateComponentItemGeozone , updateItemName = UpdateComponentItemName , updateItemQuantity = UpdateComponentItemQuantity } diff --git a/src/Page/Textile.elm b/src/Page/Textile.elm index a9cd6e5f46..6788321d98 100644 --- a/src/Page/Textile.elm +++ b/src/Page/Textile.elm @@ -16,9 +16,9 @@ import Browser.Navigation as Navigation import Data.AutocompleteSelector as AutocompleteSelector import Data.Bookmark as Bookmark exposing (Bookmark) import Data.Component as Component exposing (Component, Index) -import Data.Country as Country import Data.Dataset as Dataset import Data.Example as Example +import Data.Geozone as Geozone import Data.Gitbook as Gitbook import Data.Impact as Impact import Data.Impact.Definition as Definition exposing (Definition) @@ -157,7 +157,7 @@ type Msg | UpdatePrice (Maybe Economics.Price) | UpdatePrinting (Maybe Printing) | UpdateRenamedBookmarkName Bookmark String - | UpdateStepCountry Label Country.Code + | UpdateStepGeozone Label Geozone.Code | UpdateSurfaceMass (Maybe Unit.SurfaceMass) | UpdateTrimQuantity Index Component.Quantity | UpdateUpcycled Bool @@ -616,9 +616,9 @@ update ({ db, queries, navKey } as session) msg model = { model | bookmarkBeingRenamed = Just { bookmark | name = name } } |> App.createUpdate session - ( UpdateStepCountry label code, _ ) -> + ( UpdateStepGeozone label code, _ ) -> App.createUpdate session model - |> updateQuery (Query.updateStepCountry label code query) + |> updateQuery (Query.updateStepGeozone label code query) ( UpdateSurfaceMass surfaceMass, _ ) -> App.createUpdate session model @@ -659,7 +659,7 @@ updateExistingMaterial query pageUpdate oldMaterial newMaterial = { id = newMaterial.id , share = oldMaterial.share , spinning = Nothing - , country = Nothing + , geozone = Nothing } in pageUpdate @@ -889,7 +889,7 @@ lifeCycleStepsView db { activeTab, impact } simulator = , setModal = SetModal , toggleFading = ToggleFading , toggleStep = ToggleStep - , updateCountry = UpdateStepCountry + , updateGeozone = UpdateStepGeozone , updateAirTransportRatio = UpdateAirTransportRatio , updateDyeingProcessType = UpdateDyeingProcessType , updateMaterial = UpdateMaterial @@ -983,7 +983,7 @@ simulatorFormView session model ({ inputs } as simulator) = , setDetailed = \_ -> NoOp , title = "Accessoires" , updateElementAmount = \_ _ -> NoOp - , updateItemCountry = \_ _ -> NoOp + , updateItemGeozone = \_ _ -> NoOp , updateItemName = \_ _ -> NoOp , updateItemQuantity = UpdateTrimQuantity } diff --git a/src/Server.elm b/src/Server.elm index 8b08f4a0dd..5fa9553b62 100644 --- a/src/Server.elm +++ b/src/Server.elm @@ -6,11 +6,11 @@ port module Server exposing ) import Data.Component as Component exposing (Component) -import Data.Country as Country exposing (Country) import Data.Food.Ingredient as Ingredient import Data.Food.Origin as Origin import Data.Food.Query as FoodQuery import Data.Food.Recipe as Recipe +import Data.Geozone as Geozone exposing (Geozone) import Data.Impact as Impact import Data.Impact.Definition as Definition import Data.Process as Process exposing (Process) @@ -166,10 +166,10 @@ executeTextileQuery request db encoder query = |> Result.withDefault ( 500, Encode.string "Impossible de charger la configuration des composants" ) -encodeCountry : Country -> Encode.Value -encodeCountry { code, name } = +encodeGeozone : Geozone -> Encode.Value +encodeGeozone { code, name } = Encode.object - [ ( "code", Country.encodeCode code ) + [ ( "code", Geozone.encodeCode code ) , ( "name", Encode.string name ) ] @@ -243,10 +243,10 @@ handleRequest : Db -> Request -> JsonResponse handleRequest db request = case Route.endpoint db request of -- GET routes - Just Route.FoodGetCountryList -> - db.countries + Just Route.FoodGetGeozoneList -> + db.geozones |> Scope.anyOf [ Scope.Food ] - |> Encode.list encodeCountry + |> Encode.list encodeGeozone |> respondWith 200 Just Route.FoodGetIngredientList -> @@ -268,10 +268,10 @@ handleRequest db request = |> encodeProcessList |> respondWith 200 - Just Route.TextileGetCountryList -> - db.countries + Just Route.TextileGetGeozoneList -> + db.geozones |> Scope.anyOf [ Scope.Textile ] - |> Encode.list encodeCountry + |> Encode.list encodeGeozone |> respondWith 200 Just Route.TextileGetMaterialList -> diff --git a/src/Server/Route.elm b/src/Server/Route.elm index 1d11962cbd..1e778a321d 100644 --- a/src/Server/Route.elm +++ b/src/Server/Route.elm @@ -27,8 +27,8 @@ ExpressJS server directly (see server.js). type Route = -- Food Routes -- GET - -- Food country list - FoodGetCountryList + -- Food geozone list + FoodGetGeozoneList -- Food ingredient list | FoodGetIngredientList -- Food packaging list @@ -41,8 +41,8 @@ type Route -- -- Textile Routes -- GET - -- Textile country list - | TextileGetCountryList + -- Textile geozone list + | TextileGetGeozoneList -- Textile Material list | TextileGetMaterialList -- Textile Product list @@ -62,8 +62,8 @@ parser : Db -> Encode.Value -> Parser (Route -> a) a parser db body = Parser.oneOf [ -- Food - (s "GET" s "food" s "countries") - |> Parser.map FoodGetCountryList + (s "GET" s "food" s "geozones") + |> Parser.map FoodGetGeozoneList , (s "GET" s "food" s "ingredients") |> Parser.map FoodGetIngredientList , (s "GET" s "food" s "transforms") @@ -74,8 +74,8 @@ parser db body = |> Parser.map (FoodPostRecipe (decodeFoodQueryBody db body)) -- Textile - , (s "GET" s "textile" s "countries") - |> Parser.map TextileGetCountryList + , (s "GET" s "textile" s "geozones") + |> Parser.map TextileGetGeozoneList , (s "GET" s "textile" s "materials") |> Parser.map TextileGetMaterialList , (s "GET" s "textile" s "products") diff --git a/src/Static/Db.elm b/src/Static/Db.elm index cc08e75a6c..8f2da31a05 100644 --- a/src/Static/Db.elm +++ b/src/Static/Db.elm @@ -5,8 +5,8 @@ module Static.Db exposing import Data.Common.Db as Common import Data.Component as Component exposing (Component) -import Data.Country exposing (Country) import Data.Food.Db as FoodDb +import Data.Geozone exposing (Geozone) import Data.Impact as Impact import Data.Impact.Definition exposing (Definitions) import Data.Object.Db as ObjectDb @@ -20,10 +20,10 @@ import Static.Json as StaticJson type alias Db = { components : List Component - , countries : List Country , definitions : Definitions , distances : Distances , food : FoodDb.Db + , geozones : List Geozone , object : ObjectDb.Db , processes : List Process , textile : TextileDb.Db @@ -38,7 +38,6 @@ db = (\processes -> Ok Db |> RE.andMap (decodeRawComponents StaticJson.rawJsonComponents) - |> RE.andMap (countries processes) |> RE.andMap impactDefinitions |> RE.andMap distances |> RE.andMap @@ -47,6 +46,7 @@ db = StaticJson.foodProductExamplesJson StaticJson.foodIngredientsJson ) + |> RE.andMap (geozones processes) |> RE.andMap (ObjectDb.buildFromJson StaticJson.objectExamplesJson @@ -81,9 +81,9 @@ impactDefinitions = Common.impactsFromJson StaticJson.impactsJson -countries : List Process -> Result String (List Country) -countries processes = - Common.countriesFromJson processes StaticJson.countriesJson +geozones : List Process -> Result String (List Geozone) +geozones processes = + Common.geozonesFromJson processes StaticJson.geozonesJson distances : Result String Distances diff --git a/src/Static/Json.elm-template b/src/Static/Json.elm-template index 7ca3da372b..8d522de5fe 100644 --- a/src/Static/Json.elm-template +++ b/src/Static/Json.elm-template @@ -1,6 +1,6 @@ module Static.Json exposing ( RawJsonComponents - , countriesJson + , geozonesJson , foodIngredientsJson , foodProductExamplesJson , impactsJson @@ -22,9 +22,9 @@ type alias RawJsonComponents = } -countriesJson : String -countriesJson = - """%countriesJson%""" +geozonesJson : String +geozonesJson = + """%geozonesJson%""" foodProductExamplesJson : String diff --git a/src/Views/BaseElement.elm b/src/Views/BaseElement.elm index f75ad60597..0a61c64713 100644 --- a/src/Views/BaseElement.elm +++ b/src/Views/BaseElement.elm @@ -2,7 +2,7 @@ module Views.BaseElement exposing (Config, deleteItemButton, view) import Autocomplete exposing (Autocomplete) import Data.AutocompleteSelector as AutocompleteSelector -import Data.Country as Country exposing (Country) +import Data.Geozone as Geozone exposing (Geozone) import Data.Impact exposing (Impacts) import Data.Impact.Definition exposing (Definition, Definitions) import Html exposing (..) @@ -13,16 +13,16 @@ import Views.Icon as Icon type alias BaseElement element quantity = - { country : Maybe Country - , element : element + { element : element + , geozone : Maybe Geozone , quantity : quantity } type alias Db element = - { countries : List Country - , definitions : Definitions + { definitions : Definitions , elements : List element + , geozones : List Geozone } @@ -30,7 +30,7 @@ type alias Config element quantity msg = { allowEmptyList : Bool , baseElement : BaseElement element quantity , db : Db element - , defaultCountry : String + , defaultGeozone : String , delete : element -> msg , excluded : List element , impact : Impacts @@ -76,33 +76,33 @@ view ({ baseElement, db, impact } as config) = , autocompleteState |> config.selectElement baseElement.element |> selectorView config - , db.countries + , db.geozones |> List.sortBy .name |> List.map (\{ code, name } -> option - [ selected (Maybe.map .code baseElement.country == Just code) - , value <| Country.codeToString code + [ selected (Maybe.map .code baseElement.geozone == Just code) + , value <| Geozone.codeToString code ] [ text name ] ) |> (::) (option [ value "" - , selected (baseElement.country == Nothing) + , selected (baseElement.geozone == Nothing) ] - [ text <| "Par défaut (" ++ config.defaultCountry ++ ")" ] + [ text <| "Par défaut (" ++ config.defaultGeozone ++ ")" ] ) |> select - [ class "form-select form-select CountrySelector" + [ class "form-select form-select GeozoneSelector" , onInput (\val -> updateEvent { baseElement - | country = + | geozone = if val /= "" then - Country.codeFromString val - |> (\countryCode -> Country.findByCode countryCode db.countries) + Geozone.codeFromString val + |> (\geozoneCode -> Geozone.findByCode geozoneCode db.geozones) |> Result.toMaybe else diff --git a/src/Views/Component.elm b/src/Views/Component.elm index 9c1f066796..9c71f1e997 100644 --- a/src/Views/Component.elm +++ b/src/Views/Component.elm @@ -17,7 +17,7 @@ import Data.Component as Component , TargetElement , TargetItem ) -import Data.Country as Country exposing (Country) +import Data.Geozone as Geozone exposing (Geozone) import Data.Impact as Impact import Data.Impact.Definition as Definition exposing (Definition) import Data.Process as Process exposing (Process) @@ -63,7 +63,7 @@ type alias Config db msg = , setDetailed : List Index -> msg , title : String , updateElementAmount : TargetElement -> Maybe Amount -> msg - , updateItemCountry : Index -> Maybe Country.Code -> msg + , updateItemGeozone : Index -> Maybe Geozone.Code -> msg , updateItemName : TargetItem -> String -> msg , updateItemQuantity : Index -> Quantity -> msg } @@ -143,7 +143,7 @@ addElementTransformButton { db, items, openSelectProcessModal, scope } material componentView : Config db msg -> Index -> Item -> ExpandedItem -> Results -> List (Html msg) -componentView config itemIndex item { component, country, elements, quantity } itemResults = +componentView config itemIndex item { component, elements, geozone, quantity } itemResults = let collapsed = config.detailed @@ -193,7 +193,7 @@ componentView config itemIndex item { component, country, elements, quantity } i |> value ] [] - , config.db.countries + , config.db.geozones |> Scope.anyOf [ config.scope ] |> List.sortBy .name |> List.map (\{ code, name } -> ( name, Just code )) @@ -202,10 +202,10 @@ componentView config itemIndex item { component, country, elements, quantity } i (\( name, maybeCode ) -> option [ maybeCode - |> Maybe.map Country.codeToString + |> Maybe.map Geozone.codeToString |> Maybe.withDefault "" |> value - , selected <| Maybe.map .code country == maybeCode + , selected <| Maybe.map .code geozone == maybeCode ] [ text name ] ) @@ -213,12 +213,12 @@ componentView config itemIndex item { component, country, elements, quantity } i [ class "form-select w-33" , onInput <| \str -> - config.updateItemCountry itemIndex + config.updateItemGeozone itemIndex (if String.isEmpty str then Nothing else - Just <| Country.codeFromString str + Just <| Geozone.codeFromString str ) ] ] @@ -455,7 +455,7 @@ amountInput config targetElement unit amount = elementView : Config db msg -> TargetItem -> Index -> ExpandedElement -> Results -> Html msg -elementView config targetItem elementIndex { amount, country, material, transforms } elementResults = +elementView config targetItem elementIndex { amount, geozone, material, transforms } elementResults = let ( materialResults, transformsResults ) = case Component.extractItems elementResults of @@ -486,7 +486,7 @@ elementView config targetItem elementIndex { amount, country, material, transfor , th [] [] ] :: elementMaterialView config ( targetItem, elementIndex ) materialResults material amount - :: elementTransformsView config ( targetItem, elementIndex ) country transformsResults transforms + :: elementTransformsView config ( targetItem, elementIndex ) geozone transformsResults transforms ++ (if config.scope /= Scope.Textile then [ tr [] [ td [ colspan 2 ] [] @@ -559,15 +559,15 @@ elementMaterialView config targetElement materialResults material amount = ] -elementTransformsView : Config db msg -> TargetElement -> Maybe Country -> List Results -> List Process -> List (Html msg) -elementTransformsView config targetElement maybeCountry transformsResults transforms = +elementTransformsView : Config db msg -> TargetElement -> Maybe Geozone -> List Results -> List Process -> List (Html msg) +elementTransformsView config targetElement maybeGeozone transformsResults transforms = List.map3 (\transformIndex transformResult transform -> let tooltipText = "Procédé\u{00A0}: " ++ Process.getDisplayName transform - ++ (Component.loadEnergyMixes config.db.processes maybeCountry + ++ (Component.loadEnergyMixes config.db.processes maybeGeozone |> Result.map (\{ elec, heat } -> "\nÉlectricité\u{00A0}: " diff --git a/src/Views/CountrySelect.elm b/src/Views/GeozoneSelect.elm similarity index 56% rename from src/Views/CountrySelect.elm rename to src/Views/GeozoneSelect.elm index 8dd670c7c6..f6db660977 100644 --- a/src/Views/CountrySelect.elm +++ b/src/Views/GeozoneSelect.elm @@ -1,6 +1,6 @@ -module Views.CountrySelect exposing (view) +module Views.GeozoneSelect exposing (view) -import Data.Country as Country exposing (Country) +import Data.Geozone as Geozone exposing (Geozone) import Data.Scope as Scope exposing (Scope) import Html exposing (..) import Html.Attributes exposing (..) @@ -9,29 +9,29 @@ import Html.Events exposing (..) type alias Config msg = { attributes : List (Attribute msg) - , countries : List Country - , onSelect : Country.Code -> msg + , geozones : List Geozone + , onSelect : Geozone.Code -> msg , scope : Scope - , selectedCountry : Country.Code + , selectedGeozone : Geozone.Code } view : Config msg -> Html msg -view { attributes, countries, onSelect, scope, selectedCountry } = - countries +view { attributes, geozones, onSelect, scope, selectedGeozone } = + geozones |> Scope.anyOf [ scope ] |> List.sortBy .name |> List.map (\{ code, name } -> option - [ selected (selectedCountry == code) - , value <| Country.codeToString code + [ selected (selectedGeozone == code) + , value <| Geozone.codeToString code ] [ text name ] ) |> select (class "form-select" - :: onInput (Country.codeFromString >> onSelect) + :: onInput (Geozone.codeFromString >> onSelect) :: attributes ) diff --git a/src/Views/Textile/Step.elm b/src/Views/Textile/Step.elm index 745918b3cb..a76c651c75 100644 --- a/src/Views/Textile/Step.elm +++ b/src/Views/Textile/Step.elm @@ -2,9 +2,9 @@ module Views.Textile.Step exposing (view) import Autocomplete exposing (Autocomplete) import Data.AutocompleteSelector as AutocompleteSelector -import Data.Country as Country import Data.Dataset as Dataset import Data.Env as Env +import Data.Geozone as Geozone import Data.Gitbook as Gitbook import Data.Impact as Impact exposing (noComplementsImpacts) import Data.Impact.Definition as Definition exposing (Definition) @@ -41,8 +41,8 @@ import Views.Button as Button import Views.ComplementsDetails as ComplementsDetails import Views.Component.SplitInput as SplitInput import Views.Component.StepsBorder as StepsBorder -import Views.CountrySelect as CountrySelect import Views.Format as Format +import Views.GeozoneSelect as GeozoneSelect import Views.Icon as Icon import Views.Link as Link import Views.RangeSlider as RangeSlider @@ -65,9 +65,9 @@ type alias Config msg modal = , toggleFading : Bool -> msg , toggleStep : Label -> msg , updateAirTransportRatio : Maybe Split -> msg - , updateCountry : Label -> Country.Code -> msg , updateDyeingProcessType : ProcessType -> msg , updateFabricProcess : Fabric -> msg + , updateGeozone : Label -> Geozone.Code -> msg , updateMakingComplexity : MakingComplexity -> msg , updateMakingDeadStock : Maybe Split -> msg , updateMakingWaste : Maybe Split -> msg @@ -84,30 +84,30 @@ type alias ViewWithTransport msg = { step : Html msg, transport : Html msg } -countryField : Config msg modal -> Html msg -countryField { current, db, updateCountry } = +geozoneField : Config msg modal -> Html msg +geozoneField { current, db, updateGeozone } = div [] [ if current.editable then - CountrySelect.view + GeozoneSelect.view { attributes = [ class "form-select" , disabled (not current.enabled) - , onInput (Country.codeFromString >> updateCountry current.label) + , onInput (Geozone.codeFromString >> updateGeozone current.label) ] - , countries = db.countries - , onSelect = updateCountry current.label + , geozones = db.geozones + , onSelect = updateGeozone current.label , scope = Scope.Textile - , selectedCountry = current.country.code + , selectedGeozone = current.geozone.code } else div [ class "fs-6 text-muted d-flex align-items-center gap-2 " ] [ span [ class "cursor-help" - , title "Le pays n'est pas modifiable à cette étape" + , title "La zone géographique n'est pas modifiable à cette étape" ] [ Icon.lock ] - , text current.country.name + , text current.geozone.name ] ] @@ -517,14 +517,14 @@ viewMaterials config = |> List.map (\materialInput -> let - nextCountry = + nextGeozone = config.next |> Maybe.withDefault config.current - |> .country + |> .geozone transport = materialInput - |> Step.computeMaterialTransportAndImpact config.db nextCountry config.current.outputMass + |> Step.computeMaterialTransportAndImpact config.db nextGeozone config.current.outputMass in li [ class "ElementFormWrapper list-group-item" ] (List.concat @@ -662,15 +662,15 @@ createElementSelectorConfig cfg materialInput = let materialQuery : MaterialQuery materialQuery = - { country = materialInput.country |> Maybe.map .code + { geozone = materialInput.geozone |> Maybe.map .code , id = materialInput.material.id , share = materialInput.share , spinning = materialInput.spinning } baseElement = - { country = materialInput.country - , element = materialInput.material + { element = materialInput.material + , geozone = materialInput.geozone , quantity = materialInput.share } @@ -686,14 +686,14 @@ createElementSelectorConfig cfg materialInput = { allowEmptyList = False , baseElement = baseElement , db = - { countries = - cfg.db.countries + { definitions = cfg.db.definitions + , elements = cfg.db.textile.materials + , geozones = + cfg.db.geozones |> Scope.anyOf [ Scope.Textile ] |> List.sortBy .name - , definitions = cfg.db.definitions - , elements = cfg.db.textile.materials } - , defaultCountry = materialInput.material.geographicOrigin + , defaultGeozone = materialInput.material.geographicOrigin , delete = cfg.deleteMaterial , excluded = excluded , impact = impacts @@ -715,7 +715,7 @@ createElementSelectorConfig cfg materialInput = cfg.updateMaterial materialQuery { materialQuery - | country = newElement.country |> Maybe.map .code + | geozone = newElement.geozone |> Maybe.map .code , id = newElement.element.id , share = newElement.quantity } @@ -832,7 +832,7 @@ ennoblingToxicityView db ({ selectedImpact, inputs } as config) current = |> List.map (\{ material, share } -> Formula.materialDyeingToxicityImpacts current.impacts - { aquaticPollutionScenario = current.country.aquaticPollutionScenario + { aquaticPollutionScenario = current.geozone.aquaticPollutionScenario , dyeingToxicityProcess = if Origin.isSynthetic material.origin then db.textile.wellKnown.dyeingSynthetic @@ -855,7 +855,7 @@ ennoblingToxicityView db ({ selectedImpact, inputs } as config) current = in current.outputMass |> Formula.materialPrintingToxicityImpacts current.impacts - { aquaticPollutionScenario = current.country.aquaticPollutionScenario + { aquaticPollutionScenario = current.geozone.aquaticPollutionScenario , printingToxicityProcess = printingToxicityProcess , surfaceMass = inputs.surfaceMass |> Maybe.withDefault inputs.product.surfaceMass } @@ -1044,7 +1044,7 @@ regulatoryStepView ({ current } as config) = div [ class "StepBody card-body row align-items-center" ] [ div [ class "col-lg-7" ] - [ countryField config + [ geozoneField config , case current.label of Label.Ennobling -> div [ class "mt-2" ] @@ -1080,9 +1080,9 @@ advancedStepView ({ db, inputs, selectedImpact, current } as config) = div [ class "card-group" ] [ div [ class "card border-start-0 border-top-0 border-bottom-0" ] [ infoListElement - [ li [ class "list-group-item" ] [ countryField config ] - , viewProcessInfo <| Maybe.map ((++) "Elec : ") current.processInfo.countryElec - , viewProcessInfo <| Maybe.map ((++) "Chaleur : ") current.processInfo.countryHeat + [ li [ class "list-group-item" ] [ geozoneField config ] + , viewProcessInfo <| Maybe.map ((++) "Elec : ") current.processInfo.geozoneElec + , viewProcessInfo <| Maybe.map ((++) "Chaleur : ") current.processInfo.geozoneHeat , viewProcessInfo current.processInfo.distribution , viewProcessInfo current.processInfo.useIroning , viewProcessInfo current.processInfo.useNonIroning diff --git a/styles.scss b/styles.scss index 7de314360c..aab37dc476 100644 --- a/styles.scss +++ b/styles.scss @@ -800,7 +800,7 @@ q { grid-gap: 5px; grid-template-columns: 100px 35% 2fr 1fr 90px 31px; grid-template-areas: - "quantityInputWrapper elementSelector countrySelector countrySelector impactDisplay baseElementDelete" + "quantityInputWrapper elementSelector geozoneSelector geozoneSelector impactDisplay baseElementDelete" ". complements complements complements complements . " ". . transportDistances transportDistances transportImpact . "; align-items: center; @@ -810,7 +810,7 @@ q { grid-template-columns: 90px minmax(100px, 60%) 60px 31px; grid-template-areas: "quantityInputWrapper elementSelector impactDisplay impactDisplay " - "countrySelector countrySelector countrySelector baseElementDelete" + "geozoneSelector geozoneSelector geozoneSelector baseElementDelete" "complements complements complements complements " "transportDistances transportDistances transportImpact transportImpact "; } @@ -824,8 +824,8 @@ q { margin-right: 5px; } } - .CountrySelector { - grid-area: countrySelector; + .GeozoneSelector { + grid-area: geozoneSelector; } .ElementDelete { grid-area: baseElementDelete; diff --git a/tests/Data/ComponentTest.elm b/tests/Data/ComponentTest.elm index 931e57d854..0489e96113 100644 --- a/tests/Data/ComponentTest.elm +++ b/tests/Data/ComponentTest.elm @@ -622,7 +622,7 @@ suite = |> Expect.equal (Ok <| Just - { country = Nothing + { geozone = Nothing , custom = Nothing , id = testComponent.id , quantity = Component.quantityFromInt 1 diff --git a/tests/Data/Food/QueryTest.elm b/tests/Data/Food/QueryTest.elm index 8732c757d2..e9011644a7 100644 --- a/tests/Data/Food/QueryTest.elm +++ b/tests/Data/Food/QueryTest.elm @@ -14,15 +14,15 @@ suite = |> Decode.decodeString Query.decode |> Expect.err |> asTest "should fail on invalid JSON" - , """{"ingredients": [{"id":"db0e5f44-34b4-4160-b003-77c828d75e60","mass":500,"country":"BR"}],"transform":null,"packaging":[],"distribution":"ambient","preparation":[]}""" + , """{"ingredients": [{"id":"db0e5f44-34b4-4160-b003-77c828d75e60","mass":500,"geozone":"BR"}],"transform":null,"packaging":[],"distribution":"ambient","preparation":[]}""" |> Decode.decodeString Query.decode |> Expect.ok |> asTest "should decode a null transform" - , """{"ingredients": [{"id":"db0e5f44-34b4-4160-b003-77c828d75e60","mass":500,"country":"BR"}],"packaging":[],"distribution":"ambient","preparation":[]}""" + , """{"ingredients": [{"id":"db0e5f44-34b4-4160-b003-77c828d75e60","mass":500,"geozone":"BR"}],"packaging":[],"distribution":"ambient","preparation":[]}""" |> Decode.decodeString Query.decode |> Expect.ok |> asTest "should decode a missing transform" - , """{"ingredients": [{"id":"db0e5f44-34b4-4160-b003-77c828d75e60","mass":500,"country":"BR"}],"packaging":[],"distribution":"invalid","preparation":[]}""" + , """{"ingredients": [{"id":"db0e5f44-34b4-4160-b003-77c828d75e60","mass":500,"geozone":"BR"}],"packaging":[],"distribution":"invalid","preparation":[]}""" |> Decode.decodeString Query.decode |> Expect.err |> asTest "should fail an invalid distribution" diff --git a/tests/Data/Food/RecipeTest.elm b/tests/Data/Food/RecipeTest.elm index 4ff31c8405..35c480b693 100644 --- a/tests/Data/Food/RecipeTest.elm +++ b/tests/Data/Food/RecipeTest.elm @@ -1,11 +1,11 @@ module Data.Food.RecipeTest exposing (..) -import Data.Country as Country import Data.Example import Data.Food.Ingredient as Ingredient import Data.Food.Preparation as Preparation import Data.Food.Recipe as Recipe import Data.Food.Retail as Retail +import Data.Geozone as Geozone import Data.Impact as Impact import Data.Impact.Definition as Definition import Data.Unit as Unit @@ -211,12 +211,12 @@ suite = [ { ingredients = [ { id = eggId , mass = Mass.grams 120 - , country = Nothing + , geozone = Nothing , planeTransport = Ingredient.PlaneNotApplicable } , { id = wheatId , mass = Mass.grams 140 - , country = Nothing + , geozone = Nothing , planeTransport = Ingredient.PlaneNotApplicable } ] @@ -258,7 +258,7 @@ suite = mango = { id = mangoId , mass = Mass.grams 120 - , country = Nothing + , geozone = Nothing , planeTransport = Ingredient.ByPlane } @@ -274,7 +274,7 @@ suite = [ { ingredients = [ { id = eggId , mass = Mass.grams 120 - , country = Nothing + , geozone = Nothing , planeTransport = Ingredient.PlaneNotApplicable } ] @@ -297,7 +297,7 @@ suite = |> Result.map firstIngredientAirDistance |> Expect.equal (Ok (Just 18000)) |> asTest "should have air transport for mango from its default origin" - , { ingredients = [ { mango | country = Just (Country.codeFromString "CN"), planeTransport = Ingredient.ByPlane } ] + , { ingredients = [ { mango | geozone = Just (Geozone.codeFromString "CN"), planeTransport = Ingredient.ByPlane } ] , transform = Nothing , packaging = [] , distribution = Just Retail.ambient @@ -306,8 +306,8 @@ suite = |> Recipe.compute db |> Result.map firstIngredientAirDistance |> Expect.equal (Ok (Just 8189)) - |> asTest "should always have air transport for mango even from other countries if 'planeTransport' is 'byPlane'" - , { ingredients = [ { mango | country = Just (Country.codeFromString "CN"), planeTransport = Ingredient.NoPlane } ] + |> asTest "should always have air transport for mango even from other geographical zones if 'planeTransport' is 'byPlane'" + , { ingredients = [ { mango | geozone = Just (Geozone.codeFromString "CN"), planeTransport = Ingredient.NoPlane } ] , transform = Nothing , packaging = [] , distribution = Just Retail.ambient @@ -316,7 +316,7 @@ suite = |> Recipe.compute db |> Result.map firstIngredientAirDistance |> Expect.equal (Ok (Just 0)) - |> asTest "should not have air transport for mango from other countries if 'planeTransport' is 'noPlane'" + |> asTest "should not have air transport for mango from other geographical zones if 'planeTransport' is 'noPlane'" ] ] diff --git a/tests/Data/Textile/FormulaTest.elm b/tests/Data/Textile/FormulaTest.elm index 0b0b7e7775..a5122c8013 100644 --- a/tests/Data/Textile/FormulaTest.elm +++ b/tests/Data/Textile/FormulaTest.elm @@ -58,14 +58,14 @@ suite = defaultImpacts { makingComplexity = MakingComplexity.Medium , fadingProcess = Nothing - , countryElecProcess = + , geozoneElecProcess = { sampleProcess | impacts = Impact.empty |> Impact.updateImpact db.definitions Definition.Cch (Unit.impact 0.5) |> Impact.updateImpact db.definitions Definition.Fwe (Unit.impact 1.5) } - , countryHeatProcess = + , geozoneHeatProcess = { sampleProcess | impacts = Impact.empty @@ -78,16 +78,16 @@ suite = |> Impact.getImpact Definition.Cch |> Unit.impactToFloat |> Expect.within (Expect.Absolute 0.01) 0.435 - |> asTest "should compute Making step cch from process and country data" + |> asTest "should compute Making step cch from process and geozone data" , res.impacts |> Impact.getImpact Definition.Fwe |> Unit.impactToFloat |> Expect.within (Expect.Absolute 0.01) 1.305 - |> asTest "should compute Making step fwe from process and country data" + |> asTest "should compute Making step fwe from process and geozone data" , res.kwh |> Energy.inKilowattHours |> Expect.within (Expect.Absolute 0.01) 0.87 - |> asTest "should compute Making step kwh from process and country data" + |> asTest "should compute Making step kwh from process and geozone data" ] ) , describe "Formula.weavingImpact" @@ -95,7 +95,7 @@ suite = res = Formula.weavingImpacts defaultImpacts - { countryElecProcess = + { geozoneElecProcess = { sampleProcess | impacts = Impact.empty @@ -135,7 +135,7 @@ suite = |> Formula.knittingImpacts defaultImpacts { elec = Energy.kilowattHours 5 - , countryElecProcess = + , geozoneElecProcess = { sampleProcess | impacts = Impact.empty diff --git a/tests/Data/Textile/InputsTest.elm b/tests/Data/Textile/InputsTest.elm index 0ee146ae60..13293946d6 100644 --- a/tests/Data/Textile/InputsTest.elm +++ b/tests/Data/Textile/InputsTest.elm @@ -1,6 +1,6 @@ module Data.Textile.InputsTest exposing (..) -import Data.Country as Country +import Data.Geozone as Geozone import Data.Split as Split import Data.Textile.Inputs as Inputs import Data.Textile.Material as Material @@ -16,30 +16,30 @@ suite : Test suite = suiteWithDb "Data.Inputs" (\db -> - [ describe "Query countries validation" - [ suiteFromResult "should replace the first country with the material's default country" + [ describe "Query geographical zones validation" + [ suiteFromResult "should replace the first geographical zone with the material's default geographical zone" tShirtCotonFrance (\query -> [ { query - | countryFabric = Just (Country.Code "CN") - , countryDyeing = Just (Country.Code "CN") - , countryMaking = Just (Country.Code "CN") + | geozoneFabric = Just (Geozone.Code "CN") + , geozoneDyeing = Just (Geozone.Code "CN") + , geozoneMaking = Just (Geozone.Code "CN") } |> Inputs.fromQuery db - |> Result.map Inputs.countryList + |> Result.map Inputs.geozoneList |> Result.andThen (LE.getAt 0 >> Maybe.map .code >> Result.fromMaybe "") - |> Expect.equal (Ok (Country.codeFromString "CN")) - |> asTest "replace the first country with the material's default country" + |> Expect.equal (Ok (Geozone.codeFromString "CN")) + |> asTest "replace the first geographical zone with the material's default geographical zone" ] ) , { default - | countryFabric = Just (Country.Code "XX") - , countryDyeing = Just (Country.Code "CN") - , countryMaking = Just (Country.Code "CN") + | geozoneFabric = Just (Geozone.Code "XX") + , geozoneDyeing = Just (Geozone.Code "CN") + , geozoneMaking = Just (Geozone.Code "CN") } |> Inputs.fromQuery db - |> Expect.equal (Err "Code pays invalide: XX.") - |> asTest "validate country codes" + |> Expect.equal (Err "Code de zone géographique invalide: XX.") + |> asTest "validate geographical zone codes" ] , let testComplementEqual x = @@ -68,12 +68,12 @@ suite = [ { id = cottonId , share = Split.half , spinning = Nothing - , country = Nothing + , geozone = Nothing } , { id = syntheticId , share = Split.half , spinning = Nothing - , country = Nothing + , geozone = Nothing } ] } @@ -109,12 +109,12 @@ suite = [ { id = cottonId , share = Split.half , spinning = Nothing - , country = Nothing + , geozone = Nothing } , { id = syntheticId , share = Split.half , spinning = Nothing - , country = Nothing + , geozone = Nothing } ] } diff --git a/tests/Data/Textile/LifeCycleTest.elm b/tests/Data/Textile/LifeCycleTest.elm index 6bb70fd60a..b119d17e9f 100644 --- a/tests/Data/Textile/LifeCycleTest.elm +++ b/tests/Data/Textile/LifeCycleTest.elm @@ -1,6 +1,6 @@ module Data.Textile.LifeCycleTest exposing (..) -import Data.Country as Country +import Data.Geozone as Geozone import Data.Textile.Inputs as Inputs import Data.Textile.LifeCycle as LifeCycle exposing (LifeCycle) import Data.Textile.Query exposing (Query) @@ -43,9 +43,9 @@ suite = |> Result.map (\query -> { query - | countryFabric = Just (Country.Code "FR") - , countryDyeing = Just (Country.Code "IN") -- Ennoblement in India - , countryMaking = Just (Country.Code "FR") + | geozoneFabric = Just (Geozone.Code "FR") + , geozoneDyeing = Just (Geozone.Code "IN") -- Ennoblement in India + , geozoneMaking = Just (Geozone.Code "FR") } ) in diff --git a/tests/Data/Textile/QueryTest.elm b/tests/Data/Textile/QueryTest.elm index 9eb7ed3e9d..5a1189f54e 100644 --- a/tests/Data/Textile/QueryTest.elm +++ b/tests/Data/Textile/QueryTest.elm @@ -1,6 +1,6 @@ module Data.Textile.QueryTest exposing (..) -import Data.Country as Country +import Data.Geozone as Geozone import Data.Split as Split import Data.Textile.Inputs as Inputs import Data.Textile.MakingComplexity as MakingComplexity @@ -21,7 +21,7 @@ sampleQuery = [ { id = polyesterId , share = Split.full , spinning = Nothing - , country = Just (Country.Code "CN") + , geozone = Just (Geozone.Code "CN") } ] } @@ -111,7 +111,7 @@ suite = [ [ { id = id , share = Split.tenth , spinning = Nothing - , country = Nothing + , geozone = Nothing } ] |> Query.validateMaterials @@ -124,16 +124,16 @@ suite = (Material.idFromString "73ef624d-250e-4a9a-af5d-43505b21b527") (\cottonId syntheticId -> [ [ { id = cottonId - , share = Split.half - , spinning = Nothing - , country = Nothing - } - , { id = syntheticId - , share = Split.half - , spinning = Nothing - , country = Nothing - } - ] + , share = Split.half + , spinning = Nothing + , geozone = Nothing + } + , { id = syntheticId + , share = Split.half + , spinning = Nothing + , geozone = Nothing + } + ] |> Query.validateMaterials |> Expect.ok |> asTest "validates complete sum of materials" @@ -146,21 +146,21 @@ suite = (Material.idFromString "62a4d6fb-3276-4ba5-93a3-889ecd3bff84") (\polyesterId polypropyleneId cottonId -> [ [ { id = polyesterId - , share = Split.sixty - , spinning = Nothing - , country = Nothing - } - , { id = polypropyleneId - , share = Split.thirty - , spinning = Nothing - , country = Nothing - } - , { id = cottonId - , share = Split.tenth - , spinning = Nothing - , country = Nothing - } - ] + , share = Split.sixty + , spinning = Nothing + , geozone = Nothing + } + , { id = polypropyleneId + , share = Split.thirty + , spinning = Nothing + , geozone = Nothing + } + , { id = cottonId + , share = Split.tenth + , spinning = Nothing + , geozone = Nothing + } + ] |> Query.validateMaterials |> Expect.ok |> asTest "validates complete sum of materials with rounding error" diff --git a/tests/Data/Textile/SimulatorTest.elm b/tests/Data/Textile/SimulatorTest.elm index 2b566e9d86..620c398c47 100644 --- a/tests/Data/Textile/SimulatorTest.elm +++ b/tests/Data/Textile/SimulatorTest.elm @@ -1,7 +1,7 @@ module Data.Textile.SimulatorTest exposing (..) import Data.Component as Component -import Data.Country as Country +import Data.Geozone as Geozone import Data.Impact as Impact import Data.Impact.Definition as Definition import Data.Split as Split @@ -66,7 +66,7 @@ suite = tShirtCotonFrance (\query -> [ { query - | countrySpinning = Nothing + | geozoneSpinning = Nothing } |> expectImpact db ecs 1290.7 |> asTest "compute a simulation ecs impact" @@ -173,7 +173,7 @@ suite = , suiteFromResult "should be full for products not coming from Europe or Turkey" tShirtCotonFrance (\query -> - [ { query | countryMaking = Just (Country.Code "CN") } + [ { query | geozoneMaking = Just (Geozone.Code "CN") } |> computeWithDefaultComponentConfig db |> Result.map (.lifeCycle >> LifeCycle.getStepProp Label.Making .airTransportRatio Split.half) |> Expect.equal (Ok Split.full) @@ -189,7 +189,7 @@ suite = | numberOfReferences = Just 10 , price = Just <| Economics.priceFromFloat 100 , physicalDurability = Just <| Unit.physicalDurability 1.1 - , countryMaking = Just (Country.Code "CN") + , geozoneMaking = Just (Geozone.Code "CN") } in [ tShirtCotonWithSmallerPhysicalDurabilityCn @@ -203,7 +203,7 @@ suite = tShirtCotonFrance (\query -> [ { query - | countryMaking = Just (Country.Code "CN") + | geozoneMaking = Just (Geozone.Code "CN") , airTransportRatio = Just Split.two } |> computeWithDefaultComponentConfig db @@ -258,7 +258,7 @@ suite = [ -- This example gives a durability index different from 1, ecoscores should differ """ { "business": "small-business", - "countrySpinning": "MA", + "geozoneSpinning": "MA", "mass": 0.3, "materials": [ { @@ -280,7 +280,7 @@ suite = -- durability should be strictly equivalent """ { "business": "small-business", - "countrySpinning": "MA", + "geozoneSpinning": "MA", "mass": 0.3, "materials": [ { diff --git a/tests/Data/TransportTest.elm b/tests/Data/TransportTest.elm index 1bace82ea6..ae45be9725 100644 --- a/tests/Data/TransportTest.elm +++ b/tests/Data/TransportTest.elm @@ -1,6 +1,6 @@ module Data.TransportTest exposing (..) -import Data.Country as Country +import Data.Geozone as Geozone import Data.Impact as Impact exposing (Impacts) import Data.Transport as Transport exposing (Transport, getTransportBetween) import Dict.Any as AnyDict @@ -32,25 +32,25 @@ suite : Test suite = suiteWithDb "Data.Transport" (\db -> - [ db.countries + [ db.geozones |> List.map (\{ code } -> AnyDict.keys db.distances |> List.member code |> Expect.equal True - |> asTest ("Country " ++ Country.codeToString code ++ " should have transports data available") + |> asTest ("Geozone " ++ Geozone.codeToString code ++ " should have transports data available") ) |> describe "transports data availability checks" , describe "getTransportBetween" [ db.distances - |> Transport.getTransportBetween Impact.empty (Country.Code "FR") (Country.Code "CN") + |> Transport.getTransportBetween Impact.empty (Geozone.Code "FR") (Geozone.Code "CN") |> Expect.equal (franceChina Impact.empty) - |> asTest "should retrieve distance between two countries" + |> asTest "should retrieve distance between two geographical zones" , db.distances - |> Transport.getTransportBetween Impact.empty (Country.Code "CN") (Country.Code "FR") + |> Transport.getTransportBetween Impact.empty (Geozone.Code "CN") (Geozone.Code "FR") |> Expect.equal (franceChina Impact.empty) - |> asTest "should retrieve distance between two swapped countries" - , db.countries + |> asTest "should retrieve distance between two swapped geographical zones" + , db.geozones |> List.map .code |> LE.uniquePairs |> List.map @@ -64,7 +64,7 @@ suite = ) |> List.length |> Expect.equal 0 - |> asTest "should always give a distance greater than 0 between two countries" + |> asTest "should always give a distance greater than 0 between two geographical zones" ] ] ) diff --git a/tests/Server/RouteTest.elm b/tests/Server/RouteTest.elm index bad5dc0b5c..5e9e0d778b 100644 --- a/tests/Server/RouteTest.elm +++ b/tests/Server/RouteTest.elm @@ -1,10 +1,10 @@ module Server.RouteTest exposing (..) import Data.Component as Component -import Data.Country as Country import Data.Example as Example import Data.Food.Preparation as Preparation import Data.Food.Query as FoodQuery +import Data.Geozone as Geozone import Data.Split as Split import Data.Textile.Material as Material import Data.Textile.Product as Product @@ -71,19 +71,19 @@ foodEndpoints db = , FoodQuery.encode { royalPizza | ingredients = - royalPizza.ingredients |> List.map (\i -> { i | country = Just <| Country.Code "XX" }) + royalPizza.ingredients |> List.map (\i -> { i | geozone = Just <| Geozone.Code "XX" }) } |> testFoodEndpoint db - |> expectFoodValidationError "ingredients" "Code pays invalide: XX." - |> asTest "validate an ingredient invalid country code" + |> expectFoodValidationError "ingredients" "Code de zone géographique invalide: XX." + |> asTest "validate an ingredient invalid geographical zone code" , FoodQuery.encode { royalPizza | ingredients = - royalPizza.ingredients |> List.map (\i -> { i | country = Just <| Country.Code "BD" }) + royalPizza.ingredients |> List.map (\i -> { i | geozone = Just <| Geozone.Code "BD" }) } |> testFoodEndpoint db - |> expectFoodValidationError "ingredients" "Le code pays BD n'est pas utilisable dans un contexte Alimentaire." - |> asTest "validate an ingredient incompatible country code" + |> expectFoodValidationError "ingredients" "Le code de zone géographique BD n'est pas utilisable dans un contexte Alimentaire." + |> asTest "validate an ingredient incompatible geographical zone code" , FoodQuery.encode { royalPizza | transform = royalPizza.transform |> Maybe.map (\t -> { t | mass = Mass.grams -1 }) @@ -163,20 +163,20 @@ textileEndpoints db = |> asTest "reject invalid physicalDurability" ] ) - , suiteFromResult "should reject invalid spinning country" + , suiteFromResult "should reject invalid spinning geozone" tShirtCotonFrance (\query -> [ TextileQuery.encode { query - | countrySpinning = Just (Country.Code "invalid") + | geozoneSpinning = Just (Geozone.Code "invalid") } |> testTextileEndpoint db - |> expectTextileValidationError "countrySpinning" "Code pays invalide: invalid." - |> asTest "reject invalid spinning country" + |> expectTextileValidationError "geozoneSpinning" "Code de zone géographique invalide: invalid." + |> asTest "reject invalid spinning geographical zone" ] ) , TestUtils.suiteFromResult2 - "should reject invalid materials country" + "should reject invalid materials geographical zone" tShirtCotonFrance (Material.idFromString "62a4d6fb-3276-4ba5-93a3-889ecd3bff84") (\query decodedId -> @@ -186,13 +186,13 @@ textileEndpoints db = [ { id = decodedId , share = Split.full , spinning = Nothing - , country = Just (Country.Code "invalid") + , geozone = Just (Geozone.Code "invalid") } ] } |> testTextileEndpoint db - |> expectTextileValidationError "materials" "Code pays invalide: invalid." - |> asTest "reject invalid materials country" + |> expectTextileValidationError "materials" "Code de zone géographique invalide: invalid." + |> asTest "reject invalid materials geographical zone" ] ) ] @@ -220,7 +220,7 @@ textileEndpoints db = [ { id = decodedId , share = Split.full , spinning = Nothing - , country = Nothing + , geozone = Nothing } ] } @@ -230,7 +230,7 @@ textileEndpoints db = ] ) , TestUtils.suiteFromResult2 - "should validate a material country code" + "should validate a material geozone code" tShirtCotonFrance (Material.idFromString "62a4d6fb-3276-4ba5-93a3-889ecd3bff84") (\query decodedId -> @@ -240,25 +240,25 @@ textileEndpoints db = [ { id = decodedId , share = Split.full , spinning = Nothing - , country = Just (Country.Code "NotACountryCode") + , geozone = Just (Geozone.Code "NotAGeozoneCode") } ] } |> testTextileEndpoint db - |> expectTextileValidationError "materials" "Code pays invalide: NotACountryCode." - |> asTest "validate a material country code" + |> expectTextileValidationError "materials" "Code de zone géographique invalide: NotAGeozoneCode." + |> asTest "validate a material geozone code" ] ) - , suiteFromResult "should validate that an ingredient country scope is valid" + , suiteFromResult "should validate that an ingredient geozone scope is valid" tShirtCotonFrance (\query -> [ TextileQuery.encode { query - | countryDyeing = Just <| Country.Code "US" + | geozoneDyeing = Just <| Geozone.Code "US" } |> testTextileEndpoint db - |> expectTextileValidationError "countryDyeing" "Le code pays US n'est pas utilisable dans un contexte Textile." - |> asTest "validate that an ingredient country scope is valid" + |> expectTextileValidationError "geozoneDyeing" "Le code de zone géographique US n'est pas utilisable dans un contexte Textile." + |> asTest "validate that an ingredient geozone scope is valid" ] ) , suiteFromResult "should validate that a trim item id is valid" @@ -272,7 +272,7 @@ textileEndpoints db = { query | trims = Just - [ { country = Nothing + [ { geozone = Nothing , custom = Nothing , id = nonExistentId , quantity = Component.quantityFromInt 1 @@ -296,7 +296,7 @@ textileEndpoints db = { query | trims = Just - [ { country = Nothing + [ { geozone = Nothing , custom = Nothing , id = id , quantity = Component.quantityFromInt -1 diff --git a/tests/Server/ServerTest.elm b/tests/Server/ServerTest.elm index 10114ae92c..a642ea2b50 100644 --- a/tests/Server/ServerTest.elm +++ b/tests/Server/ServerTest.elm @@ -56,7 +56,7 @@ suite = FoodQuery.encode { distribution = Nothing , ingredients = - [ { country = Nothing + [ { geozone = Nothing , id = id , mass = Mass.kilogram , planeTransport = Ingredient.NoPlane diff --git a/tests/TestUtils.elm b/tests/TestUtils.elm index 771f671f0e..99eab39d08 100644 --- a/tests/TestUtils.elm +++ b/tests/TestUtils.elm @@ -13,7 +13,7 @@ module TestUtils exposing , tShirtCotonFrance ) -import Data.Country as Country +import Data.Geozone as Geozone import Data.Impact as Impact exposing (Impacts) import Data.Impact.Definition as Definition exposing (Trigrams) import Data.Process as Process @@ -149,7 +149,7 @@ textileQueryFromMaterialId id = [ { id = id_ , share = Split.full , spinning = Nothing - , country = Nothing + , geozone = Nothing } ] } @@ -175,9 +175,9 @@ tShirtCotonFrance = |> Result.map (\query -> { query - | countryDyeing = Just (Country.Code "FR") - , countryFabric = Just (Country.Code "FR") - , countryMaking = Just (Country.Code "FR") - , countrySpinning = Just (Country.Code "FR") + | geozoneDyeing = Just (Geozone.Code "FR") + , geozoneFabric = Just (Geozone.Code "FR") + , geozoneMaking = Just (Geozone.Code "FR") + , geozoneSpinning = Just (Geozone.Code "FR") } ) diff --git a/tests/e2e-food.json b/tests/e2e-food.json index a1e76e5372..e0bb594dd6 100644 --- a/tests/e2e-food.json +++ b/tests/e2e-food.json @@ -89,7 +89,7 @@ "distribution": "ambient", "ingredients": [ { - "country": "BR", + "geozone": "BR", "id": "db0e5f44-34b4-4160-b003-77c828d75e60", "mass": 120 } @@ -133,7 +133,7 @@ "ingredients": [ { "byPlane": "byPlane", - "country": "BR", + "geozone": "BR", "id": "db0e5f44-34b4-4160-b003-77c828d75e60", "mass": 120 } @@ -177,7 +177,7 @@ "ingredients": [ { "byPlane": "noPlane", - "country": "BR", + "geozone": "BR", "id": "db0e5f44-34b4-4160-b003-77c828d75e60", "mass": 120 } diff --git a/tests/e2e-textile.json b/tests/e2e-textile.json index 06fc48d664..b1b720315f 100644 --- a/tests/e2e-textile.json +++ b/tests/e2e-textile.json @@ -2,9 +2,9 @@ { "name": "T-shirt 100% coton France", "query": { - "countryFabric": "FR", - "countryDyeing": "FR", - "countryMaking": "FR", + "geozoneFabric": "FR", + "geozoneDyeing": "FR", + "geozoneMaking": "FR", "mass": 0.17, "materials": [ { @@ -41,10 +41,10 @@ { "name": "T-shirt 100% coton France, Filature en Turquie", "query": { - "countryFabric": "FR", - "countryDyeing": "FR", - "countryMaking": "FR", - "countrySpinning": "TR", + "geozoneFabric": "FR", + "geozoneDyeing": "FR", + "geozoneMaking": "FR", + "geozoneSpinning": "TR", "mass": 0.17, "materials": [ { @@ -81,9 +81,9 @@ { "name": "Jupe 100% acrylique, France", "query": { - "countryFabric": "FR", - "countryDyeing": "FR", - "countryMaking": "FR", + "geozoneFabric": "FR", + "geozoneDyeing": "FR", + "geozoneMaking": "FR", "fabricProcess": "weaving", "mass": 0.3, "materials": [ @@ -121,9 +121,9 @@ { "name": "T-shirt 50% coton, 45% PET, 5% PU, France", "query": { - "countryFabric": "FR", - "countryDyeing": "FR", - "countryMaking": "FR", + "geozoneFabric": "FR", + "geozoneDyeing": "FR", + "geozoneMaking": "FR", "mass": 0.17, "materials": [ { @@ -168,9 +168,9 @@ { "name": "T-shirt 100% coton France, pas d'ennoblissement", "query": { - "countryFabric": "FR", - "countryDyeing": "FR", - "countryMaking": "FR", + "geozoneFabric": "FR", + "geozoneDyeing": "FR", + "geozoneMaking": "FR", "disabledSteps": [ "ennobling" ], @@ -211,9 +211,9 @@ "name": "Pantalon 90% coton, 10% PU, aérien 100%, Chine", "query": { "airTransportRatio": 1, - "countryFabric": "CN", - "countryDyeing": "CN", - "countryMaking": "CN", + "geozoneFabric": "CN", + "geozoneDyeing": "CN", + "geozoneMaking": "CN", "fabricProcess": "weaving", "mass": 0.45, "materials": [ @@ -255,9 +255,9 @@ { "name": "Jean 100% coton naturel, Turquie", "query": { - "countryFabric": "TR", - "countryDyeing": "TR", - "countryMaking": "TR", + "geozoneFabric": "TR", + "geozoneDyeing": "TR", + "geozoneMaking": "TR", "fabricProcess": "weaving", "fading": true, "mass": 0.45, @@ -296,9 +296,9 @@ { "name": "Jean 100% coton naturel, Turquie, non-délavé", "query": { - "countryFabric": "TR", - "countryDyeing": "TR", - "countryMaking": "TR", + "geozoneFabric": "TR", + "geozoneDyeing": "TR", + "geozoneMaking": "TR", "fabricProcess": "weaving", "fading": false, "mass": 0.45, @@ -337,9 +337,9 @@ { "name": "Jean 100% coton naturel, Turquie, 1 zip et 4 boutons en métal", "query": { - "countryFabric": "TR", - "countryDyeing": "TR", - "countryMaking": "TR", + "geozoneFabric": "TR", + "geozoneDyeing": "TR", + "geozoneMaking": "TR", "fabricProcess": "weaving", "fading": true, "mass": 0.45, @@ -388,9 +388,9 @@ { "name": "T-Shirt France, makingWaste=0", "query": { - "countryFabric": "FR", - "countryDyeing": "FR", - "countryMaking": "FR", + "geozoneFabric": "FR", + "geozoneDyeing": "FR", + "geozoneMaking": "FR", "makingWaste": 0, "mass": 0.17, "materials": [ @@ -428,9 +428,9 @@ { "name": "T-Shirt France, makingWaste=0.25", "query": { - "countryFabric": "FR", - "countryDyeing": "FR", - "countryMaking": "FR", + "geozoneFabric": "FR", + "geozoneDyeing": "FR", + "geozoneMaking": "FR", "makingWaste": 0.25, "mass": 0.17, "materials": [ @@ -468,9 +468,9 @@ { "name": "Tshirt coton, 300g/m² France, Pigment printing", "query": { - "countryFabric": "FR", - "countryDyeing": "FR", - "countryMaking": "FR", + "geozoneFabric": "FR", + "geozoneDyeing": "FR", + "geozoneMaking": "FR", "mass": 0.3, "materials": [ { @@ -511,9 +511,9 @@ { "name": "Tshirt coton, 300g/m² France, Substantive printing", "query": { - "countryFabric": "FR", - "countryDyeing": "FR", - "countryMaking": "FR", + "geozoneFabric": "FR", + "geozoneDyeing": "FR", + "geozoneMaking": "FR", "mass": 0.3, "materials": [ { @@ -555,9 +555,9 @@ { "name": "Tshirt coton, 300g/m² France, Pigment printing at 50%", "query": { - "countryFabric": "FR", - "countryDyeing": "FR", - "countryMaking": "FR", + "geozoneFabric": "FR", + "geozoneDyeing": "FR", + "geozoneMaking": "FR", "mass": 0.3, "materials": [ { @@ -599,9 +599,9 @@ { "name": "T-shirt 100% coton France, remanufacturé", "query": { - "countryFabric": "FR", - "countryDyeing": "FR", - "countryMaking": "FR", + "geozoneFabric": "FR", + "geozoneDyeing": "FR", + "geozoneMaking": "FR", "mass": 0.17, "materials": [ { diff --git a/tests/server.spec.js b/tests/server.spec.js index 6be0004a1c..825578ac84 100644 --- a/tests/server.spec.js +++ b/tests/server.spec.js @@ -23,9 +23,9 @@ describe("Web", () => { describe("API", () => { const textileQuery = { - countryFabric: "CN", - countryDyeing: "CN", - countryMaking: "CN", + geozoneFabric: "CN", + geozoneDyeing: "CN", + geozoneMaking: "CN", mass: 0.17, materials: [ { id: "62a4d6fb-3276-4ba5-93a3-889ecd3bff84", share: 0.5 }, @@ -64,9 +64,9 @@ describe("API", () => { }); describe("Textile", () => { - describe("/textile/countries", () => { - it("should render with textile countries list", async () => { - await expectListResponseContains("/api/textile/countries", { code: "FR", name: "France" }); + describe("/textile/geozones", () => { + it("should render with textile geographical zones list", async () => { + await expectListResponseContains("/api/textile/geozones", { code: "FR", name: "France" }); }); }); @@ -123,47 +123,47 @@ describe("API", () => { ); }); - it("should validate the countrySpinning param (invalid code)", async () => { + it("should validate the geozoneSpinning param (invalid code)", async () => { expectFieldErrorMessage( await makePostRequest("/api/textile/simulator", { ...textileQuery, - countrySpinning: "XX", + geozoneSpinning: "XX", }), - "countrySpinning", - /Code pays invalide: XX/, + "geozoneSpinning", + /Code de zone géographique invalide: XX/, ); }); - it("should validate the countryFabric param (invalid code)", async () => { + it("should validate the geozoneFabric param (invalid code)", async () => { expectFieldErrorMessage( await makePostRequest("/api/textile/simulator", { ...textileQuery, - countryFabric: "XX", + geozoneFabric: "XX", }), - "countryFabric", - /Code pays invalide: XX/, + "geozoneFabric", + /Code de zone géographique invalide: XX/, ); }); - it("should validate the countryDyeing param (invalid code)", async () => { + it("should validate the geozoneDyeing param (invalid code)", async () => { expectFieldErrorMessage( await makePostRequest("/api/textile/simulator", { ...textileQuery, - countryDyeing: "XX", + geozoneDyeing: "XX", }), - "countryDyeing", - /Code pays invalide: XX/, + "geozoneDyeing", + /Code de zone géographique invalide: XX/, ); }); - it("should validate the countryMaking param (invalid code)", async () => { + it("should validate the geozoneMaking param (invalid code)", async () => { expectFieldErrorMessage( await makePostRequest("/api/textile/simulator", { ...textileQuery, - countryMaking: "XX", + geozoneMaking: "XX", }), - "countryMaking", - /Code pays invalide: XX/, + "geozoneMaking", + /Code de zone géographique invalide: XX/, ); }); @@ -322,11 +322,11 @@ describe("API", () => { it("should validate multiple errored parameters", async () => { const response = await makePostRequest("/api/textile/simulator", { ...textileQuery, - countryDyeing: "BadDyeingCode", - countrySpinning: "BadSpinningCode", + geozoneDyeing: "BadDyeingCode", + geozoneSpinning: "BadSpinningCode", }); - expect(Object.keys(response.body.error)).toEqual(["countryDyeing", "countrySpinning"]); + expect(Object.keys(response.body.error)).toEqual(["geozoneDyeing", "geozoneSpinning"]); }); }); @@ -397,9 +397,9 @@ describe("API", () => { product: "jean", fabricProcess: "weaving", materials: [{ id: "62a4d6fb-3276-4ba5-93a3-889ecd3bff84", share: 1 }], - countryFabric: "TR", - countryDyeing: "TR", - countryMaking: "TR", + geozoneFabric: "TR", + geozoneDyeing: "TR", + geozoneMaking: "TR", fading: true, }; @@ -433,9 +433,9 @@ describe("API", () => { }); describe("Food", () => { - describe("/food/countries", () => { - it("should render with food countries list", async () => { - await expectListResponseContains("/api/food/countries", { code: "FR", name: "France" }); + describe("/food/geozones", () => { + it("should render with food geographical zones list", async () => { + await expectListResponseContains("/api/food/geozones", { code: "FR", name: "France" }); }); }); @@ -516,19 +516,19 @@ describe("API", () => { ); }); - it("should validate an ingredient country code", async () => { + it("should validate an ingredient geozone code", async () => { expectFieldErrorMessage( await makePostRequest("/api/food", { ingredients: [ { - country: "BadCountryCode", + geozone: "BadGeozoneCode", id: "4d5198e7-413a-4ae2-8448-535aa3b302ae", mass: 123, }, ], }), "ingredients", - /Code pays invalide: BadCountryCode/, + /Code de zone géographique invalide: BadGeozoneCode/, ); }); @@ -538,7 +538,7 @@ describe("API", () => { ingredients: [ { byPlane: "badValue", - country: "BR", + geozone: "BR", id: "db0e5f44-34b4-4160-b003-77c828d75e60", mass: 123, }, @@ -555,7 +555,7 @@ describe("API", () => { ingredients: [ { byPlane: "byPlane", - country: "BR", + geozone: "BR", id: "4d5198e7-413a-4ae2-8448-535aa3b302ae", mass: 123, },