-
Notifications
You must be signed in to change notification settings - Fork 1
/
RiskAndImpactTable.js
78 lines (64 loc) · 3.4 KB
/
RiskAndImpactTable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React from 'react';
import log from 'loglevel';
import { EMIKATHelpers } from 'csis-helpers-js';
import GenericEmikatClient from './commons/GenericEmikatClient.js';
import ParameterSelectionComponent from './commons/ParameterSelectionComponent.js';
import GenericEmikatTable from './commons/GenericEmikatTable.js';
/**
* The Risk and Impact Table!
*
* EMIKAT API URL is hardcoded and not loaded from Data Package since EMIKAT Resources are not updated anyway
* and table views do not change. See ${emikatTemplateUrl}.
*
* @param {*} props
* @see https://github.com/clarity-h2020/emikat/issues/9
* @see https://csis.myclimateservice.eu/node/1356
*/
const RiskAndImpactTable = (props) => {
log.info('creating new RiskAndImpactTable');
/**
* Combined Table View for Flood and Heat
*/
const emikatView = 'view.3155'; // old: view.2975
const emikatTemplateUrl = `https://service.emikat.at/EmiKatTst/api/scenarios/${EMIKATHelpers.EMIKAT_STUDY_ID}/feature/${emikatView}/table/${EMIKATHelpers.DATA_FORMAT}?rownum=${EMIKATHelpers.ROWNUM}&filter=SZ_ID=${EMIKATHelpers.EMIKAT_STUDY_ID}&filter=STUDY_VARIANT%3D%27BASELINE%27&filter=TIME_PERIOD%3D%27${EMIKATHelpers.TIME_PERIOD}%27&filter=EMISSIONS_SCENARIO%3D%27${EMIKATHelpers.EMISSIONS_SCENARIO}%27&filter=EVENT_FREQUENCY%3D%27${EMIKATHelpers.EVENT_FREQUENCY}%27`;
// see comment in HazardLocalEffectsTable why we define the columns here
const columns =
'&column=GRID_ID&column=HW_EXPOSEDQUANTITY&column=HW_DAMAGEPROBABILITY&column=HW_DAMAGEQUANTITY&column=HW_DISCOMFORT_LEVEL&column=HW_POPULATION_DENSITY_CLASS&column=HW_HEAT_WAVE_IMPACT&column=PF_RESIDENTIAL_BUILDINGS&column=PF_NON_RESIDENTIAL_BUILDINGS&column=PF_ROADS_M2&column=PF_DAMAGEPROBABILITY&column=PF_DAMAGE_CLASS&column=PF_FLOOD_IMPACT_EURO';
/**
* Custom formatting of column data.
*/
const resolveData = function (data) {
data.map(function transform(row) {
var index = 2; // HW_DAMAGEPROBABILITY
row.values[index] = row.values[index] !== null && !isNaN(parseFloat(row.values[index])) ?
Math.round(row.values[index] * 100000 + Number.EPSILON) / 100000 : 'n/a';
index = 3; // HW_DAMAGEQUANTITY
row.values[index] = row.values[index] !== null && !isNaN(parseFloat(row.values[index])) ?
Math.round(row.values[index] * 100 + Number.EPSILON) / 100 : 'n/a';
index = 7; // PF_RESIDENTIAL_BUILDINGS
row.values[index] = row.values[index] !== null && !isNaN(parseFloat(row.values[index])) ?
Math.round(row.values[index]) : 'n/a';
index = 8; // PF_NON_RESIDENTIAL_BUILDINGS
row.values[index] = row.values[index] !== null && !isNaN(parseFloat(row.values[index])) ?
Math.round(row.values[index]) : 'n/a';
index = 9; // PF_ROADS_M2
row.values[index] = row.values[index] !== null && !isNaN(parseFloat(row.values[index])) ?
Math.round(row.values[index]) : 'n/a';
index = 12; // PF_FLOOD_IMPACT_EURO
row.values[index] = row.values[index] !== null && !isNaN(parseFloat(row.values[index])) ?
Math.round(row.values[index]) + ' €' : 'n/a';
return row;
});
return data;
};
return (
<ParameterSelectionComponent
{...props}
emikatTemplateUrl={emikatTemplateUrl}
columns={columns}
client={GenericEmikatClient}
render={GenericEmikatTable}
props={{ resolveData: resolveData }}>
</ParameterSelectionComponent>);
};
export default RiskAndImpactTable;