Passed
Push — master ( 669be3...4762c7 )
by Guangyu
19:25 queued 10s
created

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

Complexity

Total Complexity 27
Complexity/F 0

Size

Lines of Code 651
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 27
eloc 573
mnd 27
bc 27
fnc 0
dl 0
loc 651
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
  Spinner,
17
} from 'reactstrap';
18
import CountUp from 'react-countup';
19
import Datetime from 'react-datetime';
20
import moment from 'moment';
21
import loadable from '@loadable/component';
22
import Cascader from 'rc-cascader';
23
import CardSummary from '../common/CardSummary';
24
import LineChart from '../common/LineChart';
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 ButtonIcon from '../../common/ButtonIcon';
30
import { APIBaseURL } from '../../../config';
31
import { periodTypeOptions } from '../common/PeriodTypeOptions';
32
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
33
34
35
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
36
37
const CombinedEquipmentLoad = ({ setRedirect, setRedirectUrl, t }) => {
38
  let current_moment = moment();
39
  useEffect(() => {
40
    let is_logged_in = getCookieValue('is_logged_in');
41
    let user_name = getCookieValue('user_name');
42
    let user_display_name = getCookieValue('user_display_name');
43
    let user_uuid = getCookieValue('user_uuid');
44
    let token = getCookieValue('token');
45
    if (is_logged_in === null || !is_logged_in) {
46
      setRedirectUrl(`/authentication/basic/login`);
47
      setRedirect(true);
48
    } else {
49
      //update expires time of cookies
50
      createCookie('is_logged_in', true, 1000 * 60 * 60 * 8);
51
      createCookie('user_name', user_name, 1000 * 60 * 60 * 8);
52
      createCookie('user_display_name', user_display_name, 1000 * 60 * 60 * 8);
53
      createCookie('user_uuid', user_uuid, 1000 * 60 * 60 * 8);
54
      createCookie('token', token, 1000 * 60 * 60 * 8);
55
    }
56
  });
57
  // State
58
  // Query Parameters
59
  const [selectedSpaceName, setSelectedSpaceName] = useState(undefined);
60
  const [selectedSpaceID, setSelectedSpaceID] = useState(undefined);
61
  const [combinedEquipmentList, setCombinedEquipmentList] = useState([]);
62
  const [selectedCombinedEquipment, setSelectedCombinedEquipment] = useState(undefined);
63
  const [comparisonType, setComparisonType] = useState('month-on-month');
64
  const [periodType, setPeriodType] = useState('daily');
65
  const [basePeriodBeginsDatetime, setBasePeriodBeginsDatetime] = useState(current_moment.clone().subtract(1, 'months').startOf('month'));
66
  const [basePeriodEndsDatetime, setBasePeriodEndsDatetime] = useState(current_moment.clone().subtract(1, 'months'));
67
  const [basePeriodBeginsDatetimeDisabled, setBasePeriodBeginsDatetimeDisabled] = useState(true);
68
  const [basePeriodEndsDatetimeDisabled, setBasePeriodEndsDatetimeDisabled] = useState(true);
69
  const [reportingPeriodBeginsDatetime, setReportingPeriodBeginsDatetime] = useState(current_moment.clone().startOf('month'));
70
  const [reportingPeriodEndsDatetime, setReportingPeriodEndsDatetime] = useState(current_moment);
71
  const [cascaderOptions, setCascaderOptions] = useState(undefined);
72
73
  // buttons
74
  const [submitButtonDisabled, setSubmitButtonDisabled] = useState(true);
75
  const [spinnerHidden, setSpinnerHidden] = useState(true);
76
  const [exportButtonHidden, setExportButtonHidden] = useState(true);
77
  
78
  //Results
79
  const [cardSummaryList, setCardSummaryList] = 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
  const [excelBytesBase64, setExcelBytesBase64] = useState(undefined);
91
  
92
  useEffect(() => {
93
    let isResponseOK = false;
94
    fetch(APIBaseURL + '/spaces/tree', {
95
      method: 'GET',
96
      headers: {
97
        "Content-type": "application/json",
98
        "User-UUID": getCookieValue('user_uuid'),
99
        "Token": getCookieValue('token')
100
      },
101
      body: null,
102
103
    }).then(response => {
104
      console.log(response);
105
      if (response.ok) {
106
        isResponseOK = true;
107
      }
108
      return response.json();
109
    }).then(json => {
110
      console.log(json);
111
      if (isResponseOK) {
112
        // rename keys 
113
        json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
114
        setCascaderOptions(json);
115
        setSelectedSpaceName([json[0]].map(o => o.label));
116
        setSelectedSpaceID([json[0]].map(o => o.value));
117
        // get Combined Equipments by root Space ID
118
        let isResponseOK = false;
119
        fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/combinedequipments', {
120
          method: 'GET',
121
          headers: {
122
            "Content-type": "application/json",
123
            "User-UUID": getCookieValue('user_uuid'),
124
            "Token": getCookieValue('token')
125
          },
126
          body: null,
127
128
        }).then(response => {
129
          if (response.ok) {
130
            isResponseOK = true;
131
          }
132
          return response.json();
133
        }).then(json => {
134
          if (isResponseOK) {
135
            json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
136
            console.log(json);
137
            setCombinedEquipmentList(json[0]);
138
            if (json[0].length > 0) {
139
              setSelectedCombinedEquipment(json[0][0].value);
140
              // enable submit button
141
              setSubmitButtonDisabled(false);
142
            } else {
143
              setSelectedCombinedEquipment(undefined);
144
              // disable submit button
145
              setSubmitButtonDisabled(true);
146
            }
147
          } else {
148
            toast.error(json.description)
149
          }
150
        }).catch(err => {
151
          console.log(err);
152
        });
153
        // end of get Combined Equipments by root Space ID
154
      } else {
155
        toast.error(json.description);
156
      }
157
    }).catch(err => {
158
      console.log(err);
159
    });
160
161
  }, []);
