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

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

Complexity

Total Complexity 24
Complexity/F 0

Size

Lines of Code 622
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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