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