Passed
Push — master ( 1f92a8...ce137d )
by Guangyu
04:45 queued 10s
created

src/components/MyEMS/CombinedEquipment/CombinedEquipmentEnergyCategory.js   A

Complexity

Total Complexity 23
Complexity/F 0

Size

Lines of Code 676
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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