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
|
|
|
} from 'reactstrap'; |
17
|
|
|
import CountUp from 'react-countup'; |
18
|
|
|
import Datetime from 'react-datetime'; |
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 { getCookieValue, createCookie } from '../../../helpers/utils'; |
25
|
|
|
import withRedirect from '../../../hoc/withRedirect'; |
26
|
|
|
import { withTranslation } from 'react-i18next'; |
27
|
|
|
import { toast } from 'react-toastify'; |
28
|
|
|
import { APIBaseURL } from '../../../config'; |
29
|
|
|
import { periodTypeOptions } from '../common/PeriodTypeOptions'; |
30
|
|
|
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions'; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable')); |
34
|
|
|
|
35
|
|
|
const ShopfloorStatistics = ({ setRedirect, setRedirectUrl, t }) => { |
36
|
|
|
let current_moment = moment(); |
37
|
|
|
useEffect(() => { |
38
|
|
|
let is_logged_in = getCookieValue('is_logged_in'); |
39
|
|
|
let user_name = getCookieValue('user_name'); |
40
|
|
|
let user_display_name = getCookieValue('user_display_name'); |
41
|
|
|
let user_uuid = getCookieValue('user_uuid'); |
42
|
|
|
let token = getCookieValue('token'); |
43
|
|
|
if (is_logged_in === null || !is_logged_in) { |
44
|
|
|
setRedirectUrl(`/authentication/basic/login`); |
45
|
|
|
setRedirect(true); |
46
|
|
|
} else { |
47
|
|
|
//update expires time of cookies |
48
|
|
|
createCookie('is_logged_in', true, 1000 * 60 * 60 * 8); |
49
|
|
|
createCookie('user_name', user_name, 1000 * 60 * 60 * 8); |
50
|
|
|
createCookie('user_display_name', user_display_name, 1000 * 60 * 60 * 8); |
51
|
|
|
createCookie('user_uuid', user_uuid, 1000 * 60 * 60 * 8); |
52
|
|
|
createCookie('token', token, 1000 * 60 * 60 * 8); |
53
|
|
|
} |
54
|
|
|
}); |
55
|
|
|
// State |
56
|
|
|
// Query Parameters |
57
|
|
|
const [selectedSpaceName, setSelectedSpaceName] = useState(undefined); |
58
|
|
|
const [selectedSpaceID, setSelectedSpaceID] = useState(undefined); |
59
|
|
|
const [shopfloorList, setShopfloorList] = useState([]); |
60
|
|
|
const [selectedShopfloor, setSelectedShopfloor] = useState(undefined); |
61
|
|
|
const [comparisonType, setComparisonType] = useState('month-on-month'); |
62
|
|
|
const [periodType, setPeriodType] = useState('daily'); |
63
|
|
|
const [basePeriodBeginsDatetime, setBasePeriodBeginsDatetime] = useState(current_moment.clone().subtract(1, 'months').startOf('month')); |
64
|
|
|
const [basePeriodEndsDatetime, setBasePeriodEndsDatetime] = useState(current_moment.clone().subtract(1, 'months')); |
65
|
|
|
const [basePeriodBeginsDatetimeDisabled, setBasePeriodBeginsDatetimeDisabled] = useState(true); |
66
|
|
|
const [basePeriodEndsDatetimeDisabled, setBasePeriodEndsDatetimeDisabled] = useState(true); |
67
|
|
|
const [reportingPeriodBeginsDatetime, setReportingPeriodBeginsDatetime] = useState(current_moment.clone().startOf('month')); |
68
|
|
|
const [reportingPeriodEndsDatetime, setReportingPeriodEndsDatetime] = useState(current_moment); |
69
|
|
|
const [cascaderOptions, setCascaderOptions] = useState(undefined); |
70
|
|
|
const [isDisabled, setIsDisabled] = useState(true); |
71
|
|
|
//Results |
72
|
|
|
const [shopfloorLineChartLabels, setShopfloorLineChartLabels] = useState([]); |
73
|
|
|
const [shopfloorLineChartData, setShopfloorLineChartData] = useState({}); |
74
|
|
|
const [shopfloorLineChartOptions, setShopfloorLineChartOptions] = useState([]); |
75
|
|
|
|
76
|
|
|
const [parameterLineChartLabels, setParameterLineChartLabels] = useState([]); |
77
|
|
|
const [parameterLineChartData, setParameterLineChartData] = useState({}); |
78
|
|
|
const [parameterLineChartOptions, setParameterLineChartOptions] = useState([]); |
79
|
|
|
|
80
|
|
|
const [detailedDataTableData, setDetailedDataTableData] = useState([]); |
81
|
|
|
const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]); |
82
|
|
|
|
83
|
|
|
useEffect(() => { |
84
|
|
|
let isResponseOK = false; |
85
|
|
|
fetch(APIBaseURL + '/spaces/tree', { |
86
|
|
|
method: 'GET', |
87
|
|
|
headers: { |
88
|
|
|
"Content-type": "application/json", |
89
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
90
|
|
|
"Token": getCookieValue('token') |
91
|
|
|
}, |
92
|
|
|
body: null, |
93
|
|
|
|
94
|
|
|
}).then(response => { |
95
|
|
|
console.log(response); |
96
|
|
|
if (response.ok) { |
97
|
|
|
isResponseOK = true; |
98
|
|
|
} |
99
|
|
|
return response.json(); |
100
|
|
|
}).then(json => { |
101
|
|
|
console.log(json); |
102
|
|
|
if (isResponseOK) { |
103
|
|
|
// rename keys |
104
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
105
|
|
|
setCascaderOptions(json); |
106
|
|
|
setSelectedSpaceName([json[0]].map(o => o.label)); |
107
|
|
|
setSelectedSpaceID([json[0]].map(o => o.value)); |
108
|
|
|
// get Shopfloors by root Space ID |
109
|
|
|
let isResponseOK = false; |
110
|
|
|
fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/shopfloors', { |
111
|
|
|
method: 'GET', |
112
|
|
|
headers: { |
113
|
|
|
"Content-type": "application/json", |
114
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
115
|
|
|
"Token": getCookieValue('token') |
116
|
|
|
}, |
117
|
|
|
body: null, |
118
|
|
|
|
119
|
|
|
}).then(response => { |
120
|
|
|
if (response.ok) { |
121
|
|
|
isResponseOK = true; |
122
|
|
|
} |
123
|
|
|
return response.json(); |
124
|
|
|
}).then(json => { |
125
|
|
|
if (isResponseOK) { |
126
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
127
|
|
|
console.log(json); |
128
|
|
|
setShopfloorList(json[0]); |
129
|
|
|
if (json[0].length > 0) { |
130
|
|
|
setSelectedShopfloor(json[0][0].value); |
131
|
|
|
setIsDisabled(false); |
132
|
|
|
} else { |
133
|
|
|
setSelectedShopfloor(undefined); |
134
|
|
|
setIsDisabled(true); |
135
|
|
|
} |
136
|
|
|
} else { |
137
|
|
|
toast.error(json.description) |
138
|
|
|
} |
139
|
|
|
}).catch(err => { |
140
|
|
|
console.log(err); |
141
|
|
|
}); |
142
|
|
|
// end of get Shopfloors by root Space ID |
143
|
|
|
} else { |
144
|
|
|
toast.error(json.description); |
145
|
|
|
} |
146
|
|
|
}).catch(err => { |
147
|
|
|
console.log(err); |
148
|
|
|
}); |
149
|
|
|
|
150
|
|
|
}, []); |
151
|
|
|
|
152
|
|
|
const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0'; |
153
|
|
|
|
154
|
|
|
let onSpaceCascaderChange = (value, selectedOptions) => { |
155
|
|
|
setSelectedSpaceName(selectedOptions.map(o => o.label).join('/')); |
156
|
|
|
setSelectedSpaceID(value[value.length - 1]); |
157
|
|
|
|
158
|
|
|
let isResponseOK = false; |
159
|
|
|
fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/shopfloors', { |
160
|
|
|
method: 'GET', |
161
|
|
|
headers: { |
162
|
|
|
"Content-type": "application/json", |
163
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
164
|
|
|
"Token": getCookieValue('token') |
165
|
|
|
}, |
166
|
|
|
body: null, |
167
|
|
|
|
168
|
|
|
}).then(response => { |
169
|
|
|
if (response.ok) { |
170
|
|
|
isResponseOK = true; |
171
|
|
|
} |
172
|
|
|
return response.json(); |
173
|
|
|
}).then(json => { |
174
|
|
|
if (isResponseOK) { |
175
|
|
|
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); |
176
|
|
|
console.log(json) |
177
|
|
|
setShopfloorList(json[0]); |
178
|
|
|
if (json[0].length > 0) { |
179
|
|
|
setSelectedShopfloor(json[0][0].value); |
180
|
|
|
setIsDisabled(false); |
181
|
|
|
} else { |
182
|
|
|
setSelectedShopfloor(undefined); |
183
|
|
|
setIsDisabled(true); |
184
|
|
|
} |
185
|
|
|
} else { |
186
|
|
|
toast.error(json.description) |
187
|
|
|
} |
188
|
|
|
}).catch(err => { |
189
|
|
|
console.log(err); |
190
|
|
|
}); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
let onComparisonTypeChange = ({ target }) => { |
195
|
|
|
console.log(target.value); |
196
|
|
|
setComparisonType(target.value); |
197
|
|
|
if (target.value === 'year-over-year') { |
198
|
|
|
setBasePeriodBeginsDatetimeDisabled(true); |
199
|
|
|
setBasePeriodEndsDatetimeDisabled(true); |
200
|
|
|
setBasePeriodBeginsDatetime(moment(reportingPeriodBeginsDatetime).subtract(1, 'years')); |
201
|
|
|
setBasePeriodEndsDatetime(moment(reportingPeriodEndsDatetime).subtract(1, 'years')); |
202
|
|
|
} else if (target.value === 'month-on-month') { |
203
|
|
|
setBasePeriodBeginsDatetimeDisabled(true); |
204
|
|
|
setBasePeriodEndsDatetimeDisabled(true); |
205
|
|
|
setBasePeriodBeginsDatetime(moment(reportingPeriodBeginsDatetime).subtract(1, 'months')); |
206
|
|
|
setBasePeriodEndsDatetime(moment(reportingPeriodEndsDatetime).subtract(1, 'months')); |
207
|
|
|
} else if (target.value === 'free-comparison') { |
208
|
|
|
setBasePeriodBeginsDatetimeDisabled(false); |
209
|
|
|
setBasePeriodEndsDatetimeDisabled(false); |
210
|
|
|
} else if (target.value === 'none-comparison') { |
211
|
|
|
setBasePeriodBeginsDatetime(undefined); |
212
|
|
|
setBasePeriodEndsDatetime(undefined); |
213
|
|
|
setBasePeriodBeginsDatetimeDisabled(true); |
214
|
|
|
setBasePeriodEndsDatetimeDisabled(true); |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
let onBasePeriodBeginsDatetimeChange = (newDateTime) => { |
219
|
|
|
setBasePeriodBeginsDatetime(newDateTime); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
let onBasePeriodEndsDatetimeChange = (newDateTime) => { |
223
|
|
|
setBasePeriodEndsDatetime(newDateTime); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
let onReportingPeriodBeginsDatetimeChange = (newDateTime) => { |
227
|
|
|
setReportingPeriodBeginsDatetime(newDateTime); |
228
|
|
|
if (comparisonType === 'year-over-year') { |
229
|
|
|
setBasePeriodBeginsDatetime(newDateTime.clone().subtract(1, 'years')); |
230
|
|
|
} else if (comparisonType === 'month-on-month') { |
231
|
|
|
setBasePeriodBeginsDatetime(newDateTime.clone().subtract(1, 'months')); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
let onReportingPeriodEndsDatetimeChange = (newDateTime) => { |
236
|
|
|
setReportingPeriodEndsDatetime(newDateTime); |
237
|
|
|
if (comparisonType === 'year-over-year') { |
238
|
|
|
setBasePeriodEndsDatetime(newDateTime.clone().subtract(1, 'years')); |
239
|
|
|
} else if (comparisonType === 'month-on-month') { |
240
|
|
|
setBasePeriodEndsDatetime(newDateTime.clone().subtract(1, 'months')); |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
var getValidBasePeriodBeginsDatetimes = function (currentDate) { |
245
|
|
|
return currentDate.isBefore(moment(basePeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
var getValidBasePeriodEndsDatetimes = function (currentDate) { |
249
|
|
|
return currentDate.isAfter(moment(basePeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
var getValidReportingPeriodBeginsDatetimes = function (currentDate) { |
253
|
|
|
return currentDate.isBefore(moment(reportingPeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
var getValidReportingPeriodEndsDatetimes = function (currentDate) { |
257
|
|
|
return currentDate.isAfter(moment(reportingPeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a')); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
// Handler |
261
|
|
|
const handleSubmit = e => { |
262
|
|
|
e.preventDefault(); |
263
|
|
|
console.log('handleSubmit'); |
264
|
|
|
console.log(selectedSpaceID); |
265
|
|
|
console.log(selectedShopfloor); |
266
|
|
|
console.log(periodType); |
267
|
|
|
console.log(basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined); |
268
|
|
|
console.log(basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined); |
269
|
|
|
console.log(reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss')); |
270
|
|
|
console.log(reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss')); |
271
|
|
|
|
272
|
|
|
// Reinitialize tables |
273
|
|
|
setDetailedDataTableData([]); |
274
|
|
|
|
275
|
|
|
let isResponseOK = false; |
276
|
|
|
fetch(APIBaseURL + '/reports/shopfloorstatistics?' + |
277
|
|
|
'shopfloorid=' + selectedShopfloor + |
278
|
|
|
'&periodtype=' + periodType + |
279
|
|
|
'&baseperiodstartdatetime=' + (basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') + |
280
|
|
|
'&baseperiodenddatetime=' + (basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') + |
281
|
|
|
'&reportingperiodstartdatetime=' + reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') + |
282
|
|
|
'&reportingperiodenddatetime=' + reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'), { |
283
|
|
|
method: 'GET', |
284
|
|
|
headers: { |
285
|
|
|
"Content-type": "application/json", |
286
|
|
|
"User-UUID": getCookieValue('user_uuid'), |
287
|
|
|
"Token": getCookieValue('token') |
288
|
|
|
}, |
289
|
|
|
body: null, |
290
|
|
|
|
291
|
|
|
}).then(response => { |
292
|
|
|
if (response.ok) { |
293
|
|
|
isResponseOK = true; |
294
|
|
|
} |
295
|
|
|
return response.json(); |
296
|
|
|
}).then(json => { |
297
|
|
|
if (isResponseOK) { |
298
|
|
|
console.log(json) |
299
|
|
|
|
300
|
|
|
setShopfloorLineChartLabels({ |
301
|
|
|
a0: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'], |
302
|
|
|
a1: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'], |
303
|
|
|
a2: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'], |
304
|
|
|
a3: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'], |
305
|
|
|
}); |
306
|
|
|
|
307
|
|
|
setShopfloorLineChartData({ |
308
|
|
|
a0: [4, 1, 6, 2, 7, 12, 4, 6, 5, 4, 5, 10], |
309
|
|
|
a1: [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8], |
310
|
|
|
a2: [1, 0, 2, 1, 2, 1, 1, 0, 0, 1, 0, 2], |
311
|
|
|
a3: [1, 0, 2, 1, 2, 1, 1, 0, 0, 1, 0, 2] |
312
|
|
|
}); |
313
|
|
|
|
314
|
|
|
setShopfloorLineChartOptions([ |
315
|
|
|
{ value: 'a0', label: '电' }, |
316
|
|
|
{ value: 'a1', label: '自来水' }, |
317
|
|
|
{ value: 'a2', label: '天然气' }, |
318
|
|
|
{ value: 'a3', label: '二氧化碳排放' } |
319
|
|
|
]); |
320
|
|
|
|
321
|
|
|
setParameterLineChartLabels({ |
322
|
|
|
a0: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'], |
323
|
|
|
a1: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'], |
324
|
|
|
a2: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'], |
325
|
|
|
a3: ['2020-07-01','2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09','2020-07-10','2020-07-11','2020-07-12'], |
326
|
|
|
}); |
327
|
|
|
|
328
|
|
|
setParameterLineChartData({ |
329
|
|
|
a0: [40, 31, 36, 32, 27, 32, 34, 26, 25, 24, 25, 30], |
330
|
|
|
a1: [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8], |
331
|
|
|
a2: [1, 0, 2, 1, 2, 1, 1, 0, 0, 1, 0, 2], |
332
|
|
|
a3: [1, 0, 2, 1, 2, 1, 1, 0, 0, 1, 0, 2], |
333
|
|
|
a4: [1, 0, 2, 1, 2, 1, 1, 0, 0, 1, 0, 2] |
334
|
|
|
}); |
335
|
|
|
|
336
|
|
|
setParameterLineChartOptions([ |
337
|
|
|
{ value: 'a0', label: '室外温度' }, |
338
|
|
|
{ value: 'a1', label: '相对湿度' }, |
339
|
|
|
{ value: 'a2', label: '电费率' }, |
340
|
|
|
{ value: 'a3', label: '自来水费率' }, |
341
|
|
|
{ value: 'a4', label: '天然气费率' } |
342
|
|
|
]); |
343
|
|
|
|
344
|
|
|
setDetailedDataTableData([ |
345
|
|
|
{ |
346
|
|
|
id: 1, |
347
|
|
|
startdatetime: '2020-07-01', |
348
|
|
|
a: '9872', |
349
|
|
|
b: '3457', |
350
|
|
|
c: '567', |
351
|
|
|
d: '567', |
352
|
|
|
}, |
353
|
|
|
{ |
354
|
|
|
id: 2, |
355
|
|
|
startdatetime: '2020-07-02', |
356
|
|
|
a: '9872', |
357
|
|
|
b: '3457', |
358
|
|
|
c: '567', |
359
|
|
|
d: '567', |
360
|
|
|
}, |
361
|
|
|
{ |
362
|
|
|
id: 3, |
363
|
|
|
startdatetime: '2020-07-03', |
364
|
|
|
a: '9872', |
365
|
|
|
b: '3457', |
366
|
|
|
c: '567', |
367
|
|
|
d: '567', |
368
|
|
|
}, |
369
|
|
|
{ |
370
|
|
|
id: 4, |
371
|
|
|
startdatetime: '2020-07-04', |
372
|
|
|
a: '9872', |
373
|
|
|
b: '3457', |
374
|
|
|
c: '567', |
375
|
|
|
d: '567', |
376
|
|
|
}, |
377
|
|
|
{ |
378
|
|
|
id: 5, |
379
|
|
|
startdatetime: '2020-07-05', |
380
|
|
|
a: '9872', |
381
|
|
|
b: '3457', |
382
|
|
|
c: '567', |
383
|
|
|
d: '567', |
384
|
|
|
}, |
385
|
|
|
{ |
386
|
|
|
id: 6, |
387
|
|
|
startdatetime: '2020-07-06', |
388
|
|
|
a: '9872', |
389
|
|
|
b: '3457', |
390
|
|
|
c: '567', |
391
|
|
|
d: '567', |
392
|
|
|
}, |
393
|
|
|
{ |
394
|
|
|
id: 7, |
395
|
|
|
startdatetime: '2020-07-07', |
396
|
|
|
a: '9872', |
397
|
|
|
b: '3457', |
398
|
|
|
c: '567', |
399
|
|
|
d: '567', |
400
|
|
|
}, |
401
|
|
|
{ |
402
|
|
|
id: 8, |
403
|
|
|
startdatetime: '2020-07-08', |
404
|
|
|
a: '9872', |
405
|
|
|
b: '3457', |
406
|
|
|
c: '567', |
407
|
|
|
d: '567', |
408
|
|
|
}, |
409
|
|
|
{ |
410
|
|
|
id: 9, |
411
|
|
|
startdatetime: '2020-07-09', |
412
|
|
|
a: '9872', |
413
|
|
|
b: '3457', |
414
|
|
|
c: '567', |
415
|
|
|
d: '567', |
416
|
|
|
}, |
417
|
|
|
{ |
418
|
|
|
id: 10, |
419
|
|
|
startdatetime: '2020-07-10', |
420
|
|
|
a: '9872', |
421
|
|
|
b: '3457', |
422
|
|
|
c: '567', |
423
|
|
|
d: '567', |
424
|
|
|
}, |
425
|
|
|
{ |
426
|
|
|
id: 11, |
427
|
|
|
startdatetime: '总平均值', |
428
|
|
|
a: '9872', |
429
|
|
|
b: '3457', |
430
|
|
|
c: '567', |
431
|
|
|
d: '567', |
432
|
|
|
} |
433
|
|
|
]); |
434
|
|
|
|
435
|
|
|
setDetailedDataTableColumns([ |
436
|
|
|
{ |
437
|
|
|
dataField: 'startdatetime', |
438
|
|
|
text: t('Datetime'), |
439
|
|
|
sort: true |
440
|
|
|
}, { |
441
|
|
|
dataField: 'a', |
442
|
|
|
text: '电平均值(kWh)', |
443
|
|
|
sort: true |
444
|
|
|
}, { |
445
|
|
|
dataField: 'b', |
446
|
|
|
text: '自来水平均值(M3)', |
447
|
|
|
sort: true |
448
|
|
|
}, { |
449
|
|
|
dataField: 'c', |
450
|
|
|
text: '天然气平均值(M3)', |
451
|
|
|
sort: true |
452
|
|
|
}, { |
453
|
|
|
dataField: 'd', |
454
|
|
|
text: '二氧化碳排放平均值(T)', |
455
|
|
|
sort: true |
456
|
|
|
} |
457
|
|
|
]); |
458
|
|
|
} else { |
459
|
|
|
toast.error(json.description) |
460
|
|
|
} |
461
|
|
|
}).catch(err => { |
462
|
|
|
console.log(err); |
463
|
|
|
}); |
464
|
|
|
}; |
465
|
|
|
|
466
|
|
|
|
467
|
|
|
return ( |
468
|
|
|
<Fragment> |
469
|
|
|
<div> |
470
|
|
|
<Breadcrumb> |
471
|
|
|
<BreadcrumbItem>{t('Shopfloor Data')}</BreadcrumbItem><BreadcrumbItem active>{t('Statistics')}</BreadcrumbItem> |
472
|
|
|
</Breadcrumb> |
473
|
|
|
</div> |
474
|
|
|
<Card className="bg-light mb-3"> |
475
|
|
|
<CardBody className="p-3"> |
476
|
|
|
<Form onSubmit={handleSubmit}> |
477
|
|
|
<Row form> |
478
|
|
|
<Col xs="auto"> |
479
|
|
|
<FormGroup className="form-group"> |
480
|
|
|
<Label className={labelClasses} for="space"> |
481
|
|
|
{t('Space')} |
482
|
|
|
</Label> |
483
|
|
|
<br /> |
484
|
|
|
<Cascader options={cascaderOptions} |
485
|
|
|
onChange={onSpaceCascaderChange} |
486
|
|
|
changeOnSelect |
487
|
|
|
expandTrigger="hover"> |
488
|
|
|
<Input value={selectedSpaceName || ''} readOnly /> |
489
|
|
|
</Cascader> |
490
|
|
|
</FormGroup> |
491
|
|
|
</Col> |
492
|
|
|
<Col xs="auto"> |
493
|
|
|
<FormGroup> |
494
|
|
|
<Label className={labelClasses} for="shopfloorSelect"> |
495
|
|
|
{t('Shopfloor')} |
496
|
|
|
</Label> |
497
|
|
|
<CustomInput type="select" id="shopfloorSelect" name="shopfloorSelect" onChange={({ target }) => setSelectedShopfloor(target.value)} |
498
|
|
|
> |
499
|
|
|
{shopfloorList.map((shopfloor, index) => ( |
500
|
|
|
<option value={shopfloor.value} key={shopfloor.value}> |
501
|
|
|
{shopfloor.label} |
502
|
|
|
</option> |
503
|
|
|
))} |
504
|
|
|
</CustomInput> |
505
|
|
|
</FormGroup> |
506
|
|
|
</Col> |
507
|
|
|
<Col xs="auto"> |
508
|
|
|
<FormGroup> |
509
|
|
|
<Label className={labelClasses} for="comparisonType"> |
510
|
|
|
{t('Comparison Types')} |
511
|
|
|
</Label> |
512
|
|
|
<CustomInput type="select" id="comparisonType" name="comparisonType" |
513
|
|
|
defaultValue="month-on-month" |
514
|
|
|
onChange={onComparisonTypeChange} |
515
|
|
|
> |
516
|
|
|
{comparisonTypeOptions.map((comparisonType, index) => ( |
517
|
|
|
<option value={comparisonType.value} key={comparisonType.value} > |
518
|
|
|
{t(comparisonType.label)} |
519
|
|
|
</option> |
520
|
|
|
))} |
521
|
|
|
</CustomInput> |
522
|
|
|
</FormGroup> |
523
|
|
|
</Col> |
524
|
|
|
<Col xs="auto"> |
525
|
|
|
<FormGroup> |
526
|
|
|
<Label className={labelClasses} for="periodType"> |
527
|
|
|
{t('Period Types')} |
528
|
|
|
</Label> |
529
|
|
|
<CustomInput type="select" id="periodType" name="periodType" defaultValue="daily" onChange={({ target }) => setPeriodType(target.value)} |
530
|
|
|
> |
531
|
|
|
{periodTypeOptions.map((periodType, index) => ( |
532
|
|
|
<option value={periodType.value} key={periodType.value} > |
533
|
|
|
{t(periodType.label)} |
534
|
|
|
</option> |
535
|
|
|
))} |
536
|
|
|
</CustomInput> |
537
|
|
|
</FormGroup> |
538
|
|
|
</Col> |
539
|
|
|
<Col xs="auto"> |
540
|
|
|
<FormGroup className="form-group"> |
541
|
|
|
<Label className={labelClasses} for="basePeriodBeginsDatetime"> |
542
|
|
|
{t('Base Period Begins')}{t('(Optional)')} |
543
|
|
|
</Label> |
544
|
|
|
<Datetime id='basePeriodBeginsDatetime' |
545
|
|
|
value={basePeriodBeginsDatetime} |
546
|
|
|
inputProps={{ disabled: basePeriodBeginsDatetimeDisabled }} |
547
|
|
|
onChange={onBasePeriodBeginsDatetimeChange} |
548
|
|
|
isValidDate={getValidBasePeriodBeginsDatetimes} |
549
|
|
|
closeOnSelect={true} /> |
550
|
|
|
</FormGroup> |
551
|
|
|
</Col> |
552
|
|
|
<Col xs="auto"> |
553
|
|
|
<FormGroup className="form-group"> |
554
|
|
|
<Label className={labelClasses} for="basePeriodEndsDatetime"> |
555
|
|
|
{t('Base Period Ends')}{t('(Optional)')} |
556
|
|
|
</Label> |
557
|
|
|
<Datetime id='basePeriodEndsDatetime' |
558
|
|
|
value={basePeriodEndsDatetime} |
559
|
|
|
inputProps={{ disabled: basePeriodEndsDatetimeDisabled }} |
560
|
|
|
onChange={onBasePeriodEndsDatetimeChange} |
561
|
|
|
isValidDate={getValidBasePeriodEndsDatetimes} |
562
|
|
|
closeOnSelect={true} /> |
563
|
|
|
</FormGroup> |
564
|
|
|
</Col> |
565
|
|
|
<Col xs="auto"> |
566
|
|
|
<FormGroup className="form-group"> |
567
|
|
|
<Label className={labelClasses} for="reportingPeriodBeginsDatetime"> |
568
|
|
|
{t('Reporting Period Begins')} |
569
|
|
|
</Label> |
570
|
|
|
<Datetime id='reportingPeriodBeginsDatetime' |
571
|
|
|
value={reportingPeriodBeginsDatetime} |
572
|
|
|
onChange={onReportingPeriodBeginsDatetimeChange} |
573
|
|
|
isValidDate={getValidReportingPeriodBeginsDatetimes} |
574
|
|
|
closeOnSelect={true} /> |
575
|
|
|
</FormGroup> |
576
|
|
|
</Col> |
577
|
|
|
<Col xs="auto"> |
578
|
|
|
<FormGroup className="form-group"> |
579
|
|
|
<Label className={labelClasses} for="reportingPeriodEndsDatetime"> |
580
|
|
|
{t('Reporting Period Ends')} |
581
|
|
|
</Label> |
582
|
|
|
<Datetime id='reportingPeriodEndsDatetime' |
583
|
|
|
value={reportingPeriodEndsDatetime} |
584
|
|
|
onChange={onReportingPeriodEndsDatetimeChange} |
585
|
|
|
isValidDate={getValidReportingPeriodEndsDatetimes} |
586
|
|
|
closeOnSelect={true} /> |
587
|
|
|
</FormGroup> |
588
|
|
|
</Col> |
589
|
|
|
<Col xs="auto"> |
590
|
|
|
<FormGroup> |
591
|
|
|
<br></br> |
592
|
|
|
<ButtonGroup id="submit"> |
593
|
|
|
<Button color="success" disabled={isDisabled} >{t('Submit')}</Button> |
594
|
|
|
</ButtonGroup> |
595
|
|
|
</FormGroup> |
596
|
|
|
</Col> |
597
|
|
|
</Row> |
598
|
|
|
</Form> |
599
|
|
|
</CardBody> |
600
|
|
|
</Card> |
601
|
|
|
<div className="card-deck"> |
602
|
|
|
<CardSummary rate="-0.23%" title={t('Reporting Period CATEGORY Maximum UNIT', { 'CATEGORY': '电', 'UNIT': '(kWh)' })} |
603
|
|
|
color="warning" footnote={t('Per Unit Production')} footvalue={863 / 1000} footunit="(kWh/PC)" > |
604
|
|
|
<CountUp end={863} duration={2} prefix="" separator="," decimals={2} decimal="." /> |
605
|
|
|
</CardSummary> |
606
|
|
|
<CardSummary rate="0.0%" title={t('Reporting Period CATEGORY Minimum UNIT', { 'CATEGORY': '电', 'UNIT': '(kWh)' })} |
607
|
|
|
color="success" footnote={t('Per Unit Production')} footvalue={278 / 1000} footunit="(kWh/PC)" > |
608
|
|
|
<CountUp end={278} duration={2} prefix="" separator="," decimals={2} decimal="." /> |
609
|
|
|
</CardSummary> |
610
|
|
|
<CardSummary rate="0.0%" title={t('Reporting Period CATEGORY Average UNIT', { 'CATEGORY': '电', 'UNIT': '(kWh)' })} |
611
|
|
|
color="info" footnote={t('Per Unit Production')} footvalue={587 / 1000} footunit="(kWh/PC)" > |
612
|
|
|
<CountUp end={587} duration={2} prefix="" separator="," decimals={2} decimal="." /> |
613
|
|
|
</CardSummary> |
614
|
|
|
</div> |
615
|
|
|
<div className="card-deck"> |
616
|
|
|
<CardSummary rate="-0.23%" title={t('Reporting Period CATEGORY Maximum UNIT', { 'CATEGORY': '自来水', 'UNIT': '(M3)' })} |
617
|
|
|
color="warning" footnote={t('Per Unit Production')} footvalue={863 / 1000} footunit="(M3/PC)" > |
618
|
|
|
<CountUp end={863} duration={2} prefix="" separator="," decimals={2} decimal="." /> |
619
|
|
|
</CardSummary> |
620
|
|
|
<CardSummary rate="0.0%" title={t('Reporting Period CATEGORY Minimum UNIT', { 'CATEGORY': '自来水', 'UNIT': '(M3)' })} |
621
|
|
|
color="success" footnote={t('Per Unit Production')} footvalue={278 / 1000} footunit="(M3/PC)" > |
622
|
|
|
<CountUp end={278} duration={2} prefix="" separator="," decimals={2} decimal="." /> |
623
|
|
|
</CardSummary> |
624
|
|
|
<CardSummary rate="0.0%" title={t('Reporting Period CATEGORY Average UNIT', { 'CATEGORY': '自来水', 'UNIT': '(M3)' })} |
625
|
|
|
color="info" footnote={t('Per Unit Production')} footvalue={587 / 1000} footunit="(M3/PC)" > |
626
|
|
|
<CountUp end={587} duration={2} prefix="" separator="," decimals={2} decimal="." /> |
627
|
|
|
</CardSummary> |
628
|
|
|
</div> |
629
|
|
|
<div className="card-deck"> |
630
|
|
|
<CardSummary rate="-0.23%" title={t('Reporting Period CATEGORY Maximum UNIT', { 'CATEGORY': '天然气', 'UNIT': '(M3)' })} |
631
|
|
|
color="warning" footnote={t('Per Unit Production')} footvalue={863 / 1000} footunit="(M3/PC)" > |
632
|
|
|
<CountUp end={863} duration={2} prefix="" separator="," decimals={2} decimal="." /> |
633
|
|
|
</CardSummary> |
634
|
|
|
<CardSummary rate="0.0%" title={t('Reporting Period CATEGORY Minimum UNIT', { 'CATEGORY': '天然气', 'UNIT': '(M3)' })} |
635
|
|
|
color="success" footnote={t('Per Unit Production')} footvalue={278 / 1000} footunit="(M3/PC)" > |
636
|
|
|
<CountUp end={278} duration={2} prefix="" separator="," decimals={2} decimal="." /> |
637
|
|
|
</CardSummary> |
638
|
|
|
<CardSummary rate="0.0%" title={t('Reporting Period CATEGORY Average UNIT', { 'CATEGORY': '天然气', 'UNIT': '(M3)' })} |
639
|
|
|
color="info" footnote={t('Per Unit Production')} footvalue={587 / 1000} footunit="(M3/PC)" > |
640
|
|
|
<CountUp end={587} duration={2} prefix="" separator="," decimals={2} decimal="." /> |
641
|
|
|
</CardSummary> |
642
|
|
|
</div> |
643
|
|
|
<LineChart reportingTitle={t('Reporting Period Consumption CATEGORY VALUE UNIT', { 'CATEGORY': '电', 'VALUE': 98720, 'UNIT': '(kWh)' })} |
644
|
|
|
baseTitle={t('Base Period Consumption CATEGORY VALUE UNIT', { 'CATEGORY': '电', 'VALUE': 68487, 'UNIT': '(kWh)' })} |
645
|
|
|
labels={shopfloorLineChartLabels} |
646
|
|
|
data={shopfloorLineChartData} |
647
|
|
|
options={shopfloorLineChartOptions}> |
648
|
|
|
</LineChart> |
649
|
|
|
|
650
|
|
|
<LineChart reportingTitle={t('Related Parameters')} |
651
|
|
|
baseTitle='' |
652
|
|
|
labels={parameterLineChartLabels} |
653
|
|
|
data={parameterLineChartData} |
654
|
|
|
options={parameterLineChartOptions}> |
655
|
|
|
</LineChart> |
656
|
|
|
<br /> |
657
|
|
|
<DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={50} > |
658
|
|
|
</DetailedDataTable> |
659
|
|
|
|
660
|
|
|
</Fragment> |
661
|
|
|
); |
662
|
|
|
}; |
663
|
|
|
|
664
|
|
|
export default withTranslation()(withRedirect(ShopfloorStatistics)); |
665
|
|
|
|