162
163
  const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0';
164
165
  let onSpaceCascaderChange = (value, selectedOptions) => {
166
    setSelectedSpaceName(selectedOptions.map(o => o.label).join('/'));
167
    setSelectedSpaceID(value[value.length - 1]);
168
169
    let isResponseOK = false;
170
    fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/combinedequipments', {
171
      method: 'GET',
172
      headers: {
173
        "Content-type": "application/json",
174
        "User-UUID": getCookieValue('user_uuid'),
175
        "Token": getCookieValue('token')
176
      },
177
      body: null,
178
179
    }).then(response => {
180
      if (response.ok) {
181
        isResponseOK = true;
182
      }
183
      return response.json();
184
    }).then(json => {
185
      if (isResponseOK) {
186
        json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
187
        console.log(json)
188
        setCombinedEquipmentList(json[0]);
189
        if (json[0].length > 0) {
190
          setSelectedCombinedEquipment(json[0][0].value);
191
          // enable submit button
192
          setSubmitButtonDisabled(false);
193
        } else {
194
          setSelectedCombinedEquipment(undefined);
195
          // disable submit button
196
          setSubmitButtonDisabled(true);
197
        }
198
      } else {
199
        toast.error(json.description)
200
      }
201
    }).catch(err => {
202
      console.log(err);
203
    });
204
  }
