Passed
Push — master ( c23847...6dac30 )
by Guangyu
04:22 queued 10s
created

src/components/MyEMS/Equipment/EquipmentSaving.js   A

Complexity

Total Complexity 24
Complexity/F 0

Size

Lines of Code 625
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 24
eloc 551
mnd 24
bc 24
fnc 0
dl 0
loc 625
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 { toast } from 'react-toastify';
29
import { APIBaseURL } from '../../../config';
30
import { periodTypeOptions } from '../common/PeriodTypeOptions';
31
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
32
33
34
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
35
36
const EquipmentSaving = ({ 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 [equipmentList, setEquipmentList] = useState([]);
61
  const [selectedEquipment, setSelectedEquipment] = 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 [TCEShareData, setTCEShareData] = useState([]);
74
  const [TCO2EShareData, setTCO2EShareData] = useState([]);
75
  
76
  const [cardSummaryList, setCardSummaryList] = useState([]);
77
  const [totalInTCE, setTotalInTCE] = useState({});
78
  const [totalInTCO2E, setTotalInTCO2E] = useState({});
79
  const [equipmentLineChartLabels, setEquipmentLineChartLabels] = useState([]);
80
  const [equipmentLineChartData, setEquipmentLineChartData] = useState({});
81
  const [equipmentLineChartOptions, setEquipmentLineChartOptions] = useState([]);
82
83
  const [parameterLineChartLabels, setParameterLineChartLabels] = useState([]);
84
  const [parameterLineChartData, setParameterLineChartData] = useState({});
85
  const [parameterLineChartOptions, setParameterLineChartOptions] = useState([]);
86
87
  const [detailedDataTableData, setDetailedDataTableData] = useState([]);
88
  const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]);
89
90
  useEffect(() => {
91
    let isResponseOK = false;
92
    fetch(APIBaseURL + '/spaces/tree', {
93
      method: 'GET',
94
      headers: {
95
        "Content-type": "application/json",
96
        "User-UUID": getCookieValue('user_uuid'),
97
        "Token": getCookieValue('token')
98
      },
99
      body: null,
100
101
    }).then(response => {
102
      console.log(response);
103
      if (response.ok) {
104
        isResponseOK = true;
105
      }
106
      return response.json();
107
    }).then(json => {
108
      console.log(json);
109
      if (isResponseOK) {
110
        // rename keys 
111
        json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
112
        setCascaderOptions(json);
113
        setSelectedSpaceName([json[0]].map(o => o.label));
114
        setSelectedSpaceID([json[0]].map(o => o.value));
115
        // get Equipments by root Space ID
116
        let isResponseOK = false;
117
        fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/equipments', {
118
          method: 'GET',
119
          headers: {
120
            "Content-type": "application/json",
121
            "User-UUID": getCookieValue('user_uuid'),
122
            "Token": getCookieValue('token')
123
          },
124
          body: null,
125
126
        }).then(response => {
127
          if (response.ok) {
128
            isResponseOK = true;
129
          }
130
          return response.json();
131
        }).then(json => {
132
          if (isResponseOK) {
133
            json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
134
            console.log(json);
135
            setEquipmentList(json[0]);
136
            if (json[0].length > 0) {
137
              setSelectedEquipment(json[0][0].value);
138
              setIsDisabled(false);
139
            } else {
140
              setSelectedEquipment(undefined);
141
              setIsDisabled(true);
142
            }
143
          } else {
144
            toast.error(json.description)
145
          }
146
        }).catch(err => {
147
          console.log(err);
148
        });
149
        // end of get Equipments by root Space ID
150
      } else {
151
        toast.error(json.description);
152
      }
153
    }).catch(err => {
154
      console.log(err);
155
    });
156
157
  }, []);
158
  
159
  const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0';
