Skip to content

Commit

Permalink
#9 damage class mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Mar 6, 2019
1 parent 96bfcb1 commit a9d37eb
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 24 deletions.
32 changes: 32 additions & 0 deletions app/samples/populationDamageClasses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"key": "D1",
"displayName": "Fatigue, discomfort",
"iconResource": "flower_16.png",
"unit": "Persons"
},
{
"key": "D2",
"displayName": "Heat cramps, heat exhaustion",
"iconResource": "flower_16.png",
"unit": "Persons"
},
{
"key": "D3",
"displayName": "Heat cramps, heatstroke",
"iconResource": "flower_homeless_16.png",
"unit": "Persons"
},
{
"key": "D4",
"displayName": "Heatstroke, sunstroke",
"iconResource": "flower_injured_16.png",
"unit": "Persons"
},
{
"key": "D5",
"displayName": "Death",
"iconResource": "flower_dead_16.png",
"unit": "Persons"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@ angular.module(
[
'$scope',
'$timeout',
'$http',
'de.cismet.crisma.ICMM.services.icmm',
'de.cismet.crisma.ICMM.Worldstates',
'eu.myclimateservice.csis.scenario-analysis.services.drupalService',
function ($scope, $timeout, Icmm, Worldstates, drupalService) {
function ($scope, $timeout, $http, Icmm, Worldstates, drupalService) {
'use strict';
var showIndicatorFileLoadingError, showFileLoading, loadIndicatorObjects,
loadIndicatorObject, onloadCfFile, onloadDsFile, onSeamlessEvent,
onloadIccObjects, loadCriteriaFunctions, loadDecisionStrategies;
onloadIccObjects, loadCriteriaFunctions, loadDecisionStrategies,
damageClasses;
var drupalRestApi = drupalService.drupalRestApi;
var emikatRestApi = drupalService.emikatRestApi;

// TODO: Load this kinf of information from the Data Package
$http.get('samples/populationDamageClasses.json').success(function (data) {
damageClasses = data;
}).error(function (data, status) {
console.error('Could not load populationDamageClasses: ', status, data);
});

console.log('window.seamless.connect()');
var parent = window.seamless.connect();
// Receive a message, this only works when the parent window calls send(...)
Expand Down Expand Up @@ -162,6 +171,7 @@ angular.module(
//$scope.$apply();
};

// <editor-fold defaultstate="closed" desc="=== loadIndicatorObjects ===========================">
onloadIccObjects = function (file) {
return function (e) {
console.log('load icc file: ' + file.name);
Expand Down Expand Up @@ -313,7 +323,9 @@ angular.module(
console.error(err.toString());
}
};
//</editor-fold>

// <editor-fold defaultstate="closed" desc="=== loadCriteriaFunctions ===========================">
onloadCfFile = function (theFile) {
return function (e) {
var criteriaFunctionArray;
Expand Down Expand Up @@ -398,7 +410,9 @@ angular.module(
$scope.showCfFileLoadingError('msg');
}
};
// </editor-fold>

// <editor-fold defaultstate="closed" desc="=== loadDecisionStrategies ===========================">
onloadDsFile = function (theFile) {
return function (e) {
var decisionStrategyArray;
Expand Down Expand Up @@ -484,6 +498,7 @@ angular.module(
$scope.showCfFileLoadingError('msg');
}
};
// </editor-fold>

onSeamlessEvent = function (eventData) {
console.log('load node from node id: ' + eventData.nodeId);
Expand Down Expand Up @@ -511,6 +526,9 @@ angular.module(
});
};


// <editor-fold defaultstate="closed" desc="[x] === $scope.$watch ===========================">

/*
* When the newFile property has changed the User want's to add a new list of files.
*/
Expand Down Expand Up @@ -586,17 +604,21 @@ angular.module(
}

}, true);
//</editor-fold>

// if local file /scripts/.local.js exists, load some test data
if (window.emikatProperties) {
console.warn('/scripts/.local.js found, loading test data');
emikatRestApi.getImpactScenario(window.emikatProperties.scenarioId, window.emikatProperties.viewId, window.emikatProperties.credentials).then(function (impactScenario) {
//TODO: do something useful here!
console.log(impactScenario);
var worldstates = drupalService.emikatHelper.transformImpactScenario(impactScenario);
console.log(JSON.stringify(worldstates));

emikatRestApi.getImpactScenario(
window.emikatProperties.scenarioId,
window.emikatProperties.viewId,
window.emikatProperties.credentials).then(function (impactScenario) {
//console.log(impactScenario);
var worldstates = drupalService.emikatHelper.transformImpactScenario(impactScenario, damageClasses, true);

// this is a total mess: worldstates object is awkwardly modified modified by infamous ICCM_Helper
//console.log(JSON.stringify(worldstates));

loadIndicatorObjects(worldstates);
}, function (error) {
console.log(error.message);
Expand Down
38 changes: 22 additions & 16 deletions app/scripts/services/drupalService.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,25 @@ angular.module(
};
// </editor-fold>

// <editor-fold defaultstate="closed" desc="=== emikatHelper ===========================">
// <editor-fold defaultstate="open" desc="=== emikatHelper ===========================">
$this.emikatHelper = {};

/**
* Parses, aggregates and transforms emikat API response to ICC DATA Vector
*
* @param {type} scenarioData emikat scenario data as obtained from EMIKAT REST PAI
* @param {ScenarioData} scenarioData emikat scenario data as obtained from EMIKAT REST PAI
* @param {Array} damageClasses Damage Class information
* @param {boolean} aggregate
* @param {type} icon
* @param {type} aggregate
* @returns {Array}
*/
$this.emikatHelper.transformImpactScenario = function (scenarioData, icon = 'flower_injured_16.png', aggregate = false) {
$this.emikatHelper.transformImpactScenario = function (scenarioData, damageClasses, aggregate = false, icon = 'flower_injured_16.png') {
var worldstates = [], cMap = {};
if (!scenarioData || !scenarioData.name || scenarioData.name === null || !scenarioData.rows || !scenarioData.columnnames) {
console.warn('EMIKAT Sceanrio Data is null, cannot transform result to ICC Data Array');
return worldstates;
} else {
console.info('tranforing EMIKAT Scenario: ' + scenarioData.name);
console.info('transforming (and aggregeting: '+aggregate+') EMIKAT Scenario: ' + scenarioData.name);
}

// fill associative map
Expand All @@ -228,7 +229,7 @@ angular.module(

// aggregate by vulnerability class
var indicatorSetKey = 'indicatorset';
if (aggregate === true) {
if (aggregate === false) {
indicatorSetKey += column[cMap['VULNERABILITYCLASS_ID']];
}

Expand All @@ -237,7 +238,7 @@ angular.module(
if (!indicatorSet || indicatorSet === null) {
indicatorSet = {};
indicatorSet.displayName = column[cMap['NAME']];
if (aggregate === true) {
if (aggregate === false) {
indicatorSet.displayName += ': ' + column[cMap['VULCLASS_NAME']];
}

Expand All @@ -246,24 +247,29 @@ angular.module(
}

// FIXME: Always 5 damage classes?!
for (var j = 1; j < 6; j++) {
var indicatorKey = 'indicator' + j;
for (var j = 0; j < 5; j++) {
var indicatorKey = 'indicator' + (j+1);
var indicator = indicatorSet[indicatorKey];
if (!indicator || indicator === null) {
indicator = {};
// FIXME: Damage Class Name!
indicator.displayName = 'D' + (j);
// FIXME: support different icons!
indicator.iconResource = icon;

if(damageClasses && damageClasses!== null && damageClasses[j] && damageClasses[j].displayName) {
indicator.displayName = damageClasses[j].displayName;
indicator.iconResource = damageClasses[j].iconResource;
} else {
indicator.displayName = 'D' + (j+1);
indicator.iconResource = icon;
}

indicator.unit = column[cMap['QUANTITYUNIT']];
indicator.value = 0;
indicatorSet[indicatorKey] = indicator;
}

if (aggregate === true) {
indicator.value += column[cMap['DAMAGELEVEL' + j + 'QUANTITY']];
if (aggregate === false) {
indicator.value = column[cMap['DAMAGELEVEL' + (j+1) + 'QUANTITY']];
} else {
indicator.value = column[cMap['DAMAGELEVEL' + j + 'QUANTITY']];
indicator.value += column[cMap['DAMAGELEVEL' + (j+1) + 'QUANTITY']];
}
}
}
Expand Down

0 comments on commit a9d37eb

Please sign in to comment.