205
206
207
  let onComparisonTypeChange = ({ target }) => {
208
    console.log(target.value);
209
    setComparisonType(target.value);
210
    if (target.value === 'year-over-year') {
211
      setBasePeriodBeginsDatetimeDisabled(true);
212
      setBasePeriodEndsDatetimeDisabled(true);
213
      setBasePeriodBeginsDatetime(moment(reportingPeriodBeginsDatetime).subtract(1, 'years'));
214
      setBasePeriodEndsDatetime(moment(reportingPeriodEndsDatetime).subtract(1, 'years'));
215
    } else if (target.value === 'month-on-month') {
216
      setBasePeriodBeginsDatetimeDisabled(true);
217
      setBasePeriodEndsDatetimeDisabled(true);
218
      setBasePeriodBeginsDatetime(moment(reportingPeriodBeginsDatetime).subtract(1, 'months'));
219
      setBasePeriodEndsDatetime(moment(reportingPeriodEndsDatetime).subtract(1, 'months'));
220
    } else if (target.value === 'free-comparison') {
221
      setBasePeriodBeginsDatetimeDisabled(false);
222
      setBasePeriodEndsDatetimeDisabled(false);
223
    } else if (target.value === 'none-comparison') {
224
      setBasePeriodBeginsDatetime(undefined);
225
      setBasePeriodEndsDatetime(undefined);
226
      setBasePeriodBeginsDatetimeDisabled(true);
227
      setBasePeriodEndsDatetimeDisabled(true);
228
    }
229
  }
230
231
  let onBasePeriodBeginsDatetimeChange = (newDateTime) => {
232
    setBasePeriodBeginsDatetime(newDateTime);
233
  }
234
235
  let onBasePeriodEndsDatetimeChange = (newDateTime) => {
236
    setBasePeriodEndsDatetime(newDateTime);
237
  }
238
239
  let onReportingPeriodBeginsDatetimeChange = (newDateTime) => {
240
    setReportingPeriodBeginsDatetime(newDateTime);
241
    if (comparisonType === 'year-over-year') {
242
      setBasePeriodBeginsDatetime(newDateTime.clone().subtract(1, 'years'));
243
    } else if (comparisonType === 'month-on-month') {
244
      setBasePeriodBeginsDatetime(newDateTime.clone().subtract(1, 'months'));
245
    }
246
  }
247
248
  let onReportingPeriodEndsDatetimeChange = (newDateTime) => {
249
    setReportingPeriodEndsDatetime(newDateTime);
250
    if (comparisonType === 'year-over-year') {
251
      setBasePeriodEndsDatetime(newDateTime.clone().subtract(1, 'years'));
252
    } else if (comparisonType === 'month-on-month') {
253
      setBasePeriodEndsDatetime(newDateTime.clone().subtract(1, 'months'));
254
    }
255
  }
