Passed
Push — master ( e3086e...7c86e8 )
by Guangyu
04:24
created

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

Complexity

Total Complexity 25
Complexity/F 0

Size

Lines of Code 663
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 25
eloc 588
mnd 25
bc 25
fnc 0
dl 0
loc 663
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 [TCO2EShareData, setTCO2EShareData] = useState([]);
76
77
  const [cardSummaryList, setCardSummaryList] = useState([]);
78
  const [totalInTCE, setTotalInTCE] = useState({});
79
  const [totalInTCO2E, setTotalInTCO2E] = useState({});
80
  const [combinedEquipmentLineChartLabels, setCombinedEquipmentLineChartLabels] = useState([]);
81
  const [combinedEquipmentLineChartData, setCombinedEquipmentLineChartData] = useState({});
82
  const [combinedEquipmentLineChartOptions, setCombinedEquipmentLineChartOptions] = useState([]);
83
84
  const [parameterLineChartLabels, setParameterLineChartLabels] = useState([]);
85
  const [parameterLineChartData, setParameterLineChartData] = useState({});
86
  const [parameterLineChartOptions, setParameterLineChartOptions] = useState([]);
87
88
  const [detailedDataTableData, setDetailedDataTableData] = useState([]);
89
  const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]);
90
91
  useEffect(() => {
92
    let isResponseOK = false;
93
    fetch(APIBaseURL + '/spaces/tree', {
94
      method: 'GET',
95
      headers: {
96
        "Content-type": "application/json",
97
        "User-UUID": getCookieValue('user_uuid'),
98
        "Token": getCookieValue('token')
99
      },
100
      body: null,
101
102
    }).then(response => {
103
      console.log(response)
104
      if (response.ok) {
105
        isResponseOK = true;
106
      }
107
      return response.json();
108
    }).then(json => {
109
      console.log(json)
110
      if (isResponseOK) {
111
        // rename keys 
112
        json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
113
        setCascaderOptions(json);
114
        setSelectedSpaceName([json[0]].map(o => o.label));
115
        setSelectedSpaceID([json[0]].map(o => o.value));
116
        // get Combined Equipments by root Space ID
117
        let isResponseOK = false;
118
        fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/combinedequipments', {
119
          method: 'GET',
120
          headers: {
121
            "Content-type": "application/json",
122
            "User-UUID": getCookieValue('user_uuid'),
123
            "Token": getCookieValue('token')
124
          },
125
          body: null,
126
127
        }).then(response => {
128
          if (response.ok) {
129
            isResponseOK = true;
130
          }
131
          return response.json();
132
        }).then(json => {
133
          if (isResponseOK) {
134
            json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
135
            console.log(json);
136
            setCombinedEquipmentList(json[0]);
137
            if (json[0].length > 0) {
138
              setSelectedCombinedEquipment(json[0][0].value);
139
              setIsDisabled(false);
140
            } else {
141
              setSelectedCombinedEquipment(undefined);
142
              setIsDisabled(true);
143
            }
144
          } else {
145
            toast.error(json.description)
146
          }
147
        }).catch(err => {
148
          console.log(err);
149
        });
150
        // end of get Combined Equipments by root Space ID
151
      } else {
152
        toast.error(json.description)
153
      }
154
    }).catch(err => {
155
      console.log(err);
156
    });
157
158
  }, []);
159
160
  const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0';
161
162
  let onSpaceCascaderChange = (value, selectedOptions) => {
163
    setSelectedSpaceName(selectedOptions.map(o => o.label).join('/'));
164
    setSelectedSpaceID(value[value.length - 1]);
165
166
    let isResponseOK = false;
167
    fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/combinedequipments', {
168
      method: 'GET',
169
      headers: {
170
        "Content-type": "application/json",
171
        "User-UUID": getCookieValue('user_uuid'),
172
        "Token": getCookieValue('token')
173
      },
174
      body: null,
175
176
    }).then(response => {
177
      if (response.ok) {
178
        isResponseOK = true;
179
      }
180
      return response.json();
181
    }).then(json => {
182
      if (isResponseOK) {
183
        json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
184
        console.log(json)
185
        setCombinedEquipmentList(json[0]);
186
        if (json[0].length > 0) {
187
          setSelectedCombinedEquipment(json[0][0].value);
188
          setIsDisabled(false);
189
        } else {
190
          setSelectedCombinedEquipment(undefined);
191
          setIsDisabled(true);
192
        }
193
      } else {
194
        toast.error(json.description)
195
      }
196
    }).catch(err => {
197
      console.log(err);
198
    });
