Passed
Push — master ( 414b30...be43ee )
by Guangyu
14:19 queued 13s
created

myems-web/src/components/MyEMS/CombinedEquipment/CombinedEquipmentEfficiency.js   F

Complexity

Total Complexity 60
Complexity/F 0

Size

Lines of Code 1110
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 60
eloc 914
dl 0
loc 1110
rs 3.286
c 0
b 0
f 0
mnd 60
bc 60
fnc 0
bpm 0
cpm 0
noi 0

How to fix   Complexity   

Complexity

Complex classes like myems-web/src/components/MyEMS/CombinedEquipment/CombinedEquipmentEfficiency.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import React, { Fragment, useEffect, useState, useContext } 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 moment from 'moment';
20
import loadable from '@loadable/component';
21
import Cascader from 'rc-cascader';
22
import CardSummary from '../common/CardSummary';
23
import MultiTrendChart from '../common/MultiTrendChart';
24
import { getCookieValue, createCookie } from '../../../helpers/utils';
25
import withRedirect from '../../../hoc/withRedirect';
26
import { withTranslation } from 'react-i18next';
27
import { toast } from 'react-toastify';
28
import ButtonIcon from '../../common/ButtonIcon';
29
import { APIBaseURL } from '../../../config';
30
import { periodTypeOptions } from '../common/PeriodTypeOptions';
31
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
32
import DateRangePickerWrapper from '../common/DateRangePickerWrapper';
33
import { endOfDay} from 'date-fns';
34
import AppContext from '../../../context/Context';
35
import MultipleLineChart from '../common/MultipleLineChart';
36
37
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
38
const AssociatedEquipmentTable = loadable(() => import('../common/AssociatedEquipmentTable'));
39
40
const CombinedEquipmentEfficiency = ({ setRedirect, setRedirectUrl, t }) => {
41
  let current_moment = moment();
42
  useEffect(() => {
43
    let is_logged_in = getCookieValue('is_logged_in');
44
    let user_name = getCookieValue('user_name');
45
    let user_display_name = getCookieValue('user_display_name');
46
    let user_uuid = getCookieValue('user_uuid');
47
    let token = getCookieValue('token');
48
    if (is_logged_in === null || !is_logged_in) {
49
      setRedirectUrl(`/authentication/basic/login`);
50
      setRedirect(true);
51
    } else {
52
      //update expires time of cookies
53
      createCookie('is_logged_in', true, 1000 * 60 * 60 * 8);
54
      createCookie('user_name', user_name, 1000 * 60 * 60 * 8);
55
      createCookie('user_display_name', user_display_name, 1000 * 60 * 60 * 8);
56
      createCookie('user_uuid', user_uuid, 1000 * 60 * 60 * 8);
57
      createCookie('token', token, 1000 * 60 * 60 * 8);
58
    }
59
  });
60
61
62
  // State
63
  // Query Parameters
64
  const [selectedSpaceName, setSelectedSpaceName] = useState(undefined);
65
  const [selectedSpaceID, setSelectedSpaceID] = useState(undefined);
66
  const [combinedEquipmentList, setCombinedEquipmentList] = useState([]);
67
  const [selectedCombinedEquipment, setSelectedCombinedEquipment] = useState(undefined);
68
  const [comparisonType, setComparisonType] = useState('month-on-month');
69
  const [periodType, setPeriodType] = useState('daily');
70
  const [cascaderOptions, setCascaderOptions] = useState(undefined);
71
  const [basePeriodDateRange, setBasePeriodDateRange] = useState([current_moment.clone().subtract(1, 'months').startOf('month').toDate(), current_moment.clone().subtract(1, 'months').toDate()]);
72
  const [basePeriodDateRangePickerDisabled, setBasePeriodDateRangePickerDisabled] = useState(true);
73
  const [reportingPeriodDateRange, setReportingPeriodDateRange] = useState([current_moment.clone().startOf('month').toDate(), current_moment.toDate()]);
74
  const dateRangePickerLocale = {
75
    sunday: t('sunday'),
76
    monday: t('monday'),
77
    tuesday: t('tuesday'),
78
    wednesday: t('wednesday'),
79
    thursday: t('thursday'),
80
    friday: t('friday'),
81
    saturday: t('saturday'),
82
    ok: t('ok'),
83
    today: t('today'),
84
    yesterday: t('yesterday'),
85
    hours: t('hours'),
86
    minutes: t('minutes'),
87
    seconds: t('seconds'),
88
    last7Days: t('last7Days'),
89
    formattedMonthPattern: 'yyyy-MM-dd'
90
  };
91
  const dateRangePickerStyle = { display: 'block', zIndex: 10};
92
  const { language } = useContext(AppContext);
93
94
  // buttons
95
  const [submitButtonDisabled, setSubmitButtonDisabled] = useState(true);
96
  const [spinnerHidden, setSpinnerHidden] = useState(true);
97
  const [exportButtonHidden, setExportButtonHidden] = useState(true);
98
99
  //Results
100
  const [cardSummaryList, setCardSummaryList] = useState([]);
101
102
  const [combinedEquipmentBaseAndReportingNames, setCombinedEquipmentBaseAndReportingNames] = useState({"a0":""});
103
  const [combinedEquipmentBaseAndReportingUnits, setCombinedEquipmentBaseAndReportingUnits] = useState({"a0":"()"});
104
105
  const [combinedEquipmentBaseLabels, setCombinedEquipmentBaseLabels] = useState({"a0": []});
106
  const [combinedEquipmentBaseData, setCombinedEquipmentBaseData] = useState({"a0": []});
107
  const [combinedEquipmentBaseSubtotals, setCombinedEquipmentBaseSubtotals] = useState({"a0": (0).toFixed(2)});
108
109
  const [combinedEquipmentReportingLabels, setCombinedEquipmentReportingLabels] = useState({"a0": []});
110
  const [combinedEquipmentReportingData, setCombinedEquipmentReportingData] = useState({"a0": []});
111
  const [combinedEquipmentReportingSubtotals, setCombinedEquipmentReportingSubtotals] = useState({"a0": (0).toFixed(2)});
112
113
  const [combinedEquipmentReportingRates, setCombinedEquipmentReportingRates] = useState({"a0": []});
114
  const [combinedEquipmentReportingOptions, setCombinedEquipmentReportingOptions] = useState([]);
115
116
  const [parameterLineChartLabels, setParameterLineChartLabels] = useState([]);
117
  const [parameterLineChartData, setParameterLineChartData] = useState({});
118
  const [parameterLineChartOptions, setParameterLineChartOptions] = useState([]);
119
120
  const [detailedDataTableData, setDetailedDataTableData] = useState([]);
121
  const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]);