256
257
  var getValidBasePeriodBeginsDatetimes = function (currentDate) {
258
    return currentDate.isBefore(moment(basePeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
259
  }
260
261
  var getValidBasePeriodEndsDatetimes = function (currentDate) {
262
    return currentDate.isAfter(moment(basePeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
263
  }
264
265
  var getValidReportingPeriodBeginsDatetimes = function (currentDate) {
266
    return currentDate.isBefore(moment(reportingPeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
267
  }
268
269
  var getValidReportingPeriodEndsDatetimes = function (currentDate) {
270
    return currentDate.isAfter(moment(reportingPeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
271
  }
272
273
  // Handler
274
  const handleSubmit = e => {
275
    e.preventDefault();
276
    console.log('handleSubmit');
277
    console.log(selectedSpaceID);
278
    console.log(selectedCombinedEquipment);
279
    console.log(periodType);
280
    console.log(basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined);
281
    console.log(basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : undefined);
282
    console.log(reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss'));
283
    console.log(reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'));
284
285
    // disable submit button
286
    setSubmitButtonDisabled(true);
287
    // show spinner
288
    setSpinnerHidden(false);
289
    // hide export buttion
290
    setExportButtonHidden(true)
291
292
    // Reinitialize tables
293
    setDetailedDataTableData([]);
294
    
295
    let isResponseOK = false;
296
    fetch(APIBaseURL + '/reports/combinedequipmentload?' +
297
      'combinedequipmentid=' + selectedCombinedEquipment +
298
      '&periodtype=' + periodType +
299
      '&baseperiodstartdatetime=' + (basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') +
300
      '&baseperiodenddatetime=' + (basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') +
301
      '&reportingperiodstartdatetime=' + reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') +
302
      '&reportingperiodenddatetime=' + reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'), {
303
      method: 'GET',
304
      headers: {
305
        "Content-type": "application/json",
306
        "User-UUID": getCookieValue('user_uuid'),
307
        "Token": getCookieValue('token')
308
      },
309
      body: null,
310
311
    }).then(response => {
312
      if (response.ok) {
313
        isResponseOK = true;
314
      };
315
      return response.json();
316
    }).then(json => {
317
      if (isResponseOK) {
318
        console.log(json)
319
              
320
        let cardSummaryArray = []
321
        json['reporting_period']['names'].forEach((currentValue, index) => {
322
          let cardSummaryItem = {}
323
          cardSummaryItem['name'] = json['reporting_period']['names'][index];
324
          cardSummaryItem['unit'] = json['reporting_period']['units'][index];
325
          cardSummaryItem['average'] = json['reporting_period']['averages'][index];
326
          cardSummaryItem['average_increment_rate'] = parseFloat(json['reporting_period']['averages_increment_rate'][index] * 100).toFixed(2) + "%";
327
          cardSummaryItem['maximum'] = json['reporting_period']['maximums'][index];
328
          cardSummaryItem['maximum_increment_rate'] = parseFloat(json['reporting_period']['maximums_increment_rate'][index] * 100).toFixed(2) + "%";
329
          cardSummaryItem['factor'] = json['reporting_period']['factors'][index];
330
          cardSummaryItem['factor_increment_rate'] = parseFloat(json['reporting_period']['factors_increment_rate'][index] * 100).toFixed(2) + "%";
331
          cardSummaryArray.push(cardSummaryItem);
332
        });
333
        setCardSummaryList(cardSummaryArray);
334
335
        let timestamps = {}
336
        json['reporting_period']['timestamps'].forEach((currentValue, index) => {
337
          timestamps['a' + index] = currentValue;
338
        });
339
        setCombinedEquipmentLineChartLabels(timestamps);
340
        
341
        let values = {}
342
        json['reporting_period']['sub_maximums'].forEach((currentValue, index) => {
343
          values['a' + index] = currentValue;
344
        });
345
        setCombinedEquipmentLineChartData(values);
346
        
347
        let names = Array();
348
        json['reporting_period']['names'].forEach((currentValue, index) => {
349
          let unit = json['reporting_period']['units'][index];
350
          names.push({ 'value': 'a' + index, 'label': currentValue + ' (' + unit + '/H)'});
351
        });
352
        setCombinedEquipmentLineChartOptions(names);
353
      
354
        timestamps = {}
355
        json['parameters']['timestamps'].forEach((currentValue, index) => {
356
          timestamps['a' + index] = currentValue;
357
        });
358
        setParameterLineChartLabels(timestamps);
359
360
        values = {}
361
        json['parameters']['values'].forEach((currentValue, index) => {
362
          values['a' + index] = currentValue;
363
        });
364
        setParameterLineChartData(values);
365
      
366
        names = Array();
367
        json['parameters']['names'].forEach((currentValue, index) => {
368
          if (currentValue.startsWith('TARIFF-')) {
369
            currentValue = t('Tariff') + currentValue.replace('TARIFF-', '-');
370
          }
371
          
372
          names.push({ 'value': 'a' + index, 'label': currentValue });
373
        });
374
        setParameterLineChartOptions(names);
375
      
376
        let detailed_value_list = [];
377
        if (json['reporting_period']['timestamps'].length > 0) {
378
          json['reporting_period']['timestamps'][0].forEach((currentTimestamp, timestampIndex) => {
379
            let detailed_value = {};
380
            detailed_value['id'] = timestampIndex;
381
            detailed_value['startdatetime'] = currentTimestamp;
382
            json['reporting_period']['sub_averages'].forEach((currentValue, energyCategoryIndex) => {
383
              if (json['reporting_period']['sub_averages'][energyCategoryIndex][timestampIndex] != null) {
384
                detailed_value['a' + 2 * energyCategoryIndex] = json['reporting_period']['sub_averages'][energyCategoryIndex][timestampIndex].toFixed(2);
385
              } else {
386
                detailed_value['a' + 2 * energyCategoryIndex] = '';
387
              };  
388
            
389
              if (json['reporting_period']['sub_maximums'][energyCategoryIndex][timestampIndex] != null) {
390
                detailed_value['a' + (2 * energyCategoryIndex + 1)] = json['reporting_period']['sub_maximums'][energyCategoryIndex][timestampIndex].toFixed(2);
391
              } else {
392
                detailed_value['a' + (2 * energyCategoryIndex + 1)] = '';
393
              };            
394
            });
395
            detailed_value_list.push(detailed_value);
396
          });
397
        };
398
399
        setDetailedDataTableData(detailed_value_list);
400
        
401
        let detailed_column_list = [];
402
        detailed_column_list.push({
403
          dataField: 'startdatetime',
404
          text: t('Datetime'),
405
          sort: true
406
        })
407
        json['reporting_period']['names'].forEach((currentValue, index) => {
408
          let unit = json['reporting_period']['units'][index];
409
          detailed_column_list.push({
410
            dataField: 'a' + 2 * index,
411
            text: currentValue + ' ' + t('Average Load') + ' (' + unit + '/H)',
412
            sort: true
413
          });
414
          detailed_column_list.push({
415
            dataField: 'a' + (2 * index + 1),
416
            text: currentValue + ' ' + t('Maximum Load') + ' (' + unit + '/H)',
417
            sort: true
418
          });
419
        });
420
        setDetailedDataTableColumns(detailed_column_list);
421
        
422
        setExcelBytesBase64(json['excel_bytes_base64']);
423
424
        // enable submit button
425
        setSubmitButtonDisabled(false);
426
        // hide spinner
427
        setSpinnerHidden(true);
428
        // show export buttion
429
        setExportButtonHidden(false);
430
          
431
      } else {
432
        toast.error(json.description)
433
      }
434
    }).catch(err => {
435
      console.log(err);
436
    });
437
  };
438
  
439
  const handleExport = e => {
440
    e.preventDefault();
441
    const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
442
    const fileName = 'combinedequipmentload.xlsx'
443
    var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64;
444
    fetch(fileUrl)
445
        .then(response => response.blob())
446
        .then(blob => {
447
            var link = window.document.createElement("a");
448
            link.href = window.URL.createObjectURL(blob, { type: mimeType });
449
            link.download = fileName;
450
            document.body.appendChild(link);
451
            link.click();
452
            document.body.removeChild(link);
453
        });
454
  };
455
  
456
457
458
  return (
459
    <Fragment>
460
      <div>
461
        <Breadcrumb>
462
          <BreadcrumbItem>{t('Combined Equipment Data')}</BreadcrumbItem><BreadcrumbItem active>{t('Load')}</BreadcrumbItem>
463
        </Breadcrumb>
464
      </div>
465
      <Card className="bg-light mb-3">
466
        <CardBody className="p-3">
467
          <Form onSubmit={handleSubmit}>
468
            <Row form>
469
              <Col xs="auto">
470
                <FormGroup className="form-group">
471
                  <Label className={labelClasses} for="space">
472
                    {t('Space')}
473
                  </Label>
474
                  <br />
475
                  <Cascader options={cascaderOptions}
476
                    onChange={onSpaceCascaderChange}
477
                    changeOnSelect
478
                    expandTrigger="hover">
479
                    <Input value={selectedSpaceName || ''} readOnly />
480
                  </Cascader>
481
                </FormGroup>
482
              </Col>
483
              <Col xs="auto">
484
                <FormGroup>
485
                  <Label className={labelClasses} for="combinedEquipmentSelect">
486
                    {t('Combined Equipment')}
487
                  </Label>
488
                  <CustomInput type="select" id="combinedEquipmentSelect" name="combinedEquipmentSelect" onChange={({ target }) => setSelectedCombinedEquipment(target.value)}
489
                  >
490
                    {combinedEquipmentList.map((combinedEquipment, index) => (
491
                      <option value={combinedEquipment.value} key={combinedEquipment.value}>
492
                        {combinedEquipment.label}
493
                      </option>
494
                    ))}
495
                  </CustomInput>
496
                </FormGroup>
497
              </Col>
498
              <Col xs="auto">
499
                <FormGroup>
500
                  <Label className={labelClasses} for="comparisonType">
501
                    {t('Comparison Types')}
502
                  </Label>
503
                  <CustomInput type="select" id="comparisonType" name="comparisonType"
504
                    defaultValue="month-on-month"
505
                    onChange={onComparisonTypeChange}
506
                  >
507
                    {comparisonTypeOptions.map((comparisonType, index) => (
508
                      <option value={comparisonType.value} key={comparisonType.value} >
509
                        {t(comparisonType.label)}
510
                      </option>
511
                    ))}
512
                  </CustomInput>
513
                </FormGroup>
514
              </Col>
515
              <Col xs="auto">
516
                <FormGroup>
517
                  <Label className={labelClasses} for="periodType">
518
                    {t('Period Types')}
519
                  </Label>
520
                  <CustomInput type="select" id="periodType" name="periodType" defaultValue="daily" onChange={({ target }) => setPeriodType(target.value)}
521
                  >
522
                    {periodTypeOptions.map((periodType, index) => (
523
                      <option value={periodType.value} key={periodType.value} >
524
                        {t(periodType.label)}
525
                      </option>
526
                    ))}
527
                  </CustomInput>
528
                </FormGroup>
529
              </Col>
530
              <Col xs="auto">
531
                <FormGroup className="form-group">
532
                  <Label className={labelClasses} for="basePeriodBeginsDatetime">
533
                    {t('Base Period Begins')}{t('(Optional)')}
534
                  </Label>
535
                  <Datetime id='basePeriodBeginsDatetime'
536
                    value={basePeriodBeginsDatetime}
537
                    inputProps={{ disabled: basePeriodBeginsDatetimeDisabled }}
538
                    onChange={onBasePeriodBeginsDatetimeChange}
539
                    isValidDate={getValidBasePeriodBeginsDatetimes}
540
                    closeOnSelect={true} />
541
                </FormGroup>
542
              </Col>
543
              <Col xs="auto">
544
                <FormGroup className="form-group">
545
                  <Label className={labelClasses} for="basePeriodEndsDatetime">
546
                    {t('Base Period Ends')}{t('(Optional)')}
547
                  </Label>
548
                  <Datetime id='basePeriodEndsDatetime'
549
                    value={basePeriodEndsDatetime}
550
                    inputProps={{ disabled: basePeriodEndsDatetimeDisabled }}
551
                    onChange={onBasePeriodEndsDatetimeChange}
552
                    isValidDate={getValidBasePeriodEndsDatetimes}
553
                    closeOnSelect={true} />
554
                </FormGroup>
555
              </Col>
556
              <Col xs="auto">
557
                <FormGroup className="form-group">
558
                  <Label className={labelClasses} for="reportingPeriodBeginsDatetime">
559
                    {t('Reporting Period Begins')}
560
                  </Label>
561
                  <Datetime id='reportingPeriodBeginsDatetime'
562
                    value={reportingPeriodBeginsDatetime}
563
                    onChange={onReportingPeriodBeginsDatetimeChange}
564
                    isValidDate={getValidReportingPeriodBeginsDatetimes}
565
                    closeOnSelect={true} />
566
                </FormGroup>
567
              </Col>
568
              <Col xs="auto">
569
                <FormGroup className="form-group">
570
                  <Label className={labelClasses} for="reportingPeriodEndsDatetime">
571
                    {t('Reporting Period Ends')}
572
                  </Label>
573
                  <Datetime id='reportingPeriodEndsDatetime'
574
                    value={reportingPeriodEndsDatetime}
575
                    onChange={onReportingPeriodEndsDatetimeChange}
576
                    isValidDate={getValidReportingPeriodEndsDatetimes}
577
                    closeOnSelect={true} />
578
                </FormGroup>
579
              </Col>
580
              <Col xs="auto">
581
                <FormGroup>
582
                  <br></br>
583
                  <ButtonGroup id="submit">
584
                    <Button color="success" disabled={submitButtonDisabled} >{t('Submit')}</Button>
585
                  </ButtonGroup>
586
                </FormGroup>
587
              </Col>
588
              <Col xs="auto">
589
                <FormGroup>
590
                  <br></br>
591
                  <Spinner color="primary" hidden={spinnerHidden}  />
592
                </FormGroup>
593
              </Col>
594
              <Col xs="auto">
595
                  <br></br>
596
                  <ButtonIcon icon="external-link-alt" transform="shrink-3 down-2" color="falcon-default" 
597
                  hidden={exportButtonHidden}
598
                  onClick={handleExport} >
599
                    {t('Export')}
600
                  </ButtonIcon>
601
              </Col>
602
            </Row>
603
          </Form>
604
        </CardBody>
605
      </Card>
606
      {cardSummaryList.map(cardSummaryItem => (
607
        <div className="card-deck" key={cardSummaryItem['name']}>
608
          <CardSummary key={cardSummaryItem['name'] + 'average'}
609
            rate={cardSummaryItem['average_increment_rate']}
610
            title={t('Reporting Period CATEGORY Average Load UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + '/H)' })}
611
            color="success" >
612
            {cardSummaryItem['average'] && <CountUp end={cardSummaryItem['average']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
613
          </CardSummary>
614
          <CardSummary key={cardSummaryItem['name'] + 'maximum'}
615
            rate={cardSummaryItem['maximum_increment_rate']}
616
            title={t('Reporting Period CATEGORY Maximum Load UNIT', { 'CATEGORY': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + '/H)' })}
617
            color="success" >
618
            {cardSummaryItem['maximum'] && <CountUp end={cardSummaryItem['maximum']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
619
          </CardSummary>
620
          <CardSummary key={cardSummaryItem['name'] + 'factor'}
621
            rate={cardSummaryItem['factor_increment_rate']}
622
            title={t('Reporting Period CATEGORY Load Factor', { 'CATEGORY': cardSummaryItem['name'] })}
623
            color="success" 
624
            footnote={t('Ratio of Average Load to Maximum Load')} >
625
            {cardSummaryItem['factor'] && <CountUp end={cardSummaryItem['factor']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
626
          </CardSummary>
627
        </div>
628
      ))}
629
      <LineChart reportingTitle={t('Reporting Period CATEGORY Maximum Load UNIT', { 'CATEGORY': null, 'UNIT': null })}
630
        baseTitle=''
631
        labels={combinedEquipmentLineChartLabels}
632
        data={combinedEquipmentLineChartData}
633
        options={combinedEquipmentLineChartOptions}>
634
      </LineChart>
635
636
      <LineChart reportingTitle={t('Related Parameters')}
637
        baseTitle=''
638
        labels={parameterLineChartLabels}
639
        data={parameterLineChartData}
640
        options={parameterLineChartOptions}>
641
      </LineChart>
642
      <br />
643
      <DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={50} >
644
      </DetailedDataTable>
645
646
    </Fragment>
647
  );
648
};
649
650
export default withTranslation()(withRedirect(CombinedEquipmentLoad));
651