199
  }
200
201
202
  let onComparisonTypeChange = ({ target }) => {
203
    console.log(target.value);
204
    setComparisonType(target.value);
205
    if (target.value === 'year-over-year') {
206
      setBasePeriodBeginsDatetimeDisabled(true);
207
      setBasePeriodEndsDatetimeDisabled(true);
208
      setBasePeriodBeginsDatetime(moment(reportingPeriodBeginsDatetime).subtract(1, 'years'));
209
      setBasePeriodEndsDatetime(moment(reportingPeriodEndsDatetime).subtract(1, 'years'));
210
    } else if (target.value === 'month-on-month') {
211
      setBasePeriodBeginsDatetimeDisabled(true);
212
      setBasePeriodEndsDatetimeDisabled(true);
213
      setBasePeriodBeginsDatetime(moment(reportingPeriodBeginsDatetime).subtract(1, 'months'));
214
      setBasePeriodEndsDatetime(moment(reportingPeriodEndsDatetime).subtract(1, 'months'));
215
    } else if (target.value === 'free-comparison') {
216
      setBasePeriodBeginsDatetimeDisabled(false);
217
      setBasePeriodEndsDatetimeDisabled(false);
218
    } else if (target.value === 'none-comparison') {
219
      setBasePeriodBeginsDatetime(undefined);
220
      setBasePeriodEndsDatetime(undefined);
221
      setBasePeriodBeginsDatetimeDisabled(true);
222
      setBasePeriodEndsDatetimeDisabled(true);
223
    }
224
  }
225
226
  let onBasePeriodBeginsDatetimeChange = (newDateTime) => {
227
    setBasePeriodBeginsDatetime(newDateTime);
228
  }
229
230
  let onBasePeriodEndsDatetimeChange = (newDateTime) => {
231
    setBasePeriodEndsDatetime(newDateTime);
232
  }
233
234
  let onReportingPeriodBeginsDatetimeChange = (newDateTime) => {
235
    setReportingPeriodBeginsDatetime(newDateTime);
236
    if (comparisonType === 'year-over-year') {
237
      setBasePeriodBeginsDatetime(newDateTime.clone().subtract(1, 'years'));
238
    } else if (comparisonType === 'month-on-month') {
239
      setBasePeriodBeginsDatetime(newDateTime.clone().subtract(1, 'months'));
240
    }
241
  }
242
243
  let onReportingPeriodEndsDatetimeChange = (newDateTime) => {
244
    setReportingPeriodEndsDatetime(newDateTime);
245
    if (comparisonType === 'year-over-year') {
246
      setBasePeriodEndsDatetime(newDateTime.clone().subtract(1, 'years'));
247
    } else if (comparisonType === 'month-on-month') {
248
      setBasePeriodEndsDatetime(newDateTime.clone().subtract(1, 'months'));
249
    }
250
  }
