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 SharePie from '../common/SharePie'; |
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
|
|
|
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable')); |
37
|
|
|
|
38
|
|
|
const TenantCarbon = ({ 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 [tenantList, setTenantList] = useState([]); |
63
|
|
|
const [selectedTenant, setSelectedTenant] = useState(undefined); |
64
|
|
|
const [comparisonType, setComparisonType] = useState('month-on-month'); |
65
|
|
|
const [periodType, setPeriodType] = useState('daily'); |
66
|
|
|
const [cascaderOptions, setCascaderOptions] = useState(undefined); |
67
|
|
|
const [basePeriodDateRange, setBasePeriodDateRange] = useState([current_moment.clone().subtract(1, 'months').startOf('month').toDate(), current_moment.clone().subtract(1, 'months').toDate()]); |
68
|
|
|
const [basePeriodDateRangePickerDisabled, setBasePeriodDateRangePickerDisabled] = useState(true); |
69
|
|
|
const [reportingPeriodDateRange, setReportingPeriodDateRange] = useState([current_moment.clone().startOf('month').toDate(), current_moment.toDate()]); |
70
|
|
|
const dateRangePickerLocale = { |
71
|
|
|
sunday: t('sunday'), |
72
|
|
|
monday: t('monday'), |
73
|
|
|
tuesday: t('tuesday'), |
74
|
|
|
wednesday: t('wednesday'), |
75
|
|
|
thursday: t('thursday'), |
76
|
|
|
friday: t('friday'), |
77
|
|
|
saturday: t('saturday'), |
78
|
|
|
ok: t('ok'), |
79
|
|
|
today: t('today'), |
80
|
|
|
yesterday: t('yesterday'), |
81
|
|
|
hours: t('hours'), |
82
|
|
|
minutes: t('minutes'), |
83
|
|
|
seconds: t('seconds'), |
84
|
|
|
last7Days: t('last7Days') |
85
|
|
|
}; |
86
|
|
|
const dateRangePickerStyle = { display: 'block', zIndex: 10}; |
87
|
|
|
|
88
|
|
|
// buttons |
89
|
|
|
const [submitButtonDisabled, setSubmitButtonDisabled] = useState(true); |
90
|
|
|
const [spinnerHidden, setSpinnerHidden] = useState(true); |
91
|
|
|
const [exportButtonHidden, setExportButtonHidden] = useState(true); |
92
|
|
|
|
93
|
|
|
//Results |
94
|
|
|
const [timeOfUseShareData, setTimeOfUseShareData] = useState([]); |
95
|
|
|
const [carbonShareData, setCarbonShareData] = useState([]); |
96
|
|
|
|
97
|
|
|
const [cardSummaryList, setCardSummaryList] = useState([]); |
98
|
|
|
const [tenantLineChartLabels, setTenantLineChartLabels] = useState([]); |
99
|
|
|
const [tenantLineChartData, setTenantLineChartData] = useState({}); |
100
|
|
|
const [tenantLineChartOptions, setTenantLineChartOptions] = useState([]); |
101
|
|
|
|
102
|
|
|
const [parameterLineChartLabels, setParameterLineChartLabels] = useState([]); |
103
|
|
|
const [parameterLineChartData, setParameterLineChartData] = useState({}); |
104
|
|
|
const [parameterLineChartOptions, setParameterLineChartOptions] = useState([]); |
105
|
|
|
|
106
|
|
|
const [detailedDataTableData, setDetailedDataTableData] = useState([]); |
107
|
|
|
const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]); |
108
|
|
|
const [excelBytesBase64, setExcelBytesBase64] = useState(undefined); |
109
|
|
|
|
110
|
|
|
useEffect(() => { |
111
|
|
|
let isResponseOK = false; |
112
|
|
|
fetch(APIBaseURL + '/spaces/tree', { |
113
|
|
|
method: 'GET', |
114
|
|
|
headers: { |
115
|
|
|
"Content-type": "application/json", |
116
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
117
|
|
|
"Token": getCookieValue('token') |
118
|
|
|
}, |
119
|
|
|
body: null, |
120
|
|
|
|
121
|
|
|
}).then(response => { |
122
|
|
|
console.log(response); |
123
|
|
|
if (response.ok) { |
124
|
|
|
isResponseOK = true; |
125
|
|
|
} |
126
|
|
|
return response.json(); |
127
|
|
|
}).then(json => { |
128
|
|
|
console.log(json); |
129
|
|
|
if (isResponseOK) { |
130
|
|
|
// rename keys |
131
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
132
|
|
|
setCascaderOptions(json); |
133
|
|
|
setSelectedSpaceName([json[0]].map(o => o.label)); |
134
|
|
|
setSelectedSpaceID([json[0]].map(o => o.value)); |
135
|
|
|
// get Tenants by root Space ID |
136
|
|
|
let isResponseOK = false; |
137
|
|
|
fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/tenants', { |
138
|
|
|
method: 'GET', |
139
|
|
|
headers: { |
140
|
|
|
"Content-type": "application/json", |
141
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
142
|
|
|
"Token": getCookieValue('token') |
143
|
|
|
}, |
144
|
|
|
body: null, |
145
|
|
|
|
146
|
|
|
}).then(response => { |
147
|
|
|
if (response.ok) { |
148
|
|
|
isResponseOK = true; |
149
|
|
|
} |
150
|
|
|
return response.json(); |
151
|
|
|
}).then(json => { |
152
|
|
|
if (isResponseOK) { |
153
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
154
|
|
|
console.log(json); |
155
|
|
|
setTenantList(json[0]); |
156
|
|
|
if (json[0].length > 0) { |
157
|
|
|
setSelectedTenant(json[0][0].value); |
158
|
|
|
// enable submit button |
159
|
|
|
setSubmitButtonDisabled(false); |
160
|
|
|
} else { |
161
|
|
|
setSelectedTenant(undefined); |
162
|
|
|
// disable submit button |
163
|
|
|
setSubmitButtonDisabled(true); |
164
|
|
|
} |
165
|
|
|
} else { |
166
|
|
|
toast.error(json.description) |
167
|
|
|
} |
168
|
|
|
}).catch(err => { |
169
|
|
|
console.log(err); |
170
|
|
|
}); |
171
|
|
|
// end of get Tenants by root Space ID |
172
|
|
|
} else { |
173
|
|
|
toast.error(json.description); |
174
|
|
|
} |
175
|
|
|
}).catch(err => { |
176
|
|
|
console.log(err); |
177
|
|
|
}); |
178
|
|
|
|
179
|
|
|
}, []); |
180
|
|
|
|
181
|
|
|
const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0'; |
182
|
|
|
|
183
|
|
|
let onSpaceCascaderChange = (value, selectedOptions) => { |
184
|
|
|
setSelectedSpaceName(selectedOptions.map(o => o.label).join('/')); |
185
|
|
|
setSelectedSpaceID(value[value.length - 1]); |
186
|
|
|
|
187
|
|
|
let isResponseOK = false; |
188
|
|
|
fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/tenants', { |
189
|
|
|
method: 'GET', |
190
|
|
|
headers: { |
191
|
|
|
"Content-type": "application/json", |
192
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
193
|
|
|
"Token": getCookieValue('token') |
194
|
|
|
}, |
195
|
|
|
body: null, |
196
|
|
|
|
197
|
|
|
}).then(response => { |
198
|
|
|
if (response.ok) { |
199
|
|
|
isResponseOK = true; |
200
|
|
|
} |
201
|
|
|
return response.json(); |
202
|
|
|
}).then(json => { |
203
|
|
|
if (isResponseOK) { |
204
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
205
|
|
|
console.log(json) |
206
|
|
|
setTenantList(json[0]); |
207
|
|
|
if (json[0].length > 0) { |
208
|
|
|
setSelectedTenant(json[0][0].value); |
209
|
|
|
// enable submit button |
210
|
|
|
setSubmitButtonDisabled(false); |
211
|
|
|
} else { |
212
|
|
|
setSelectedTenant(undefined); |
213
|
|
|
// disable submit button |
214
|
|
|
setSubmitButtonDisabled(true); |
215
|
|
|
} |
216
|
|
|
} else { |
217
|
|
|
toast.error(json.description) |
218
|
|
|
} |
219
|
|
|
}).catch(err => { |
220
|
|
|
console.log(err); |
221
|
|
|
}); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
let onComparisonTypeChange = ({ target }) => { |
225
|
|
|
console.log(target.value); |
226
|
|
|
setComparisonType(target.value); |
227
|
|
|
if (target.value === 'year-over-year') { |
228
|
|
|
setBasePeriodDateRangePickerDisabled(true); |
229
|
|
|
setBasePeriodDateRange([moment(reportingPeriodDateRange[0]).subtract(1, 'years').toDate(), |
230
|
|
|
moment(reportingPeriodDateRange[1]).subtract(1, 'years').toDate()]); |
231
|
|
|
} else if (target.value === 'month-on-month') { |
232
|
|
|
setBasePeriodDateRangePickerDisabled(true); |
233
|
|
|
setBasePeriodDateRange([moment(reportingPeriodDateRange[0]).subtract(1, 'months').toDate(), |
234
|
|
|
moment(reportingPeriodDateRange[1]).subtract(1, 'months').toDate()]); |
235
|
|
|
} else if (target.value === 'free-comparison') { |
236
|
|
|
setBasePeriodDateRangePickerDisabled(false); |
237
|
|
|
} else if (target.value === 'none-comparison') { |
238
|
|
|
setBasePeriodDateRange([null, null]); |
239
|
|
|
setBasePeriodDateRangePickerDisabled(true); |
240
|
|
|
} |
241
|
|
|
}; |
242
|
|
|
|
243
|
|
|
// Callback fired when value changed |
244
|
|
|
let onBasePeriodChange = (DateRange) => { |
245
|
|
|
if(DateRange == null) { |
246
|
|
|
setBasePeriodDateRange([null, null]); |
247
|
|
|
} else { |
248
|
|
|
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') { |
249
|
|
|
// if the user did not change time value, set the default time to the end of day |
250
|
|
|
DateRange[1] = endOfDay(DateRange[1]); |
251
|
|
|
} |
252
|
|
|
setBasePeriodDateRange([DateRange[0], DateRange[1]]); |
253
|
|
|
} |
254
|
|
|
}; |
255
|
|
|
|
256
|
|
|
// Callback fired when value changed |
257
|
|
|
let onReportingPeriodChange = (DateRange) => { |
258
|
|
|
if(DateRange == null) { |
259
|
|
|
setReportingPeriodDateRange([null, null]); |
260
|
|
|
} else { |
261
|
|
|
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') { |
262
|
|
|
// if the user did not change time value, set the default time to the end of day |
263
|
|
|
DateRange[1] = endOfDay(DateRange[1]); |
264
|
|
|
} |
265
|
|
|
setReportingPeriodDateRange([DateRange[0], DateRange[1]]); |
266
|
|
|
if (comparisonType === 'year-over-year') { |
267
|
|
|
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]); |
268
|
|
|
} else if (comparisonType === 'month-on-month') { |
269
|
|
|
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'months').toDate(), moment(DateRange[1]).clone().subtract(1, 'months').toDate()]); |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
}; |
273
|
|
|
|
274
|
|
|
// Callback fired when value clean |
275
|
|
|
let onBasePeriodClean = event => { |
276
|
|
|
setBasePeriodDateRange([null, null]); |
277
|
|
|
}; |
278
|
|
|
|
279
|
|
|
// Callback fired when value clean |
280
|
|
|
let onReportingPeriodClean = event => { |
281
|
|
|
setReportingPeriodDateRange([null, null]); |
282
|
|
|
}; |
283
|
|
|
|
284
|
|
|
// Handler |
285
|
|
|
const handleSubmit = e => { |
286
|
|
|
e.preventDefault(); |
287
|
|
|
console.log('handleSubmit'); |
288
|
|
|
console.log(selectedSpaceID); |
289
|
|
|
console.log(selectedTenant); |
290
|
|
|
console.log(comparisonType); |
291
|
|
|
console.log(periodType); |
292
|
|
|
console.log(basePeriodDateRange[0] != null ? moment(basePeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') : null) |
293
|
|
|
console.log(basePeriodDateRange[1] != null ? moment(basePeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss') : null) |
294
|
|
|
console.log(moment(reportingPeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss')) |
295
|
|
|
console.log(moment(reportingPeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss')); |
296
|
|
|
|
297
|
|
|
// disable submit button |
298
|
|
|
setSubmitButtonDisabled(true); |
299
|
|
|
// show spinner |
300
|
|
|
setSpinnerHidden(false); |
301
|
|
|
// hide export button |
302
|
|
|
setExportButtonHidden(true) |
303
|
|
|
|
304
|
|
|
// Reinitialize tables |
305
|
|
|
setDetailedDataTableData([]); |
306
|
|
|
|
307
|
|
|
let isResponseOK = false; |
308
|
|
|
fetch(APIBaseURL + '/reports/tenantcarbon?' + |
309
|
|
|
'tenantid=' + selectedTenant + |
310
|
|
|
'&periodtype=' + periodType + |
311
|
|
|
'&baseperiodstartdatetime=' + (basePeriodDateRange[0] != null ? moment(basePeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') : '') + |
312
|
|
|
'&baseperiodenddatetime=' + (basePeriodDateRange[1] != null ? moment(basePeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss') : '') + |
313
|
|
|
'&reportingperiodstartdatetime=' + moment(reportingPeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') + |
314
|
|
|
'&reportingperiodenddatetime=' + moment(reportingPeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss'), { |
315
|
|
|
method: 'GET', |
316
|
|
|
headers: { |
317
|
|
|
"Content-type": "application/json", |
318
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
319
|
|
|
"Token": getCookieValue('token') |
320
|
|
|
}, |
321
|
|
|
body: null, |
322
|
|
|
|
323
|
|
|
}).then(response => { |
324
|
|
|
if (response.ok) { |
325
|
|
|
isResponseOK = true; |
326
|
|
|
} |
327
|
|
|
return response.json(); |
328
|
|
|
}).then(json => { |
329
|
|
|
if (isResponseOK) { |
330
|
|
|
console.log(json) |
331
|
|
|
|
332
|
|
|
let cardSummaryList = [] |
333
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
334
|
|
|
let cardSummaryItem = {} |
335
|
|
|
cardSummaryItem['name'] = json['reporting_period']['names'][index]; |
336
|
|
|
cardSummaryItem['unit'] = json['reporting_period']['units'][index]; |
337
|
|
|
cardSummaryItem['subtotal'] = json['reporting_period']['subtotals'][index]; |
338
|
|
|
cardSummaryItem['increment_rate'] = parseFloat(json['reporting_period']['increment_rates'][index] * 100).toFixed(2) + "%"; |
339
|
|
|
cardSummaryItem['subtotal_per_unit_area'] = json['reporting_period']['subtotals_per_unit_area'][index]; |
340
|
|
|
cardSummaryList.push(cardSummaryItem); |
341
|
|
|
}); |
342
|
|
|
let cardSummaryItem = {} |
343
|
|
|
cardSummaryItem['name'] = t('Total'); |
344
|
|
|
cardSummaryItem['unit'] = json['reporting_period']['total_unit']; |
345
|
|
|
cardSummaryItem['subtotal'] = json['reporting_period']['total']; |
346
|
|
|
cardSummaryItem['increment_rate'] = parseFloat(json['reporting_period']['total_increment_rate'] * 100).toFixed(2) + "%"; |
347
|
|
|
cardSummaryItem['subtotal_per_unit_area'] = json['reporting_period']['total_per_unit_area']; |
348
|
|
|
cardSummaryList.push(cardSummaryItem); |
349
|
|
|
setCardSummaryList(cardSummaryList); |
350
|
|
|
|
351
|
|
|
let timeOfUseArray = []; |
352
|
|
|
json['reporting_period']['energy_category_ids'].forEach((currentValue, index) => { |
353
|
|
|
if(currentValue === 1) { |
354
|
|
|
// energy_category_id 1 electricity |
355
|
|
|
let timeOfUseItem = {} |
356
|
|
|
timeOfUseItem['id'] = 1; |
357
|
|
|
timeOfUseItem['name'] = t('Top-Peak'); |
358
|
|
|
timeOfUseItem['value'] = json['reporting_period']['toppeaks'][index]; |
359
|
|
|
timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
360
|
|
|
timeOfUseArray.push(timeOfUseItem); |
361
|
|
|
|
362
|
|
|
timeOfUseItem = {} |
363
|
|
|
timeOfUseItem['id'] = 2; |
364
|
|
|
timeOfUseItem['name'] = t('On-Peak'); |
365
|
|
|
timeOfUseItem['value'] = json['reporting_period']['onpeaks'][index]; |
366
|
|
|
timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
367
|
|
|
timeOfUseArray.push(timeOfUseItem); |
368
|
|
|
|
369
|
|
|
timeOfUseItem = {} |
370
|
|
|
timeOfUseItem['id'] = 3; |
371
|
|
|
timeOfUseItem['name'] = t('Mid-Peak'); |
372
|
|
|
timeOfUseItem['value'] = json['reporting_period']['midpeaks'][index]; |
373
|
|
|
timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
374
|
|
|
timeOfUseArray.push(timeOfUseItem); |
375
|
|
|
|
376
|
|
|
timeOfUseItem = {} |
377
|
|
|
timeOfUseItem['id'] = 4; |
378
|
|
|
timeOfUseItem['name'] = t('Off-Peak'); |
379
|
|
|
timeOfUseItem['value'] = json['reporting_period']['offpeaks'][index]; |
380
|
|
|
timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
381
|
|
|
timeOfUseArray.push(timeOfUseItem); |
382
|
|
|
} |
383
|
|
|
}); |
384
|
|
|
setTimeOfUseShareData(timeOfUseArray); |
385
|
|
|
|
386
|
|
|
let carbonDataArray = []; |
387
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
388
|
|
|
let carbonDataItem = {} |
389
|
|
|
carbonDataItem['id'] = index; |
390
|
|
|
carbonDataItem['name'] = currentValue; |
391
|
|
|
carbonDataItem['value'] = json['reporting_period']['subtotals'][index]; |
392
|
|
|
carbonDataItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
393
|
|
|
carbonDataArray.push(carbonDataItem); |
394
|
|
|
}); |
395
|
|
|
setCarbonShareData(carbonDataArray); |
396
|
|
|
|
397
|
|
|
let timestamps = {} |
398
|
|
|
json['reporting_period']['timestamps'].forEach((currentValue, index) => { |
399
|
|
|
timestamps['a' + index] = currentValue; |
400
|
|
|
}); |
401
|
|
|
setTenantLineChartLabels(timestamps); |
402
|
|
|
|
403
|
|
|
let values = {} |
404
|
|
|
json['reporting_period']['values'].forEach((currentValue, index) => { |
405
|
|
|
values['a' + index] = currentValue; |
406
|
|
|
}); |
407
|
|
|
setTenantLineChartData(values); |
408
|
|
|
|
409
|
|
|
let names = Array(); |
410
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
411
|
|
|
let unit = json['reporting_period']['units'][index]; |
412
|
|
|
names.push({ 'value': 'a' + index, 'label': currentValue + ' (' + unit + ')'}); |
413
|
|
|
}); |
414
|
|
|
setTenantLineChartOptions(names); |
415
|
|
|
|
416
|
|
|
timestamps = {} |
417
|
|
|
json['parameters']['timestamps'].forEach((currentValue, index) => { |
418
|
|
|
timestamps['a' + index] = currentValue; |
419
|
|
|
}); |
420
|
|
|
setParameterLineChartLabels(timestamps); |
421
|
|
|
|
422
|
|
|
values = {} |
423
|
|
|
json['parameters']['values'].forEach((currentValue, index) => { |
424
|
|
|
values['a' + index] = currentValue; |
425
|
|
|
}); |
426
|
|
|
setParameterLineChartData(values); |
427
|
|
|
|
428
|
|
|
names = Array(); |
429
|
|
|
json['parameters']['names'].forEach((currentValue, index) => { |
430
|
|
|
if (currentValue.startsWith('TARIFF-')) { |
431
|
|
|
currentValue = t('Tariff') + currentValue.replace('TARIFF-', '-'); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
names.push({ 'value': 'a' + index, 'label': currentValue }); |
435
|
|
|
}); |
436
|
|
|
setParameterLineChartOptions(names); |
437
|
|
|
|
438
|
|
|
let detailed_value_list = []; |
439
|
|
|
if (json['reporting_period']['timestamps'].length > 0) { |
440
|
|
|
json['reporting_period']['timestamps'][0].forEach((currentTimestamp, timestampIndex) => { |
441
|
|
|
let detailed_value = {}; |
442
|
|
|
detailed_value['id'] = timestampIndex; |
443
|
|
|
detailed_value['startdatetime'] = currentTimestamp; |
444
|
|
|
let total_current_timstamp = 0.0; |
445
|
|
|
json['reporting_period']['values'].forEach((currentValue, energyCategoryIndex) => { |
446
|
|
|
detailed_value['a' + energyCategoryIndex] = json['reporting_period']['values'][energyCategoryIndex][timestampIndex]; |
447
|
|
|
total_current_timstamp += json['reporting_period']['values'][energyCategoryIndex][timestampIndex]; |
448
|
|
|
}); |
449
|
|
|
detailed_value['total'] = total_current_timstamp; |
450
|
|
|
detailed_value_list.push(detailed_value); |
451
|
|
|
}); |
452
|
|
|
}; |
453
|
|
|
|
454
|
|
|
let detailed_value = {}; |
455
|
|
|
detailed_value['id'] = detailed_value_list.length; |
456
|
|
|
detailed_value['startdatetime'] = t('Subtotal'); |
457
|
|
|
let total_of_subtotals = 0.0; |
458
|
|
|
json['reporting_period']['subtotals'].forEach((currentValue, index) => { |
459
|
|
|
detailed_value['a' + index] = currentValue; |
460
|
|
|
total_of_subtotals += currentValue |
461
|
|
|
}); |
462
|
|
|
detailed_value['total'] = total_of_subtotals; |
463
|
|
|
detailed_value_list.push(detailed_value); |
464
|
|
|
setDetailedDataTableData(detailed_value_list); |
465
|
|
|
|
466
|
|
|
let detailed_column_list = []; |
467
|
|
|
detailed_column_list.push({ |
468
|
|
|
dataField: 'startdatetime', |
469
|
|
|
text: t('Datetime'), |
470
|
|
|
sort: true |
471
|
|
|
}); |
472
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
473
|
|
|
let unit = json['reporting_period']['units'][index]; |
474
|
|
|
detailed_column_list.push({ |
475
|
|
|
dataField: 'a' + index, |
476
|
|
|
text: currentValue + ' (' + unit + ')', |
477
|
|
|
sort: true, |
478
|
|
|
formatter: function (decimalValue) { |
479
|
|
|
if (typeof decimalValue === 'number') { |
480
|
|
|
return decimalValue.toFixed(2); |
481
|
|
|
} else { |
482
|
|
|
return null; |
483
|
|
|
} |
484
|
|
|
} |
485
|
|
|
}); |
486
|
|
|
}); |
487
|
|
|
detailed_column_list.push({ |
488
|
|
|
dataField: 'total', |
489
|
|
|
text: t('Total') + ' (' + json['reporting_period']['total_unit'] + ')', |
490
|
|
|
sort: true, |
491
|
|
|
formatter: function (decimalValue) { |
492
|
|
|
if (typeof decimalValue === 'number') { |
493
|
|
|
return decimalValue.toFixed(2); |
494
|
|
|
} else { |
495
|
|
|
return null; |
496
|
|
|
} |
497
|
|
|
} |
498
|
|
|
}); |
499
|
|
|
setDetailedDataTableColumns(detailed_column_list); |
500
|
|
|
|
501
|
|
|
setExcelBytesBase64(json['excel_bytes_base64']); |
502
|
|
|
|
503
|
|
|
// enable submit button |
504
|
|
|
setSubmitButtonDisabled(false); |
505
|
|
|
// hide spinner |
506
|
|
|
setSpinnerHidden(true); |
507
|
|
|
// show export button |
508
|
|
|
setExportButtonHidden(false) |
509
|
|
|
|
510
|
|
|
} else { |
511
|
|
|
toast.error(json.description) |
512
|
|
|
} |
513
|
|
|
}).catch(err => { |
514
|
|
|
console.log(err); |
515
|
|
|
}); |
516
|
|
|
}; |
517
|
|
|
|
518
|
|
|
const handleExport = e => { |
519
|
|
|
e.preventDefault(); |
520
|
|
|
const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
521
|
|
|
const fileName = 'tenantcarbon.xlsx' |
522
|
|
|
var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64; |
523
|
|
|
fetch(fileUrl) |
524
|
|
|
.then(response => response.blob()) |
525
|
|
|
.then(blob => { |
526
|
|
|
var link = window.document.createElement("a"); |
527
|
|
|
link.href = window.URL.createObjectURL(blob, { type: mimeType }); |
528
|
|
|
link.download = fileName; |
529
|
|
|
document.body.appendChild(link); |
530
|
|
|
link.click(); |
531
|
|
|
document.body.removeChild(link); |
532
|
|
|
}); |
533
|
|
|
}; |
534
|
|
|
|
535
|
|
|
|
536
|
|
|
return ( |
537
|
|
|
<Fragment> |
538
|
|
|
<div> |
539
|
|
|
<Breadcrumb> |
540
|
|
|
<BreadcrumbItem>{t('Tenant Data')}</BreadcrumbItem><BreadcrumbItem active>{t('Carbon')}</BreadcrumbItem> |
541
|
|
|
</Breadcrumb> |
542
|
|
|
</div> |
543
|
|
|
<Card className="bg-light mb-3"> |
544
|
|
|
<CardBody className="p-3"> |
545
|
|
|
<Form onSubmit={handleSubmit}> |
546
|
|
|
<Row form> |
547
|
|
|
<Col xs={6} sm={3}> |
548
|
|
|
<FormGroup className="form-group"> |
549
|
|
|
<Label className={labelClasses} for="space"> |
550
|
|
|
{t('Space')} |
551
|
|
|
</Label> |
552
|
|
|
<br /> |
553
|
|
|
<Cascader options={cascaderOptions} |
554
|
|
|
onChange={onSpaceCascaderChange} |
555
|
|
|
changeOnSelect |
556
|
|
|
expandTrigger="hover"> |
557
|
|
|
<Input value={selectedSpaceName || ''} readOnly /> |
558
|
|
|
</Cascader> |
559
|
|
|
</FormGroup> |
560
|
|
|
</Col> |
561
|
|
|
<Col xs="auto"> |
562
|
|
|
<FormGroup> |
563
|
|
|
<Label className={labelClasses} for="tenantSelect"> |
564
|
|
|
{t('Tenant')} |
565
|
|
|
</Label> |
566
|
|
|
<CustomInput type="select" id="tenantSelect" name="tenantSelect" onChange={({ target }) => setSelectedTenant(target.value)} |
567
|
|
|
> |
568
|
|
|
{tenantList.map((tenant, index) => ( |
569
|
|
|
<option value={tenant.value} key={tenant.value}> |
570
|
|
|
{tenant.label} |
571
|
|
|
</option> |
572
|
|
|
))} |
573
|
|
|
</CustomInput> |
574
|
|
|
</FormGroup> |
575
|
|
|
</Col> |
576
|
|
|
<Col xs="auto"> |
577
|
|
|
<FormGroup> |
578
|
|
|
<Label className={labelClasses} for="comparisonType"> |
579
|
|
|
{t('Comparison Types')} |
580
|
|
|
</Label> |
581
|
|
|
<CustomInput type="select" id="comparisonType" name="comparisonType" |
582
|
|
|
defaultValue="month-on-month" |
583
|
|
|
onChange={onComparisonTypeChange} |
584
|
|
|
> |
585
|
|
|
{comparisonTypeOptions.map((comparisonType, index) => ( |
586
|
|
|
<option value={comparisonType.value} key={comparisonType.value} > |
587
|
|
|
{t(comparisonType.label)} |
588
|
|
|
</option> |
589
|
|
|
))} |
590
|
|
|
</CustomInput> |
591
|
|
|
</FormGroup> |
592
|
|
|
</Col> |
593
|
|
|
<Col xs="auto"> |
594
|
|
|
<FormGroup> |
595
|
|
|
<Label className={labelClasses} for="periodType"> |
596
|
|
|
{t('Period Types')} |
597
|
|
|
</Label> |
598
|
|
|
<CustomInput type="select" id="periodType" name="periodType" defaultValue="daily" onChange={({ target }) => setPeriodType(target.value)} |
599
|
|
|
> |
600
|
|
|
{periodTypeOptions.map((periodType, index) => ( |
601
|
|
|
<option value={periodType.value} key={periodType.value} > |
602
|
|
|
{t(periodType.label)} |
603
|
|
|
</option> |
604
|
|
|
))} |
605
|
|
|
</CustomInput> |
606
|
|
|
</FormGroup> |
607
|
|
|
</Col> |
608
|
|
|
<Col xs={6} sm={3}> |
609
|
|
|
<FormGroup className="form-group"> |
610
|
|
|
<Label className={labelClasses} for="basePeriodDateRangePicker">{t('Base Period')}{t('(Optional)')}</Label> |
611
|
|
|
<DateRangePicker |
612
|
|
|
id='basePeriodDateRangePicker' |
613
|
|
|
readOnly={basePeriodDateRangePickerDisabled} |
614
|
|
|
format="yyyy-MM-dd HH:mm:ss" |
615
|
|
|
value={basePeriodDateRange} |
616
|
|
|
onChange={onBasePeriodChange} |
617
|
|
|
size="md" |
618
|
|
|
style={dateRangePickerStyle} |
619
|
|
|
onClean={onBasePeriodClean} |
620
|
|
|
locale={dateRangePickerLocale} |
621
|
|
|
placeholder={t("Select Date Range")} |
622
|
|
|
/> |
623
|
|
|
</FormGroup> |
624
|
|
|
</Col> |
625
|
|
|
<Col xs={6} sm={3}> |
626
|
|
|
<FormGroup className="form-group"> |
627
|
|
|
<Label className={labelClasses} for="reportingPeriodDateRangePicker">{t('Reporting Period')}</Label> |
628
|
|
|
<br/> |
629
|
|
|
<DateRangePicker |
630
|
|
|
id='reportingPeriodDateRangePicker' |
631
|
|
|
format="yyyy-MM-dd HH:mm:ss" |
632
|
|
|
value={reportingPeriodDateRange} |
633
|
|
|
onChange={onReportingPeriodChange} |
634
|
|
|
size="md" |
635
|
|
|
style={dateRangePickerStyle} |
636
|
|
|
onClean={onReportingPeriodClean} |
637
|
|
|
locale={dateRangePickerLocale} |
638
|
|
|
placeholder={t("Select Date Range")} |
639
|
|
|
/> |
640
|
|
|
</FormGroup> |
641
|
|
|
</Col> |
642
|
|
|
<Col xs="auto"> |
643
|
|
|
<FormGroup> |
644
|
|
|
<br></br> |
645
|
|
|
<ButtonGroup id="submit"> |
646
|
|
|
<Button color="success" disabled={submitButtonDisabled} >{t('Submit')}</Button> |
647
|
|
|
</ButtonGroup> |
648
|
|
|
</FormGroup> |
649
|
|
|
</Col> |
650
|
|
|
<Col xs="auto"> |
651
|
|
|
<FormGroup> |
652
|
|
|
<br></br> |
653
|
|
|
<Spinner color="primary" hidden={spinnerHidden} /> |
654
|
|
|
</FormGroup> |
655
|
|
|
</Col> |
656
|
|
|
<Col xs="auto"> |
657
|
|
|
<br></br> |
658
|
|
|
<ButtonIcon icon="external-link-alt" transform="shrink-3 down-2" color="falcon-default" |
659
|
|
|
hidden={exportButtonHidden} |
660
|
|
|
onClick={handleExport} > |
661
|
|
|
{t('Export')} |
662
|
|
|
</ButtonIcon> |
663
|
|
|
</Col> |
664
|
|
|
</Row> |
665
|
|
|
</Form> |
666
|
|
|
</CardBody> |
667
|
|
|
</Card> |
668
|
|
|
<div className="card-deck"> |
669
|
|
|
{cardSummaryList.map(cardSummaryItem => ( |
670
|
|
|
<CardSummary key={cardSummaryItem['name']} |
671
|
|
|
rate={cardSummaryItem['increment_rate']} |
672
|
|
|
title={t('Reporting Period Carbon Dioxide Emissions CATEGORY UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })} |
673
|
|
|
color="success" |
674
|
|
|
footnote={t('Per Unit Area')} |
675
|
|
|
footvalue={cardSummaryItem['subtotal_per_unit_area']} |
676
|
|
|
footunit={"(" + cardSummaryItem['unit'] + "/M²)"} > |
677
|
|
|
{cardSummaryItem['subtotal'] && <CountUp end={cardSummaryItem['subtotal']} duration={2} prefix="" separator="," decimal="." decimals={2} />} |
678
|
|
|
</CardSummary> |
679
|
|
|
))} |
680
|
|
|
</div> |
681
|
|
|
<Row noGutters> |
682
|
|
|
<Col className="mb-3 pr-lg-2 mb-3"> |
683
|
|
|
<SharePie data={timeOfUseShareData} title={t('Electricity Carbon Dioxide Emissions by Time-Of-Use')} /> |
684
|
|
|
</Col> |
685
|
|
|
<Col className="mb-3 pr-lg-2 mb-3"> |
686
|
|
|
<SharePie data={carbonShareData} title={t('Carbon Dioxide Emissions by Energy Category')} /> |
687
|
|
|
</Col> |
688
|
|
|
</Row> |
689
|
|
|
<LineChart reportingTitle={t('Reporting Period Carbon Dioxide Emissions CATEGORY VALUE UNIT', { 'CATEGORY': null, 'VALUE': null, 'UNIT': null })} |
690
|
|
|
baseTitle='' |
691
|
|
|
labels={tenantLineChartLabels} |
692
|
|
|
data={tenantLineChartData} |
693
|
|
|
options={tenantLineChartOptions}> |
694
|
|
|
</LineChart> |
695
|
|
|
|
696
|
|
|
<LineChart reportingTitle={t('Related Parameters')} |
697
|
|
|
baseTitle='' |
698
|
|
|
labels={parameterLineChartLabels} |
699
|
|
|
data={parameterLineChartData} |
700
|
|
|
options={parameterLineChartOptions}> |
701
|
|
|
</LineChart> |
702
|
|
|
<br /> |
703
|
|
|
<DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={50} > |
704
|
|
|
</DetailedDataTable> |
705
|
|
|
|
706
|
|
|
</Fragment> |
707
|
|
|
); |
708
|
|
|
}; |
709
|
|
|
|
710
|
|
|
export default withTranslation()(withRedirect(TenantCarbon)); |
711
|
|
|
|