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

src/components/MyEMS/Space/SpaceEnergyCategory.js   A

Complexity

Total Complexity 19
Complexity/F 0

Size

Lines of Code 631
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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