122
123
  const [associatedEquipmentTableData, setAssociatedEquipmentTableData] = useState([]);
124
  const [associatedEquipmentTableColumns, setAssociatedEquipmentTableColumns] = useState([{dataField: 'name', text: t('Associated Equipment'), sort: true }]);
125
126
127
  const [excelBytesBase64, setExcelBytesBase64] = useState(undefined);
128
129
  useEffect(() => {
130
    let isResponseOK = false;
131
    fetch(APIBaseURL + '/spaces/tree', {
132
      method: 'GET',
133
      headers: {
134
        "Content-type": "application/json",
135
        "User-UUID": getCookieValue('user_uuid'),
136
        "Token": getCookieValue('token')
137
      },
138
      body: null,
139
140
    }).then(response => {
141
      console.log(response);
142
      if (response.ok) {
143
        isResponseOK = true;
144
      }
145
      return response.json();
146
    }).then(json => {
147
      console.log(json);
148
      if (isResponseOK) {
149
        // rename keys 
150
        json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
151
        setCascaderOptions(json);
152
        setSelectedSpaceName([json[0]].map(o => o.label));
153
        setSelectedSpaceID([json[0]].map(o => o.value));
154
        // get CombinedEquipments by root Space ID
155
        let isResponseOK = false;
156
        fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/combinedequipments', {
157
          method: 'GET',
158
          headers: {
159
            "Content-type": "application/json",
160
            "User-UUID": getCookieValue('user_uuid'),
161
            "Token": getCookieValue('token')
162
          },
163
          body: null,
164
165
        }).then(response => {
166
          if (response.ok) {
167
            isResponseOK = true;
168
          }
169
          return response.json();
170
        }).then(json => {
171
          if (isResponseOK) {
172
            json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
173
            console.log(json);
174
            setCombinedEquipmentList(json[0]);
175
            if (json[0].length > 0) {
176
              setSelectedCombinedEquipment(json[0][0].value);
177
              // enable submit button
178
              setSubmitButtonDisabled(false);
179
            } else {
180
              setSelectedCombinedEquipment(undefined);
181
              // disable submit button
182
              setSubmitButtonDisabled(true);
183
            }
184
          } else {
185
            toast.error(t(json.description))
186
          }
187
        }).catch(err => {
188
          console.log(err);
189
        });
190
        // end of get CombinedEquipments by root Space ID
191
      } else {
192
        toast.error(t(json.description));
193
      }
194
    }).catch(err => {
195
      console.log(err);
196
    });
197
198
  }, []);
199
  
200
  const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0';
201
202
  let onSpaceCascaderChange = (value, selectedOptions) => {
203
    console.log(value, selectedOptions);
204
    setSelectedSpaceName(selectedOptions.map(o => o.label).join('/'));
205
    setSelectedSpaceID(value[value.length - 1]);
206
207
    let isResponseOK = false;
208
    fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/combinedequipments', {
209
      method: 'GET',
210
      headers: {
211
        "Content-type": "application/json",
212
        "User-UUID": getCookieValue('user_uuid'),
213
        "Token": getCookieValue('token')
214
      },
215
      body: null,
216
217
    }).then(response => {
218
      if (response.ok) {
219
        isResponseOK = true;
220
      }
221
      return response.json();
222
    }).then(json => {
223
      if (isResponseOK) {
224
        json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
225
        console.log(json)
226
        setCombinedEquipmentList(json[0]);
227
        if (json[0].length > 0) {
228
          setSelectedCombinedEquipment(json[0][0].value);
229
          // enable submit button
230
          setSubmitButtonDisabled(false);
231
        } else {
232
          setSelectedCombinedEquipment(undefined);
233
          // disable submit button
234
          setSubmitButtonDisabled(true);
235
        }
236
237
        // hide export button
238
        setExportButtonHidden(true)
239
      } else {
240
        toast.error(t(json.description))
241
      }
242
    }).catch(err => {
243
      console.log(err);
244
    });
245
  }
246
247
  let onComparisonTypeChange = ({ target }) => {
248
    console.log(target.value);
249
    setComparisonType(target.value);
250
    if (target.value === 'year-over-year') {
251
      setBasePeriodDateRangePickerDisabled(true);
252
      setBasePeriodDateRange([moment(reportingPeriodDateRange[0]).subtract(1, 'years').toDate(),
253
        moment(reportingPeriodDateRange[1]).subtract(1, 'years').toDate()]);
254
    } else if (target.value === 'month-on-month') {
255
      setBasePeriodDateRangePickerDisabled(true);
256
      setBasePeriodDateRange([moment(reportingPeriodDateRange[0]).subtract(1, 'months').toDate(),
257
        moment(reportingPeriodDateRange[1]).subtract(1, 'months').toDate()]);
258
    } else if (target.value === 'free-comparison') {
259
      setBasePeriodDateRangePickerDisabled(false);
260
    } else if (target.value === 'none-comparison') {
261
      setBasePeriodDateRange([null, null]);
262
      setBasePeriodDateRangePickerDisabled(true);
263
    }
264
  };
265
266
  // Callback fired when value changed
267
  let onBasePeriodChange = (DateRange) => {
268
    if(DateRange == null) {
269
      setBasePeriodDateRange([null, null]);
270
    } else {
271
      if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
272
        // if the user did not change time value, set the default time to the end of day
273
        DateRange[1] = endOfDay(DateRange[1]);
274
      }
275
      setBasePeriodDateRange([DateRange[0], DateRange[1]]);
276
    }
277
  };
278
279
  // Callback fired when value changed
280
  let onReportingPeriodChange = (DateRange) => {
281
    if(DateRange == null) {
282
      setReportingPeriodDateRange([null, null]);
283
    } else {
284
      if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
285
        // if the user did not change time value, set the default time to the end of day
286
        DateRange[1] = endOfDay(DateRange[1]);
287
      }
288
      setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
289
      if (comparisonType === 'year-over-year') {
290
        setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]);
291
      } else if (comparisonType === 'month-on-month') {
292
        setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'months').toDate(), moment(DateRange[1]).clone().subtract(1, 'months').toDate()]);
293
      }
294
    }
295
  };
296
297
  // Callback fired when value clean
298
  let onBasePeriodClean = event => {
299
    setBasePeriodDateRange([null, null]);
300
  };
301
302
  // Callback fired when value clean
303
  let onReportingPeriodClean = event => {
304
    setReportingPeriodDateRange([null, null]);
305
  };
