Skip to content

Commit

Permalink
[Datamodel] Move Environmental Impact Data to own Scenario subelement
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonBein committed Aug 28, 2024
1 parent 1e157c0 commit fab2411
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 125 deletions.
13 changes: 10 additions & 3 deletions dataModel/SimulationModelDescriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export const SimulationModelDescriptor = {
{ "name": "currency", "type": "Currency", default : Currencies.EURO },
{ "name": "resourceParameters", "type": "ResourceParameters" },
{ "name": "models", "type": "Model", isMany : true },
{ "name": "environmentImpactParameters", "type": "EnvironmentImpactParameters" },
]
},

{
"name" : "EnvironmentImpactParameters",
"properties": [
{ "name": "costDrivers", "type": "AbstractCostDriver", isMany : true },
{ "name": "variants", "type": "Variant", isMany : true }
]
},

Expand All @@ -58,9 +67,7 @@ export const SimulationModelDescriptor = {
"properties": [
{ "name": "roles", "type": "Role", isMany : true },
{ "name": "resources", "type": "Resource", isMany : true },
{ "name": "timeTables", "type": "Timetable", isMany : true },
{ "name": "costDrivers", "type": "AbstractCostDriver", isMany : true },
{ "name": "variants", "type": "Variant", isMany : true }
{ "name": "timeTables", "type": "Timetable", isMany : true }
]
},

