1
|
|
|
import React, { Fragment, useEffect, useState, useContext } 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 MultiTrendChart from '../common/MultiTrendChart'; |
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 DateRangePickerWrapper from '../common/DateRangePickerWrapper'; |
34
|
|
|
import { endOfDay} from 'date-fns'; |
35
|
|
|
import AppContext from '../../../context/Context'; |
36
|
|
|
import MultipleLineChart from '../common/MultipleLineChart'; |
37
|
|
|
|
38
|
|
|
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable')); |
39
|
|
|
|
40
|
|
|
const ShopfloorCarbon = ({ setRedirect, setRedirectUrl, t }) => { |
41
|
|
|
let current_moment = moment(); |
42
|
|
|
useEffect(() => { |
43
|
|
|
let is_logged_in = getCookieValue('is_logged_in'); |
44
|
|
|
let user_name = getCookieValue('user_name'); |
45
|
|
|
let user_display_name = getCookieValue('user_display_name'); |
46
|
|
|
let user_uuid = getCookieValue('user_uuid'); |
47
|
|
|
let token = getCookieValue('token'); |
48
|
|
|
if (is_logged_in === null || !is_logged_in) { |
49
|
|
|
setRedirectUrl(`/authentication/basic/login`); |
50
|
|
|
setRedirect(true); |
51
|
|
|
} else { |
52
|
|
|
//update expires time of cookies |
53
|
|
|
createCookie('is_logged_in', true, 1000 * 60 * 60 * 8); |
54
|
|
|
createCookie('user_name', user_name, 1000 * 60 * 60 * 8); |
55
|
|
|
createCookie('user_display_name', user_display_name, 1000 * 60 * 60 * 8); |
56
|
|
|
createCookie('user_uuid', user_uuid, 1000 * 60 * 60 * 8); |
57
|
|
|
createCookie('token', token, 1000 * 60 * 60 * 8); |
58
|
|
|
} |
59
|
|
|
}); |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
// State |
63
|
|
|
// Query Parameters |
64
|
|
|
const [selectedSpaceName, setSelectedSpaceName] = useState(undefined); |
65
|
|
|
const [selectedSpaceID, setSelectedSpaceID] = useState(undefined); |
66
|
|
|
const [shopfloorList, setShopfloorList] = useState([]); |
67
|
|
|
const [selectedShopfloor, setSelectedShopfloor] = useState(undefined); |
68
|
|
|
const [comparisonType, setComparisonType] = useState('month-on-month'); |
69
|
|
|
const [periodType, setPeriodType] = useState('daily'); |
70
|
|
|
const [cascaderOptions, setCascaderOptions] = useState(undefined); |
71
|
|
|
const [basePeriodDateRange, setBasePeriodDateRange] = useState([current_moment.clone().subtract(1, 'months').startOf('month').toDate(), current_moment.clone().subtract(1, 'months').toDate()]); |
72
|
|
|
const [basePeriodDateRangePickerDisabled, setBasePeriodDateRangePickerDisabled] = useState(true); |
73
|
|
|
const [reportingPeriodDateRange, setReportingPeriodDateRange] = useState([current_moment.clone().startOf('month').toDate(), current_moment.toDate()]); |
74
|
|
|
const dateRangePickerLocale = { |
75
|
|
|
sunday: t('sunday'), |
76
|
|
|
monday: t('monday'), |
77
|
|
|
tuesday: t('tuesday'), |
78
|
|
|
wednesday: t('wednesday'), |
79
|
|
|
thursday: t('thursday'), |
80
|
|
|
friday: t('friday'), |
81
|
|
|
saturday: t('saturday'), |
82
|
|
|
ok: t('ok'), |
83
|
|
|
today: t('today'), |
84
|
|
|
yesterday: t('yesterday'), |
85
|
|
|
hours: t('hours'), |
86
|
|
|
minutes: t('minutes'), |
87
|
|
|
seconds: t('seconds'), |
88
|
|
|
last7Days: t('last7Days'), |
89
|
|
|
formattedMonthPattern: 'yyyy-MM-dd' |
90
|
|
|
}; |
91
|
|
|
const dateRangePickerStyle = { display: 'block', zIndex: 10}; |
92
|
|
|
const { language } = useContext(AppContext); |
93
|
|
|
|
94
|
|
|
// buttons |
95
|
|
|
const [submitButtonDisabled, setSubmitButtonDisabled] = useState(true); |
96
|
|
|
const [spinnerHidden, setSpinnerHidden] = useState(true); |
97
|
|
|
const [exportButtonHidden, setExportButtonHidden] = useState(true); |
98
|
|
|
|
99
|
|
|
//Results |
100
|
|
|
const [timeOfUseShareData, setTimeOfUseShareData] = useState([]); |
101
|
|
|
const [carbonShareData, setCarbonShareData] = useState([]); |
102
|
|
|
|
103
|
|
|
const [cardSummaryList, setCardSummaryList] = useState([]); |
104
|
|
|
|
105
|
|
|
const [shopfloorBaseAndReportingNames, setShopfloorBaseAndReportingNames] = useState({"a0":""}); |
106
|
|
|
const [shopfloorBaseAndReportingUnits, setShopfloorBaseAndReportingUnits] = useState({"a0":"()"}); |
107
|
|
|
|
108
|
|
|
const [shopfloorBaseLabels, setShopfloorBaseLabels] = useState({"a0": []}); |
109
|
|
|
const [shopfloorBaseData, setShopfloorBaseData] = useState({"a0": []}); |
110
|
|
|
const [shopfloorBaseSubtotals, setShopfloorBaseSubtotals] = useState({"a0": (0).toFixed(2)}); |
111
|
|
|
|
112
|
|
|
const [shopfloorReportingLabels, setShopfloorReportingLabels] = useState({"a0": []}); |
113
|
|
|
const [shopfloorReportingData, setShopfloorReportingData] = useState({"a0": []}); |
114
|
|
|
const [shopfloorReportingSubtotals, setShopfloorReportingSubtotals] = useState({"a0": (0).toFixed(2)}); |
115
|
|
|
|
116
|
|
|
const [shopfloorReportingRates, setShopfloorReportingRates] = useState({"a0": []}); |
117
|
|
|
const [shopfloorReportingOptions, setShopfloorReportingOptions] = useState([]); |
118
|
|
|
|
119
|
|
|
const [parameterLineChartLabels, setParameterLineChartLabels] = useState([]); |
120
|
|
|
const [parameterLineChartData, setParameterLineChartData] = useState({}); |
121
|
|
|
const [parameterLineChartOptions, setParameterLineChartOptions] = useState([]); |
122
|
|
|
|
123
|
|
|
const [detailedDataTableData, setDetailedDataTableData] = useState([]); |
124
|
|
|
const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]); |
125
|
|
|
const [excelBytesBase64, setExcelBytesBase64] = useState(undefined); |
126
|
|
|
|
127
|
|
|
useEffect(() => { |
128
|
|
|
let isResponseOK = false; |
129
|
|
|
fetch(APIBaseURL + '/spaces/tree', { |
130
|
|
|
method: 'GET', |
131
|
|
|
headers: { |
132
|
|
|
"Content-type": "application/json", |
133
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
134
|
|
|
"Token": getCookieValue('token') |
135
|
|
|
}, |
136
|
|
|
body: null, |
137
|
|
|
|
138
|
|
|
}).then(response => { |
139
|
|
|
console.log(response); |
140
|
|
|
if (response.ok) { |
141
|
|
|
isResponseOK = true; |
142
|
|
|
} |
143
|
|
|
return response.json(); |
144
|
|
|
}).then(json => { |
145
|
|
|
console.log(json); |
146
|
|
|
if (isResponseOK) { |
147
|
|
|
// rename keys |
148
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
149
|
|
|
setCascaderOptions(json); |
150
|
|
|
setSelectedSpaceName([json[0]].map(o => o.label)); |
151
|
|
|
setSelectedSpaceID([json[0]].map(o => o.value)); |
152
|
|
|
// get Shopfloors by root Space ID |
153
|
|
|
let isResponseOK = false; |
154
|
|
|
fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/shopfloors', { |
155
|
|
|
method: 'GET', |
156
|
|
|
headers: { |
157
|
|
|
"Content-type": "application/json", |
158
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
159
|
|
|
"Token": getCookieValue('token') |
160
|
|
|
}, |
161
|
|
|
body: null, |
162
|
|
|
|
163
|
|
|
}).then(response => { |
164
|
|
|
if (response.ok) { |
165
|
|
|
isResponseOK = true; |
166
|
|
|
} |
167
|
|
|
return response.json(); |
168
|
|
|
}).then(json => { |
169
|
|
|
if (isResponseOK) { |
170
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
171
|
|
|
console.log(json); |
172
|
|
|
setShopfloorList(json[0]); |
173
|
|
|
if (json[0].length > 0) { |
174
|
|
|
setSelectedShopfloor(json[0][0].value); |
175
|
|
|
// enable submit button |
176
|
|
|
setSubmitButtonDisabled(false); |
177
|
|
|
} else { |
178
|
|
|
setSelectedShopfloor(undefined); |
179
|
|
|
// disable submit button |
180
|
|
|
setSubmitButtonDisabled(true); |
181
|
|
|
} |
182
|
|
|
} else { |
183
|
|
|
toast.error(t(json.description)) |
184
|
|
|
} |
185
|
|
|
}).catch(err => { |
186
|
|
|
console.log(err); |
187
|
|
|
}); |
188
|
|
|
// end of get Shopfloors by root Space ID |
189
|
|
|
} else { |
190
|
|
|
toast.error(t(json.description)); |
191
|
|
|
} |
192
|
|
|
}).catch(err => { |
193
|
|
|
console.log(err); |
194
|
|
|
}); |
195
|
|
|
|
196
|
|
|
}, []); |
197
|
|
|
|
198
|
|
|
const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0'; |
199
|
|
|
|
200
|
|
|
let onSpaceCascaderChange = (value, selectedOptions) => { |
201
|
|
|
setSelectedSpaceName(selectedOptions.map(o => o.label).join('/')); |
202
|
|
|
setSelectedSpaceID(value[value.length - 1]); |
203
|
|
|
|
204
|
|
|
let isResponseOK = false; |
205
|
|
|
fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/shopfloors', { |
206
|
|
|
method: 'GET', |
207
|
|
|
headers: { |
208
|
|
|
"Content-type": "application/json", |
209
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
210
|
|
|
"Token": getCookieValue('token') |
211
|
|
|
}, |
212
|
|
|
body: null, |
213
|
|
|
|
214
|
|
|
}).then(response => { |
215
|
|
|
if (response.ok) { |
216
|
|
|
isResponseOK = true; |
217
|
|
|
} |
218
|
|
|
return response.json(); |
219
|
|
|
}).then(json => { |
220
|
|
|
if (isResponseOK) { |
221
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
222
|
|
|
console.log(json) |
223
|
|
|
setShopfloorList(json[0]); |
224
|
|
|
if (json[0].length > 0) { |
225
|
|
|
setSelectedShopfloor(json[0][0].value); |
226
|
|
|
// enable submit button |
227
|
|
|
setSubmitButtonDisabled(false); |
228
|
|
|
} else { |
229
|
|
|
setSelectedShopfloor(undefined); |
230
|
|
|
// disable submit button |
231
|
|
|
setSubmitButtonDisabled(true); |
232
|
|
|
} |
233
|
|
|
} else { |
234
|
|
|
toast.error(t(json.description)) |
235
|
|
|
} |
236
|
|
|
}).catch(err => { |
237
|
|
|
console.log(err); |
238
|
|
|
}); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
|
242
|
|
|
let onComparisonTypeChange = ({ target }) => { |
243
|
|
|
console.log(target.value); |
244
|
|
|
setComparisonType(target.value); |
245
|
|
|
if (target.value === 'year-over-year') { |
246
|
|
|
setBasePeriodDateRangePickerDisabled(true); |
247
|
|
|
setBasePeriodDateRange([moment(reportingPeriodDateRange[0]).subtract(1, 'years').toDate(), |
248
|
|
|
moment(reportingPeriodDateRange[1]).subtract(1, 'years').toDate()]); |
249
|
|
|
} else if (target.value === 'month-on-month') { |
250
|
|
|
setBasePeriodDateRangePickerDisabled(true); |
251
|
|
|
setBasePeriodDateRange([moment(reportingPeriodDateRange[0]).subtract(1, 'months').toDate(), |
252
|
|
|
moment(reportingPeriodDateRange[1]).subtract(1, 'months').toDate()]); |
253
|
|
|
} else if (target.value === 'free-comparison') { |
254
|
|
|
setBasePeriodDateRangePickerDisabled(false); |
255
|
|
|
} else if (target.value === 'none-comparison') { |
256
|
|
|
setBasePeriodDateRange([null, null]); |
257
|
|
|
setBasePeriodDateRangePickerDisabled(true); |
258
|
|
|
} |
259
|
|
|
}; |
260
|
|
|
|
261
|
|
|
// Callback fired when value changed |
262
|
|
|
let onBasePeriodChange = (DateRange) => { |
263
|
|
|
if(DateRange == null) { |
264
|
|
|
setBasePeriodDateRange([null, null]); |
265
|
|
|
} else { |
266
|
|
|
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') { |
267
|
|
|
// if the user did not change time value, set the default time to the end of day |
268
|
|
|
DateRange[1] = endOfDay(DateRange[1]); |
269
|
|
|
} |
270
|
|
|
setBasePeriodDateRange([DateRange[0], DateRange[1]]); |
271
|
|
|
} |
272
|
|
|
}; |
273
|
|
|
|
274
|
|
|
// Callback fired when value changed |
275
|
|
|
let onReportingPeriodChange = (DateRange) => { |
276
|
|
|
if(DateRange == null) { |
277
|
|
|
setReportingPeriodDateRange([null, null]); |
278
|
|
|
} else { |
279
|
|
|
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') { |
280
|
|
|
// if the user did not change time value, set the default time to the end of day |
281
|
|
|
DateRange[1] = endOfDay(DateRange[1]); |
282
|
|
|
} |
283
|
|
|
setReportingPeriodDateRange([DateRange[0], DateRange[1]]); |
284
|
|
|
if (comparisonType === 'year-over-year') { |
285
|
|
|
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]); |
286
|
|
|
} else if (comparisonType === 'month-on-month') { |
287
|
|
|
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'months').toDate(), moment(DateRange[1]).clone().subtract(1, 'months').toDate()]); |
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
}; |
291
|
|
|
|
292
|
|
|
// Callback fired when value clean |
293
|
|
|
let onBasePeriodClean = event => { |
294
|
|
|
setBasePeriodDateRange([null, null]); |
295
|
|
|
}; |
296
|
|
|
|
297
|
|
|
// Callback fired when value clean |
298
|
|
|
let onReportingPeriodClean = event => { |
299
|
|
|
setReportingPeriodDateRange([null, null]); |
300
|
|
|
}; |
301
|
|
|
|
302
|
|
|
const isBasePeriodTimestampExists = (base_period_data) => { |
303
|
|
|
const timestamps = base_period_data['timestamps']; |
304
|
|
|
|
305
|
|
|
if (timestamps.length === 0) { |
306
|
|
|
return false; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
for (let i = 0; i < timestamps.length; i++) { |
310
|
|
|
if (timestamps[i].length > 0) { |
311
|
|
|
return true; |
312
|
|
|
} |
313
|
|
|
} |
314
|
|
|
return false |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
// Handler |
318
|
|
|
const handleSubmit = e => { |
319
|
|
|
e.preventDefault(); |
320
|
|
|
console.log('handleSubmit'); |
321
|
|
|
console.log(selectedSpaceID); |
322
|
|
|
console.log(selectedShopfloor); |
323
|
|
|
console.log(comparisonType); |
324
|
|
|
console.log(periodType); |
325
|
|
|
console.log(basePeriodDateRange[0] != null ? moment(basePeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') : null) |
326
|
|
|
console.log(basePeriodDateRange[1] != null ? moment(basePeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss') : null) |
327
|
|
|
console.log(moment(reportingPeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss')) |
328
|
|
|
console.log(moment(reportingPeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss')); |
329
|
|
|
|
330
|
|
|
// disable submit button |
331
|
|
|
setSubmitButtonDisabled(true); |
332
|
|
|
// show spinner |
333
|
|
|
setSpinnerHidden(false); |
334
|
|
|
// hide export button |
335
|
|
|
setExportButtonHidden(true) |
336
|
|
|
|
337
|
|
|
// Reinitialize tables |
338
|
|
|
setDetailedDataTableData([]); |
339
|
|
|
|
340
|
|
|
let isResponseOK = false; |
341
|
|
|
fetch(APIBaseURL + '/reports/shopfloorcarbon?' + |
342
|
|
|
'shopfloorid=' + selectedShopfloor + |
343
|
|
|
'&periodtype=' + periodType + |
344
|
|
|
'&baseperiodstartdatetime=' + (basePeriodDateRange[0] != null ? moment(basePeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') : '') + |
345
|
|
|
'&baseperiodenddatetime=' + (basePeriodDateRange[1] != null ? moment(basePeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss') : '') + |
346
|
|
|
'&reportingperiodstartdatetime=' + moment(reportingPeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') + |
347
|
|
|
'&reportingperiodenddatetime=' + moment(reportingPeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss') + |
348
|
|
|
'&language=' + language, { |
349
|
|
|
method: 'GET', |
350
|
|
|
headers: { |
351
|
|
|
"Content-type": "application/json", |
352
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
353
|
|
|
"Token": getCookieValue('token') |
354
|
|
|
}, |
355
|
|
|
body: null, |
356
|
|
|
|
357
|
|
|
}).then(response => { |
358
|
|
|
if (response.ok) { |
359
|
|
|
isResponseOK = true; |
360
|
|
|
}; |
361
|
|
|
return response.json(); |
362
|
|
|
}).then(json => { |
363
|
|
|
if (isResponseOK) { |
364
|
|
|
console.log(json); |
365
|
|
|
|
366
|
|
|
let cardSummaryList = [] |
367
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
368
|
|
|
let cardSummaryItem = {} |
369
|
|
|
cardSummaryItem['name'] = json['reporting_period']['names'][index]; |
370
|
|
|
cardSummaryItem['unit'] = json['reporting_period']['units'][index]; |
371
|
|
|
cardSummaryItem['subtotal'] = json['reporting_period']['subtotals'][index]; |
372
|
|
|
cardSummaryItem['increment_rate'] = parseFloat(json['reporting_period']['increment_rates'][index] * 100).toFixed(2) + "%"; |
373
|
|
|
cardSummaryItem['subtotal_per_unit_area'] = json['reporting_period']['subtotals_per_unit_area'][index]; |
374
|
|
|
cardSummaryList.push(cardSummaryItem); |
375
|
|
|
}); |
376
|
|
|
let cardSummaryItem = {} |
377
|
|
|
cardSummaryItem['name'] = t('Total'); |
378
|
|
|
cardSummaryItem['unit'] = json['reporting_period']['total_unit']; |
379
|
|
|
cardSummaryItem['subtotal'] = json['reporting_period']['total']; |
380
|
|
|
cardSummaryItem['increment_rate'] = parseFloat(json['reporting_period']['total_increment_rate'] * 100).toFixed(2) + "%"; |
381
|
|
|
cardSummaryItem['subtotal_per_unit_area'] = json['reporting_period']['total_per_unit_area']; |
382
|
|
|
cardSummaryList.push(cardSummaryItem); |
383
|
|
|
setCardSummaryList(cardSummaryList); |
384
|
|
|
|
385
|
|
|
let timeOfUseArray = []; |
386
|
|
|
json['reporting_period']['energy_category_ids'].forEach((currentValue, index) => { |
387
|
|
|
if(currentValue === 1) { |
388
|
|
|
// energy_category_id 1 electricity |
389
|
|
|
let timeOfUseItem = {} |
390
|
|
|
timeOfUseItem['id'] = 1; |
391
|
|
|
timeOfUseItem['name'] = t('Top-Peak'); |
392
|
|
|
timeOfUseItem['value'] = json['reporting_period']['toppeaks'][index]; |
393
|
|
|
timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
394
|
|
|
timeOfUseArray.push(timeOfUseItem); |
395
|
|
|
|
396
|
|
|
timeOfUseItem = {} |
397
|
|
|
timeOfUseItem['id'] = 2; |
398
|
|
|
timeOfUseItem['name'] = t('On-Peak'); |
399
|
|
|
timeOfUseItem['value'] = json['reporting_period']['onpeaks'][index]; |
400
|
|
|
timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
401
|
|
|
timeOfUseArray.push(timeOfUseItem); |
402
|
|
|
|
403
|
|
|
timeOfUseItem = {} |
404
|
|
|
timeOfUseItem['id'] = 3; |
405
|
|
|
timeOfUseItem['name'] = t('Mid-Peak'); |
406
|
|
|
timeOfUseItem['value'] = json['reporting_period']['midpeaks'][index]; |
407
|
|
|
timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
408
|
|
|
timeOfUseArray.push(timeOfUseItem); |
409
|
|
|
|
410
|
|
|
timeOfUseItem = {} |
411
|
|
|
timeOfUseItem['id'] = 4; |
412
|
|
|
timeOfUseItem['name'] = t('Off-Peak'); |
413
|
|
|
timeOfUseItem['value'] = json['reporting_period']['offpeaks'][index]; |
414
|
|
|
timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
415
|
|
|
timeOfUseArray.push(timeOfUseItem); |
416
|
|
|
} |
417
|
|
|
}); |
418
|
|
|
setTimeOfUseShareData(timeOfUseArray); |
419
|
|
|
|
420
|
|
|
let carbonDataArray = []; |
421
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
422
|
|
|
let carbonDataItem = {} |
423
|
|
|
carbonDataItem['id'] = index; |
424
|
|
|
carbonDataItem['name'] = currentValue; |
425
|
|
|
carbonDataItem['value'] = json['reporting_period']['subtotals'][index]; |
426
|
|
|
carbonDataItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); |
427
|
|
|
carbonDataArray.push(carbonDataItem); |
428
|
|
|
}); |
429
|
|
|
setCarbonShareData(carbonDataArray); |
430
|
|
|
|
431
|
|
|
let base_timestamps = {} |
432
|
|
|
json['base_period']['timestamps'].forEach((currentValue, index) => { |
433
|
|
|
base_timestamps['a' + index] = currentValue; |
434
|
|
|
}); |
435
|
|
|
setShopfloorBaseLabels(base_timestamps) |
436
|
|
|
|
437
|
|
|
let base_values = {} |
438
|
|
|
json['base_period']['values'].forEach((currentValue, index) => { |
439
|
|
|
base_values['a' + index] = currentValue; |
440
|
|
|
}); |
441
|
|
|
setShopfloorBaseData(base_values) |
442
|
|
|
|
443
|
|
|
/* |
444
|
|
|
* Tip: |
445
|
|
|
* base_names === reporting_names |
446
|
|
|
* base_units === reporting_units |
447
|
|
|
* */ |
448
|
|
|
|
449
|
|
|
let base_and_reporting_names = {} |
450
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
451
|
|
|
base_and_reporting_names['a' + index] = currentValue; |
452
|
|
|
}); |
453
|
|
|
setShopfloorBaseAndReportingNames(base_and_reporting_names) |
454
|
|
|
|
455
|
|
|
let base_and_reporting_units = {} |
456
|
|
|
json['reporting_period']['units'].forEach((currentValue, index) => { |
457
|
|
|
base_and_reporting_units['a' + index] = "("+currentValue+")"; |
458
|
|
|
}); |
459
|
|
|
setShopfloorBaseAndReportingUnits(base_and_reporting_units) |
460
|
|
|
|
461
|
|
|
let base_subtotals = {} |
462
|
|
|
json['base_period']['subtotals'].forEach((currentValue, index) => { |
463
|
|
|
base_subtotals['a' + index] = currentValue.toFixed(2); |
464
|
|
|
}); |
465
|
|
|
setShopfloorBaseSubtotals(base_subtotals) |
466
|
|
|
|
467
|
|
|
let reporting_timestamps = {} |
468
|
|
|
json['reporting_period']['timestamps'].forEach((currentValue, index) => { |
469
|
|
|
reporting_timestamps['a' + index] = currentValue; |
470
|
|
|
}); |
471
|
|
|
setShopfloorReportingLabels(reporting_timestamps); |
472
|
|
|
|
473
|
|
|
let reporting_values = {} |
474
|
|
|
json['reporting_period']['values'].forEach((currentValue, index) => { |
475
|
|
|
reporting_values['a' + index] = currentValue; |
476
|
|
|
}); |
477
|
|
|
setShopfloorReportingData(reporting_values); |
478
|
|
|
|
479
|
|
|
let reporting_subtotals = {} |
480
|
|
|
json['reporting_period']['subtotals'].forEach((currentValue, index) => { |
481
|
|
|
reporting_subtotals['a' + index] = currentValue.toFixed(2); |
482
|
|
|
}); |
483
|
|
|
setShopfloorReportingSubtotals(reporting_subtotals); |
484
|
|
|
|
485
|
|
|
let rates = {} |
486
|
|
|
json['reporting_period']['rates'].forEach((currentValue, index) => { |
487
|
|
|
let currentRate = Array(); |
488
|
|
|
currentValue.forEach((rate) => { |
489
|
|
|
currentRate.push(rate ? parseFloat(rate * 100).toFixed(2) : '0.00'); |
490
|
|
|
}); |
491
|
|
|
rates['a' + index] = currentRate; |
492
|
|
|
}); |
493
|
|
|
setShopfloorReportingRates(rates) |
494
|
|
|
|
495
|
|
|
let options = Array(); |
496
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
497
|
|
|
let unit = json['reporting_period']['units'][index]; |
498
|
|
|
options.push({ 'value': 'a' + index, 'label': currentValue + ' (' + unit + ')'}); |
499
|
|
|
}); |
500
|
|
|
setShopfloorReportingOptions(options); |
501
|
|
|
|
502
|
|
|
let timestamps = {} |
503
|
|
|
json['parameters']['timestamps'].forEach((currentValue, index) => { |
504
|
|
|
timestamps['a' + index] = currentValue; |
505
|
|
|
}); |
506
|
|
|
setParameterLineChartLabels(timestamps); |
507
|
|
|
|
508
|
|
|
let values = {} |
509
|
|
|
json['parameters']['values'].forEach((currentValue, index) => { |
510
|
|
|
values['a' + index] = currentValue; |
511
|
|
|
}); |
512
|
|
|
setParameterLineChartData(values); |
513
|
|
|
|
514
|
|
|
let names = Array(); |
515
|
|
|
json['parameters']['names'].forEach((currentValue, index) => { |
516
|
|
|
|
517
|
|
|
names.push({ 'value': 'a' + index, 'label': currentValue }); |
518
|
|
|
}); |
519
|
|
|
setParameterLineChartOptions(names); |
520
|
|
|
|
521
|
|
|
if(!isBasePeriodTimestampExists(json['base_period'])) { |
522
|
|
|
let detailed_value_list = []; |
523
|
|
|
if (json['reporting_period']['timestamps'].length > 0) { |
524
|
|
|
json['reporting_period']['timestamps'][0].forEach((currentTimestamp, timestampIndex) => { |
525
|
|
|
let detailed_value = {}; |
526
|
|
|
detailed_value['id'] = timestampIndex; |
527
|
|
|
detailed_value['startdatetime'] = currentTimestamp; |
528
|
|
|
let total_current_timstamp = 0.0; |
529
|
|
|
json['reporting_period']['values'].forEach((currentValue, energyCategoryIndex) => { |
530
|
|
|
detailed_value['a' + energyCategoryIndex] = json['reporting_period']['values'][energyCategoryIndex][timestampIndex]; |
531
|
|
|
total_current_timstamp += json['reporting_period']['values'][energyCategoryIndex][timestampIndex]; |
532
|
|
|
}); |
533
|
|
|
detailed_value['total'] = total_current_timstamp; |
534
|
|
|
detailed_value_list.push(detailed_value); |
535
|
|
|
}); |
536
|
|
|
} |
537
|
|
|
; |
538
|
|
|
|
539
|
|
|
let detailed_value = {}; |
540
|
|
|
detailed_value['id'] = detailed_value_list.length; |
541
|
|
|
detailed_value['startdatetime'] = t('Subtotal'); |
542
|
|
|
let total_of_subtotals = 0.0; |
543
|
|
|
json['reporting_period']['subtotals'].forEach((currentValue, index) => { |
544
|
|
|
detailed_value['a' + index] = currentValue; |
545
|
|
|
total_of_subtotals += currentValue |
546
|
|
|
}); |
547
|
|
|
detailed_value['total'] = total_of_subtotals; |
548
|
|
|
detailed_value_list.push(detailed_value); |
549
|
|
|
setTimeout(() => { |
550
|
|
|
setDetailedDataTableData(detailed_value_list); |
551
|
|
|
}, 0) |
552
|
|
|
|
553
|
|
|
let detailed_column_list = []; |
554
|
|
|
detailed_column_list.push({ |
555
|
|
|
dataField: 'startdatetime', |
556
|
|
|
text: t('Datetime'), |
557
|
|
|
sort: true |
558
|
|
|
}); |
559
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
560
|
|
|
let unit = json['reporting_period']['units'][index]; |
561
|
|
|
detailed_column_list.push({ |
562
|
|
|
dataField: 'a' + index, |
563
|
|
|
text: currentValue + ' (' + unit + ')', |
564
|
|
|
sort: true, |
565
|
|
|
formatter: function (decimalValue) { |
566
|
|
|
if (typeof decimalValue === 'number') { |
567
|
|
|
return decimalValue.toFixed(2); |
568
|
|
|
} else { |
569
|
|
|
return null; |
570
|
|
|
} |
571
|
|
|
} |
572
|
|
|
}); |
573
|
|
|
}); |
574
|
|
|
detailed_column_list.push({ |
575
|
|
|
dataField: 'total', |
576
|
|
|
text: t('Total') + ' (' + json['reporting_period']['total_unit'] + ')', |
577
|
|
|
sort: true, |
578
|
|
|
formatter: function (decimalValue) { |
579
|
|
|
if (typeof decimalValue === 'number') { |
580
|
|
|
return decimalValue.toFixed(2); |
581
|
|
|
} else { |
582
|
|
|
return null; |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
}); |
586
|
|
|
setDetailedDataTableColumns(detailed_column_list); |
587
|
|
|
}else { |
588
|
|
|
/* |
589
|
|
|
* Tip: |
590
|
|
|
* json['base_period']['names'] === json['reporting_period']['names'] |
591
|
|
|
* json['base_period']['units'] === json['reporting_period']['units'] |
592
|
|
|
* */ |
593
|
|
|
let detailed_column_list = []; |
594
|
|
|
detailed_column_list.push({ |
595
|
|
|
dataField: 'basePeriodDatetime', |
596
|
|
|
text: t('Base Period') + ' - ' + t('Datetime'), |
597
|
|
|
sort: true |
598
|
|
|
}) |
599
|
|
|
|
600
|
|
|
json['base_period']['names'].forEach((currentValue, index) => { |
601
|
|
|
let unit = json['base_period']['units'][index]; |
602
|
|
|
detailed_column_list.push({ |
603
|
|
|
dataField: 'a' + index, |
604
|
|
|
text: t('Base Period') + ' - ' + currentValue + ' (' + unit + ')', |
605
|
|
|
sort: true, |
606
|
|
|
formatter: function (decimalValue) { |
607
|
|
|
if (typeof decimalValue === 'number') { |
608
|
|
|
return decimalValue.toFixed(2); |
609
|
|
|
} else { |
610
|
|
|
return null; |
611
|
|
|
} |
612
|
|
|
} |
613
|
|
|
}) |
614
|
|
|
}); |
615
|
|
|
|
616
|
|
|
detailed_column_list.push({ |
617
|
|
|
dataField: 'basePeriodTotal', |
618
|
|
|
text: t('Base Period') + ' - ' + t('Total') + ' (' + json['reporting_period']['total_unit'] + ')', |
619
|
|
|
sort: true, |
620
|
|
|
formatter: function (decimalValue) { |
621
|
|
|
if (typeof decimalValue === 'number') { |
622
|
|
|
return decimalValue.toFixed(2); |
623
|
|
|
} else { |
624
|
|
|
return null; |
625
|
|
|
} |
626
|
|
|
} |
627
|
|
|
}) |
628
|
|
|
|
629
|
|
|
detailed_column_list.push({ |
630
|
|
|
dataField: 'reportingPeriodDatetime', |
631
|
|
|
text: t('Reporting Period') + ' - ' + t('Datetime'), |
632
|
|
|
sort: true |
633
|
|
|
}) |
634
|
|
|
|
635
|
|
|
json['reporting_period']['names'].forEach((currentValue, index) => { |
636
|
|
|
let unit = json['reporting_period']['units'][index]; |
637
|
|
|
detailed_column_list.push({ |
638
|
|
|
dataField: 'b' + index, |
639
|
|
|
text: t('Reporting Period') + ' - ' + currentValue + ' (' + unit + ')', |
640
|
|
|
sort: true, |
641
|
|
|
formatter: function (decimalValue) { |
642
|
|
|
if (typeof decimalValue === 'number') { |
643
|
|
|
return decimalValue.toFixed(2); |
644
|
|
|
} else { |
645
|
|
|
return null; |
646
|
|
|
} |
647
|
|
|
} |
648
|
|
|
}) |
649
|
|
|
}); |
650
|
|
|
|
651
|
|
|
detailed_column_list.push({ |
652
|
|
|
dataField: 'reportingPeriodTotal', |
653
|
|
|
text: t('Reporting Period') + ' - ' + t('Total') + ' (' + json['reporting_period']['total_unit'] + ')', |
654
|
|
|
sort: true, |
655
|
|
|
formatter: function (decimalValue) { |
656
|
|
|
if (typeof decimalValue === 'number') { |
657
|
|
|
return decimalValue.toFixed(2); |
658
|
|
|
} else { |
659
|
|
|
return null; |
660
|
|
|
} |
661
|
|
|
} |
662
|
|
|
}) |
663
|
|
|
|
664
|
|
|
setDetailedDataTableColumns(detailed_column_list); |
665
|
|
|
|
666
|
|
|
let detailed_value_list = []; |
667
|
|
|
if (json['base_period']['timestamps'].length > 0 || json['reporting_period']['timestamps'].length > 0) { |
668
|
|
|
const max_timestamps_length = json['base_period']['timestamps'][0].length >= json['reporting_period']['timestamps'][0].length? |
669
|
|
|
json['base_period']['timestamps'][0].length : json['reporting_period']['timestamps'][0].length; |
670
|
|
|
for (let index = 0; index < max_timestamps_length; index++) { |
671
|
|
|
let detailed_value = {}; |
672
|
|
|
detailed_value['id'] = index; |
673
|
|
|
detailed_value['basePeriodDatetime'] = index < json['base_period']['timestamps'][0].length? json['base_period']['timestamps'][0][index] : null; |
674
|
|
|
detailed_value['basePeriodTotal'] = 0.0; |
675
|
|
|
if (detailed_value['basePeriodDatetime'] == null) { |
676
|
|
|
detailed_value['basePeriodTotal'] = null; |
677
|
|
|
} |
678
|
|
|
json['base_period']['values'].forEach((currentValue, energyCategoryIndex) => { |
679
|
|
|
detailed_value['a' + energyCategoryIndex] = index < json['base_period']['values'][energyCategoryIndex].length? json['base_period']['values'][energyCategoryIndex][index] : null; |
680
|
|
|
if(detailed_value['a' + energyCategoryIndex] != null) { |
681
|
|
|
detailed_value['basePeriodTotal'] += detailed_value['a' + energyCategoryIndex]; |
682
|
|
|
} |
683
|
|
|
}); |
684
|
|
|
detailed_value['reportingPeriodDatetime'] = index < json['reporting_period']['timestamps'][0].length? json['reporting_period']['timestamps'][0][index] : null; |
685
|
|
|
detailed_value['reportingPeriodTotal'] = 0.0; |
686
|
|
|
if (detailed_value['reportingPeriodDatetime'] == null) { |
687
|
|
|
detailed_value['reportingPeriodTotal'] = null; |
688
|
|
|
} |
689
|
|
|
json['reporting_period']['values'].forEach((currentValue, energyCategoryIndex) => { |
690
|
|
|
detailed_value['b' + energyCategoryIndex] = index < json['reporting_period']['values'][energyCategoryIndex].length? json['reporting_period']['values'][energyCategoryIndex][index] : null; |
691
|
|
|
if(detailed_value['b' + energyCategoryIndex] != null) { |
692
|
|
|
detailed_value['reportingPeriodTotal'] += detailed_value['b' + energyCategoryIndex]; |
693
|
|
|
} |
694
|
|
|
}); |
695
|
|
|
detailed_value_list.push(detailed_value); |
696
|
|
|
} |
697
|
|
|
|
698
|
|
|
let detailed_value = {}; |
699
|
|
|
detailed_value['id'] = detailed_value_list.length; |
700
|
|
|
detailed_value['basePeriodDatetime'] = t('Subtotal'); |
701
|
|
|
let total_of_subtotals_from_base_period = 0.0 |
702
|
|
|
json['base_period']['subtotals'].forEach((currentValue, index) => { |
703
|
|
|
detailed_value['a' + index] = currentValue; |
704
|
|
|
total_of_subtotals_from_base_period += detailed_value['a' + index]; |
705
|
|
|
}); |
706
|
|
|
detailed_value['basePeriodTotal'] = total_of_subtotals_from_base_period; |
707
|
|
|
|
708
|
|
|
let total_of_subtotals_from_reporting_period = 0.0 |
709
|
|
|
detailed_value['reportingPeriodDatetime'] = t('Subtotal'); |
710
|
|
|
json['reporting_period']['subtotals'].forEach((currentValue, index) => { |
711
|
|
|
detailed_value['b' + index] = currentValue; |
712
|
|
|
total_of_subtotals_from_reporting_period += detailed_value['b' + index]; |
713
|
|
|
}); |
714
|
|
|
detailed_value['reportingPeriodTotal'] =total_of_subtotals_from_reporting_period; |
715
|
|
|
detailed_value_list.push(detailed_value); |
716
|
|
|
setTimeout( () => { |
717
|
|
|
setDetailedDataTableData(detailed_value_list); |
718
|
|
|
}, 0) |
719
|
|
|
} |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
setExcelBytesBase64(json['excel_bytes_base64']); |
723
|
|
|
|
724
|
|
|
// enable submit button |
725
|
|
|
setSubmitButtonDisabled(false); |
726
|
|
|
// hide spinner |
727
|
|
|
setSpinnerHidden(true); |
728
|
|
|
// show export button |
729
|
|
|
setExportButtonHidden(false); |
730
|
|
|
|
731
|
|
|
} else { |
732
|
|
|
toast.error(t(json.description)) |
733
|
|
|
} |
734
|
|
|
}).catch(err => { |
735
|
|
|
console.log(err); |
736
|
|
|
}); |
737
|
|
|
}; |
738
|
|
|
|
739
|
|
|
const handleExport = e => { |
740
|
|
|
e.preventDefault(); |
741
|
|
|
const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
742
|
|
|
const fileName = 'shopfloorcarbon.xlsx' |
743
|
|
|
var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64; |
744
|
|
|
fetch(fileUrl) |
745
|
|
|
.then(response => response.blob()) |
746
|
|
|
.then(blob => { |
747
|
|
|
var link = window.document.createElement("a"); |
748
|
|
|
link.href = window.URL.createObjectURL(blob, { type: mimeType }); |
749
|
|
|
link.download = fileName; |
750
|
|
|
document.body.appendChild(link); |
751
|
|
|
link.click(); |
752
|
|
|
document.body.removeChild(link); |
753
|
|
|
}); |
754
|
|
|
}; |
755
|
|
|
|
756
|
|
|
|
757
|
|
|
return ( |
758
|
|
|
<Fragment> |
759
|
|
|
<div> |
760
|
|
|
<Breadcrumb> |
761
|
|
|
<BreadcrumbItem>{t('Shopfloor Data')}</BreadcrumbItem><BreadcrumbItem active>{t('Carbon')}</BreadcrumbItem> |
762
|
|
|
</Breadcrumb> |
763
|
|
|
</div> |
764
|
|
|
<Card className="bg-light mb-3"> |
765
|
|
|
<CardBody className="p-3"> |
766
|
|
|
<Form onSubmit={handleSubmit}> |
767
|
|
|
<Row form> |
768
|
|
|
<Col xs={6} sm={3}> |
769
|
|
|
<FormGroup className="form-group"> |
770
|
|
|
<Label className={labelClasses} for="space"> |
771
|
|
|
{t('Space')} |
772
|
|
|
</Label> |
773
|
|
|
<br /> |
774
|
|
|
<Cascader options={cascaderOptions} |
775
|
|
|
onChange={onSpaceCascaderChange} |
776
|
|
|
changeOnSelect |
777
|
|
|
expandTrigger="hover"> |
778
|
|
|
<Input value={selectedSpaceName || ''} readOnly /> |
779
|
|
|
</Cascader> |
780
|
|
|
</FormGroup> |
781
|
|
|
</Col> |
782
|
|
|
<Col xs="auto"> |
783
|
|
|
<FormGroup> |
784
|
|
|
<Label className={labelClasses} for="shopfloorSelect"> |
785
|
|
|
{t('Shopfloor')} |
786
|
|
|
</Label> |
787
|
|
|
<CustomInput type="select" id="shopfloorSelect" name="shopfloorSelect" onChange={({ target }) => setSelectedShopfloor(target.value)} |
788
|
|
|
> |
789
|
|
|
{shopfloorList.map((shopfloor, index) => ( |
790
|
|
|
<option value={shopfloor.value} key={shopfloor.value}> |
791
|
|
|
{shopfloor.label} |
792
|
|
|
</option> |
793
|
|
|
))} |
794
|
|
|
</CustomInput> |
795
|
|
|
</FormGroup> |
796
|
|
|
</Col> |
797
|
|
|
<Col xs="auto"> |
798
|
|
|
<FormGroup> |
799
|
|
|
<Label className={labelClasses} for="comparisonType"> |
800
|
|
|
{t('Comparison Types')} |
801
|
|
|
</Label> |
802
|
|
|
<CustomInput type="select" id="comparisonType" name="comparisonType" |
803
|
|
|
defaultValue="month-on-month" |
804
|
|
|
onChange={onComparisonTypeChange} |
805
|
|
|
> |
806
|
|
|
{comparisonTypeOptions.map((comparisonType, index) => ( |
807
|
|
|
<option value={comparisonType.value} key={comparisonType.value} > |
808
|
|
|
{t(comparisonType.label)} |
809
|
|
|
</option> |
810
|
|
|
))} |
811
|
|
|
</CustomInput> |
812
|
|
|
</FormGroup> |
813
|
|
|
</Col> |
814
|
|
|
<Col xs="auto"> |
815
|
|
|
<FormGroup> |
816
|
|
|
<Label className={labelClasses} for="periodType"> |
817
|
|
|
{t('Period Types')} |
818
|
|
|
</Label> |
819
|
|
|
<CustomInput type="select" id="periodType" name="periodType" defaultValue="daily" onChange={({ target }) => setPeriodType(target.value)} |
820
|
|
|
> |
821
|
|
|
{periodTypeOptions.map((periodType, index) => ( |
822
|
|
|
<option value={periodType.value} key={periodType.value} > |
823
|
|
|
{t(periodType.label)} |
824
|
|
|
</option> |
825
|
|
|
))} |
826
|
|
|
</CustomInput> |
827
|
|
|
</FormGroup> |
828
|
|
|
</Col> |
829
|
|
|
<Col xs={6} sm={3}> |
830
|
|
|
<FormGroup className="form-group"> |
831
|
|
|
<Label className={labelClasses} for="basePeriodDateRangePicker">{t('Base Period')}{t('(Optional)')}</Label> |
832
|
|
|
<DateRangePickerWrapper |
833
|
|
|
id='basePeriodDateRangePicker' |
834
|
|
|
disabled={basePeriodDateRangePickerDisabled} |
835
|
|
|
format="yyyy-MM-dd HH:mm:ss" |
836
|
|
|
value={basePeriodDateRange} |
837
|
|
|
onChange={onBasePeriodChange} |
838
|
|
|
size="md" |
839
|
|
|
style={dateRangePickerStyle} |
840
|
|
|
onClean={onBasePeriodClean} |
841
|
|
|
locale={dateRangePickerLocale} |
842
|
|
|
placeholder={t("Select Date Range")} |
843
|
|
|
/> |
844
|
|
|
</FormGroup> |
845
|
|
|
</Col> |
846
|
|
|
<Col xs={6} sm={3}> |
847
|
|
|
<FormGroup className="form-group"> |
848
|
|
|
<Label className={labelClasses} for="reportingPeriodDateRangePicker">{t('Reporting Period')}</Label> |
849
|
|
|
<br/> |
850
|
|
|
<DateRangePickerWrapper |
851
|
|
|
id='reportingPeriodDateRangePicker' |
852
|
|
|
format="yyyy-MM-dd HH:mm:ss" |
853
|
|
|
value={reportingPeriodDateRange} |
854
|
|
|
onChange={onReportingPeriodChange} |
855
|
|
|
size="md" |
856
|
|
|
style={dateRangePickerStyle} |
857
|
|
|
onClean={onReportingPeriodClean} |
858
|
|
|
locale={dateRangePickerLocale} |
859
|
|
|
placeholder={t("Select Date Range")} |
860
|
|
|
/> |
861
|
|
|
</FormGroup> |
862
|
|
|
</Col> |
863
|
|
|
<Col xs="auto"> |
864
|
|
|
<FormGroup> |
865
|
|
|
<br></br> |
866
|
|
|
<ButtonGroup id="submit"> |
867
|
|
|
<Button color="success" disabled={submitButtonDisabled} >{t('Submit')}</Button> |
868
|
|
|
</ButtonGroup> |
869
|
|
|
</FormGroup> |
870
|
|
|
</Col> |
871
|
|
|
<Col xs="auto"> |
872
|
|
|
<FormGroup> |
873
|
|
|
<br></br> |
874
|
|
|
<Spinner color="primary" hidden={spinnerHidden} /> |
875
|
|
|
</FormGroup> |
876
|
|
|
</Col> |
877
|
|
|
<Col xs="auto"> |
878
|
|
|
<br></br> |
879
|
|
|
<ButtonIcon icon="external-link-alt" transform="shrink-3 down-2" color="falcon-default" |
880
|
|
|
hidden={exportButtonHidden} |
881
|
|
|
onClick={handleExport} > |
882
|
|
|
{t('Export')} |
883
|
|
|
</ButtonIcon> |
884
|
|
|
</Col> |
885
|
|
|
</Row> |
886
|
|
|
</Form> |
887
|
|
|
</CardBody> |
888
|
|
|
</Card> |
889
|
|
|
<div className="card-deck"> |
890
|
|
|
{cardSummaryList.map(cardSummaryItem => ( |
891
|
|
|
<CardSummary key={cardSummaryItem['name']} |
892
|
|
|
rate={cardSummaryItem['increment_rate']} |
893
|
|
|
title={t('Reporting Period Carbon Dioxide Emissions CATEGORY UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })} |
894
|
|
|
color="success" |
895
|
|
|
footnote={t('Per Unit Area')} |
896
|
|
|
footvalue={cardSummaryItem['subtotal_per_unit_area']} |
897
|
|
|
footunit={"(" + cardSummaryItem['unit'] + "/M²)"} > |
898
|
|
|
{cardSummaryItem['subtotal'] && <CountUp end={cardSummaryItem['subtotal']} duration={2} prefix="" separator="," decimal="." decimals={2} />} |
899
|
|
|
</CardSummary> |
900
|
|
|
))} |
901
|
|
|
</div> |
902
|
|
|
<Row noGutters> |
903
|
|
|
<Col className="mb-3 pr-lg-2 mb-3"> |
904
|
|
|
<SharePie data={timeOfUseShareData} title={t('Electricity Carbon Dioxide Emissions by Time-Of-Use')} /> |
905
|
|
|
</Col> |
906
|
|
|
<Col className="mb-3 pr-lg-2 mb-3"> |
907
|
|
|
<SharePie data={carbonShareData} title={t('Carbon Dioxide Emissions by Energy Category')} /> |
908
|
|
|
</Col> |
909
|
|
|
</Row> |
910
|
|
|
|
911
|
|
|
<MultiTrendChart reportingTitle = {{"name": "Reporting Period Carbon Dioxide Emissions CATEGORY VALUE UNIT", "substitute": ["CATEGORY", "VALUE", "UNIT"], "CATEGORY": shopfloorBaseAndReportingNames, "VALUE": shopfloorReportingSubtotals, "UNIT": shopfloorBaseAndReportingUnits}} |
912
|
|
|
baseTitle = {{"name": "Base Period Carbon Dioxide Emissions CATEGORY VALUE UNIT", "substitute": ["CATEGORY", "VALUE", "UNIT"], "CATEGORY": shopfloorBaseAndReportingNames, "VALUE": shopfloorBaseSubtotals, "UNIT": shopfloorBaseAndReportingUnits}} |
913
|
|
|
reportingTooltipTitle = {{"name": "Reporting Period Carbon Dioxide Emissions CATEGORY VALUE UNIT", "substitute": ["CATEGORY", "VALUE", "UNIT"], "CATEGORY": shopfloorBaseAndReportingNames, "VALUE": null, "UNIT": shopfloorBaseAndReportingUnits}} |
914
|
|
|
baseTooltipTitle = {{"name": "Base Period Carbon Dioxide Emissions CATEGORY VALUE UNIT", "substitute": ["CATEGORY", "VALUE", "UNIT"], "CATEGORY": shopfloorBaseAndReportingNames, "VALUE": null, "UNIT": shopfloorBaseAndReportingUnits}} |
915
|
|
|
reportingLabels={shopfloorReportingLabels} |
916
|
|
|
reportingData={shopfloorReportingData} |
917
|
|
|
baseLabels={shopfloorBaseLabels} |
918
|
|
|
baseData={shopfloorBaseData} |
919
|
|
|
rates={shopfloorReportingRates} |
920
|
|
|
options={shopfloorReportingOptions}> |
921
|
|
|
</MultiTrendChart> |
922
|
|
|
|
923
|
|
|
<MultipleLineChart reportingTitle={t('Related Parameters')} |
924
|
|
|
baseTitle='' |
925
|
|
|
labels={parameterLineChartLabels} |
926
|
|
|
data={parameterLineChartData} |
927
|
|
|
options={parameterLineChartOptions}> |
928
|
|
|
</MultipleLineChart> |
929
|
|
|
<br /> |
930
|
|
|
<DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={50} > |
931
|
|
|
</DetailedDataTable> |
932
|
|
|
|
933
|
|
|
</Fragment> |
934
|
|
|
); |
935
|
|
|
}; |
936
|
|
|
|
937
|
|
|
export default withTranslation()(withRedirect(ShopfloorCarbon)); |
938
|
|
|
|