160
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] + '/equipments', {
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
        setEquipmentList(json[0]);
186
        if (json[0].length > 0) {
187
          setSelectedEquipment(json[0][0].value);
188
          setIsDisabled(false);
189
        } else {
190
          setSelectedEquipment(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(selectedEquipment);
274
    console.log(comparisonType);
275
    console.log(periodType);
276
    console.log(basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined);
277
    console.log(basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined);
278
    console.log(reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss'));
279
    console.log(reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'));
280
281
    // Reinitialize tables
282
    setDetailedDataTableData([]);
283
    
284
    let isResponseOK = false;
285
    fetch(APIBaseURL + '/reports/equipmentsaving?' +
286
      'equipmentid=' + selectedEquipment +
287
      '&periodtype=' + periodType +
288
      '&baseperiodstartdatetime=' + (basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') +
289
      '&baseperiodenddatetime=' + (basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') +
290
      '&reportingperiodstartdatetime=' + reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') +
291
      '&reportingperiodenddatetime=' + reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'), {
292
      method: 'GET',
293
      headers: {
294
        "Content-type": "application/json",
295
        "User-UUID": getCookieValue('user_uuid'),
296
        "Token": getCookieValue('token')
297
      },
298
      body: null,
299
300
    }).then(response => {
301
      if (response.ok) {
302
        isResponseOK = true;
303
      }
304
      return response.json();
305
    }).then(json => {
306
      if (isResponseOK) {
307
        console.log(json)
308
        
309
        let cardSummaryArray = []
310
        json['reporting_period']['names'].forEach((currentValue, index) => {
311
          let cardSummaryItem = {}
312
          cardSummaryItem['name'] = json['reporting_period']['names'][index];
313
          cardSummaryItem['unit'] = json['reporting_period']['units'][index];
314
          cardSummaryItem['subtotal'] = json['reporting_period']['subtotals_saving'][index];
315
          cardSummaryItem['increment_rate'] = parseFloat(json['reporting_period']['increment_rates_saving'][index] * 100).toFixed(2) + "%";
316
          cardSummaryArray.push(cardSummaryItem);
317
        });
318
        setCardSummaryList(cardSummaryArray);
319
320
        let totalInTCE = {}; 
321
        totalInTCE['value'] = json['reporting_period']['total_in_kgce_saving'] / 1000; // convert from kg to t
322
        totalInTCE['increment_rate'] = parseFloat(json['reporting_period']['increment_rate_in_kgce_saving'] * 100).toFixed(2) + "%";
323
        setTotalInTCE(totalInTCE);
324
325
        let totalInTCO2E = {}; 
326
        totalInTCO2E['value'] = json['reporting_period']['total_in_kgco2e_saving'] / 1000; // convert from kg to t
327
        totalInTCO2E['increment_rate'] = parseFloat(json['reporting_period']['increment_rate_in_kgco2e_saving'] * 100).toFixed(2) + "%";
328
        setTotalInTCO2E(totalInTCO2E);
329
330
        let TCEDataArray = [];
331
        json['reporting_period']['names'].forEach((currentValue, index) => {
332
          let TCEDataItem = {}
333
          TCEDataItem['id'] = index;
334
          TCEDataItem['name'] = currentValue;
335
          TCEDataItem['value'] = json['reporting_period']['subtotals_in_kgce_saving'][index] / 1000; // convert from kg to t
336
          TCEDataItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16);
337
          TCEDataArray.push(TCEDataItem);
338
        });
339
        setTCEShareData(TCEDataArray);
340
341
        let TCO2EDataArray = [];
342
        json['reporting_period']['names'].forEach((currentValue, index) => {
343
          let TCO2EDataItem = {}
344
          TCO2EDataItem['id'] = index;
345
          TCO2EDataItem['name'] = currentValue;
346
          TCO2EDataItem['value'] = json['reporting_period']['subtotals_in_kgco2e_saving'][index] / 1000; // convert from kg to t
347
          TCO2EDataItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16);
348
          TCO2EDataArray.push(TCO2EDataItem);
349
        });
350
        setTCO2EShareData(TCO2EDataArray);
351
352
        let timestamps = {}
353
        json['reporting_period']['timestamps'].forEach((currentValue, index) => {
354
          timestamps['a' + index] = currentValue;
355
        });
356
        setEquipmentLineChartLabels(timestamps);
357
        
358
        let values = {}
359
        json['reporting_period']['values_saving'].forEach((currentValue, index) => {
360
          values['a' + index] = currentValue;
361
        });
362
        setEquipmentLineChartData(values);
363
        
364
        let names = Array();
365
        json['reporting_period']['names'].forEach((currentValue, index) => {
366
          let unit = json['reporting_period']['units'][index];
367
          names.push({ 'value': 'a' + index, 'label': currentValue + ' (' + unit + ')'});
368
        });
369
        setEquipmentLineChartOptions(names);
370
       
371
        timestamps = {}
372
        json['parameters']['timestamps'].forEach((currentValue, index) => {
373
          timestamps['a' + index] = currentValue;
374
        });
375
        setParameterLineChartLabels(timestamps);
376
377
        values = {}
378
        json['parameters']['values'].forEach((currentValue, index) => {
379
          values['a' + index] = currentValue;
380
        });
381
        setParameterLineChartData(values);
382
      
383
        names = Array();
384
        json['parameters']['names'].forEach((currentValue, index) => {
385
          if (currentValue.startsWith('TARIFF-')) {
386
            currentValue = t('Tariff') + currentValue.replace('TARIFF-', '-');
387
          }
388
          
389
          names.push({ 'value': 'a' + index, 'label': currentValue });
390
        });
391
        setParameterLineChartOptions(names);
392
        
393
        let detailed_value_list = [];
394
        json['reporting_period']['timestamps'][0].forEach((currentTimestamp, timestampIndex) => {
395
          let detailed_value = {};
396
          detailed_value['id'] = timestampIndex;
397
          detailed_value['startdatetime'] = currentTimestamp;
398
          json['reporting_period']['values_saving'].forEach((currentValue, energyCategoryIndex) => {
399
            detailed_value['a' + energyCategoryIndex] = json['reporting_period']['values_saving'][energyCategoryIndex][timestampIndex].toFixed(2);
400
          });
401
          detailed_value_list.push(detailed_value);
402
        });
403
404
        let detailed_value = {};
405
        detailed_value['id'] = detailed_value_list.length;
406
        detailed_value['startdatetime'] = t('Subtotal');
407
        json['reporting_period']['subtotals_saving'].forEach((currentValue, index) => {
408
            detailed_value['a' + index] = currentValue.toFixed(2);
409
          });
410
        detailed_value_list.push(detailed_value);
411
        setDetailedDataTableData(detailed_value_list);
412
        
413
        let detailed_column_list = [];
414
        detailed_column_list.push({
415
          dataField: 'startdatetime',
416
          text: t('Datetime'),
417
          sort: true
418
        });
419
        json['reporting_period']['names'].forEach((currentValue, index) => {
420
          let unit = json['reporting_period']['units'][index];
421
          detailed_column_list.push({
422
            dataField: 'a' + index,
423
            text: currentValue + ' (' + unit + ')',
424
            sort: true
425
          });
426
        });
427
        setDetailedDataTableColumns(detailed_column_list);
428
      
429
      } else {
430
        toast.error(json.description)
431
      }
432
    }).catch(err => {
433
      console.log(err);
434
    });
435
  };
436
437
438
  return (
439
    <Fragment>
440
      <div>
441
        <Breadcrumb>
442
          <BreadcrumbItem>{t('Equipment Data')}</BreadcrumbItem><BreadcrumbItem active>{t('Saving')}</BreadcrumbItem>
443
        </Breadcrumb>
444
      </div>
445
      <Card className="bg-light mb-3">
446
        <CardBody className="p-3">
447
          <Form onSubmit={handleSubmit}>
448
            <Row form>
449
              <Col xs="auto">
450
                <FormGroup className="form-group">
451
                  <Label className={labelClasses} for="space">
452
                    {t('Space')}
453
                  </Label>
454
                  <br />
455
                  <Cascader options={cascaderOptions}
456
                    onChange={onSpaceCascaderChange}
457
                    changeOnSelect
458
                    expandTrigger="hover">
459
                    <Input value={selectedSpaceName || ''} readOnly />
460
                  </Cascader>
461
                </FormGroup>
462
              </Col>
463
              <Col xs="auto">
464
                <FormGroup>
465
                  <Label className={labelClasses} for="equipmentSelect">
466
                    {t('Equipment')}
467
                  </Label>
468
                  <CustomInput type="select" id="equipmentSelect" name="equipmentSelect" onChange={({ target }) => setSelectedEquipment(target.value)}
469
                  >
470
                    {equipmentList.map((equipment, index) => (
471
                      <option value={equipment.value} key={equipment.value}>
472
                        {equipment.label}
473
                      </option>
474
                    ))}
475
                  </CustomInput>
476
                </FormGroup>
477
              </Col>
478
              <Col xs="auto">
479
                <FormGroup>
480
                  <Label className={labelClasses} for="comparisonType">
481
                    {t('Comparison Types')}
482
                  </Label>
483
                  <CustomInput type="select" id="comparisonType" name="comparisonType"
484
                    defaultValue="month-on-month"
485
                    onChange={onComparisonTypeChange}
486
                  >
487
                    {comparisonTypeOptions.map((comparisonType, index) => (
488
                      <option value={comparisonType.value} key={comparisonType.value} >
489
                        {t(comparisonType.label)}
490
                      </option>
491
                    ))}
492
                  </CustomInput>
493
                </FormGroup>
494
              </Col>
495
              <Col xs="auto">
496
                <FormGroup>
497
                  <Label className={labelClasses} for="periodType">
498
                    {t('Period Types')}
499
                  </Label>
500
                  <CustomInput type="select" id="periodType" name="periodType" defaultValue="daily" onChange={({ target }) => setPeriodType(target.value)}
501
                  >
502
                    {periodTypeOptions.map((periodType, index) => (
503
                      <option value={periodType.value} key={periodType.value} >
504
                        {t(periodType.label)}
505
                      </option>
506
                    ))}
507
                  </CustomInput>
508
                </FormGroup>
509
              </Col>
510
              <Col xs="auto">
511
                <FormGroup className="form-group">
512
                  <Label className={labelClasses} for="basePeriodBeginsDatetime">
513
                    {t('Base Period Begins')}{t('(Optional)')}
514
                  </Label>
515
                  <Datetime id='basePeriodBeginsDatetime'
516
                    value={basePeriodBeginsDatetime}
517
                    inputProps={{ disabled: basePeriodBeginsDatetimeDisabled }}
518
                    onChange={onBasePeriodBeginsDatetimeChange}
519
                    isValidDate={getValidBasePeriodBeginsDatetimes}
520
                    closeOnSelect={true} />
521
                </FormGroup>
522
              </Col>
523
              <Col xs="auto">
524
                <FormGroup className="form-group">
525
                  <Label className={labelClasses} for="basePeriodEndsDatetime">
526
                    {t('Base Period Ends')}{t('(Optional)')}
527
                  </Label>
528
                  <Datetime id='basePeriodEndsDatetime'
529
                    value={basePeriodEndsDatetime}
530
                    inputProps={{ disabled: basePeriodEndsDatetimeDisabled }}
531
                    onChange={onBasePeriodEndsDatetimeChange}
532
                    isValidDate={getValidBasePeriodEndsDatetimes}
533
                    closeOnSelect={true} />
534
                </FormGroup>
535
              </Col>
536
              <Col xs="auto">
537
                <FormGroup className="form-group">
538
                  <Label className={labelClasses} for="reportingPeriodBeginsDatetime">
539
                    {t('Reporting Period Begins')}
540
                  </Label>
541
                  <Datetime id='reportingPeriodBeginsDatetime'
542
                    value={reportingPeriodBeginsDatetime}
543
                    onChange={onReportingPeriodBeginsDatetimeChange}
544
                    isValidDate={getValidReportingPeriodBeginsDatetimes}
545
                    closeOnSelect={true} />
546
                </FormGroup>
547
              </Col>
548
              <Col xs="auto">
549
                <FormGroup className="form-group">
550
                  <Label className={labelClasses} for="reportingPeriodEndsDatetime">
551
                    {t('Reporting Period Ends')}
552
                  </Label>
553
                  <Datetime id='reportingPeriodEndsDatetime'
554
                    value={reportingPeriodEndsDatetime}
555
                    onChange={onReportingPeriodEndsDatetimeChange}
556
                    isValidDate={getValidReportingPeriodEndsDatetimes}
557
                    closeOnSelect={true} />
558
                </FormGroup>
559
              </Col>
560
              <Col xs="auto">
561
                <FormGroup>
562
                  <br></br>
563
                  <ButtonGroup id="submit">
564
                    <Button color="success" disabled={isDisabled} >{t('Submit')}</Button>
565
                  </ButtonGroup>
566
                </FormGroup>
567
              </Col>
568
            </Row>
569
          </Form>
570
        </CardBody>
571
      </Card>
572
      <div className="card-deck">
573
        {cardSummaryList.map(cardSummaryItem => (
574
          <CardSummary key={cardSummaryItem['name']}
575
            rate={cardSummaryItem['increment_rate']}
576
            title={t('Reporting Period Savings CATEGORY (Baseline - Actual) UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })}
577
            color="success" >
578
            {cardSummaryItem['subtotal'] && <CountUp end={cardSummaryItem['subtotal']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
579
          </CardSummary>
580
        ))}
581
       
582
        <CardSummary 
583
          rate={totalInTCE['increment_rate'] || ''} 
584
          title={t('Reporting Period Savings CATEGORY (Baseline - Actual) UNIT', { 'CATEGORY': t('Ton of Standard Coal'), 'UNIT': '(TCE)' })}
585
          color="warning" >
586
          {totalInTCE['value'] && <CountUp end={totalInTCE['value']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
587
        </CardSummary>
588
        <CardSummary 
589
          rate={totalInTCO2E['increment_rate'] || ''} 
590
          title={t('Reporting Period Decreased CATEGORY (Baseline - Actual) UNIT', { 'CATEGORY': t('Ton of Carbon Dioxide Emissions'), 'UNIT': '(TCO2E)' })}
591
          color="warning" >
592
          {totalInTCO2E['value'] && <CountUp end={totalInTCO2E['value']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
593
        </CardSummary>
594
      </div>
595
      <Row noGutters>
596
        <Col className="mb-3 pr-lg-2 mb-3">
597
          <SharePie data={TCEShareData} title={t('Ton of Standard Coal by Energy Category')} />
598
        </Col>
599
        <Col className="mb-3 pr-lg-2 mb-3">
600
          <SharePie data={TCO2EShareData} title={t('Carbon Dioxide Emissions by Energy Category')} />
601
        </Col>
602
      </Row>
603
      <LineChart reportingTitle={t('Reporting Period Savings CATEGORY VALUE UNIT', { 'CATEGORY': null, 'VALUE': null, 'UNIT': null })}
604
        baseTitle=''
605
        labels={equipmentLineChartLabels}
606
        data={equipmentLineChartData}
607
        options={equipmentLineChartOptions}>
608
      </LineChart>
609
610
      <LineChart reportingTitle={t('Related Parameters')}
611
        baseTitle=''
612
        labels={parameterLineChartLabels}
613
        data={parameterLineChartData}
614
        options={parameterLineChartOptions}>
615
      </LineChart>
616
      <br />
617
      <DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={50} >
618
      </DetailedDataTable>
619
620
    </Fragment>
621
  );
622
};
623
624
export default withTranslation()(withRedirect(EquipmentSaving));
625