251
252
  var getValidBasePeriodBeginsDatetimes = function (currentDate) {
253
    return currentDate.isBefore(moment(basePeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
254
  }
255
256
  var getValidBasePeriodEndsDatetimes = function (currentDate) {
257
    return currentDate.isAfter(moment(basePeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
258
  }
259
260
  var getValidReportingPeriodBeginsDatetimes = function (currentDate) {
261
    return currentDate.isBefore(moment(reportingPeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
262
  }
263
264
  var getValidReportingPeriodEndsDatetimes = function (currentDate) {
265
    return currentDate.isAfter(moment(reportingPeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
266
  }
267
268
  // Handler
269
  const handleSubmit = e => {
270
    e.preventDefault();
271
    console.log('handleSubmit');
272
    console.log(selectedSpaceID);
273
    console.log(selectedCombinedEquipment);
274
    console.log(periodType);
275
    console.log(basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined);
276
    console.log(basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined);
277
    console.log(reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss'));
278
    console.log(reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'));
279
280
    // Reinitialize tables
281
    setDetailedDataTableData([]);
282
    
283
    let isResponseOK = false;
284
    fetch(APIBaseURL + '/reports/combinedequipmentenergycategory?' +
285
      'combinedequipmentid=' + selectedCombinedEquipment +
286
      '&periodtype=' + periodType +
287
      '&baseperiodstartdatetime=' + (basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') +
288
      '&baseperiodenddatetime=' + (basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') +
289
      '&reportingperiodstartdatetime=' + reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') +
290
      '&reportingperiodenddatetime=' + reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'), {
291
      method: 'GET',
292
      headers: {
293
        "Content-type": "application/json",
294
        "User-UUID": getCookieValue('user_uuid'),
295
        "Token": getCookieValue('token')
296
      },
297
      body: null,
298
299
    }).then(response => {
300
      if (response.ok) {
301
        isResponseOK = true;
302
      }
303
      return response.json();
304
    }).then(json => {
305
      if (isResponseOK) {
306
        console.log(json)
307
              
308
        let cardSummaryArray = []
309
        json['reporting_period']['names'].forEach((currentValue, index) => {
310
          let cardSummaryItem = {}
311
          cardSummaryItem['name'] = json['reporting_period']['names'][index];
312
          cardSummaryItem['unit'] = json['reporting_period']['units'][index];
313
          cardSummaryItem['subtotal'] = json['reporting_period']['subtotals'][index];
314
          cardSummaryItem['increment_rate'] = parseFloat(json['reporting_period']['increment_rates'][index] * 100).toFixed(2) + "%";
315
          cardSummaryArray.push(cardSummaryItem);
316
        });
317
        setCardSummaryList(cardSummaryArray);
318
        
319
        let timeOfUseArray = [];
320
        json['reporting_period']['energy_category_ids'].forEach((currentValue, index) => {
321
          if(currentValue == 1) {
322
            // energy_category_id 1 electricity
323
            let timeOfUseItem = {}
324
            timeOfUseItem['id'] = 1;
325
            timeOfUseItem['name'] =  t('Top-Peak');
326
            timeOfUseItem['value'] = json['reporting_period']['toppeaks'][index];
327
            timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16);
328
            timeOfUseArray.push(timeOfUseItem);
329
            
330
            timeOfUseItem = {}
331
            timeOfUseItem['id'] = 2;
332
            timeOfUseItem['name'] =  t('On-Peak');
333
            timeOfUseItem['value'] = json['reporting_period']['onpeaks'][index];
334
            timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16);
335
            timeOfUseArray.push(timeOfUseItem);
336
337
            timeOfUseItem = {}
338
            timeOfUseItem['id'] = 3;
339
            timeOfUseItem['name'] =  t('Mid-Peak');
340
            timeOfUseItem['value'] = json['reporting_period']['midpeaks'][index];
341
            timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16);
342
            timeOfUseArray.push(timeOfUseItem);
343
344
            timeOfUseItem = {}
345
            timeOfUseItem['id'] = 4;
346
            timeOfUseItem['name'] =  t('Off-Peak');
347
            timeOfUseItem['value'] = json['reporting_period']['offpeaks'][index];
348
            timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16);
349
            timeOfUseArray.push(timeOfUseItem);
350
          }
351
        });
352
        setTimeOfUseShareData(timeOfUseArray);
353
354
        
355
        let totalInTCE = {}; 
356
        totalInTCE['value'] = json['reporting_period']['total_in_kgce'] / 1000; // convert from kg to t
357
        totalInTCE['increment_rate'] = parseFloat(json['reporting_period']['increment_rate_in_kgce'] * 100).toFixed(2) + "%";
358
        setTotalInTCE(totalInTCE);
359
360
        let totalInTCO2E = {}; 
361
        totalInTCO2E['value'] = json['reporting_period']['total_in_kgco2e'] / 1000; // convert from kg to t
362
        totalInTCO2E['increment_rate'] = parseFloat(json['reporting_period']['increment_rate_in_kgco2e'] * 100).toFixed(2) + "%";
363
        setTotalInTCO2E(totalInTCO2E);
364
365
        let TCEDataArray = [];
366
        json['reporting_period']['names'].forEach((currentValue, index) => {
367
          let TCEDataItem = {}
368
          TCEDataItem['id'] = index;
369
          TCEDataItem['name'] = currentValue;
370
          TCEDataItem['value'] = json['reporting_period']['subtotals_in_kgce'][index] / 1000; // convert from kg to t
371
          TCEDataItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16);
372
          TCEDataArray.push(TCEDataItem);
373
        });
374
        setTCEShareData(TCEDataArray);
375
376
        let TCO2EDataArray = [];
377
        json['reporting_period']['names'].forEach((currentValue, index) => {
378
          let TCO2EDataItem = {}
379
          TCO2EDataItem['id'] = index;
380
          TCO2EDataItem['name'] = currentValue;
381
          TCO2EDataItem['value'] = json['reporting_period']['subtotals_in_kgco2e'][index] / 1000; // convert from kg to t
382
          TCO2EDataItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16);
383
          TCO2EDataArray.push(TCO2EDataItem);
384
        });
385
        setTCO2EShareData(TCO2EDataArray);
386
387
        let timestamps = {}
388
        json['reporting_period']['timestamps'].forEach((currentValue, index) => {
389
          timestamps['a' + index] = currentValue;
390
        });
391
        setCombinedEquipmentLineChartLabels(timestamps);
392
        
393
        let values = {}
394
        json['reporting_period']['values'].forEach((currentValue, index) => {
395
          values['a' + index] = currentValue;
396
        });
397
        setCombinedEquipmentLineChartData(values);
398
        
399
        let names = Array();
400
        json['reporting_period']['names'].forEach((currentValue, index) => {
401
          let unit = json['reporting_period']['units'][index];
402
          names.push({ 'value': 'a' + index, 'label': currentValue + ' (' + unit + ')'});
403
        });
404
        setCombinedEquipmentLineChartOptions(names);
405
       
406
        timestamps = {}
407
        json['parameters']['timestamps'].forEach((currentValue, index) => {
408
          timestamps['a' + index] = currentValue;
409
        });
410
        setParameterLineChartLabels(timestamps);
411
412
        values = {}
413
        json['parameters']['values'].forEach((currentValue, index) => {
414
          values['a' + index] = currentValue;
415
        });
416
        setParameterLineChartData(values);
417
      
418
        names = Array();
419
        json['parameters']['names'].forEach((currentValue, index) => {
420
          if (currentValue.startsWith('TARIFF-')) {
421
            currentValue = t('Tariff') + currentValue.replace('TARIFF-', '-');
422
          }
423
          
424
          names.push({ 'value': 'a' + index, 'label': currentValue });
425
        });
426
        setParameterLineChartOptions(names);
427
        
428
        let detailed_value_list = [];
429
        json['reporting_period']['timestamps'][0].forEach((currentTimestamp, timestampIndex) => {
430
          let detailed_value = {};
431
          detailed_value['id'] = timestampIndex;
432
          detailed_value['startdatetime'] = currentTimestamp;
433
          json['reporting_period']['values'].forEach((currentValue, energyCategoryIndex) => {
434
            detailed_value['a' + energyCategoryIndex] = json['reporting_period']['values'][energyCategoryIndex][timestampIndex].toFixed(2);
435
          });
436
          detailed_value_list.push(detailed_value);
437
        });
438
439
        let detailed_value = {};
440
        detailed_value['id'] = detailed_value_list.length;
441
        detailed_value['startdatetime'] = t('Subtotal');
442
        json['reporting_period']['subtotals'].forEach((currentValue, index) => {
443
            detailed_value['a' + index] = currentValue.toFixed(2);
444
          });
445
        detailed_value_list.push(detailed_value);
446
        setDetailedDataTableData(detailed_value_list);
447
        
448
        let detailed_column_list = [];
449
        detailed_column_list.push({
450
          dataField: 'startdatetime',
451
          text: t('Datetime'),
452
          sort: true
453
        })
454
        json['reporting_period']['names'].forEach((currentValue, index) => {
455
          let unit = json['reporting_period']['units'][index];
456
          detailed_column_list.push({
457
            dataField: 'a' + index,
458
            text: currentValue + ' (' + unit + ')',
459
            sort: true
460
          })
461
        });
462
        setDetailedDataTableColumns(detailed_column_list);
463
      } else {
464
        toast.error(json.description)
465
      }
466
    }).catch(err => {
467
      console.log(err);
468
    });
469
  };
470
471
472
  return (
473
    <Fragment>
474
      <div>
475
        <Breadcrumb>
476
          <BreadcrumbItem>{t('Combined Equipment Data')}</BreadcrumbItem><BreadcrumbItem active>{t('Energy Category Data')}</BreadcrumbItem>
477
        </Breadcrumb>
478
      </div>
479
      <Card className="bg-light mb-3">
480
        <CardBody className="p-3">
481
          <Form onSubmit={handleSubmit}>
482
            <Row form>
483
              <Col xs="auto">
484
                <FormGroup className="form-group">
485
                  <Label className={labelClasses} for="space">
486
                    {t('Space')}
487
                  </Label>
488
                  <br />
489
                  <Cascader options={cascaderOptions}
490
                    onChange={onSpaceCascaderChange}
491
                    changeOnSelect
492
                    expandTrigger="hover">
493
                    <Input value={selectedSpaceName || ''} readOnly />
494
                  </Cascader>
495
                </FormGroup>
496
              </Col>
497
              <Col xs="auto">
498
                <FormGroup>
499
                  <Label className={labelClasses} for="combinedEquipmentSelect">
500
                    {t('Combined Equipment')}
501
                  </Label>
502
                  <CustomInput type="select" id="combinedEquipmentSelect" name="combinedEquipmentSelect" onChange={({ target }) => setSelectedCombinedEquipment(target.value)}
503
                  >
504
                    {combinedEquipmentList.map((combinedEquipment, index) => (
505
                      <option value={combinedEquipment.value} key={combinedEquipment.value}>
506
                        {combinedEquipment.label}
507
                      </option>
508
                    ))}
509
                  </CustomInput>
510
                </FormGroup>
511
              </Col>
512
              <Col xs="auto">
513
                <FormGroup>
514
                  <Label className={labelClasses} for="comparisonType">
515
                    {t('Comparison Types')}
516
                  </Label>
517
                  <CustomInput type="select" id="comparisonType" name="comparisonType"
518
                    defaultValue="month-on-month"
519
                    onChange={onComparisonTypeChange}
520
                  >
521
                    {comparisonTypeOptions.map((comparisonType, index) => (
522
                      <option value={comparisonType.value} key={comparisonType.value} >
523
                        {t(comparisonType.label)}
524
                      </option>
525
                    ))}
526
                  </CustomInput>
527
                </FormGroup>
528
              </Col>
529
              <Col xs="auto">
530
                <FormGroup>
531
                  <Label className={labelClasses} for="periodType">
532
                    {t('Period Types')}
533
                  </Label>
534
                  <CustomInput type="select" id="periodType" name="periodType" defaultValue="daily" onChange={({ target }) => setPeriodType(target.value)}
535
                  >
536
                    {periodTypeOptions.map((periodType, index) => (
537
                      <option value={periodType.value} key={periodType.value} >
538
                        {t(periodType.label)}
539
                      </option>
540
                    ))}
541
                  </CustomInput>
542
                </FormGroup>
543
              </Col>
544
              <Col xs="auto">
545
                <FormGroup className="form-group">
546
                  <Label className={labelClasses} for="basePeriodBeginsDatetime">
547
                    {t('Base Period Begins')}{t('(Optional)')}
548
                  </Label>
549
                  <Datetime id='basePeriodBeginsDatetime'
550
                    value={basePeriodBeginsDatetime}
551
                    inputProps={{ disabled: basePeriodBeginsDatetimeDisabled }}
552
                    onChange={onBasePeriodBeginsDatetimeChange}
553
                    isValidDate={getValidBasePeriodBeginsDatetimes}
554
                    closeOnSelect={true} />
555
                </FormGroup>
556
              </Col>
557
              <Col xs="auto">
558
                <FormGroup className="form-group">
559
                  <Label className={labelClasses} for="basePeriodEndsDatetime">
560
                    {t('Base Period Ends')}{t('(Optional)')}
561
                  </Label>
562
                  <Datetime id='basePeriodEndsDatetime'
563
                    value={basePeriodEndsDatetime}
564
                    inputProps={{ disabled: basePeriodEndsDatetimeDisabled }}
565
                    onChange={onBasePeriodEndsDatetimeChange}
566
                    isValidDate={getValidBasePeriodEndsDatetimes}
567
                    closeOnSelect={true} />
568
                </FormGroup>
569
              </Col>
570
              <Col xs="auto">
571
                <FormGroup className="form-group">
572
                  <Label className={labelClasses} for="reportingPeriodBeginsDatetime">
573
                    {t('Reporting Period Begins')}
574
                  </Label>
575
                  <Datetime id='reportingPeriodBeginsDatetime'
576
                    value={reportingPeriodBeginsDatetime}
577
                    onChange={onReportingPeriodBeginsDatetimeChange}
578
                    isValidDate={getValidReportingPeriodBeginsDatetimes}
579
                    closeOnSelect={true} />
580
                </FormGroup>
581
              </Col>
582
              <Col xs="auto">
583
                <FormGroup className="form-group">
584
                  <Label className={labelClasses} for="reportingPeriodEndsDatetime">
585
                    {t('Reporting Period Ends')}
586
                  </Label>
587
                  <Datetime id='reportingPeriodEndsDatetime'
588
                    value={reportingPeriodEndsDatetime}
589
                    onChange={onReportingPeriodEndsDatetimeChange}
590
                    isValidDate={getValidReportingPeriodEndsDatetimes}
591
                    closeOnSelect={true} />
592
                </FormGroup>
593
              </Col>
594
              <Col xs="auto">
595
                <FormGroup>
596
                  <br></br>
597
                  <ButtonGroup id="submit">
598
                    <Button color="success" disabled={isDisabled} >{t('Submit')}</Button>
599
                  </ButtonGroup>
600
                </FormGroup>
601
              </Col>
602
            </Row>
603
          </Form>
604
        </CardBody>
605
      </Card>
606
      <div className="card-deck">
607
        {cardSummaryList.map(cardSummaryItem => (
608
          <CardSummary key={cardSummaryItem['name']}
609
            rate={cardSummaryItem['increment_rate']}
610
            title={t('Reporting Period Consumption CATEGORY UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })}
611
            color="success" >
612
            {cardSummaryItem['subtotal'] && <CountUp end={cardSummaryItem['subtotal']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
613
          </CardSummary>
614
        ))}
615
       
616
        <CardSummary 
617
          rate={totalInTCE['increment_rate'] || ''} 
618
          title={t('Reporting Period Consumption CATEGORY UNIT', { 'CATEGORY': t('Ton of Standard Coal'), 'UNIT': '(TCE)' })}
619
          color="warning" >
620
          {totalInTCE['value'] && <CountUp end={totalInTCE['value']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
621
        </CardSummary>
622
        <CardSummary 
623
          rate={totalInTCO2E['increment_rate'] || ''} 
624
          title={t('Reporting Period Consumption CATEGORY UNIT', { 'CATEGORY': t('Ton of Carbon Dioxide Emissions'), 'UNIT': '(TCO2E)' })}
625
          color="warning" >
626
          {totalInTCO2E['value'] && <CountUp end={totalInTCO2E['value']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
627
        </CardSummary>
628
      </div>
629
630
      <Row noGutters>
631
        <Col className="mb-3 pr-lg-2 mb-3">
632
          <SharePie data={timeOfUseShareData} title={t('Electricity Consumption by Time-Of-Use')} />
633
        </Col>
634
        <Col className="mb-3 pr-lg-2 mb-3">
635
          <SharePie data={TCEShareData} title={t('Ton of Standard Coal by Energy Category')} />
636
        </Col>
637
        <Col className="mb-3 pr-lg-2 mb-3">
638
          <SharePie data={TCO2EShareData} title={t('Carbon Dioxide Emissions by Energy Category')} />
639
        </Col>
640
      </Row>
641
      <LineChart reportingTitle={t('Reporting Period Consumption CATEGORY VALUE UNIT', { 'CATEGORY': null, 'VALUE': null, 'UNIT': null })}
642
        baseTitle=''
643
        labels={combinedEquipmentLineChartLabels}
644
        data={combinedEquipmentLineChartData}
645
        options={combinedEquipmentLineChartOptions}>
646
      </LineChart>
647
648
      <LineChart reportingTitle={t('Related Parameters')}
649
        baseTitle=''
650
        labels={parameterLineChartLabels}
651
        data={parameterLineChartData}
652
        options={parameterLineChartOptions}>
653
      </LineChart>
654
      <br />
655
      <DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={50} >
656
      </DetailedDataTable>
657
658
    </Fragment>
659
  );
660
};
661
662
export default withTranslation()(withRedirect(CombinedEquipmentEnergyCategory));
663