Expand Down
226 changes: 114 additions & 112 deletions frontend/cypress/fixtures/lca/lcaTestScenario.json
Original file line number Diff line number Diff line change
Expand Up @@ -988,118 +988,120 @@
}
]
}
],
"costDrivers":[
{
"id":"Delivery",
"name":"Delivery",
"concreteCostDrivers":[
{
"id":"eb2d7a95-af12-4c07-8483-76c222bd2a8a",
"name":"Delivery_A_Lorry",
"cost":0.000009222736147284307
},
{
"id":"2320625c-91a6-46fe-a338-30e31da90aeb",
"name":"Delivery_B_Small_Lorry",
"cost":0.000017790529652615878
},
{
"id":"e4b2ab16-bab1-44be-91df-8a1e859553f6",
"name":"Delivery_B_Lorry",
"cost":0.000013834104220926462
},
{
"id":"7d56ac6e-0d5b-41e4-b83e-cbb43557a937",
"name":"Delivery_A_Small_Lorry",
"cost":0.000011860353101743918
}
]
},
{
"id":"Shipment",
"name":"Shipment",
"concreteCostDrivers":[
{
"id":"ef48baf7-4885-4d95-96b8-8d3d4a1092dc",
"name":"Shipment_A_Lorry",
"cost":0.000025279427000910646
},
{
"id":"7fa79147-2fa5-47f8-9bd5-b4a05ec65b49",
"name":"Shipment_A_Rail_Electric",
"cost":-3.9450807802685816e-7
},
{
"id":"a0cd2fa8-a7b4-4805-a662-38f701862a2f",
"name":"Shipment_B_Lorry",
"cost":0.00005055885400182129
},
{
"id":"256b0228-f05a-4e35-a5f2-efec99b0b406",
"name":"Shipment_B_Rail_Electric",
"cost":-7.890161560537163e-7
}
]
},
{
"id":"Re-Routing",
"name":"Re-Routing",
"concreteCostDrivers":[
{
"id":"70957e6a-c47e-4cc2-b4cf-ca3863153c9f",
"name":"Re-Routing_A_Lorry",
"cost":0.000002766820844185292
},
{
"id":"985e5853-47ad-48b9-af14-db5f46249f4a",
"name":"Re-Routing_A_Small_Lorry",
"cost":0.000003558105930523175
}
]
},
{
"id":"Packaging Material",
"name":"Packaging Material",
"concreteCostDrivers":[
{
"id":"1ce01d66-552b-4bc2-9103-680d37531c72",
"name":"Packaging_Material_B",
"cost":0.000004607338473103258
},
{
"id":"ee2a9ffc-24ae-499b-b11e-77f52094aa21",
"name":"Packaging_Material_A",
"cost":0.000009214676946206515
}
]
},
{
"id":"Receipt",
"name":"Receipt",
"concreteCostDrivers":[
{
"id":"1964790c-5d5f-412c-b6a1-beb2df9508c9",
"name":"Receipt",
"cost":0.000005075463136208346
}
]
},
{
"id":"Filling Material",
"name":"Filling Material",
"concreteCostDrivers":[
{
"id":"fdd48db8-b321-43a1-9a01-569963bc5f71",
"name":"Filling_A",
"cost":0.000005119664581012698
}
]
}
],
"variants":[

]
]
},
"environmentImpactParameters" : {
"costDrivers":[
{
"id":"Delivery",
"name":"Delivery",
"concreteCostDrivers":[
{
"id":"eb2d7a95-af12-4c07-8483-76c222bd2a8a",
"name":"Delivery_A_Lorry",
"cost":0.000009222736147284307
},
{
"id":"2320625c-91a6-46fe-a338-30e31da90aeb",
"name":"Delivery_B_Small_Lorry",
"cost":0.000017790529652615878
},
{
"id":"e4b2ab16-bab1-44be-91df-8a1e859553f6",
"name":"Delivery_B_Lorry",
"cost":0.000013834104220926462
},
{
"id":"7d56ac6e-0d5b-41e4-b83e-cbb43557a937",
"name":"Delivery_A_Small_Lorry",
"cost":0.000011860353101743918
}
]
},
{
"id":"Shipment",
"name":"Shipment",
"concreteCostDrivers":[
{
"id":"ef48baf7-4885-4d95-96b8-8d3d4a1092dc",
"name":"Shipment_A_Lorry",
"cost":0.000025279427000910646
},
{
"id":"7fa79147-2fa5-47f8-9bd5-b4a05ec65b49",
"name":"Shipment_A_Rail_Electric",
"cost":-3.9450807802685816e-7
},
{
"id":"a0cd2fa8-a7b4-4805-a662-38f701862a2f",
"name":"Shipment_B_Lorry",
"cost":0.00005055885400182129
},
{
"id":"256b0228-f05a-4e35-a5f2-efec99b0b406",
"name":"Shipment_B_Rail_Electric",
"cost":-7.890161560537163e-7
}
]
},
{
"id":"Re-Routing",
"name":"Re-Routing",
"concreteCostDrivers":[
{
"id":"70957e6a-c47e-4cc2-b4cf-ca3863153c9f",
"name":"Re-Routing_A_Lorry",
"cost":0.000002766820844185292
},
{
"id":"985e5853-47ad-48b9-af14-db5f46249f4a",
"name":"Re-Routing_A_Small_Lorry",
"cost":0.000003558105930523175
}
]
},
{
"id":"Packaging Material",
"name":"Packaging Material",
"concreteCostDrivers":[
{
"id":"1ce01d66-552b-4bc2-9103-680d37531c72",
"name":"Packaging_Material_B",
"cost":0.000004607338473103258
},
{
"id":"ee2a9ffc-24ae-499b-b11e-77f52094aa21",
"name":"Packaging_Material_A",
"cost":0.000009214676946206515
}
]
},
{
"id":"Receipt",
"name":"Receipt",
"concreteCostDrivers":[
{
"id":"1964790c-5d5f-412c-b6a1-beb2df9508c9",
"name":"Receipt",
"cost":0.000005075463136208346
}
]
},
{
"id":"Filling Material",
"name":"Filling Material",
"concreteCostDrivers":[
{
"id":"fdd48db8-b321-43a1-9a01-569963bc5f71",
"name":"Filling_A",
"cost":0.000005119664581012698
}
]
}
],
"variants":[

]
},
"models":[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Activity = ({ getData, currentElement, setCurrentRightSideBar }) => {
const scenario = getData().getCurrentScenario();

if (scenario) {
const costDrivers = scenario.resourceParameters.costDrivers;
const costDrivers = scenario.environmentImpactParameters.costDrivers;
if (costDrivers) {
setAllAbstractCostDrivers(costDrivers);
}
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/Lca/Logic/LcaDataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const getCostDriversFromScenario = (getData) => {
const scenario = getData().getCurrentScenario();

if (scenario) {
const costDrivers = scenario.resourceParameters.costDrivers;
const costDrivers = scenario.environmentImpactParameters.costDrivers;
if (costDrivers) {
const uniqueCostDrivers = Array.from(new Map(costDrivers.map(item => [item.id, item])).values());
return uniqueCostDrivers;
Expand All @@ -16,8 +16,8 @@ export const getCostDriversFromScenario = (getData) => {
export const getVariants = (getData) => {
const scenario = getData().getCurrentScenario();

if (scenario && scenario.resourceParameters.variants) {
return scenario.resourceParameters.variants;
if (scenario && scenario.environmentImpactParameters.variants) {
return scenario.environmentImpactParameters.variants;
}
return [];
};
Expand Down Expand Up @@ -47,7 +47,7 @@ export const mapAbstractDriversFromConcrete = (concreteCostDrivers) => {
};

export const saveAllCostDrivers = async (abstractCostDrivers, getData) => {
getData().getCurrentScenario().resourceParameters.costDrivers = abstractCostDrivers;
getData().getCurrentScenario().environmentImpactParameters.costDrivers = abstractCostDrivers;
await getData().saveCurrentScenario();
};

Expand All @@ -67,12 +67,12 @@ export const saveCostVariant = async (variant, updatedVariants, getData) => {
mappings: driversMappings,
});
let updatedVariantsObject = [...updatedVariants.filter(v => v.id !== variant.id), updatedVariant];
getData().getCurrentScenario().resourceParameters.variants = updatedVariantsObject;
getData().getCurrentScenario().environmentImpactParameters.variants = updatedVariantsObject;
await getData().saveCurrentScenario();
};


export const deleteVariantFromConfiguration = async (variantId, getData) => {
getData().getCurrentScenario().resourceParameters.variants = getData().getCurrentScenario().resourceParameters.variants.filter(v => v.id !== variantId);
getData().getCurrentScenario().environmentImpactParameters.variants = getData().getCurrentScenario().environmentImpactParameters.variants.filter(v => v.id !== variantId);
await getData().saveCurrentScenario();
};
2 changes: 1 addition & 1 deletion frontend/src/components/Simulation/SimulationPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const SimulationPage = ({projectName, getData, toasting }) => {

// function to start the simulation
const start = async () => {
let variants = getData().getCurrentScenario().resourceParameters.variants;
let variants = getData().getCurrentScenario().environmentImpactParameters.variants;
if(variants.reduce((sum, variant) => sum + parseInt(variant.frequency), 0) != 100)
{
toasting("error", "Frequencies sum is not 100%", "For correct simulation, the sum of frequencies must be 100%");
Expand Down
2 changes: 1 addition & 1 deletion scyllaConverter/GlobConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function createGlobConfig(scenario) {
//timetables:
timetables.timetable = conv_ele.createTimeTables(scenario.resourceParameters.timeTables);

costDriver.abstractCostDriver = conv_ele.createAbstractCostDrivers(scenario.resourceParameters.costDrivers);
costDriver.abstractCostDriver = conv_ele.createAbstractCostDrivers(scenario.environmentImpactParameters.costDrivers);

attributes.id = scenario.scenarioName + '_Global'
globConfig.resourceData = resourceData;
Expand Down
2 changes: 1 addition & 1 deletion scyllaConverter/SimConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function createSimConfig(scenario, processModel) {
elementsById
} = await moddle.fromXML(processModel.BPMN, 'bpmn:Definitions');

costVariantConfig.variant = conv_ele.createVariants(scenario.resourceParameters.variants);
costVariantConfig.variant = conv_ele.createVariants(scenario.environmentImpactParameters.variants);
simConfig.costVariantConfig = costVariantConfig;

// create Tasks:
Expand Down

0 comments on commit fab2411

Please sign in to comment.