|
1
|
|
|
import React, { Fragment, useEffect, useState } from 'react'; |
|
2
|
|
|
import { |
|
3
|
|
|
Breadcrumb, |
|
4
|
|
|
BreadcrumbItem, |
|
5
|
|
|
Row, |
|
6
|
|
|
Col, |
|
7
|
|
|
Card, |
|
8
|
|
|
CardBody, |
|
9
|
|
|
Button, |
|
10
|
|
|
ButtonGroup, |
|
11
|
|
|
Form, |
|
12
|
|
|
FormGroup, |
|
13
|
|
|
Input, |
|
14
|
|
|
Label, |
|
15
|
|
|
CustomInput, |
|
16
|
|
|
Spinner |
|
17
|
|
|
} from 'reactstrap'; |
|
18
|
|
|
import CountUp from 'react-countup'; |
|
19
|
|
|
import Datetime from 'react-datetime'; |
|
20
|
|
|
import moment from 'moment'; |
|
21
|
|
|
import loadable from '@loadable/component'; |
|
22
|
|
|
import Cascader from 'rc-cascader'; |
|
23
|
|
|
import CardSummary from '../common/CardSummary'; |
|
24
|
|
|
import LineChart from '../common/LineChart'; |
|
25
|
|
|
import { getCookieValue, createCookie } from '../../../helpers/utils'; |
|
26
|
|
|
import withRedirect from '../../../hoc/withRedirect'; |
|
27
|
|
|
import { withTranslation } from 'react-i18next'; |
|
28
|
|
|
import { toast } from 'react-toastify'; |
|
29
|
|
|
import ButtonIcon from '../../common/ButtonIcon'; |
|
30
|
|
|
import { APIBaseURL } from '../../../config'; |
|
31
|
|
|
import { periodTypeOptions } from '../common/PeriodTypeOptions'; |
|
32
|
|
|
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions'; |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable')); |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
const SpaceStatistics = ({ setRedirect, setRedirectUrl, t }) => { |
|
39
|
|
|
let current_moment = moment(); |
|
40
|
|
|
useEffect(() => { |
|
41
|
|
|
let is_logged_in = getCookieValue('is_logged_in'); |
|
42
|
|
|
let user_name = getCookieValue('user_name'); |
|
43
|
|
|
let user_display_name = getCookieValue('user_display_name'); |
|
44
|
|
|
let user_uuid = getCookieValue('user_uuid'); |
|
45
|
|
|
let token = getCookieValue('token'); |
|
46
|
|
|
if (is_logged_in === null || !is_logged_in) { |
|
47
|
|
|
setRedirectUrl(`/authentication/basic/login`); |
|
48
|
|
|
setRedirect(true); |
|
49
|
|
|
} else { |
|
50
|
|
|
//update expires time of cookies |
|
51
|
|
|
createCookie('is_logged_in', true, 1000 * 60 * 60 * 8); |
|
52
|
|
|
createCookie('user_name', user_name, 1000 * 60 * 60 * 8); |
|
53
|
|
|
createCookie('user_display_name', user_display_name, 1000 * 60 * 60 * 8); |
|
54
|
|
|
createCookie('user_uuid', user_uuid, 1000 * 60 * 60 * 8); |
|
55
|
|
|
createCookie('token', token, 1000 * 60 * 60 * 8); |
|
56
|
|
|
} |
|
57
|
|
|
}); |
|
58
|
|
|
// State |
|
59
|
|
|
// Query Parameters |
|
60
|
|
|
const [selectedSpaceName, setSelectedSpaceName] = useState(undefined); |
|
61
|
|
|
const [selectedSpaceID, setSelectedSpaceID] = useState(undefined); |
|
62
|
|
|
const [comparisonType, setComparisonType] = useState('month-on-month'); |
|
63
|
|
|
const [periodType, setPeriodType] = useState('daily'); |
|
64
|
|
|
const [basePeriodBeginsDatetime, setBasePeriodBeginsDatetime] = useState(current_moment.clone().subtract(1, 'months').startOf('month')); |
|
65
|
|
|
const [basePeriodEndsDatetime, setBasePeriodEndsDatetime] = useState(current_moment.clone().subtract(1, 'months')); |
|
66
|
|
|
const [basePeriodBeginsDatetimeDisabled, setBasePeriodBeginsDatetimeDisabled] = useState(true); |
|
67
|
|
|
const [basePeriodEndsDatetimeDisabled, setBasePeriodEndsDatetimeDisabled] = useState(true); |
|
68
|
|
|
const [reportingPeriodBeginsDatetime, setReportingPeriodBeginsDatetime] = useState(current_moment.clone().startOf('month')); |
|
69
|
|
|
const [reportingPeriodEndsDatetime, setReportingPeriodEndsDatetime] = useState(current_moment); |
|
70
|
|
|
const [cascaderOptions, setCascaderOptions] = useState(undefined); |
|
71
|
|
|
|
|
72
|
|
|
// buttons |
|
73
|
|
|
const [submitButtonDisabled, setSubmitButtonDisabled] = useState(true); |
|
74
|
|
|
const [spinnerHidden, setSpinnerHidden] = useState(true); |
|
75
|
|
|
const [exportButtonHidden, setExportButtonHidden] = useState(true); |
|
76
|
|
|
|
|
77
|
|
|
//Results |
|
78
|
|
|
const [cardSummaryList, setCardSummaryList] = useState([]); |
|
79
|
|
|
const [spaceLineChartLabels, setSpaceLineChartLabels] = useState([]); |
|
80
|
|
|
const [spaceLineChartData, setSpaceLineChartData] = useState({}); |
|
81
|
|
|
const [spaceLineChartOptions, setSpaceLineChartOptions] = useState([]); |
|
82
|
|
|
|
|
83
|
|
|
const [parameterLineChartLabels, setParameterLineChartLabels] = useState([]); |
|
84
|
|
|
const [parameterLineChartData, setParameterLineChartData] = useState({}); |
|
85
|
|
|
const [parameterLineChartOptions, setParameterLineChartOptions] = useState([]); |
|
86
|
|
|
|
|
87
|
|
|
const [detailedDataTableData, setDetailedDataTableData] = useState([]); |
|
88
|
|
|
const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]); |
|
89
|
|
|
const [excelBytesBase64, setExcelBytesBase64] = useState(undefined); |
|
90
|
|
|
|
|
91
|
|
|
useEffect(() => { |
|
92
|
|
|
let isResponseOK = false; |
|
93
|
|
|
fetch(APIBaseURL + '/spaces/tree', { |
|
94
|
|
|
method: 'GET', |
|
95
|
|
|
headers: { |
|
96
|
|
|
"Content-type": "application/json", |
|
97
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
|
98
|
|
|
"Token": getCookieValue('token') |
|
99
|
|
|
}, |
|
100
|
|
|
body: null, |
|
101
|
|
|
|
|
102
|
|
|
}).then(response => { |
|
103
|
|
|
console.log(response); |
|
104
|
|
|
if (response.ok) { |
|
105
|
|
|
isResponseOK = true; |
|
106
|
|
|
// enable submit button |
|
107
|
|
|
setSubmitButtonDisabled(false); |
|
108
|
|
|
} |
|
109
|
|
|
return response.json(); |
|
110
|
|
|
}).then(json => { |
|
111
|
|
|
console.log(json); |
|
112
|
|
|
if (isResponseOK) { |
|
113
|
|
|
// rename keys |
|
114
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
|
115
|
|
|
setCascaderOptions(json); |
|
116
|
|
|
setSelectedSpaceName([json[0]].map(o => o.label)); |
|
117
|
|
|
setSelectedSpaceID([json[0]].map(o => o.value)); |
|
118
|
|
|
} else { |
|
119
|
|
|
toast.error(json.description); |
|
120
|
|
|
} |
|
121
|
|
|
}).catch(err => { |
|
122
|
|
|
console.log(err); |
|
123
|
|
|
}); |
|
124
|
|
|
|
|
125
|
|
|
}, []); |
|
126
|
|
|
const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0'; |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
let onSpaceCascaderChange = (value, selectedOptions) => { |
|
130
|
|
|
console.log(value, selectedOptions); |
|
131
|
|
|
setSelectedSpaceName(selectedOptions.map(o => o.label).join('/')); |
|
132
|
|
|
setSelectedSpaceID(value[value.length - 1]); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
let onComparisonTypeChange = ({ target }) => { |
|
137
|
|
|
console.log(target.value); |
|
138
|
|
|
setComparisonType(target.value); |
|
139
|
|
|
if (target.value === 'year-over-year') { |
|
140
|
|
|
setBasePeriodBeginsDatetimeDisabled(true); |
|
141
|
|
|
setBasePeriodEndsDatetimeDisabled(true); |
|
142
|
|
|
setBasePeriodBeginsDatetime(moment(reportingPeriodBeginsDatetime).subtract(1, 'years')); |
|
143
|
|
|
setBasePeriodEndsDatetime(moment(reportingPeriodEndsDatetime).subtract(1, 'years')); |
|
144
|
|
|
} else if (target.value === 'month-on-month') { |
|
145
|
|
|
setBasePeriodBeginsDatetimeDisabled(true); |
|
146
|
|
|
setBasePeriodEndsDatetimeDisabled(true); |
|
147
|
|
|
setBasePeriodBeginsDatetime(moment(reportingPeriodBeginsDatetime).subtract(1, 'months')); |
|
148
|
|
|
setBasePeriodEndsDatetime(moment(reportingPeriodEndsDatetime).subtract(1, 'months')); |
|
149
|
|
|
} else if (target.value === 'free-comparison') { |
|
150
|
|
|
setBasePeriodBeginsDatetimeDisabled(false); |
|
151
|
|
|
setBasePeriodEndsDatetimeDisabled(false); |
|
152
|
|
|
} else if (target.value === 'none-comparison') { |
|
153
|
|
|
setBasePeriodBeginsDatetime(undefined); |
|
154
|
|
|
setBasePeriodEndsDatetime(undefined); |
|
155
|
|
|
setBasePeriodBeginsDatetimeDisabled(true); |
|
156
|
|
|
setBasePeriodEndsDatetimeDisabled(true); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
let onBasePeriodBeginsDatetimeChange = (newDateTime) => { |
|
161
|
|
|
setBasePeriodBeginsDatetime(newDateTime); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
let onBasePeriodEndsDatetimeChange = (newDateTime) => { |
|
165
|
|
|
setBasePeriodEndsDatetime(newDateTime); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
let onReportingPeriodBeginsDatetimeChange = (newDateTime) => { |
|
169
|
|
|
setReportingPeriodBeginsDatetime(newDateTime); |
|
170
|
|
|
if (comparisonType === 'year-over-year') { |
|
171
|
|
|
setBasePeriodBeginsDatetime(newDateTime.clone().subtract(1, 'years')); |
|
172
|
|
|
} else if (comparisonType === 'month-on-month') { |
|
173
|
|
|
setBasePeriodBeginsDatetime(newDateTime.clone().subtract(1, 'months')); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
let onReportingPeriodEndsDatetimeChange = (newDateTime) => { |
|
178
|
|
|
setReportingPeriodEndsDatetime(newDateTime); |
|
179
|
|
|
if (comparisonType === 'year-over-year') { |
|
180
|
|
|
setBasePeriodEndsDatetime(newDateTime.clone().subtract(1, 'years')); |
|
181
|
|
|
} else if (comparisonType === 'month-on-month') { |
|
182
|
|
|
setBasePeriodEndsDatetime(newDateTime.clone().subtract(1, 'months')); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
var getValidBasePeriodBeginsDatetimes = function (currentDate) { |
|
187
|
|
|
return currentDate.isBefore(moment(basePeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
var getValidBasePeriodEndsDatetimes = function (currentDate) { |
|
191
|
|
|
return currentDate.isAfter(moment(basePeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
var getValidReportingPeriodBeginsDatetimes = function (currentDate) { |
|
195
|
|
|
return currentDate.isBefore(moment(reportingPeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
var getValidReportingPeriodEndsDatetimes = function (currentDate) { |
|
199
|
|
|
return currentDate.isAfter(moment(reportingPeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
// Handler |
|
203
|
|
|
const handleSubmit = e => { |
|
204
|
|
|
e.preventDefault(); |
|
205
|
|
|
console.log('handleSubmit'); |
|
206
|
|
|
console.log(selectedSpaceID); |
|
207
|
|
|
console.log(comparisonType); |
|
208
|
|
|
console.log(periodType); |
|
209
|
|
|
console.log(basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined); |
|
210
|
|
|
console.log(basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined); |
|
211
|
|
|
console.log(reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss')); |
|
212
|
|
|
console.log(reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss')); |
|
213
|
|
|
|
|
214
|
|
|
// disable submit button |
|
215
|
|
|
setSubmitButtonDisabled(true); |
|
216
|
|
|
// show spinner |
|
217
|
|
|
setSpinnerHidden(false); |
|
218
|
|
|
// hide export buttion |
|
219
|
|
|
setExportButtonHidden(true) |
|
220
|
|
|
|
|
221
|
|
|
// Reinitialize tables |
|
222
|
|
|
setDetailedDataTableData([]); |
|
223
|
|
|
|
|
224
|
|
|
let isResponseOK = false; |
|
225
|
|
|
fetch(APIBaseURL + '/reports/spacestatistics?' + |
|
226
|
|
|
'spaceid=' + selectedSpaceID + |
|
227
|
|
|
'&periodtype=' + periodType + |
|
228
|
|
|
'&baseperiodstartdatetime=' + (basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') + |
|
229
|
|
|
'&baseperiodenddatetime=' + (basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') + |
|
230
|
|
|
'&reportingperiodstartdatetime=' + reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') + |
|
231
|
|
|
'&reportingperiodenddatetime=' + reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'), { |
|
232
|
|
|
method: 'GET', |
|
233
|
|
|
headers: { |
|
234
|
|
|
"Content-type": "application/json", |
|
235
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
|
236
|
|
|
"Token": getCookieValue('token') |
|
237
|
|
|
}, |
|
238
|
|
|
body: null, |
|
239
|
|
|
|
|
240
|
|
|
}).then(response => { |
|
241
|
|
|
if (response.ok) { |
|
242
|
|
|
isResponseOK = true; |
|
243
|
|
|
} |
|
244
|
|
|
return response.json(); |
|
245
|
|
|
}).then(json => { |
|
246
|
|
|
if (isResponseOK) { |
|
247
|
|
|
console.log(json) |
|
248
|
|
|
let cardSummaryArray = [] |
|
249
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
|
250
|
|
|
let cardSummaryItem = {} |
|
251
|
|
|
cardSummaryItem['name'] = json['reporting_period']['names'][index]; |
|
252
|
|
|
cardSummaryItem['unit'] = json['reporting_period']['units'][index]; |
|
253
|
|
|
cardSummaryItem['mean'] = json['reporting_period']['means'][index]; |
|
254
|
|
|
cardSummaryItem['mean_increment_rate'] = parseFloat(json['reporting_period']['means_increment_rate'][index] * 100).toFixed(2) + "%"; |
|
255
|
|
|
cardSummaryItem['mean_per_unit_area'] = json['reporting_period']['means_per_unit_area'][index]; |
|
256
|
|
|
cardSummaryItem['median'] = json['reporting_period']['medians'][index]; |
|
257
|
|
|
cardSummaryItem['median_increment_rate'] = parseFloat(json['reporting_period']['medians_increment_rate'][index] * 100).toFixed(2) + "%"; |
|
258
|
|
|
cardSummaryItem['median_per_unit_area'] = json['reporting_period']['medians_per_unit_area'][index]; |
|
259
|
|
|
cardSummaryItem['minimum'] = json['reporting_period']['minimums'][index]; |
|
260
|
|
|
cardSummaryItem['minimum_increment_rate'] = parseFloat(json['reporting_period']['minimums_increment_rate'][index] * 100).toFixed(2) + "%"; |
|
261
|
|
|
cardSummaryItem['minimum_per_unit_area'] = json['reporting_period']['minimums_per_unit_area'][index]; |
|
262
|
|
|
cardSummaryItem['maximum'] = json['reporting_period']['maximums'][index]; |
|
263
|
|
|
cardSummaryItem['maximum_increment_rate'] = parseFloat(json['reporting_period']['maximums_increment_rate'][index] * 100).toFixed(2) + "%"; |
|
264
|
|
|
cardSummaryItem['maximum_per_unit_area'] = json['reporting_period']['maximums_per_unit_area'][index]; |
|
265
|
|
|
cardSummaryItem['stdev'] = json['reporting_period']['stdevs'][index]; |
|
266
|
|
|
cardSummaryItem['stdev_increment_rate'] = parseFloat(json['reporting_period']['stdevs_increment_rate'][index] * 100).toFixed(2) + "%"; |
|
267
|
|
|
cardSummaryItem['stdev_per_unit_area'] = json['reporting_period']['stdevs_per_unit_area'][index]; |
|
268
|
|
|
cardSummaryItem['variance'] = json['reporting_period']['variances'][index]; |
|
269
|
|
|
cardSummaryItem['variance_increment_rate'] = parseFloat(json['reporting_period']['variances_increment_rate'][index] * 100).toFixed(2) + "%"; |
|
270
|
|
|
cardSummaryItem['variance_per_unit_area'] = json['reporting_period']['variances_per_unit_area'][index]; |
|
271
|
|
|
cardSummaryArray.push(cardSummaryItem); |
|
272
|
|
|
}); |
|
273
|
|
|
setCardSummaryList(cardSummaryArray); |
|
274
|
|
|
|
|
275
|
|
|
let timestamps = {} |
|
276
|
|
|
json['reporting_period']['timestamps'].forEach((currentValue, index) => { |
|
277
|
|
|
timestamps['a' + index] = currentValue; |
|
278
|
|
|
}); |
|
279
|
|
|
setSpaceLineChartLabels(timestamps); |
|
280
|
|
|
|
|
281
|
|
|
let values = {} |
|
282
|
|
|
json['reporting_period']['values'].forEach((currentValue, index) => { |
|
283
|
|
|
values['a' + index] = currentValue; |
|
284
|
|
|
}); |
|
285
|
|
|
setSpaceLineChartData(values); |
|
286
|
|
|
|
|
287
|
|
|
let names = Array(); |
|
288
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
|
289
|
|
|
let unit = json['reporting_period']['units'][index]; |
|
290
|
|
|
names.push({ 'value': 'a' + index, 'label': currentValue + ' (' + unit + ')'}); |
|
291
|
|
|
}); |
|
292
|
|
|
setSpaceLineChartOptions(names); |
|
293
|
|
|
|
|
294
|
|
|
timestamps = {} |
|
295
|
|
|
json['parameters']['timestamps'].forEach((currentValue, index) => { |
|
296
|
|
|
timestamps['a' + index] = currentValue; |
|
297
|
|
|
}); |
|
298
|
|
|
setParameterLineChartLabels(timestamps); |
|
299
|
|
|
|
|
300
|
|
|
values = {} |
|
301
|
|
|
json['parameters']['values'].forEach((currentValue, index) => { |
|
302
|
|
|
values['a' + index] = currentValue; |
|
303
|
|
|
}); |
|
304
|
|
|
setParameterLineChartData(values); |
|
305
|
|
|
|
|
306
|
|
|
names = Array(); |
|
307
|
|
|
json['parameters']['names'].forEach((currentValue, index) => { |
|
308
|
|
|
if (currentValue.startsWith('TARIFF-')) { |
|
309
|
|
|
currentValue = t('Tariff') + currentValue.replace('TARIFF-', '-'); |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
names.push({ 'value': 'a' + index, 'label': currentValue }); |
|
313
|
|
|
}); |
|
314
|
|
|
setParameterLineChartOptions(names); |
|
315
|
|
|
|
|
316
|
|
|
let detailed_value_list = []; |
|
317
|
|
|
if (json['reporting_period']['timestamps'].length > 0) { |
|
318
|
|
|
json['reporting_period']['timestamps'][0].forEach((currentTimestamp, timestampIndex) => { |
|
319
|
|
|
let detailed_value = {}; |
|
320
|
|
|
detailed_value['id'] = timestampIndex; |
|
321
|
|
|
detailed_value['startdatetime'] = currentTimestamp; |
|
322
|
|
|
json['reporting_period']['values'].forEach((currentValue, energyCategoryIndex) => { |
|
323
|
|
|
detailed_value['a' + energyCategoryIndex] = json['reporting_period']['values'][energyCategoryIndex][timestampIndex].toFixed(2); |
|
324
|
|
|
}); |
|
325
|
|
|
detailed_value_list.push(detailed_value); |
|
326
|
|
|
}); |
|
327
|
|
|
}; |
|
328
|
|
|
|
|
329
|
|
|
let detailed_value = {}; |
|
330
|
|
|
detailed_value['id'] = detailed_value_list.length; |
|
331
|
|
|
detailed_value['startdatetime'] = t('Subtotal'); |
|
332
|
|
|
json['reporting_period']['subtotals'].forEach((currentValue, index) => { |
|
333
|
|
|
detailed_value['a' + index] = currentValue.toFixed(2); |
|
334
|
|
|
}); |
|
335
|
|
|
detailed_value_list.push(detailed_value); |
|
336
|
|
|
setDetailedDataTableData(detailed_value_list); |
|
337
|
|
|
|
|
338
|
|
|
let detailed_column_list = []; |
|
339
|
|
|
detailed_column_list.push({ |
|
340
|
|
|
dataField: 'startdatetime', |
|
341
|
|
|
text: t('Datetime'), |
|
342
|
|
|
sort: true |
|
343
|
|
|
}) |
|
344
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
|
345
|
|
|
let unit = json['reporting_period']['units'][index]; |
|
346
|
|
|
detailed_column_list.push({ |
|
347
|
|
|
dataField: 'a' + index, |
|
348
|
|
|
text: currentValue + ' (' + unit + ')', |
|
349
|
|
|
sort: true |
|
350
|
|
|
}) |
|
351
|
|
|
}); |
|
352
|
|
|
setDetailedDataTableColumns(detailed_column_list); |
|
353
|
|
|
|
|
354
|
|
|
setExcelBytesBase64(json['excel_bytes_base64']); |
|
355
|
|
|
|
|
356
|
|
|
// enable submit button |
|
357
|
|
|
setSubmitButtonDisabled(false); |
|
358
|
|
|
// hide spinner |
|
359
|
|
|
setSpinnerHidden(true); |
|
360
|
|
|
// show export buttion |
|
361
|
|
|
setExportButtonHidden(false) |
|
362
|
|
|
|
|
363
|
|
|
} else { |
|
364
|
|
|
toast.error(json.description) |
|
365
|
|
|
} |
|
366
|
|
|
}).catch(err => { |
|
367
|
|
|
console.log(err); |
|
368
|
|
|
}); |
|
369
|
|
|
}; |
|
370
|
|
|
|
|
371
|
|
|
const handleExport = e => { |
|
372
|
|
|
e.preventDefault(); |
|
373
|
|
|
const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
|
374
|
|
|
const fileName = 'spacestatistics.xlsx' |
|
375
|
|
|
var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64; |
|
376
|
|
|
fetch(fileUrl) |
|
377
|
|
|
.then(response => response.blob()) |
|
378
|
|
|
.then(blob => { |
|
379
|
|
|
var link = window.document.createElement("a"); |
|
380
|
|
|
link.href = window.URL.createObjectURL(blob, { type: mimeType }); |
|
381
|
|
|
link.download = fileName; |
|
382
|
|
|
document.body.appendChild(link); |
|
383
|
|
|
link.click(); |
|
384
|
|
|
document.body.removeChild(link); |
|
385
|
|
|
}); |
|
386
|
|
|
}; |
|
387
|
|
|
|
|
388
|
|
|
|
|
389
|
|
|
|
|
390
|
|
|
return ( |
|
391
|
|
|
<Fragment> |
|
392
|
|
|
<div> |
|
393
|
|
|
<Breadcrumb> |
|
394
|
|
|
<BreadcrumbItem>{t('Space Data')}</BreadcrumbItem><BreadcrumbItem active>{t('Statistics')}</BreadcrumbItem> |
|
395
|
|
|
</Breadcrumb> |
|
396
|
|
|
</div> |
|
397
|
|
|
<Card className="bg-light mb-3"> |
|
398
|
|
|
<CardBody className="p-3"> |
|
399
|
|
|
<Form onSubmit={handleSubmit}> |
|
400
|
|
|
<Row form> |
|
401
|
|
|
<Col xs="auto"> |
|
402
|
|
|
<FormGroup className="form-group"> |
|
403
|
|
|
<Label className={labelClasses} for="space"> |
|
404
|
|
|
{t('Space')} |
|
405
|
|
|
</Label> |
|
406
|
|
|
<br /> |
|
407
|
|
|
<Cascader options={cascaderOptions} |
|
408
|
|
|
onChange={onSpaceCascaderChange} |
|
409
|
|
|
changeOnSelect |
|
410
|
|
|
expandTrigger="hover"> |
|
411
|
|
|
<Input value={selectedSpaceName || ''} readOnly /> |
|
412
|
|
|
</Cascader> |
|
413
|
|
|
</FormGroup> |
|
414
|
|
|
</Col> |
|
415
|
|
|
<Col xs="auto"> |
|
416
|
|
|
<FormGroup> |
|
417
|
|
|
<Label className={labelClasses} for="comparisonType"> |
|
418
|
|
|
{t('Comparison Types')} |
|
419
|
|
|
</Label> |
|
420
|
|
|
<CustomInput type="select" id="comparisonType" name="comparisonType" |
|
421
|
|
|
defaultValue="month-on-month" |
|
422
|
|
|
onChange={onComparisonTypeChange} |
|
423
|
|
|
> |
|
424
|
|
|
{comparisonTypeOptions.map((comparisonType, index) => ( |
|
425
|
|
|
<option value={comparisonType.value} key={comparisonType.value} > |
|
426
|
|
|
{t(comparisonType.label)} |
|
427
|
|
|
</option> |
|
428
|
|
|
))} |
|
429
|
|
|
</CustomInput> |
|
430
|
|
|
</FormGroup> |
|
431
|
|
|
</Col> |
|
432
|
|
|
<Col xs="auto"> |
|
433
|
|
|
<FormGroup> |
|
434
|
|
|
<Label className={labelClasses} for="periodType"> |
|
435
|
|
|
{t('Period Types')} |
|
436
|
|
|
</Label> |
|
437
|
|
|
<CustomInput type="select" id="periodType" name="periodType" defaultValue="daily" onChange={({ target }) => setPeriodType(target.value)} |
|
438
|
|
|
> |
|
439
|
|
|
{periodTypeOptions.map((periodType, index) => ( |
|
440
|
|
|
<option value={periodType.value} key={periodType.value} > |
|
441
|
|
|
{t(periodType.label)} |
|
442
|
|
|
</option> |
|
443
|
|
|
))} |
|
444
|
|
|
</CustomInput> |
|
445
|
|
|
</FormGroup> |
|
446
|
|
|
</Col> |
|
447
|
|
|
<Col xs="auto"> |
|
448
|
|
|
<FormGroup className="form-group"> |
|
449
|
|
|
<Label className={labelClasses} for="basePeriodBeginsDatetime"> |
|
450
|
|
|
{t('Base Period Begins')}{t('(Optional)')} |
|
451
|
|
|
</Label> |
|
452
|
|
|
<Datetime id='basePeriodBeginsDatetime' |
|
453
|
|
|
value={basePeriodBeginsDatetime} |
|
454
|
|
|
inputProps={{ disabled: basePeriodBeginsDatetimeDisabled }} |
|
455
|
|
|
onChange={onBasePeriodBeginsDatetimeChange} |
|
456
|
|
|
isValidDate={getValidBasePeriodBeginsDatetimes} |
|
457
|
|
|
closeOnSelect={true} /> |
|
458
|
|
|
</FormGroup> |
|
459
|
|
|
</Col> |
|
460
|
|
|
<Col xs="auto"> |
|
461
|
|
|
<FormGroup className="form-group"> |
|
462
|
|
|
<Label className={labelClasses} for="basePeriodEndsDatetime"> |
|
463
|
|
|
{t('Base Period Ends')}{t('(Optional)')} |
|
464
|
|
|
</Label> |
|
465
|
|
|
<Datetime id='basePeriodEndsDatetime' |
|
466
|
|
|
value={basePeriodEndsDatetime} |
|
467
|
|
|
inputProps={{ disabled: basePeriodEndsDatetimeDisabled }} |
|
468
|
|
|
onChange={onBasePeriodEndsDatetimeChange} |
|
469
|
|
|
isValidDate={getValidBasePeriodEndsDatetimes} |
|
470
|
|
|
closeOnSelect={true} /> |
|
471
|
|
|
</FormGroup> |
|
472
|
|
|
</Col> |
|
473
|
|
|
<Col xs="auto"> |
|
474
|
|
|
<FormGroup className="form-group"> |
|
475
|
|
|
<Label className={labelClasses} for="reportingPeriodBeginsDatetime"> |
|
476
|
|
|
{t('Reporting Period Begins')} |
|
477
|
|
|
</Label> |
|
478
|
|
|
<Datetime id='reportingPeriodBeginsDatetime' |
|
479
|
|
|
value={reportingPeriodBeginsDatetime} |
|
480
|
|
|
onChange={onReportingPeriodBeginsDatetimeChange} |
|
481
|
|
|
isValidDate={getValidReportingPeriodBeginsDatetimes} |
|
482
|
|
|
closeOnSelect={true} /> |
|
483
|
|
|
</FormGroup> |
|
484
|
|
|
</Col> |
|
485
|
|
|
<Col xs="auto"> |
|
486
|
|
|
<FormGroup className="form-group"> |
|
487
|
|
|
<Label className={labelClasses} for="reportingPeriodEndsDatetime"> |
|
488
|
|
|
{t('Reporting Period Ends')} |
|
489
|
|
|
</Label> |
|
490
|
|
|
<Datetime id='reportingPeriodEndsDatetime' |
|
491
|
|
|
value={reportingPeriodEndsDatetime} |
|
492
|
|
|
onChange={onReportingPeriodEndsDatetimeChange} |
|
493
|
|
|
isValidDate={getValidReportingPeriodEndsDatetimes} |
|
494
|
|
|
closeOnSelect={true} /> |
|
495
|
|
|
</FormGroup> |
|
496
|
|
|
</Col> |
|
497
|
|
|
<Col xs="auto"> |
|
498
|
|
|
<FormGroup> |
|
499
|
|
|
<br></br> |
|
500
|
|
|
<ButtonGroup id="submit"> |
|
501
|
|
|
<Button color="success" disabled={submitButtonDisabled} >{t('Submit')}</Button> |
|
502
|
|
|
</ButtonGroup> |
|
503
|
|
|
</FormGroup> |
|
504
|
|
|
</Col> |
|
505
|
|
|
<Col xs="auto"> |
|
506
|
|
|
<FormGroup> |
|
507
|
|
|
<br></br> |
|
508
|
|
|
<Spinner color="primary" hidden={spinnerHidden} /> |
|
509
|
|
|
</FormGroup> |
|
510
|
|
|
</Col> |
|
511
|
|
|
<Col xs="auto"> |
|
512
|
|
|
<br></br> |
|
513
|
|
|
<ButtonIcon icon="external-link-alt" transform="shrink-3 down-2" color="falcon-default" |
|
514
|
|
|
hidden={exportButtonHidden} |
|
515
|
|
|
onClick={handleExport} > |
|
516
|
|
|
{t('Export')} |
|
517
|
|
|
</ButtonIcon> |
|
518
|
|
|
</Col> |
|
519
|
|
|
</Row> |
|
520
|
|
|
</Form> |
|
521
|
|
|
</CardBody> |
|
522
|
|
|
</Card> |
|
523
|
|
|
{cardSummaryList.map(cardSummaryItem => ( |
|
524
|
|
|
<div className="card-deck" key={cardSummaryItem['name']}> |
|
525
|
|
|
<CardSummary key={cardSummaryItem['name'] + 'mean'} |
|
526
|
|
|
rate={cardSummaryItem['mean_increment_rate']} |
|
527
|
|
|
title={t('Reporting Period CATEGORY Mean UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })} |
|
528
|
|
|
color="success" |
|
529
|
|
|
footnote={t('Per Unit Area')} |
|
530
|
|
|
footvalue={cardSummaryItem['mean_per_unit_area']} |
|
531
|
|
|
footunit={"(" + cardSummaryItem['unit'] + "/M²)"} > |
|
532
|
|
|
{cardSummaryItem['mean'] && <CountUp end={cardSummaryItem['mean']} duration={2} prefix="" separator="," decimal="." decimals={2} />} |
|
533
|
|
|
</CardSummary> |
|
534
|
|
|
<CardSummary key={cardSummaryItem['name'] + 'median'} |
|
535
|
|
|
rate={cardSummaryItem['median_increment_rate']} |
|
536
|
|
|
title={t('Reporting Period CATEGORY Median UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })} |
|
537
|
|
|
color="success" |
|
538
|
|
|
footnote={t('Per Unit Area')} |
|
539
|
|
|
footvalue={cardSummaryItem['median_per_unit_area']} |
|
540
|
|
|
footunit={"(" + cardSummaryItem['unit'] + "/M²)"} > |
|
541
|
|
|
{cardSummaryItem['median'] && <CountUp end={cardSummaryItem['median']} duration={2} prefix="" separator="," decimal="." decimals={2} />} |
|
542
|
|
|
</CardSummary> |
|
543
|
|
|
<CardSummary key={cardSummaryItem['name'] + 'minimum'} |
|
544
|
|
|
rate={cardSummaryItem['minimum_increment_rate']} |
|
545
|
|
|
title={t('Reporting Period CATEGORY Minimum UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })} |
|
546
|
|
|
color="success" |
|
547
|
|
|
footnote={t('Per Unit Area')} |
|
548
|
|
|
footvalue={cardSummaryItem['minimum_per_unit_area']} |
|
549
|
|
|
footunit={"(" + cardSummaryItem['unit'] + "/M²)"} > |
|
550
|
|
|
{cardSummaryItem['minimum'] && <CountUp end={cardSummaryItem['minimum']} duration={2} prefix="" separator="," decimal="." decimals={2} />} |
|
551
|
|
|
</CardSummary> |
|
552
|
|
|
<CardSummary key={cardSummaryItem['name'] + 'maximum'} |
|
553
|
|
|
rate={cardSummaryItem['maximum_increment_rate']} |
|
554
|
|
|
title={t('Reporting Period CATEGORY Maximum UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })} |
|
555
|
|
|
color="success" |
|
556
|
|
|
footnote={t('Per Unit Area')} |
|
557
|
|
|
footvalue={cardSummaryItem['maximum_per_unit_area']} |
|
558
|
|
|
footunit={"(" + cardSummaryItem['unit'] + "/M²)"} > |
|
559
|
|
|
{cardSummaryItem['maximum'] && <CountUp end={cardSummaryItem['maximum']} duration={2} prefix="" separator="," decimal="." decimals={2} />} |
|
560
|
|
|
</CardSummary> |
|
561
|
|
|
<CardSummary key={cardSummaryItem['name'] + 'stdev'} |
|
562
|
|
|
rate={cardSummaryItem['stdev_increment_rate']} |
|
563
|
|
|
title={t('Reporting Period CATEGORY Stdev UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })} |
|
564
|
|
|
color="success" |
|
565
|
|
|
footnote={t('Per Unit Area')} |
|
566
|
|
|
footvalue={cardSummaryItem['stdev_per_unit_area']} |
|
567
|
|
|
footunit={"(" + cardSummaryItem['unit'] + "/M²)"} > |
|
568
|
|
|
{cardSummaryItem['stdev'] && <CountUp end={cardSummaryItem['stdev']} duration={2} prefix="" separator="," decimal="." decimals={2} />} |
|
569
|
|
|
</CardSummary> |
|
570
|
|
|
<CardSummary key={cardSummaryItem['name'] + 'variance'} |
|
571
|
|
|
rate={cardSummaryItem['variance_increment_rate']} |
|
572
|
|
|
title={t('Reporting Period CATEGORY Variance UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })} |
|
573
|
|
|
color="success" |
|
574
|
|
|
footnote={t('Per Unit Area')} |
|
575
|
|
|
footvalue={cardSummaryItem['variance_per_unit_area']} |
|
576
|
|
|
footunit={"(" + cardSummaryItem['unit'] + "/M²)"} > |
|
577
|
|
|
{cardSummaryItem['variance'] && <CountUp end={cardSummaryItem['variance']} duration={2} prefix="" separator="," decimal="." decimals={2} />} |
|
578
|
|
|
</CardSummary> |
|
579
|
|
|
</div> |
|
580
|
|
|
))} |
|
581
|
|
|
<LineChart reportingTitle={t('Reporting Period Consumption CATEGORY VALUE UNIT', { 'CATEGORY': null, 'VALUE': null, 'UNIT': null })} |
|
582
|
|
|
baseTitle='' |
|
583
|
|
|
labels={spaceLineChartLabels} |
|
584
|
|
|
data={spaceLineChartData} |
|
585
|
|
|
options={spaceLineChartOptions}> |
|
586
|
|
|
</LineChart> |
|
587
|
|
|
|
|
588
|
|
|
<LineChart reportingTitle={t('Related Parameters')} |
|
589
|
|
|
baseTitle='' |
|
590
|
|
|
labels={parameterLineChartLabels} |
|
591
|
|
|
data={parameterLineChartData} |
|
592
|
|
|
options={parameterLineChartOptions}> |
|
593
|
|
|
</LineChart> |
|
594
|
|
|
<DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={50} > |
|
595
|
|
|
</DetailedDataTable> |
|
596
|
|
|
<br /> |
|
597
|
|
|
|
|
598
|
|
|
</Fragment> |
|
599
|
|
|
); |
|
600
|
|
|
}; |
|
601
|
|
|
|
|
602
|
|
|
export default withTranslation()(withRedirect(SpaceStatistics)); |
|
603
|
|
|
|