306
307
  const isBasePeriodTimestampExists = (base_period_data) => {
308
    const timestamps = base_period_data['timestamps'];
309
310
    if (timestamps.length === 0) {
311
      return false;
312
    }
313
314
    for (let i = 0; i < timestamps.length; i++) {
315
      if (timestamps[i].length > 0) {
316
        return true;
317
      }
318
    }
319
    return false
320
  }
321
322
  const sortByNumber = (originalArr, key) => {
323
    let sortArr = Array();
324
    let index = 0;
325
    while (sortArr.length < originalArr.length) {
326
      for (let i = 0; i < originalArr.length; i++) {
327
        if (originalArr[i][key].substring(1) === index.toString()) {
328
          sortArr.push(originalArr[i])
329
        }
330
      }
331
      index += 1
332
    }
333
    return sortArr;
334
  }
335
336
  // Handler
337
  const handleSubmit = e => {
338
    e.preventDefault();
339
    console.log('handleSubmit');
340
    console.log(selectedSpaceID);
341
    console.log(selectedCombinedEquipment);
342
    console.log(comparisonType);
343
    console.log(periodType);
344
    console.log(basePeriodDateRange[0] != null ? moment(basePeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') : null)
345
    console.log(basePeriodDateRange[1] != null ? moment(basePeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss') : null)
346
    console.log(moment(reportingPeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss'))
347
    console.log(moment(reportingPeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss'));
348
349
    // disable submit button
350
    setSubmitButtonDisabled(true);
351
    // show spinner
352
    setSpinnerHidden(false);
353
    // hide export button
354
    setExportButtonHidden(true)
355
356
    // Reinitialize tables
357
    setDetailedDataTableData([]);
358
    setAssociatedEquipmentTableData([]);
359
360
    
361
    let isResponseOK = false;
362
    fetch(APIBaseURL + '/reports/combinedequipmentefficiency?' +
363
      'combinedequipmentid=' + selectedCombinedEquipment +
364
      '&periodtype=' + periodType +
365
      '&baseperiodstartdatetime=' + (basePeriodDateRange[0] != null ? moment(basePeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') : '') +
366
      '&baseperiodenddatetime=' + (basePeriodDateRange[1] != null ? moment(basePeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss') : '') +
367
      '&reportingperiodstartdatetime=' + moment(reportingPeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') +
368
      '&reportingperiodenddatetime=' + moment(reportingPeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss') +
369
      '&language=' + language, {
370
      method: 'GET',
371
      headers: {
372
        "Content-type": "application/json",
373
        "User-UUID": getCookieValue('user_uuid'),
374
        "Token": getCookieValue('token')
375
      },
376
      body: null,
377
378
    }).then(response => {
379
      if (response.ok) {
380
        isResponseOK = true;
381
      };
382
      return response.json();
383
    }).then(json => {
384
      if (isResponseOK) {
385
        console.log(json);
386
387
        let cardSummaryArray = []
388
        json['reporting_period_efficiency']['names'].forEach((currentValue, index) => {
389
          let cardSummaryItem = {}
390
          cardSummaryItem['name'] = json['reporting_period_efficiency']['names'][index];
391
          cardSummaryItem['unit'] = json['reporting_period_efficiency']['units'][index];
392
          cardSummaryItem['cumulation'] = json['reporting_period_efficiency']['cumulations'][index];
393
          cardSummaryItem['increment_rate'] = parseFloat(json['reporting_period_efficiency']['increment_rates'][index] * 100).toFixed(2) + "%";
394
395
          cardSummaryItem['numerator_name'] = json['reporting_period_efficiency']['numerator_names'][index];
396
          cardSummaryItem['numerator_unit'] = json['reporting_period_efficiency']['numerator_units'][index];
397
          cardSummaryItem['numerator_cumulation'] = json['reporting_period_efficiency']['numerator_cumulations'][index];
398
          cardSummaryItem['increment_rates_num'] = parseFloat(json['reporting_period_efficiency']['increment_rates_num'][index] * 100).toFixed(2) + "%";
399
400
          cardSummaryItem['denominator_name'] = json['reporting_period_efficiency']['denominator_names'][index];
401
          cardSummaryItem['denominator_unit'] = json['reporting_period_efficiency']['denominator_units'][index];
402
          cardSummaryItem['denominator_cumulation'] = json['reporting_period_efficiency']['denominator_cumulations'][index];
403
          cardSummaryItem['increment_rates_den'] = parseFloat(json['reporting_period_efficiency']['increment_rates_den'][index] * 100).toFixed(2) + "%";
404
          cardSummaryArray.push(cardSummaryItem);
405
        });
406
        setCardSummaryList(cardSummaryArray);
407
408
        let base_timestamps = {}
409
        json['base_period_efficiency']['timestamps'].forEach((currentValue, index) => {
410
          base_timestamps['a' + index] = currentValue;
411
        });
412
        json['base_period_efficiency']['numerator_timestamps'].forEach((currentValue, index) => {
413
          base_timestamps['b' + index] = currentValue;
414
        });
415
        json['base_period_efficiency']['denominator_timestamps'].forEach((currentValue, index) => {
416
          base_timestamps['c' + index] = currentValue;
417
        });
418
        setCombinedEquipmentBaseLabels(base_timestamps)
419
420
        let base_values = {}
421
        json['base_period_efficiency']['values'].forEach((currentValue, index) => {
422
          base_values['a' + index] = currentValue;
423
        });
424
        json['base_period_efficiency']['numerator_values'].forEach((currentValue, index) => {
425
          base_values['b' + index] = currentValue;
426
        });
427
        json['base_period_efficiency']['denominator_values'].forEach((currentValue, index) => {
428
          base_values['c' + index] = currentValue;
429
        });
430
        setCombinedEquipmentBaseData(base_values)
431
432
        /*
433
        * Tip:
434
        *     base_names === reporting_names
435
        *     base_units === reporting_units
436
        * */
437
438
        let base_and_reporting_names = {}
439
        json['reporting_period_efficiency']['names'].forEach((currentValue, index) => {
440
          base_and_reporting_names['a' + index] = currentValue;
441
        });
442
        json['reporting_period_efficiency']['numerator_names'].forEach((currentValue, index) => {
443
          base_and_reporting_names['b' + index] = currentValue;
444
        });
445
        json['reporting_period_efficiency']['denominator_names'].forEach((currentValue, index) => {
446
          base_and_reporting_names['c' + index] = currentValue;
447
        });
448
        setCombinedEquipmentBaseAndReportingNames(base_and_reporting_names)
449
450
        let base_and_reporting_units = {}
451
        json['reporting_period_efficiency']['units'].forEach((currentValue, index) => {
452
          base_and_reporting_units['a' + index] = "("+currentValue+")";
453
        });
454
        json['reporting_period_efficiency']['numerator_units'].forEach((currentValue, index) => {
455
          base_and_reporting_units['b' + index] = "("+currentValue+")";
456
        });
457
        json['reporting_period_efficiency']['denominator_units'].forEach((currentValue, index) => {
458
          base_and_reporting_units['c' + index] = "("+currentValue+")";
459
        });
460
        setCombinedEquipmentBaseAndReportingUnits(base_and_reporting_units)
461
462
        let base_subtotals = {}
463
        json['base_period_efficiency']['cumulations'].forEach((currentValue, index) => {
464
          base_subtotals['a' + index] = currentValue.toFixed(2);
465
        });
466
        json['base_period_efficiency']['numerator_cumulations'].forEach((currentValue, index) => {
467
          base_subtotals['b' + index] = currentValue.toFixed(2);
468
        });
469
        json['base_period_efficiency']['denominator_cumulations'].forEach((currentValue, index) => {
470
          base_subtotals['c' + index] = currentValue.toFixed(2);
471
        });
472
        setCombinedEquipmentBaseSubtotals(base_subtotals)
473
474
        let reporting_timestamps = {}
475
        json['reporting_period_efficiency']['timestamps'].forEach((currentValue, index) => {
476
          reporting_timestamps['a' + index] = currentValue;
477
        });
478
        json['reporting_period_efficiency']['numerator_timestamps'].forEach((currentValue, index) => {
479
          reporting_timestamps['b' + index] = currentValue;
480
        });
481
        json['reporting_period_efficiency']['denominator_timestamps'].forEach((currentValue, index) => {
482
          reporting_timestamps['c' + index] = currentValue;
483
        });
484
        setCombinedEquipmentReportingLabels(reporting_timestamps);
485
486
        let reporting_values = {}
487
        json['reporting_period_efficiency']['values'].forEach((currentValue, index) => {
488
          reporting_values['a' + index] = currentValue;
489
        });
490
        json['reporting_period_efficiency']['numerator_values'].forEach((currentValue, index) => {
491
          reporting_values['b' + index] = currentValue;
492
        });
493
        json['reporting_period_efficiency']['denominator_values'].forEach((currentValue, index) => {
494
          reporting_values['c' + index] = currentValue;
495
        });
496
        setCombinedEquipmentReportingData(reporting_values);
497
498
        let reporting_subtotals = {}
499
        json['reporting_period_efficiency']['cumulations'].forEach((currentValue, index) => {
500
          reporting_subtotals['a' + index] = currentValue.toFixed(2);
501
        });
502
        json['reporting_period_efficiency']['numerator_cumulations'].forEach((currentValue, index) => {
503
          reporting_subtotals['b' + index] = currentValue.toFixed(2);
504
        });
505
        json['reporting_period_efficiency']['denominator_cumulations'].forEach((currentValue, index) => {
506
          reporting_subtotals['c' + index] = currentValue.toFixed(2);
507
        });
508
        setCombinedEquipmentReportingSubtotals(reporting_subtotals);
509
510
        let rates = {}
511
        json['reporting_period_efficiency']['rates'].forEach((currentValue, index) => {
512
          let currentRate = Array();
513
          currentValue.forEach((rate) => {
514
            currentRate.push(rate ? parseFloat(rate * 100).toFixed(2) : '0.00');
515
          });
516
          rates['a' + index] = currentRate;
517
        });
518
        json['reporting_period_efficiency']['numerator_rates'].forEach((currentValue, index) => {
519
          let currentRate = Array();
520
          currentValue.forEach((rate) => {
521
            currentRate.push(rate ? parseFloat(rate * 100).toFixed(2) : '0.00');
522
          });
523
          rates['b' + index] = currentRate;
524
        });
525
        json['reporting_period_efficiency']['denominator_rates'].forEach((currentValue, index) => {
526
          let currentRate = Array();
527
          currentValue.forEach((rate) => {
528
            currentRate.push(rate ? parseFloat(rate * 100).toFixed(2) : '0.00');
529
          });
530
          rates['c' + index] = currentRate;
531
        });
532
        setCombinedEquipmentReportingRates(rates)
533
534
        let options = Array();
535
        json['reporting_period_efficiency']['names'].forEach((currentValue, index) => {
536
          let unit = json['reporting_period_efficiency']['units'][index];
537
          options.push({ 'value': 'a' + index, 'label': currentValue + ' (' + unit + ')'});
538
        });
539
        json['reporting_period_efficiency']['numerator_names'].forEach((currentValue, index) => {
540
          let name = json['reporting_period_efficiency']['names'][index];
541
          let unit = json['reporting_period_efficiency']['numerator_units'][index];
542
          options.push({ 'value': 'b' + index, 'label': name + "-" + currentValue + ' (' + unit + ')'});
543
        });
544
        json['reporting_period_efficiency']['denominator_names'].forEach((currentValue, index) => {
545
          let name = json['reporting_period_efficiency']['names'][index];
546
          let unit = json['reporting_period_efficiency']['denominator_units'][index];
547
          options.push({ 'value': 'c' + index, 'label': name + "-" + currentValue + ' (' + unit + ')'});
548
        });
549
        setCombinedEquipmentReportingOptions(sortByNumber(options, "value"));
550
       
551
        let timestamps = {}
552
        json['parameters']['timestamps'].forEach((currentValue, index) => {
553
          timestamps['a' + index] = currentValue;
554
        });
555
        setParameterLineChartLabels(timestamps);
556
557
        let values = {}
558
        json['parameters']['values'].forEach((currentValue, index) => {
559
          values['a' + index] = currentValue;
560
        });
561
        setParameterLineChartData(values);
562
      
563
        let names = Array();
564
        json['parameters']['names'].forEach((currentValue, index) => {
565
          
566
          names.push({ 'value': 'a' + index, 'label': currentValue });
567
        });
568
        setParameterLineChartOptions(names);
569
570
        if(!isBasePeriodTimestampExists(json['base_period_efficiency'])) {
571
          let detailed_value_list = [];
572
          if (json['reporting_period_efficiency']['timestamps'].length > 0) {
573
            json['reporting_period_efficiency']['timestamps'][0].forEach((currentTimestamp, timestampIndex) => {
574
              let detailed_value = {};
575
              detailed_value['id'] = timestampIndex;
576
              detailed_value['startdatetime'] = currentTimestamp;
577
              json['reporting_period_efficiency']['values'].forEach((currentValue, parameterIndex) => {
578
                if (json['reporting_period_efficiency']['values'][parameterIndex][timestampIndex] != null) {
579
                  detailed_value['a' + parameterIndex] = json['reporting_period_efficiency']['values'][parameterIndex][timestampIndex];
580
                } else {
581
                  detailed_value['a' + parameterIndex] = null;
582
                }
583
                ;
584
              });
585
              json['reporting_period_efficiency']['numerator_values'].forEach((currentValue, parameterIndex) => {
586
                if (json['reporting_period_efficiency']['numerator_values'][parameterIndex][timestampIndex] != null) {
587
                  detailed_value['b' + parameterIndex] = json['reporting_period_efficiency']['numerator_values'][parameterIndex][timestampIndex];
588
                } else {
589
                  detailed_value['b' + parameterIndex] = null;
590
                }
591
                ;
592
              });
593
              json['reporting_period_efficiency']['denominator_values'].forEach((currentValue, parameterIndex) => {
594
                if (json['reporting_period_efficiency']['denominator_values'][parameterIndex][timestampIndex] != null) {
595
                  detailed_value['c' + parameterIndex] = json['reporting_period_efficiency']['denominator_values'][parameterIndex][timestampIndex];
596
                } else {
597
                  detailed_value['c' + parameterIndex] = null;
598
                }
599
                ;
600
              });
601
              detailed_value_list.push(detailed_value);
602
            });
603
          }
604
          ;
605
606
          let detailed_value = {};
607
          detailed_value['id'] = detailed_value_list.length;
608
          detailed_value['startdatetime'] = t('Subtotal');
609
          json['reporting_period_efficiency']['cumulations'].forEach((currentValue, index) => {
610
            detailed_value['a' + index] = currentValue;
611
          });
612
          json['reporting_period_efficiency']['numerator_cumulations'].forEach((currentValue, index) => {
613
            detailed_value['b' + index] = currentValue;
614
          });
615
          json['reporting_period_efficiency']['denominator_cumulations'].forEach((currentValue, index) => {
616
            detailed_value['c' + index] = currentValue;
617
          });
618
619
          detailed_value_list.push(detailed_value);
620
          setTimeout(() => {
621
            setDetailedDataTableData(detailed_value_list);
622
          }, 0)
623
624
          let detailed_column_list = [];
625
          detailed_column_list.push({
626
            dataField: 'startdatetime',
627
            text: t('Datetime'),
628
            sort: true
629
          })
630
          json['reporting_period_efficiency']['names'].forEach((currentValue, index) => {
631
            let unit = json['reporting_period_efficiency']['units'][index];
632
            let numerator_name = json['reporting_period_efficiency']['numerator_names'][index];
633
            let numerator_unit = json['reporting_period_efficiency']['numerator_units'][index];
634
            let denominator_name = json['reporting_period_efficiency']['denominator_names'][index];
635
            let denominator_unit = json['reporting_period_efficiency']['denominator_units'][index];
636
            detailed_column_list.push({
637
              dataField: 'a' + index,
638
              text: currentValue + ' (' + unit + ')',
639
              sort: true,
640
              formatter: function (decimalValue) {
641
                if (typeof decimalValue === 'number') {
642
                  return decimalValue.toFixed(2);
643
                } else {
644
                  return null;
645
                }
646
              }
647
            })
648
            detailed_column_list.push({
649
              dataField: 'b' + index,
650
              text: currentValue + '-' + numerator_name + ' (' + numerator_unit + ')',
651
              sort: true,
652
              formatter: function (decimalValue) {
653
                if (typeof decimalValue === 'number') {
654
                  return decimalValue.toFixed(2);
655
                } else {
656
                  return null;
657
                }
658
              }
659
            })
660
            detailed_column_list.push({
661
              dataField: 'c' + index,
662
              text: currentValue + '-' + denominator_name + ' (' + denominator_unit + ')',
663
              sort: true,
664
              formatter: function (decimalValue) {
665
                if (typeof decimalValue === 'number') {
666
                  return decimalValue.toFixed(2);
667
                } else {
668
                  return null;
669
                }
670
              }
671
            })
672
          });
673
          setDetailedDataTableColumns(detailed_column_list);
674
        }else {
675
          /*
676
          * Tip:
677
          *     json['base_period_efficiency']['names'] ===  json['reporting_period_efficiency']['names']
678
          *     json['base_period_efficiency']['units'] ===  json['reporting_period_efficiency']['units']
679
          * */
680
          let detailed_column_list = [];
681
          detailed_column_list.push({
682
            dataField: 'basePeriodDatetime',
683
            text: t('Base Period') + ' - ' + t('Datetime'),
684
            sort: true
685
          })
686
687
          let original_detailed_column_list = []
688
          json['reporting_period_efficiency']['names'].forEach((currentValue, index) => {
689
            let unit = json['reporting_period_efficiency']['units'][index];
690
            original_detailed_column_list.push({
691
              dataField: 'a' + index,
692
              text: t('Base Period') + ' - ' + currentValue + ' (' + unit + ')',
693
              sort: true,
694
              formatter: function (decimalValue) {
695
                if (typeof decimalValue === 'number') {
696
                  return decimalValue.toFixed(2);
697
                } else {
698
                  return null;
699
                }
700
              }
701
            })
702
          });
703
704
          json['reporting_period_efficiency']['numerator_names'].forEach((currentValue, index) => {
705
            let name = json['reporting_period_efficiency']['names'][index]
706
            let unit = json['reporting_period_efficiency']['numerator_units'][index];
707
            original_detailed_column_list.push({
708
              dataField: 'b' + index,
709
              text: t('Base Period') + ' - ' + name + '-' + currentValue + ' (' + unit + ')',
710
              sort: true,
711
              formatter: function (decimalValue) {
712
                if (typeof decimalValue === 'number') {
713
                  return decimalValue.toFixed(2);
714
                } else {
715
                  return null;
716
                }
717
              }
718
            })
719
          });
720
721
          json['reporting_period_efficiency']['denominator_names'].forEach((currentValue, index) => {
722
            let name = json['reporting_period_efficiency']['names'][index]
723
            let unit = json['reporting_period_efficiency']['denominator_units'][index];
724
            original_detailed_column_list.push({
725
              dataField: 'c' + index,
726
              text: t('Base Period') + ' - ' + name + '-' + currentValue + ' (' + unit + ')',
727
              sort: true,
728
              formatter: function (decimalValue) {
729
                if (typeof decimalValue === 'number') {
730
                  return decimalValue.toFixed(2);
731
                } else {
732
                  return null;
733
                }
734
              }
735
            })
736
          });
737
738
          detailed_column_list = [...detailed_column_list, ...sortByNumber(original_detailed_column_list, "dataField")];
739
740
          detailed_column_list.push({
741
            dataField: 'reportingPeriodDatetime',
742
            text: t('Reporting Period') + ' - ' + t('Datetime'),
743
            sort: true
744
          })
745
746
          original_detailed_column_list = []
747
          json['reporting_period_efficiency']['names'].forEach((currentValue, index) => {
748
            let unit = json['reporting_period_efficiency']['units'][index];
749
            original_detailed_column_list.push({
750
              dataField: 'd' + index,
751
              text: t('Reporting Period') + ' - ' + currentValue + ' (' + unit + ')',
752
              sort: true,
753
              formatter: function (decimalValue) {
754
                if (typeof decimalValue === 'number') {
755
                  return decimalValue.toFixed(2);
756
                } else {
757
                  return null;
758
                }
759
              }
760
            })
761
          });
762
763
          json['reporting_period_efficiency']['numerator_names'].forEach((currentValue, index) => {
764
            let name = json['reporting_period_efficiency']['names'][index]
765
            let unit = json['reporting_period_efficiency']['numerator_units'][index];
766
            original_detailed_column_list.push({
767
              dataField: 'e' + index,
768
              text: t('Reporting Period') + ' - ' + name + '-' + currentValue + ' (' + unit + ')',
769
              sort: true,
770
              formatter: function (decimalValue) {
771
                if (typeof decimalValue === 'number') {
772
                  return decimalValue.toFixed(2);
773
                } else {
774
                  return null;
775
                }
776
              }
777
            })
778
          });
779
780
          json['reporting_period_efficiency']['denominator_names'].forEach((currentValue, index) => {
781
            let name = json['reporting_period_efficiency']['names'][index]
782
            let unit = json['reporting_period_efficiency']['denominator_units'][index];
783
            original_detailed_column_list.push({
784
              dataField: 'f' + index,
785
              text: t('Reporting Period') + ' - ' + name + '-' + currentValue + ' (' + unit + ')',
786
              sort: true,
787
              formatter: function (decimalValue) {
788
                if (typeof decimalValue === 'number') {
789
                  return decimalValue.toFixed(2);
790
                } else {
791
                  return null;
792
                }
793
              }
794
            })
795
          });
796
          detailed_column_list = [...detailed_column_list, ...sortByNumber(original_detailed_column_list, "dataField")];
797
          setDetailedDataTableColumns(detailed_column_list);
798
799
          let detailed_value_list = [];
800
          if (json['base_period_efficiency']['timestamps'].length > 0 || json['reporting_period_efficiency']['timestamps'].length > 0) {
801
            const max_timestamps_length = json['base_period_efficiency']['timestamps'][0].length >= json['reporting_period_efficiency']['timestamps'][0].length ?
802
                json['base_period_efficiency']['timestamps'][0].length : json['reporting_period_efficiency']['timestamps'][0].length;
803
            for (let index = 0; index < max_timestamps_length; index++) {
804
              let detailed_value = {};
805
              detailed_value['id'] = index;
806
              detailed_value['basePeriodDatetime'] = index < json['base_period_efficiency']['timestamps'][0].length ? json['base_period_efficiency']['timestamps'][0][index] : null;
807
              json['base_period_efficiency']['values'].forEach((currentValue, energyCategoryIndex) => {
808
                detailed_value['a' + energyCategoryIndex] = index < json['base_period_efficiency']['values'][energyCategoryIndex].length ? json['base_period_efficiency']['values'][energyCategoryIndex][index] : null;
809
              });
810
              json['base_period_efficiency']['numerator_values'].forEach((currentValue, energyCategoryIndex) => {
811
                detailed_value['b' + energyCategoryIndex] = index < json['base_period_efficiency']['numerator_values'][energyCategoryIndex].length ? json['base_period_efficiency']['numerator_values'][energyCategoryIndex][index] : null;
812
              });
813
              json['base_period_efficiency']['denominator_values'].forEach((currentValue, energyCategoryIndex) => {
814
                detailed_value['c' + energyCategoryIndex] = index < json['base_period_efficiency']['denominator_values'][energyCategoryIndex].length ? json['base_period_efficiency']['denominator_values'][energyCategoryIndex][index] : null;
815
              });
816
              detailed_value['reportingPeriodDatetime'] = index < json['reporting_period_efficiency']['timestamps'][0].length ? json['reporting_period_efficiency']['timestamps'][0][index] : null;
817
              json['reporting_period_efficiency']['values'].forEach((currentValue, energyCategoryIndex) => {
818
                detailed_value['d' + energyCategoryIndex] = index < json['reporting_period_efficiency']['values'][energyCategoryIndex].length ? json['reporting_period_efficiency']['values'][energyCategoryIndex][index] : null;
819
              });
820
              json['reporting_period_efficiency']['numerator_values'].forEach((currentValue, energyCategoryIndex) => {
821
                detailed_value['e' + energyCategoryIndex] = index < json['reporting_period_efficiency']['numerator_values'][energyCategoryIndex].length ? json['reporting_period_efficiency']['numerator_values'][energyCategoryIndex][index] : null;
822
              });
823
              json['reporting_period_efficiency']['values'].forEach((currentValue, energyCategoryIndex) => {
824
                detailed_value['f' + energyCategoryIndex] = index < json['reporting_period_efficiency']['denominator_values'][energyCategoryIndex].length ? json['reporting_period_efficiency']['denominator_values'][energyCategoryIndex][index] : null;
825
              });
826
              detailed_value_list.push(detailed_value);
827
            }
828
829
            let detailed_value = {};
830
            detailed_value['id'] = detailed_value_list.length;
831
            detailed_value['basePeriodDatetime'] = t('Subtotal');
832
            json['base_period_efficiency']['cumulations'].forEach((currentValue, index) => {
833
              detailed_value['a' + index] = currentValue;
834
            });
835
            json['base_period_efficiency']['numerator_cumulations'].forEach((currentValue, index) => {
836
              detailed_value['b' + index] = currentValue;
837
            });
838
            json['base_period_efficiency']['denominator_cumulations'].forEach((currentValue, index) => {
839
              detailed_value['c' + index] = currentValue;
840
            });
841
            detailed_value['reportingPeriodDatetime'] = t('Subtotal');
842
            json['reporting_period_efficiency']['cumulations'].forEach((currentValue, index) => {
843
              detailed_value['d' + index] = currentValue;
844
            });
845
            json['reporting_period_efficiency']['numerator_cumulations'].forEach((currentValue, index) => {
846
              detailed_value['e' + index] = currentValue;
847
            });
848
            json['reporting_period_efficiency']['denominator_cumulations'].forEach((currentValue, index) => {
849
              detailed_value['f' + index] = currentValue;
850
            });
851
            detailed_value_list.push(detailed_value);
852
            setTimeout(() => {
853
              setDetailedDataTableData(detailed_value_list);
854
            }, 0)
855
          }
856
        }
857
858
        let associated_equipment_value_list = [];
859
        if (json['associated_equipment']['associated_equipment_names_array'].length > 0) {
860
          json['associated_equipment']['associated_equipment_names_array'][0].forEach((currentEquipmentName, equipmentIndex) => {
861
            let associated_equipment_value = {};
862
            associated_equipment_value['id'] = equipmentIndex;
863
            associated_equipment_value['name'] = currentEquipmentName;
864
            json['associated_equipment']['energy_category_names'].forEach((currentValue, energyCategoryIndex) => {
865
              associated_equipment_value['a' + energyCategoryIndex] = json['associated_equipment']['subtotals_array'][energyCategoryIndex][equipmentIndex].toFixed(2);
866
            });
867
            associated_equipment_value_list.push(associated_equipment_value);
868
          });
869
        };
870
871
        setAssociatedEquipmentTableData(associated_equipment_value_list);
872
873
        let associated_equipment_column_list = [];
874
        associated_equipment_column_list.push({
875
          dataField: 'name',
876
          text: t('Associated Equipment'),
877
          sort: true
878
        });
879
        json['associated_equipment']['energy_category_names'].forEach((currentValue, index) => {
880
          let unit = json['associated_equipment']['units'][index];
881
          associated_equipment_column_list.push({
882
            dataField: 'a' + index,
883
            text: currentValue + ' (' + unit + ')',
884
            sort: true
885
          });
886
        });
887
888
        setAssociatedEquipmentTableColumns(associated_equipment_column_list);
889
890
        setExcelBytesBase64(json['excel_bytes_base64']);
891
      
892
        // enable submit button
893
        setSubmitButtonDisabled(false);
894
        // hide spinner
895
        setSpinnerHidden(true);
896
        // show export button
897
        setExportButtonHidden(false);
898
899
      } else {
900
        toast.error(t(json.description))
901
      }
902
    }).catch(err => {
903
      console.log(err);
904
    });      
905
  };
906
  
907
  const handleExport = e => {
908
    e.preventDefault();
909
    const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
910
    const fileName = 'combinedequipmentefficiency.xlsx'
911
    var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64;
912
    fetch(fileUrl)
913
        .then(response => response.blob())
914
        .then(blob => {
915
            var link = window.document.createElement("a");
916
            link.href = window.URL.createObjectURL(blob, { type: mimeType });
917
            link.download = fileName;
918
            document.body.appendChild(link);
919
            link.click();
920
            document.body.removeChild(link);
921
        });
922
  };
923
  
924
925
  return (
926
    <Fragment>
927
      <div>
928
        <Breadcrumb>
929
          <BreadcrumbItem>{t('Combined Equipment Data')}</BreadcrumbItem><BreadcrumbItem active>{t('Efficiency')}</BreadcrumbItem>
930
        </Breadcrumb>
931
      </div>
932
      <Card className="bg-light mb-3">
933
        <CardBody className="p-3">
934
          <Form onSubmit={handleSubmit}>
935
            <Row form>
936
              <Col xs={6} sm={3}>
937
                <FormGroup className="form-group">
938
                  <Label className={labelClasses} for="space">
939
                    {t('Space')}
940
                  </Label>
941
                  <br />
942
                  <Cascader options={cascaderOptions}
943
                    onChange={onSpaceCascaderChange}
944
                    changeOnSelect
945
                    expandTrigger="hover">
946
                    <Input value={selectedSpaceName || ''} readOnly />
947
                  </Cascader>
948
                </FormGroup>
949
              </Col>
950
              <Col xs="auto">
951
                <FormGroup>
952
                  <Label className={labelClasses} for="combinedEquipmentSelect">
953
                    {t('Combined Equipment')}
954
                  </Label>
955
                  <CustomInput type="select" id="combinedEquipmentSelect" name="combinedEquipmentSelect" onChange={({ target }) => setSelectedCombinedEquipment(target.value)}
956
                  >
957
                    {combinedEquipmentList.map((combinedEquipment, index) => (
958
                      <option value={combinedEquipment.value} key={combinedEquipment.value}>
959
                        {combinedEquipment.label}
960
                      </option>
961
                    ))}
962
                  </CustomInput>
963
                </FormGroup>
964
              </Col>
965
              <Col xs="auto">
966
                <FormGroup>
967
                  <Label className={labelClasses} for="comparisonType">
968
                    {t('Comparison Types')}
969
                  </Label>
970
                  <CustomInput type="select" id="comparisonType" name="comparisonType"
971
                    defaultValue="month-on-month"
972
                    onChange={onComparisonTypeChange}
973
                  >
974
                    {comparisonTypeOptions.map((comparisonType, index) => (
975
                      <option value={comparisonType.value} key={comparisonType.value} >
976
                        {t(comparisonType.label)}
977
                      </option>
978
                    ))}
979
                  </CustomInput>
980
                </FormGroup>
981
              </Col>
982
              <Col xs="auto">
983
                <FormGroup>
984
                  <Label className={labelClasses} for="periodType">
985
                    {t('Period Types')}
986
                  </Label>
987
                  <CustomInput type="select" id="periodType" name="periodType" defaultValue="daily" onChange={({ target }) => setPeriodType(target.value)}
988
                  >
989
                    {periodTypeOptions.map((periodType, index) => (
990
                      <option value={periodType.value} key={periodType.value} >
991
                        {t(periodType.label)}
992
                      </option>
993
                    ))}
994
                  </CustomInput>
995
                </FormGroup>
996
              </Col>
997
              <Col xs={6} sm={3}>
998
                <FormGroup className="form-group">
999
                  <Label className={labelClasses} for="basePeriodDateRangePicker">{t('Base Period')}{t('(Optional)')}</Label>
1000
                  <DateRangePickerWrapper 
1001
                    id='basePeriodDateRangePicker'
1002
                    disabled={basePeriodDateRangePickerDisabled}
1003
                    format="yyyy-MM-dd HH:mm:ss"
1004
                    value={basePeriodDateRange}
1005
                    onChange={onBasePeriodChange}
1006
                    size="md"
1007
                    style={dateRangePickerStyle}
1008
                    onClean={onBasePeriodClean}
1009
                    locale={dateRangePickerLocale}
1010
                    placeholder={t("Select Date Range")}
1011
                   />
1012
                </FormGroup>
1013
              </Col>
1014
              <Col xs={6} sm={3}>
1015
                <FormGroup className="form-group">
1016
                  <Label className={labelClasses} for="reportingPeriodDateRangePicker">{t('Reporting Period')}</Label>
1017
                  <br/>
1018
                  <DateRangePickerWrapper
1019
                    id='reportingPeriodDateRangePicker'
1020
                    format="yyyy-MM-dd HH:mm:ss"
1021
                    value={reportingPeriodDateRange}
1022
                    onChange={onReportingPeriodChange}
1023
                    size="md"
1024
                    style={dateRangePickerStyle}
1025
                    onClean={onReportingPeriodClean}
1026
                    locale={dateRangePickerLocale}
1027
                    placeholder={t("Select Date Range")}
1028
                  />
1029
                </FormGroup>
1030
              </Col>
1031
              <Col xs="auto">
1032
                <FormGroup>
1033
                  <br></br>
1034
                  <ButtonGroup id="submit">
1035
                    <Button color="success" disabled={submitButtonDisabled} >{t('Submit')}</Button>
1036
                  </ButtonGroup>
1037
                </FormGroup>
1038
              </Col>
1039
              <Col xs="auto">
1040
                <FormGroup>
1041
                  <br></br>
1042
                  <Spinner color="primary" hidden={spinnerHidden}  />
1043
                </FormGroup>
1044
              </Col>
1045
              <Col xs="auto">
1046
                  <br></br>
1047
                  <ButtonIcon icon="external-link-alt" transform="shrink-3 down-2" color="falcon-default" 
1048
                  hidden={exportButtonHidden}
1049
                  onClick={handleExport} >
1050
                    {t('Export')}
1051
                  </ButtonIcon>
1052
              </Col>
1053
            </Row>
1054
          </Form>
1055
        </CardBody>
1056
      </Card>
1057
      {cardSummaryList.map(cardSummaryItem => (
1058
        <div className="card-deck" key={cardSummaryItem['name']}>
1059
          <CardSummary key={cardSummaryItem['name']}
1060
            rate={cardSummaryItem['increment_rate']}
1061
            title={t('Reporting Period Cumulative Efficiency NAME UNIT', { 'NAME': cardSummaryItem['name'], 'UNIT': '(' + cardSummaryItem['unit'] + ')' })}
1062
            color="success" >
1063
            {cardSummaryItem['cumulation'] && <CountUp end={cardSummaryItem['cumulation']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
1064
          </CardSummary>
1065
          <CardSummary key={cardSummaryItem['numerator_name']}
1066
            rate={cardSummaryItem['increment_rates_num']}
1067
            title={t('Reporting Period Output CATEGORY UNIT', { 'CATEGORY': cardSummaryItem['name'] + '-' + cardSummaryItem['numerator_name'], 'UNIT': '(' + cardSummaryItem['numerator_unit'] + ')' })}
1068
            color="success" >
1069
            {cardSummaryItem['numerator_cumulation'] && <CountUp end={cardSummaryItem['numerator_cumulation']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
1070
          </CardSummary>
1071
          <CardSummary key={cardSummaryItem['denominator_name']}
1072
            rate={cardSummaryItem['increment_rates_den']}
1073
            title={t('Reporting Period Consumption CATEGORY UNIT', { 'CATEGORY': cardSummaryItem['name'] + '-' + cardSummaryItem['denominator_name'], 'UNIT': '(' + cardSummaryItem['denominator_unit'] + ')' })}
1074
            color="success" >
1075
            {cardSummaryItem['denominator_cumulation'] && <CountUp end={cardSummaryItem['denominator_cumulation']} duration={2} prefix="" separator="," decimal="." decimals={2} />}
1076
          </CardSummary>
1077
        </div>
1078
      ))}
1079
1080
      <MultiTrendChart reportingTitle = {{"name": "Reporting Period Cumulative Efficiency NAME VALUE UNIT", "substitute": ["NAME", "VALUE", "UNIT"], "NAME": combinedEquipmentBaseAndReportingNames, "VALUE": combinedEquipmentReportingSubtotals, "UNIT": combinedEquipmentBaseAndReportingUnits}}
1081
        baseTitle = {{"name": "Base Period Cumulative Efficiency NAME VALUE UNIT", "substitute": ["NAME", "VALUE", "UNIT"], "NAME": combinedEquipmentBaseAndReportingNames, "VALUE": combinedEquipmentBaseSubtotals, "UNIT": combinedEquipmentBaseAndReportingUnits}}
1082
        reportingTooltipTitle = {{"name": "Reporting Period Cumulative Efficiency NAME VALUE UNIT", "substitute": ["NAME", "VALUE", "UNIT"], "NAME": combinedEquipmentBaseAndReportingNames, "VALUE": null, "UNIT": combinedEquipmentBaseAndReportingUnits}}
1083
        baseTooltipTitle = {{"name": "Base Period Cumulative Efficiency NAME VALUE UNIT", "substitute": ["NAME", "VALUE", "UNIT"], "NAME": combinedEquipmentBaseAndReportingNames, "VALUE": null, "UNIT": combinedEquipmentBaseAndReportingUnits}}
1084
        reportingLabels={combinedEquipmentReportingLabels}
1085
        reportingData={combinedEquipmentReportingData}
1086
        baseLabels={combinedEquipmentBaseLabels}
1087
        baseData={combinedEquipmentBaseData}
1088
        rates={combinedEquipmentReportingRates}
1089
        options={combinedEquipmentReportingOptions}>
1090
      </MultiTrendChart>
1091
1092
      <MultipleLineChart reportingTitle={t('Related Parameters')}
1093
        baseTitle=''
1094
        labels={parameterLineChartLabels}
1095
        data={parameterLineChartData}
1096
        options={parameterLineChartOptions}>
1097
      </MultipleLineChart>
1098
      <br />
1099
      <DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={50} >
1100
      </DetailedDataTable>
1101
      <br />
1102
      <AssociatedEquipmentTable data={associatedEquipmentTableData} title={t('Associated Equipment Data')} columns={associatedEquipmentTableColumns}>
1103
      </AssociatedEquipmentTable>
1104
1105
    </Fragment>
1106
  );
1107
};
1108
1109
export default withTranslation()(withRedirect(CombinedEquipmentEfficiency));
1110