|
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 moment from 'moment'; |
|
20
|
|
|
import loadable from '@loadable/component'; |
|
21
|
|
|
import Cascader from 'rc-cascader'; |
|
22
|
|
|
import CardSummary from '../common/CardSummary'; |
|
23
|
|
|
import LineChart from '../common/LineChart'; |
|
24
|
|
|
import MultipleLineChart from '../common/MultipleLineChart'; |
|
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
|
|
|
import { DateRangePicker } from 'rsuite'; |
|
34
|
|
|
import { endOfDay} from 'date-fns'; |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable')); |
|
38
|
|
|
|
|
39
|
|
|
const MeterComparison = ({ setRedirect, setRedirectUrl, t }) => { |
|
40
|
|
|
let current_moment = moment(); |
|
41
|
|
|
useEffect(() => { |
|
42
|
|
|
let is_logged_in = getCookieValue('is_logged_in'); |
|
43
|
|
|
let user_name = getCookieValue('user_name'); |
|
44
|
|
|
let user_display_name = getCookieValue('user_display_name'); |
|
45
|
|
|
let user_uuid = getCookieValue('user_uuid'); |
|
46
|
|
|
let token = getCookieValue('token'); |
|
47
|
|
|
if (is_logged_in === null || !is_logged_in) { |
|
48
|
|
|
setRedirectUrl(`/authentication/basic/login`); |
|
49
|
|
|
setRedirect(true); |
|
50
|
|
|
} else { |
|
51
|
|
|
//update expires time of cookies |
|
52
|
|
|
createCookie('is_logged_in', true, 1000 * 60 * 60 * 8); |
|
53
|
|
|
createCookie('user_name', user_name, 1000 * 60 * 60 * 8); |
|
54
|
|
|
createCookie('user_display_name', user_display_name, 1000 * 60 * 60 * 8); |
|
55
|
|
|
createCookie('user_uuid', user_uuid, 1000 * 60 * 60 * 8); |
|
56
|
|
|
createCookie('token', token, 1000 * 60 * 60 * 8); |
|
57
|
|
|
} |
|
58
|
|
|
}); |
|
59
|
|
|
|
|
60
|
|
|
// State |
|
61
|
|
|
//Query Form |
|
62
|
|
|
const [selectedSpaceName1, setSelectedSpaceName1] = useState(undefined); |
|
63
|
|
|
const [selectedSpaceName2, setSelectedSpaceName2] = useState(undefined); |
|
64
|
|
|
const [selectedSpaceID1, setSelectedSpaceID1] = useState(undefined); |
|
65
|
|
|
const [selectedSpaceID2, setSelectedSpaceID2] = useState(undefined); |
|
66
|
|
|
const [meterList1, setMeterList1] = useState([]); |
|
67
|
|
|
const [meterList2, setMeterList2] = useState([]); |
|
68
|
|
|
const [filteredMeterList1, setFilteredMeterList1] = useState([]); |
|
69
|
|
|
const [filteredMeterList2, setFilteredMeterList2] = useState([]); |
|
70
|
|
|
const [selectedMeter1, setSelectedMeter1] = useState(undefined); |
|
71
|
|
|
const [selectedMeter2, setSelectedMeter2] = useState(undefined); |
|
72
|
|
|
const [periodType, setPeriodType] = useState('daily'); |
|
73
|
|
|
const [cascaderOptions, setCascaderOptions] = useState(undefined); |
|
74
|
|
|
const [reportingPeriodDateRange, setReportingPeriodDateRange] = useState([current_moment.clone().startOf('month').toDate(), current_moment.toDate()]); |
|
75
|
|
|
const dateRangePickerLocale = { |
|
76
|
|
|
sunday: t('sunday'), |
|
77
|
|
|
monday: t('monday'), |
|
78
|
|
|
tuesday: t('tuesday'), |
|
79
|
|
|
wednesday: t('wednesday'), |
|
80
|
|
|
thursday: t('thursday'), |
|
81
|
|
|
friday: t('friday'), |
|
82
|
|
|
saturday: t('saturday'), |
|
83
|
|
|
ok: t('ok'), |
|
84
|
|
|
today: t('today'), |
|
85
|
|
|
yesterday: t('yesterday'), |
|
86
|
|
|
hours: t('hours'), |
|
87
|
|
|
minutes: t('minutes'), |
|
88
|
|
|
seconds: t('seconds'), |
|
89
|
|
|
last7Days: t('last7Days') |
|
90
|
|
|
}; |
|
91
|
|
|
const dateRangePickerStyle = { display: 'block', zIndex: 10}; |
|
92
|
|
|
|
|
93
|
|
|
// buttons |
|
94
|
|
|
const [submitButtonDisabled, setSubmitButtonDisabled] = useState(true); |
|
95
|
|
|
const [spinnerHidden, setSpinnerHidden] = useState(true); |
|
96
|
|
|
const [exportButtonHidden, setExportButtonHidden] = useState(true); |
|
97
|
|
|
|
|
98
|
|
|
//Results |
|
99
|
|
|
const [meter1, setMeter1] = useState({ 'name': undefined, 'energy_category_id': undefined, 'energy_category_name': undefined, 'unit_of_measure': undefined }); |
|
100
|
|
|
const [meter2, setMeter2] = useState({ 'name': undefined, 'energy_category_id': undefined, 'energy_category_name': undefined, 'unit_of_measure': undefined }); |
|
101
|
|
|
const [reportingPeriodEnergyConsumptionInCategory1, setReportingPeriodEnergyConsumptionInCategory1] = useState(0); |
|
102
|
|
|
const [reportingPeriodEnergyConsumptionInCategory2, setReportingPeriodEnergyConsumptionInCategory2] = useState(0); |
|
103
|
|
|
const [meterLineChartOptions1, setMeterLineChartOptions1] = useState([]); |
|
104
|
|
|
const [meterLineChartOptions2, setMeterLineChartOptions2] = useState([]); |
|
105
|
|
|
const [meterLineChartData1, setMeterLineChartData1] = useState({}); |
|
106
|
|
|
const [meterLineChartData2, setMeterLineChartData2] = useState({}); |
|
107
|
|
|
const [meterLineChartLabels1, setMeterLineChartLabels1] = useState([]); |
|
108
|
|
|
const [meterLineChartLabels2, setMeterLineChartLabels2] = useState([]); |
|
109
|
|
|
const [parameterLineChartOptions, setParameterLineChartOptions] = useState([]); |
|
110
|
|
|
const [parameterLineChartData, setParameterLineChartData] = useState({}); |
|
111
|
|
|
const [parameterLineChartLabels, setParameterLineChartLabels] = useState([]); |
|
112
|
|
|
const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]); |
|
113
|
|
|
const [detailedDataTableData, setDetailedDataTableData] = useState([]); |
|
114
|
|
|
const [excelBytesBase64, setExcelBytesBase64] = useState(undefined); |
|
115
|
|
|
|
|
116
|
|
|
useEffect(() => { |
|
117
|
|
|
let isResponseOK = false; |
|
118
|
|
|
fetch(APIBaseURL + '/spaces/tree', { |
|
119
|
|
|
method: 'GET', |
|
120
|
|
|
headers: { |
|
121
|
|
|
"Content-type": "application/json", |
|
122
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
|
123
|
|
|
"Token": getCookieValue('token') |
|
124
|
|
|
}, |
|
125
|
|
|
body: null, |
|
126
|
|
|
|
|
127
|
|
|
}).then(response => { |
|
128
|
|
|
console.log(response); |
|
129
|
|
|
if (response.ok) { |
|
130
|
|
|
isResponseOK = true; |
|
131
|
|
|
} |
|
132
|
|
|
return response.json(); |
|
133
|
|
|
}).then(json => { |
|
134
|
|
|
console.log(json); |
|
135
|
|
|
if (isResponseOK) { |
|
136
|
|
|
// rename keys |
|
137
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
|
138
|
|
|
setCascaderOptions(json); |
|
139
|
|
|
setSelectedSpaceName1([json[0]].map(o => o.label)); |
|
140
|
|
|
setSelectedSpaceName2([json[0]].map(o => o.label)); |
|
141
|
|
|
setSelectedSpaceID1([json[0]].map(o => o.value)); |
|
142
|
|
|
setSelectedSpaceID2([json[0]].map(o => o.value)); |
|
143
|
|
|
// get Meters by root Space ID |
|
144
|
|
|
let isResponseOK = false; |
|
145
|
|
|
fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/meters', { |
|
146
|
|
|
method: 'GET', |
|
147
|
|
|
headers: { |
|
148
|
|
|
"Content-type": "application/json", |
|
149
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
|
150
|
|
|
"Token": getCookieValue('token') |
|
151
|
|
|
}, |
|
152
|
|
|
body: null, |
|
153
|
|
|
|
|
154
|
|
|
}).then(response => { |
|
155
|
|
|
if (response.ok) { |
|
156
|
|
|
isResponseOK = true; |
|
157
|
|
|
} |
|
158
|
|
|
return response.json(); |
|
159
|
|
|
}).then(json => { |
|
160
|
|
|
if (isResponseOK) { |
|
161
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
|
162
|
|
|
console.log(json); |
|
163
|
|
|
setMeterList1(json[0]); |
|
164
|
|
|
setMeterList2(json[0]); |
|
165
|
|
|
setFilteredMeterList1(json[0]); |
|
166
|
|
|
setFilteredMeterList2(json[0]); |
|
167
|
|
|
if (json[0].length > 0) { |
|
168
|
|
|
setSelectedMeter1(json[0][0].value); |
|
169
|
|
|
setSelectedMeter2(json[0][0].value); |
|
170
|
|
|
// enable submit button |
|
171
|
|
|
setSubmitButtonDisabled(false); |
|
172
|
|
|
} else { |
|
173
|
|
|
setSelectedMeter1(undefined); |
|
174
|
|
|
setSelectedMeter2(undefined); |
|
175
|
|
|
// disable submit button |
|
176
|
|
|
setSubmitButtonDisabled(true); |
|
177
|
|
|
} |
|
178
|
|
|
} else { |
|
179
|
|
|
toast.error(json.description) |
|
180
|
|
|
} |
|
181
|
|
|
}).catch(err => { |
|
182
|
|
|
console.log(err); |
|
183
|
|
|
}); |
|
184
|
|
|
// end of get Meters by root Space ID |
|
185
|
|
|
} else { |
|
186
|
|
|
toast.error(json.description); |
|
187
|
|
|
} |
|
188
|
|
|
}).catch(err => { |
|
189
|
|
|
console.log(err); |
|
190
|
|
|
}); |
|
191
|
|
|
|
|
192
|
|
|
}, [t,]); |
|
193
|
|
|
|
|
194
|
|
|
const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0'; |
|
195
|
|
|
|
|
196
|
|
|
|
|
197
|
|
|
let onSpaceCascaderChange1 = (value, selectedOptions) => { |
|
198
|
|
|
setSelectedSpaceName1(selectedOptions.map(o => o.label).join('/')); |
|
199
|
|
|
setSelectedSpaceID1(value[value.length - 1]); |
|
200
|
|
|
|
|
201
|
|
|
let isResponseOK = false; |
|
202
|
|
|
fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/meters', { |
|
203
|
|
|
method: 'GET', |
|
204
|
|
|
headers: { |
|
205
|
|
|
"Content-type": "application/json", |
|
206
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
|
207
|
|
|
"Token": getCookieValue('token') |
|
208
|
|
|
}, |
|
209
|
|
|
body: null, |
|
210
|
|
|
|
|
211
|
|
|
}).then(response => { |
|
212
|
|
|
if (response.ok) { |
|
213
|
|
|
isResponseOK = true; |
|
214
|
|
|
} |
|
215
|
|
|
return response.json(); |
|
216
|
|
|
}).then(json => { |
|
217
|
|
|
if (isResponseOK) { |
|
218
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
|
219
|
|
|
console.log(json) |
|
220
|
|
|
setMeterList1(json[0]); |
|
221
|
|
|
setFilteredMeterList1(json[0]); |
|
222
|
|
|
if (json[0].length > 0) { |
|
223
|
|
|
setSelectedMeter1(json[0][0].value); |
|
224
|
|
|
// enable submit button |
|
225
|
|
|
setSubmitButtonDisabled(false); |
|
226
|
|
|
} else { |
|
227
|
|
|
setSelectedMeter1(undefined); |
|
228
|
|
|
// disable submit button |
|
229
|
|
|
setSubmitButtonDisabled(true); |
|
230
|
|
|
} |
|
231
|
|
|
} else { |
|
232
|
|
|
toast.error(json.description) |
|
233
|
|
|
} |
|
234
|
|
|
}).catch(err => { |
|
235
|
|
|
console.log(err); |
|
236
|
|
|
}); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
let onSpaceCascaderChange2 = (value, selectedOptions) => { |
|
240
|
|
|
setSelectedSpaceName2(selectedOptions.map(o => o.label).join('/')); |
|
241
|
|
|
setSelectedSpaceID2(value[value.length - 1]); |
|
242
|
|
|
|
|
243
|
|
|
let isResponseOK = false; |
|
244
|
|
|
fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/meters', { |
|
245
|
|
|
method: 'GET', |
|
246
|
|
|
headers: { |
|
247
|
|
|
"Content-type": "application/json", |
|
248
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
|
249
|
|
|
"Token": getCookieValue('token') |
|
250
|
|
|
}, |
|
251
|
|
|
body: null, |
|
252
|
|
|
|
|
253
|
|
|
}).then(response => { |
|
254
|
|
|
if (response.ok) { |
|
255
|
|
|
isResponseOK = true; |
|
256
|
|
|
} |
|
257
|
|
|
return response.json(); |
|
258
|
|
|
}).then(json => { |
|
259
|
|
|
if (isResponseOK) { |
|
260
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
|
261
|
|
|
console.log(json) |
|
262
|
|
|
setMeterList2(json[0]); |
|
263
|
|
|
setFilteredMeterList2(json[0]); |
|
264
|
|
|
if (json[0].length > 0) { |
|
265
|
|
|
setSelectedMeter2(json[0][0].value); |
|
266
|
|
|
// enable submit button |
|
267
|
|
|
setSubmitButtonDisabled(false); |
|
268
|
|
|
} else { |
|
269
|
|
|
setSelectedMeter2(undefined); |
|
270
|
|
|
// disable submit button |
|
271
|
|
|
setSubmitButtonDisabled(true); |
|
272
|
|
|
} |
|
273
|
|
|
} else { |
|
274
|
|
|
toast.error(json.description) |
|
275
|
|
|
} |
|
276
|
|
|
}).catch(err => { |
|
277
|
|
|
console.log(err); |
|
278
|
|
|
}); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
const onSearchMeter1 = ({ target }) => { |
|
282
|
|
|
const keyword = target.value.toLowerCase(); |
|
283
|
|
|
const filteredResult = meterList1.filter( |
|
284
|
|
|
meter => meter.label.toLowerCase().includes(keyword) |
|
285
|
|
|
); |
|
286
|
|
|
setFilteredMeterList1(keyword.length ? filteredResult : meterList1); |
|
287
|
|
|
if (filteredResult.length > 0) { |
|
288
|
|
|
setSelectedMeter1(filteredResult[0].value); |
|
289
|
|
|
// enable submit button |
|
290
|
|
|
setSubmitButtonDisabled(false); |
|
291
|
|
|
} else { |
|
292
|
|
|
setSelectedMeter1(undefined); |
|
293
|
|
|
// disable submit button |
|
294
|
|
|
setSubmitButtonDisabled(true); |
|
295
|
|
|
}; |
|
296
|
|
|
let customInputTarget = document.getElementById('meterSelect1'); |
|
297
|
|
|
customInputTarget.value = filteredResult[0].value; |
|
298
|
|
|
}; |
|
299
|
|
|
|
|
300
|
|
|
const onSearchMeter2 = ({ target }) => { |
|
301
|
|
|
const keyword = target.value.toLowerCase(); |
|
302
|
|
|
const filteredResult = meterList2.filter( |
|
303
|
|
|
meter => meter.label.toLowerCase().includes(keyword) |
|
304
|
|
|
); |
|
305
|
|
|
setFilteredMeterList1(keyword.length ? filteredResult : meterList2); |
|
306
|
|
|
if (filteredResult.length > 0) { |
|
307
|
|
|
setSelectedMeter1(filteredResult[0].value); |
|
308
|
|
|
// enable submit button |
|
309
|
|
|
setSubmitButtonDisabled(false); |
|
310
|
|
|
} else { |
|
311
|
|
|
setSelectedMeter1(undefined); |
|
312
|
|
|
// disable submit button |
|
313
|
|
|
setSubmitButtonDisabled(true); |
|
314
|
|
|
}; |
|
315
|
|
|
let customInputTarget = document.getElementById('meterSelect2'); |
|
316
|
|
|
customInputTarget.value = filteredResult[0].value; |
|
317
|
|
|
}; |
|
318
|
|
|
|
|
319
|
|
|
// Callback fired when value changed |
|
320
|
|
|
let onReportingPeriodChange = (DateRange) => { |
|
321
|
|
|
if(DateRange == null) { |
|
322
|
|
|
setReportingPeriodDateRange([null, null]); |
|
323
|
|
|
} else { |
|
324
|
|
|
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') { |
|
325
|
|
|
// if the user did not change time value, set the default time to the end of day |
|
326
|
|
|
DateRange[1] = endOfDay(DateRange[1]); |
|
327
|
|
|
} |
|
328
|
|
|
setReportingPeriodDateRange([DateRange[0], DateRange[1]]); |
|
329
|
|
|
|
|
330
|
|
|
} |
|
331
|
|
|
}; |
|
332
|
|
|
|
|
333
|
|
|
// Callback fired when value clean |
|
334
|
|
|
let onReportingPeriodClean = event => { |
|
335
|
|
|
setReportingPeriodDateRange([null, null]); |
|
336
|
|
|
}; |
|
337
|
|
|
|
|
338
|
|
|
|
|
339
|
|
|
// Handler |
|
340
|
|
|
const handleSubmit = e => { |
|
341
|
|
|
e.preventDefault(); |
|
342
|
|
|
console.log('handleSubmit'); |
|
343
|
|
|
console.log(selectedSpaceID1); |
|
344
|
|
|
console.log(selectedMeter1); |
|
345
|
|
|
console.log(selectedSpaceID2); |
|
346
|
|
|
console.log(selectedMeter2); |
|
347
|
|
|
console.log(periodType); |
|
348
|
|
|
console.log(moment(reportingPeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss')) |
|
349
|
|
|
console.log(moment(reportingPeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss')); |
|
350
|
|
|
|
|
351
|
|
|
// disable submit button |
|
352
|
|
|
setSubmitButtonDisabled(true); |
|
353
|
|
|
// show spinner |
|
354
|
|
|
setSpinnerHidden(false); |
|
355
|
|
|
// hide export button |
|
356
|
|
|
setExportButtonHidden(true) |
|
357
|
|
|
|
|
358
|
|
|
// Reinitialize tables |
|
359
|
|
|
setDetailedDataTableData([]); |
|
360
|
|
|
|
|
361
|
|
|
let isResponseOK = false; |
|
362
|
|
|
fetch(APIBaseURL + '/reports/metercomparison?' + |
|
363
|
|
|
'meterid1=' + selectedMeter1 + |
|
364
|
|
|
'&meterid2=' + selectedMeter2 + |
|
365
|
|
|
'&periodtype=' + periodType + |
|
366
|
|
|
'&reportingperiodstartdatetime=' + moment(reportingPeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') + |
|
367
|
|
|
'&reportingperiodenddatetime=' + moment(reportingPeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss'), { |
|
368
|
|
|
method: 'GET', |
|
369
|
|
|
headers: { |
|
370
|
|
|
"Content-type": "application/json", |
|
371
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
|
372
|
|
|
"Token": getCookieValue('token') |
|
373
|
|
|
}, |
|
374
|
|
|
body: null, |
|
375
|
|
|
|
|
376
|
|
|
}).then(response => { |
|
377
|
|
|
if (response.ok) { |
|
378
|
|
|
isResponseOK = true; |
|
379
|
|
|
}; |
|
380
|
|
|
return response.json(); |
|
381
|
|
|
}).then(json => { |
|
382
|
|
|
if (isResponseOK) { |
|
383
|
|
|
console.log(json) |
|
384
|
|
|
setMeter1({ |
|
385
|
|
|
'name': json['meter1']['name'], |
|
386
|
|
|
'energy_category_id': json['meter1']['energy_category_id'], |
|
387
|
|
|
'energy_category_name': json['meter1']['energy_category_name'], |
|
388
|
|
|
'unit_of_measure': json['meter1']['unit_of_measure'] |
|
389
|
|
|
}); |
|
390
|
|
|
setMeter2({ |
|
391
|
|
|
'name': json['meter2']['name'], |
|
392
|
|
|
'energy_category_id': json['meter2']['energy_category_id'], |
|
393
|
|
|
'energy_category_name': json['meter2']['energy_category_name'], |
|
394
|
|
|
'unit_of_measure': json['meter2']['unit_of_measure'] |
|
395
|
|
|
}); |
|
396
|
|
|
setReportingPeriodEnergyConsumptionInCategory1(json['reporting_period1']['total_in_category']); |
|
397
|
|
|
setReportingPeriodEnergyConsumptionInCategory2(json['reporting_period2']['total_in_category']); |
|
398
|
|
|
let names1 = Array(); |
|
399
|
|
|
names1.push({ 'value': 'a0', 'label': json['meter1']['energy_category_name'] }); |
|
400
|
|
|
setMeterLineChartOptions1(names1); |
|
401
|
|
|
|
|
402
|
|
|
let names2 = Array(); |
|
403
|
|
|
names2.push({ 'value': 'a0', 'label': json['meter2']['energy_category_name'] }); |
|
404
|
|
|
setMeterLineChartOptions2(names2); |
|
405
|
|
|
|
|
406
|
|
|
let timestamps1 = {} |
|
407
|
|
|
timestamps1['a0'] = json['reporting_period1']['timestamps']; |
|
408
|
|
|
setMeterLineChartLabels1(timestamps1); |
|
409
|
|
|
|
|
410
|
|
|
let timestamps2 = {} |
|
411
|
|
|
timestamps2['a0'] = json['reporting_period2']['timestamps']; |
|
412
|
|
|
setMeterLineChartLabels2(timestamps2); |
|
413
|
|
|
|
|
414
|
|
|
let values1 = {'a0':[]} |
|
415
|
|
|
json['reporting_period1']['values'].forEach((currentValue, index) => { |
|
416
|
|
|
values1['a0'][index] = currentValue.toFixed(2); |
|
417
|
|
|
}); |
|
418
|
|
|
setMeterLineChartData1(values1) |
|
419
|
|
|
|
|
420
|
|
|
let values2 = {'a0':[]} |
|
421
|
|
|
json['reporting_period2']['values'].forEach((currentValue, index) => { |
|
422
|
|
|
values2['a0'][index] = currentValue.toFixed(2); |
|
423
|
|
|
}); |
|
424
|
|
|
setMeterLineChartData2(values2) |
|
425
|
|
|
|
|
426
|
|
|
names1 = Array(); |
|
427
|
|
|
let index1 = 0 |
|
428
|
|
|
json['parameters1']['names'].forEach((currentValue, index) => { |
|
429
|
|
|
names1.push({ 'value': 'a' + index1, 'label': currentValue }); |
|
430
|
|
|
index1 = index1 + 1 |
|
431
|
|
|
}); |
|
432
|
|
|
json['parameters2']['names'].forEach((currentValue, index) => { |
|
433
|
|
|
names1.push({ 'value': 'a' + index1, 'label': currentValue }); |
|
434
|
|
|
index1 = index1 + 1 |
|
435
|
|
|
}); |
|
436
|
|
|
setParameterLineChartOptions(names1); |
|
437
|
|
|
|
|
438
|
|
|
timestamps1 = {} |
|
439
|
|
|
index1 = 0 |
|
440
|
|
|
json['parameters1']['timestamps'].forEach((currentValue, index) => { |
|
441
|
|
|
timestamps1['a' + index1] = currentValue; |
|
442
|
|
|
index1 = index1 + 1 |
|
443
|
|
|
}); |
|
444
|
|
|
json['parameters2']['timestamps'].forEach((currentValue, index) => { |
|
445
|
|
|
timestamps1['a' + index1] = currentValue; |
|
446
|
|
|
index1 = index1 + 1 |
|
447
|
|
|
}); |
|
448
|
|
|
setParameterLineChartLabels(timestamps1); |
|
449
|
|
|
|
|
450
|
|
|
index1 = 0 |
|
451
|
|
|
json['parameters1']['values'].forEach((currentValue, index) => { |
|
452
|
|
|
values1['a' + index1] = currentValue; |
|
453
|
|
|
index1 += 1 |
|
454
|
|
|
}); |
|
455
|
|
|
json['parameters2']['values'].forEach((currentValue, index) => { |
|
456
|
|
|
values1['a' + index1] = currentValue; |
|
457
|
|
|
index1 += 1 |
|
458
|
|
|
}); |
|
459
|
|
|
setParameterLineChartData(values1); |
|
460
|
|
|
|
|
461
|
|
|
setDetailedDataTableColumns([{ |
|
462
|
|
|
dataField: 'startdatetime', |
|
463
|
|
|
text: t('Datetime'), |
|
464
|
|
|
sort: true |
|
465
|
|
|
}, { |
|
466
|
|
|
dataField: 'a0', |
|
467
|
|
|
text: json['meter1']['name'] + json['meter1']['energy_category_name'] + ' (' + json['meter1']['unit_of_measure'] + ')', |
|
468
|
|
|
sort: true, |
|
469
|
|
|
formatter: function (decimalValue) { |
|
470
|
|
|
if (typeof decimalValue === 'number') { |
|
471
|
|
|
return decimalValue.toFixed(2); |
|
472
|
|
|
} else { |
|
473
|
|
|
return null; |
|
474
|
|
|
} |
|
475
|
|
|
} |
|
476
|
|
|
}, { |
|
477
|
|
|
dataField: 'a1', |
|
478
|
|
|
text: json['meter2']['name'] + json['meter2']['energy_category_name'] + ' (' + json['meter2']['unit_of_measure'] + ')', |
|
479
|
|
|
sort: true, |
|
480
|
|
|
formatter: function (decimalValue) { |
|
481
|
|
|
if (typeof decimalValue === 'number') { |
|
482
|
|
|
return decimalValue.toFixed(2); |
|
483
|
|
|
} else { |
|
484
|
|
|
return null; |
|
485
|
|
|
} |
|
486
|
|
|
} |
|
487
|
|
|
}]); |
|
488
|
|
|
|
|
489
|
|
|
let detailed_value_list = []; |
|
490
|
|
|
json['reporting_period1']['timestamps'].forEach((currentTimestamp, timestampIndex) => { |
|
491
|
|
|
let detailed_value = {}; |
|
492
|
|
|
detailed_value['id'] = timestampIndex; |
|
493
|
|
|
detailed_value['startdatetime'] = currentTimestamp; |
|
494
|
|
|
detailed_value['a0'] = json['reporting_period1']['values'][timestampIndex]; |
|
495
|
|
|
detailed_value['a1'] = json['reporting_period2']['values'][timestampIndex]; |
|
496
|
|
|
detailed_value_list.push(detailed_value); |
|
497
|
|
|
}); |
|
498
|
|
|
|
|
499
|
|
|
let detailed_value = {}; |
|
500
|
|
|
detailed_value['id'] = detailed_value_list.length; |
|
501
|
|
|
detailed_value['startdatetime'] = t('Total'); |
|
502
|
|
|
detailed_value['a0'] = json['reporting_period1']['total_in_category']; |
|
503
|
|
|
detailed_value['a1'] = json['reporting_period2']['total_in_category']; |
|
504
|
|
|
detailed_value_list.push(detailed_value); |
|
505
|
|
|
setTimeout( () => { |
|
506
|
|
|
setDetailedDataTableData(detailed_value_list); |
|
507
|
|
|
}, 0) |
|
508
|
|
|
|
|
509
|
|
|
setExcelBytesBase64(json['excel_bytes_base64']); |
|
510
|
|
|
|
|
511
|
|
|
// enable submit button |
|
512
|
|
|
setSubmitButtonDisabled(false); |
|
513
|
|
|
// hide spinner |
|
514
|
|
|
setSpinnerHidden(true); |
|
515
|
|
|
// show export button |
|
516
|
|
|
setExportButtonHidden(false); |
|
517
|
|
|
|
|
518
|
|
|
} else { |
|
519
|
|
|
toast.error(json.description) |
|
520
|
|
|
setSpinnerHidden(true); |
|
521
|
|
|
setSubmitButtonDisabled(false); |
|
522
|
|
|
} |
|
523
|
|
|
}).catch(err => { |
|
524
|
|
|
console.log(err); |
|
525
|
|
|
}); |
|
526
|
|
|
}; |
|
527
|
|
|
|
|
528
|
|
|
const handleExport = e => { |
|
529
|
|
|
e.preventDefault(); |
|
530
|
|
|
const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
|
531
|
|
|
const fileName = 'metercomparison.xlsx' |
|
532
|
|
|
var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64; |
|
533
|
|
|
fetch(fileUrl) |
|
534
|
|
|
.then(response => response.blob()) |
|
535
|
|
|
.then(blob => { |
|
536
|
|
|
var link = window.document.createElement("a"); |
|
537
|
|
|
link.href = window.URL.createObjectURL(blob, { type: mimeType }); |
|
538
|
|
|
link.download = fileName; |
|
539
|
|
|
document.body.appendChild(link); |
|
540
|
|
|
link.click(); |
|
541
|
|
|
document.body.removeChild(link); |
|
542
|
|
|
}); |
|
543
|
|
|
}; |
|
544
|
|
|
|
|
545
|
|
|
|
|
546
|
|
|
return ( |
|
547
|
|
|
<Fragment> |
|
548
|
|
|
<div> |
|
549
|
|
|
<Breadcrumb> |
|
550
|
|
|
<BreadcrumbItem>{t('Meter Data')}</BreadcrumbItem><BreadcrumbItem active>{t('Meter Comparison')}</BreadcrumbItem> |
|
551
|
|
|
</Breadcrumb> |
|
552
|
|
|
</div> |
|
553
|
|
|
<Card className="bg-light mb-3"> |
|
554
|
|
|
<CardBody className="p-3"> |
|
555
|
|
|
<Form onSubmit={handleSubmit}> |
|
556
|
|
|
<Row form > |
|
557
|
|
|
<Col xs={6} sm={3}> |
|
558
|
|
|
<FormGroup className="form-group"> |
|
559
|
|
|
<Label className={labelClasses} for="space"> |
|
560
|
|
|
{t('Space')}1 |
|
561
|
|
|
</Label> |
|
562
|
|
|
<br /> |
|
563
|
|
|
<Cascader options={cascaderOptions} |
|
564
|
|
|
onChange={onSpaceCascaderChange1} |
|
565
|
|
|
changeOnSelect |
|
566
|
|
|
expandTrigger="hover"> |
|
567
|
|
|
<Input value={selectedSpaceName1 || ''} readOnly /> |
|
568
|
|
|
</Cascader> |
|
569
|
|
|
</FormGroup> |
|
570
|
|
|
</Col> |
|
571
|
|
|
<Col xs="auto"> |
|
572
|
|
|
<FormGroup> |
|
573
|
|
|
<Label className={labelClasses} for="meterSelect1"> |
|
574
|
|
|
{t('Meter')}1 |
|
575
|
|
|
</Label> |
|
576
|
|
|
|
|
577
|
|
|
<Form inline> |
|
578
|
|
|
<Input placeholder={t('Search')} onChange={onSearchMeter1} /> |
|
579
|
|
|
<CustomInput type="select" id="meterSelect1" name="meterSelect1" onChange={({ target }) => setSelectedMeter1(target.value)} |
|
580
|
|
|
> |
|
581
|
|
|
{filteredMeterList1.map((meter, index) => ( |
|
582
|
|
|
<option value={meter.value} key={meter.value}> |
|
583
|
|
|
{meter.label} |
|
584
|
|
|
</option> |
|
585
|
|
|
))} |
|
586
|
|
|
</CustomInput> |
|
587
|
|
|
</Form> |
|
588
|
|
|
</FormGroup> |
|
589
|
|
|
</Col> |
|
590
|
|
|
</Row> |
|
591
|
|
|
<Row> |
|
592
|
|
|
<Col xs={6} sm={3}> |
|
593
|
|
|
<FormGroup className="form-group"> |
|
594
|
|
|
<Label className={labelClasses} for="space"> |
|
595
|
|
|
{t('Space')}2 |
|
596
|
|
|
</Label> |
|
597
|
|
|
<br /> |
|
598
|
|
|
<Cascader options={cascaderOptions} |
|
599
|
|
|
onChange={onSpaceCascaderChange2} |
|
600
|
|
|
changeOnSelect |
|
601
|
|
|
expandTrigger="hover"> |
|
602
|
|
|
<Input value={selectedSpaceName2 || ''} readOnly /> |
|
603
|
|
|
</Cascader> |
|
604
|
|
|
</FormGroup> |
|
605
|
|
|
</Col> |
|
606
|
|
|
<Col xs="auto"> |
|
607
|
|
|
<FormGroup> |
|
608
|
|
|
<Label className={labelClasses} for="meterSelect2"> |
|
609
|
|
|
{t('Meter')}2 |
|
610
|
|
|
</Label> |
|
611
|
|
|
|
|
612
|
|
|
<Form inline> |
|
613
|
|
|
<Input placeholder={t('Search')} onChange={onSearchMeter2} /> |
|
614
|
|
|
<CustomInput type="select" id="meterSelect2" name="meterSelect2" onChange={({ target }) => setSelectedMeter2(target.value)} |
|
615
|
|
|
> |
|
616
|
|
|
{filteredMeterList2.map((meter, index) => ( |
|
617
|
|
|
<option value={meter.value} key={meter.value}> |
|
618
|
|
|
{meter.label} |
|
619
|
|
|
</option> |
|
620
|
|
|
))} |
|
621
|
|
|
</CustomInput> |
|
622
|
|
|
</Form> |
|
623
|
|
|
</FormGroup> |
|
624
|
|
|
</Col> |
|
625
|
|
|
</Row> |
|
626
|
|
|
<Row> |
|
627
|
|
|
<Col xs="auto"> |
|
628
|
|
|
<FormGroup> |
|
629
|
|
|
<Label className={labelClasses} for="periodType"> |
|
630
|
|
|
{t('Period Types')} |
|
631
|
|
|
</Label> |
|
632
|
|
|
<CustomInput type="select" id="periodType" name="periodType" defaultValue="daily" onChange={({ target }) => setPeriodType(target.value)} |
|
633
|
|
|
> |
|
634
|
|
|
{periodTypeOptions.map((periodType, index) => ( |
|
635
|
|
|
<option value={periodType.value} key={periodType.value} > |
|
636
|
|
|
{t(periodType.label)} |
|
637
|
|
|
</option> |
|
638
|
|
|
))} |
|
639
|
|
|
</CustomInput> |
|
640
|
|
|
</FormGroup> |
|
641
|
|
|
</Col> |
|
642
|
|
|
|
|
643
|
|
|
<Col xs={6} sm={3}> |
|
644
|
|
|
<FormGroup className="form-group"> |
|
645
|
|
|
<Label className={labelClasses} for="reportingPeriodDateRangePicker">{t('Reporting Period')}</Label> |
|
646
|
|
|
<br/> |
|
647
|
|
|
<DateRangePicker |
|
648
|
|
|
id='reportingPeriodDateRangePicker' |
|
649
|
|
|
format="yyyy-MM-dd HH:mm:ss" |
|
650
|
|
|
value={reportingPeriodDateRange} |
|
651
|
|
|
onChange={onReportingPeriodChange} |
|
652
|
|
|
size="md" |
|
653
|
|
|
style={dateRangePickerStyle} |
|
654
|
|
|
onClean={onReportingPeriodClean} |
|
655
|
|
|
locale={dateRangePickerLocale} |
|
656
|
|
|
placeholder={t("Select Date Range")} |
|
657
|
|
|
/> |
|
658
|
|
|
</FormGroup> |
|
659
|
|
|
</Col> |
|
660
|
|
|
<Col xs="auto"> |
|
661
|
|
|
<FormGroup> |
|
662
|
|
|
<br/> |
|
663
|
|
|
<ButtonGroup id="submit"> |
|
664
|
|
|
<Button color="success" disabled={submitButtonDisabled} >{t('Submit')}</Button> |
|
665
|
|
|
</ButtonGroup> |
|
666
|
|
|
</FormGroup> |
|
667
|
|
|
</Col> |
|
668
|
|
|
<Col xs="auto"> |
|
669
|
|
|
<FormGroup> |
|
670
|
|
|
<br></br> |
|
671
|
|
|
<Spinner color="primary" hidden={spinnerHidden} /> |
|
672
|
|
|
</FormGroup> |
|
673
|
|
|
</Col> |
|
674
|
|
|
<Col xs="auto"> |
|
675
|
|
|
<br></br> |
|
676
|
|
|
<ButtonIcon icon="external-link-alt" transform="shrink-3 down-2" color="falcon-default" |
|
677
|
|
|
hidden={exportButtonHidden} |
|
678
|
|
|
onClick={handleExport} > |
|
679
|
|
|
{t('Export')} |
|
680
|
|
|
</ButtonIcon> |
|
681
|
|
|
</Col> |
|
682
|
|
|
</Row> |
|
683
|
|
|
</Form> |
|
684
|
|
|
</CardBody> |
|
685
|
|
|
</Card> |
|
686
|
|
|
<div className="card-deck"> |
|
687
|
|
|
<CardSummary id="cardSummary1" title={t('METER CATEGORY VALUE UNIT', { 'METER': meter1['name'], 'CATEGORY': meter1['energy_category_name'], 'UNIT': '(' + meter1['unit_of_measure'] + ')' })} |
|
688
|
|
|
color="success" > |
|
689
|
|
|
<CountUp end={reportingPeriodEnergyConsumptionInCategory1} duration={2} prefix="" separator="," decimals={2} decimal="." /> |
|
690
|
|
|
</CardSummary> |
|
691
|
|
|
<CardSummary id="cardSummary2" title={t('METER CATEGORY VALUE UNIT', { 'METER': meter2['name'], 'CATEGORY': meter2['energy_category_name'], 'UNIT': '(' + meter2['unit_of_measure'] + ')' })} |
|
692
|
|
|
color="success" > |
|
693
|
|
|
<CountUp end={reportingPeriodEnergyConsumptionInCategory2} duration={2} prefix="" separator="," decimals={2} decimal="." /> |
|
694
|
|
|
</CardSummary> |
|
695
|
|
|
</div> |
|
696
|
|
|
<LineChart id="meterLineChart1" reportingTitle={t('METER CATEGORY VALUE UNIT', { 'METER': meter1['name'], 'CATEGORY': meter1['energy_category_name'], 'VALUE': reportingPeriodEnergyConsumptionInCategory1.toFixed(2), 'UNIT': '(' + meter1['unit_of_measure'] + ')' })} |
|
697
|
|
|
|
|
698
|
|
|
labels={meterLineChartLabels1} |
|
699
|
|
|
data={meterLineChartData1} |
|
700
|
|
|
options={meterLineChartOptions1}> |
|
701
|
|
|
</LineChart> |
|
702
|
|
|
<LineChart id="meterLineChart2" reportingTitle={t('METER CATEGORY VALUE UNIT', { 'METER': meter2['name'], 'CATEGORY': meter2['energy_category_name'], 'VALUE': reportingPeriodEnergyConsumptionInCategory2.toFixed(2), 'UNIT': '(' + meter2['unit_of_measure'] + ')' })} |
|
703
|
|
|
|
|
704
|
|
|
labels={meterLineChartLabels2} |
|
705
|
|
|
data={meterLineChartData2} |
|
706
|
|
|
options={meterLineChartOptions2}> |
|
707
|
|
|
</LineChart> |
|
708
|
|
|
|
|
709
|
|
|
<MultipleLineChart reportingTitle={t('Related Parameters')} |
|
710
|
|
|
baseTitle='' |
|
711
|
|
|
labels={parameterLineChartLabels} |
|
712
|
|
|
data={parameterLineChartData} |
|
713
|
|
|
options={parameterLineChartOptions}> |
|
714
|
|
|
</MultipleLineChart> |
|
715
|
|
|
<br /> |
|
716
|
|
|
<DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={50} > |
|
717
|
|
|
</DetailedDataTable> |
|
718
|
|
|
|
|
719
|
|
|
</Fragment> |
|
720
|
|
|
); |
|
721
|
|
|
}; |
|
722
|
|
|
|
|
723
|
|
|
export default withTranslation()(withRedirect(MeterComparison)); |