Passed
Push — master ( 9b8d43...1b197b )
by
unknown
11:09 queued 14s
created

myems-web/src/components/MyEMS/EnergyStoragePowerStation/MultipleDashboard.js   A

Complexity

Total Complexity 14
Complexity/F 0

Size

Lines of Code 1333
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 571
mnd 14
bc 14
fnc 0
dl 0
loc 1333
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React, { Fragment, useEffect, useState, useContext } from 'react';
2
import CountUp from 'react-countup';
3
import { Col, Row, Spinner, Nav, NavItem, NavLink, TabContent, TabPane } from 'reactstrap';
4
import EnergyStoragePowerStationTableCard from './EnergyStoragePowerStationTableCard';
5
import CardSummary from '../common/CardSummary';
6
import { toast } from 'react-toastify';
7
import { getCookieValue, createCookie, checkEmpty } from '../../../helpers/utils';
8
import withRedirect from '../../../hoc/withRedirect';
9
import { withTranslation } from 'react-i18next';
10
import moment from 'moment';
11
import { APIBaseURL, settings } from '../../../config';
12
import { getItemFromStore } from '../../../helpers/utils';
13
import CustomizeMapBox from '../common/CustomizeMapBox';
14
import classNames from 'classnames';
15
import AppContext from '../../../context/Context';
16
import StackBarChart from './StackBarChart';
17
18
const MultipleDashboard = ({ setRedirect, setRedirectUrl, t }) => {
19
  let current_moment = moment();
20
  const [isFetchDashboard, setIsFetchDashboard] = useState(true);
21
  const [periodType, setPeriodType] = useState('monthly');
22
  const [basePeriodBeginsDatetime, setBasePeriodBeginsDatetime] = useState(
23
    current_moment
24
      .clone()
25
      .subtract(1, 'years')
26
      .startOf('year')
27
  );
28
  const [basePeriodEndsDatetime, setBasePeriodEndsDatetime] = useState(current_moment.clone().subtract(1, 'years'));
29
  const [reportingPeriodBeginsDatetime, setReportingPeriodBeginsDatetime] = useState(
30
    current_moment.clone().startOf('year')
31
  );
32
  const [reportingPeriodEndsDatetime, setReportingPeriodEndsDatetime] = useState(current_moment);
33
  const [spinnerHidden, setSpinnerHidden] = useState(false);
34
  const [activeTabLeft, setActiveTabLeft] = useState('1');
35
  const toggleTabLeft = tab => {
36
    if (activeTabLeft !== tab) setActiveTabLeft(tab);
37
  };
38
  const [activeTabRight, setActiveTabRight] = useState('1');
39
  const toggleTabRight = tab => {
40
    if (activeTabRight !== tab) setActiveTabRight(tab);
41
  };
42
  const { currency } = useContext(AppContext);
43
44
  //Results
45
46
  const [energyStoragePowerStationList, setEnergyStoragePowerStationList] = useState([]);
47
  const [totalRatedCapacity, setTotalRatedCapacity] = useState({});
48
  const [totalRatedPower, setTotalRatedPower] = useState({});
49
  const [chargeRankingList, setChargeRankingList] = useState([]);
50
  const [totalCharge, setTotalCharge] = useState({});
51
  const [dischargeRankingList, setDischargeRankingList] = useState([]);
52
  const [totalDischarge, setTotalDischarge] = useState({});
53
  const [revenueRankingList, setRevenueRankingList] = useState([]);
54
  const [totalRevenue, setTotalRevenue] = useState({});
55
56
  const [chargeData, setChargeData] = useState({});
57
  const [dischargeData, setDischargeData] = useState({});
58
  const [monthLabels, setMonthLabels] = useState([]);
59
  const [stations, setStations] = useState([]);
60
  const [language, setLanguage] = useState(getItemFromStore('myems_web_ui_language', settings.language));
61
  const [geojson, setGeojson] = useState({});
62
  const [rootLatitude, setRootLatitude] = useState('');
63
  const [rootLongitude, setRootLongitude] = useState('');
64
65
  useEffect(() => {
66
    let is_logged_in = getCookieValue('is_logged_in');
67
    let user_name = getCookieValue('user_name');
68
    let user_display_name = getCookieValue('user_display_name');
69
    let user_uuid = getCookieValue('user_uuid');
70
    let token = getCookieValue('token');
71
    if (checkEmpty(is_logged_in) || checkEmpty(token) || checkEmpty(user_uuid) || !is_logged_in) {
72
      setRedirectUrl(`/authentication/basic/login`);
73
      setRedirect(true);
74
    } else {
75
      //update expires time of cookies
76
      createCookie('is_logged_in', true, settings.cookieExpireTime);
77
      createCookie('user_name', user_name, settings.cookieExpireTime);
78
      createCookie('user_display_name', user_display_name, settings.cookieExpireTime);
79
      createCookie('user_uuid', user_uuid, settings.cookieExpireTime);
80
      createCookie('token', token, settings.cookieExpireTime);
81
82
      let isResponseOK = false;
83
      if (isFetchDashboard) {
84
        setIsFetchDashboard(false);
85
        toast(
86
          <Fragment>
87
            {t('Welcome to MyEMS')}
88
            <br />
89
            {t('An Industry Leading Open Source Energy Management System')}
90
          </Fragment>
91
        );
92
93
        fetch(
94
          APIBaseURL +
95
            '/reports/energystoragepowerstationdashboard?' +
96
            'useruuid=' +
97
            user_uuid +
98
            '&periodtype=' +
99
            periodType +
100
            '&baseperiodstartdatetime=' +
101
            (basePeriodBeginsDatetime != null ? basePeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') +
102
            '&baseperiodenddatetime=' +
103
            (basePeriodEndsDatetime != null ? basePeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss') : '') +
104
            '&reportingperiodstartdatetime=' +
105
            reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') +
106
            '&reportingperiodenddatetime=' +
107
            reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'),
108
          {
109
            method: 'GET',
110
            headers: {
111
              'Content-type': 'application/json',
112
              'User-UUID': getCookieValue('user_uuid'),
113
              Token: getCookieValue('token')
114
            },
115
            body: null
116
          }
117
        )
118
          .then(response => {
119
            if (response.ok) {
120
              isResponseOK = true;
121
            }
122
            return response.json();
123
          })
124
          .then(json => {
125
            if (isResponseOK) {
126
              console.log(json);
127
              // hide spinner
128
              setSpinnerHidden(true);
129
130
              let energyStoragePowerStationList = [];
131
              let chargeRankingList = [];
132
              let dischargeRankingList = [];
133
              let revenueList = [];
134
              let totalRatedCapacity = 0;
135
              let totalRatedPower = 0;
136
137
              setRootLongitude(json['energy_storage_power_stations'][0]['longitude']);
138
              setRootLatitude(json['energy_storage_power_stations'][0]['latitude']);
139
              let geojson = {};
140
              let geojsonData = [];
141
              json['energy_storage_power_stations'].forEach((currentValue, index) => {
142
                let energyStoragePowerStationItem = json['energy_storage_power_stations'][index];
143
                totalRatedCapacity += energyStoragePowerStationItem['rated_capacity'];
144
                totalRatedPower += energyStoragePowerStationItem['rated_power'];
145
                if (energyStoragePowerStationItem['latitude'] && energyStoragePowerStationItem['longitude']) {
146
                  geojsonData.push({
147
                    type: 'Feature',
148
                    geometry: {
149
                      type: 'Point',
150
                      coordinates: [energyStoragePowerStationItem['longitude'], energyStoragePowerStationItem['latitude']]
151
                    },
152
                    properties: {
153
                      title: energyStoragePowerStationItem['name'],
154
                      description: energyStoragePowerStationItem['description'],
155
                      uuid: energyStoragePowerStationItem['uuid'],
156
                      url: '/energystoragepowerstation/details'
157
                    }
158
                  });
159
                }
160
                energyStoragePowerStationItem['nameuuid'] = energyStoragePowerStationItem['name'] + energyStoragePowerStationItem['uuid']
161
                energyStoragePowerStationList.push(energyStoragePowerStationItem);
162
163
              });
164
              setEnergyStoragePowerStationList(energyStoragePowerStationList);
165
              setTotalRatedCapacity(totalRatedCapacity);
166
              setTotalRatedPower(totalRatedPower);
167
              geojson['type'] = 'FeatureCollection';
168
              geojson['features'] = geojsonData;
169
              setGeojson(geojson);
170
171
              json['charge_ranking'].forEach((currentValue, index) => {
172
                // display at most 8 items
173
                if (index < 9) {
174
                  let energyStoragePowerStationItem = json['charge_ranking'][index];
175
                  energyStoragePowerStationItem['unit'] = 'kWh';
176
                  chargeRankingList.push(energyStoragePowerStationItem);
177
                }
178
              });
179
              setChargeRankingList(chargeRankingList);
180
              setTotalCharge(json['totalCharge']);
181
182
              json['discharge_ranking'].forEach((currentValue, index) => {
183
                // display at most 8 items
184
                if (index < 9) {
185
                  let energyStoragePowerStationItem = json['discharge_ranking'][index];
186
                  energyStoragePowerStationItem['unit'] = 'kWh';
187
                  dischargeRankingList.push(energyStoragePowerStationItem);
188
                }
189
              });
190
              setDischargeRankingList(dischargeRankingList);
191
              setTotalDischarge(json['totalDischarge']);
192
193
              json['revenue_ranking'].forEach((currentValue, index) => {
194
                // display at most 8 items
195
                if (index < 9) {
196
                  let energyStoragePowerStationItem = json['revenue_ranking'][index];
197
                  energyStoragePowerStationItem['unit'] = currency;
198
                  revenueList.push(energyStoragePowerStationItem);
199
                }
200
              });
201
              setRevenueRankingList(revenueList);
202
              setTotalRevenue(json['totalRevenue']);
203
204
              setChargeData({
205
                "energy_category_names": [
206
                  "电",
207
                  "自来水",
208
                  "中水"
209
                ],
210
                "units": [
211
                  "kWh",
212
                  "m³",
213
                  "m³"
214
                ],
215
                "station_names_array": [
216
                  [
217
                    "市政府",
218
                    "办公楼",
219
                    "商场",
220
                    "酒店",
221
                    "博物馆",
222
                    "工厂",
223
                    "连锁门店",
224
                    "住宅小区",
225
                    "医院",
226
                    "大学",
227
                    "机场",
228
                    "火车站",
229
                    "养殖场",
230
                    "公寓",
231
                    "地铁站",
232
                    "体育场",
233
                    "公用动力",
234
                    "数据中心",
235
                    "调试空间"
236
                  ],
237
                  [
238
                    "市政府",
239
                    "办公楼",
240
                    "商场",
241
                    "酒店",
242
                    "博物馆",
243
                    "工厂",
244
                    "连锁门店",
245
                    "住宅小区",
246
                    "医院",
247
                    "大学",
248
                    "机场",
249
                    "火车站",
250
                    "养殖场",
251
                    "公寓",
252
                    "地铁站",
253
                    "体育场",
254
                    "公用动力",
255
                    "数据中心",
256
                    "调试空间"
257
                  ],
258
                  [
259
                    "市政府",
260
                    "办公楼",
261
                    "商场",
262
                    "酒店",
263
                    "博物馆",
264
                    "工厂",
265
                    "连锁门店",
266
                    "住宅小区",
267
                    "医院",
268
                    "大学",
269
                    "机场",
270
                    "火车站",
271
                    "养殖场",
272
                    "公寓",
273
                    "地铁站",
274
                    "体育场",
275
                    "公用动力",
276
                    "数据中心",
277
                    "调试空间"
278
                  ]
279
                ],
280
                "subtotals_array": [
281
                  [
282
                    [
283
                      249750,
284
                      270624,
285
                      272466,
286
                      4923
287
                    ],
288
                    [
289
                      321643,
290
                      313145,
291
                      308747,
292
                      5850
293
                    ],
294
                    [
295
                      418717.4,
296
                      560630.81,
297
                      636595.148,
298
                      11413.727
299
                    ],
300
                    [
301
                      56443,
302
                      50486,
303
                      56289,
304
                      1025
305
                    ],
306
                    [
307
                      33373,
308
                      32371,
309
                      34711,
310
                      742
311
                    ],
312
                    [
313
                      265079,
314
                      241453,
315
                      280577,
316
                      6303
317
                    ],
318
                    [
319
                      915373,
320
                      890210,
321
                      927197,
322
                      17239
323
                    ],
324
                    [
325
                      298949,
326
                      295176,
327
                      295817,
328
                      5299
329
                    ],
330
                    [
331
                      391019,
332
                      403682,
333
                      388199,
334
                      6822
335
                    ],
336
                    [
337
                      86646,
338
                      88858,
339
                      81414,
340
                      1239
341
                    ],
342
                    [
343
                      56955,
344
                      54198,
345
                      53549,
346
                      856
347
                    ],
348
                    [
349
                      123019,
350
                      112940,
351
                      123116,
352
                      2354
353
                    ],
354
                    [
355
                      262764,
356
                      261836,
357
                      254340,
358
                      4490
359
                    ],
360
                    [
361
                      108901,
362
                      102409,
363
                      106710,
364
                      2036
365
                    ],
366
                    [
367
                      148513,
368
                      148198,
369
                      145109,
370
                      2387
371
                    ],
372
                    [
373
                      310292,
374
                      322014,
375
                      331632,
376
                      5663
377
                    ],
378
                    [
379
                      71470,
380
                      63270,
381
                      120189,
382
                      3689
383
                    ],
384
                    [
385
                      187,
386
                      173,
387
                      11712,
388
                      998
389
                    ],
390
                    [
391
                      8591912.256,
392
                      9846005.212,
393
                      10995783.798,
394
                      217001.644
395
                    ]
396
                  ],
397
                  [
398
                    [
399
                      0,
400
                      0,
401
                      0,
402
                      0
403
                    ],
404
                    [
405
                      119,
406
                      108,
407
                      126,
408
                      2
409
                    ],
410
                    [
411
                      0,
412
                      0,
413
                      0,
414
                      0
415
                    ],
416
                    [
417
                      0,
418
                      0,
419
                      0,
420
                      0
421
                    ],
422
                    [
423
                      0,
424
                      0,
425
                      0,
426
                      0
427
                    ],
428
                    [
429
                      0,
430
                      0,
431
                      0,
432
                      0
433
                    ],
434
                    [
435
                      8714,
436
                      8343,
437
                      3316,
438
                      0
439
                    ],
440
                    [
441
                      0,
442
                      0,
443
                      0,
444
                      0
445
                    ],
446
                    [
447
                      265,
448
                      253,
449
                      215,
450
                      3
451
                    ],
452
                    [
453
                      0,
454
                      0,
455
                      0,
456
                      0
457
                    ],
458
                    [
459
                      8714,
460
                      8343,
461
                      3316,
462
                      0
463
                    ],
464
                    [
465
                      0,
466
                      0,
467
                      0,
468
                      0
469
                    ],
470
                    [
471
                      0,
472
                      0,
473
                      0,
474
                      0
475
                    ],
476
                    [
477
                      0,
478
                      0,
479
                      0,
480
                      0
481
                    ],
482
                    [
483
                      0,
484
                      0,
485
                      0,
486
                      0
487
                    ],
488
                    [
489
                      0,
490
                      0,
491
                      0,
492
                      0
493
                    ],
494
                    [
495
                      0,
496
                      0,
497
                      0,
498
                      0
499
                    ],
500
                    [
501
                      0,
502
                      0,
503
                      0,
504
                      0
505
                    ],
506
                    [
507
                      17812,
508
                      17047,
509
                      6973,
510
                      5
511
                    ]
512
                  ],
513
                  [
514
                    [
515
                      546,
516
                      597,
517
                      56,
518
                      1
519
                    ],
520
                    [
521
                      106,
522
                      180,
523
                      91,
524
                      2
525
                    ],
526
                    [
527
                      0,
528
                      0,
529
                      0,
530
                      0
531
                    ],
532
                    [
533
                      47,
534
                      38,
535
                      71,
536
                      3
537
                    ],
538
                    [
539
                      133,
540
                      137,
541
                      136,
542
                      1
543
                    ],
544
                    [
545
                      0,
546
                      0,
547
                      0,
548
                      0
549
                    ],
550
                    [
551
                      0,
552
                      0,
553
                      0,
554
                      0
555
                    ],
556
                    [
557
                      0,
558
                      0,
559
                      0,
560
                      0
561
                    ],
562
                    [
563
                      356,
564
                      382,
565
                      431,
566
                      7
567
                    ],
568
                    [
569
                      0,
570
                      0,
571
                      0,
572
                      0
573
                    ],
574
                    [
575
                      0,
576
                      0,
577
                      0,
578
                      0
579
                    ],
580
                    [
581
                      41,
582
                      33,
583
                      47,
584
                      1
585
                    ],
586
                    [
587
                      0,
588
                      0,
589
                      0,
590
                      0
591
                    ],
592
                    [
593
                      0,
594
                      0,
595
                      0,
596
                      0
597
                    ],
598
                    [
599
                      39,
600
                      34,
601
                      36,
602
                      1
603
                    ],
604
                    [
605
                      237,
606
                      263,
607
                      316,
608
                      4
609
                    ],
610
                    [
611
                      0,
612
                      0,
613
                      0,
614
                      0
615
                    ],
616
                    [
617
                      0,
618
                      0,
619
                      0,
620
                      0
621
                    ],
622
                    [
623
                      2683,
624
                      2925,
625
                      2501,
626
                      42
627
                    ]
628
                  ]
629
                ],
630
                "subtotals_in_kgce_array": [
631
                  [
632
                    98124.849,
633
                    116774.355,
634
                    200164.921455,
635
                    20201.889,
636
                    12447.231,
637
                    97589.676,
638
                    338252.337,
639
                    110114.643,
640
                    146335.806,
641
                    31753.311,
642
                    20363.634,
643
                    44455.767,
644
                    96361.89,
645
                    39366.888,
646
                    54637.461,
647
                    119260.923,
648
                    31810.014,
649
                    1607.61,
650
                    3647036.45793
651
                  ],
652
                  [
653
                    0,
654
                    30.53,
655
                    0,
656
                    0,
657
                    0,
658
                    0,
659
                    1752.078,
660
                    0,
661
                    63.296,
662
                    0,
663
                    1752.078,
664
                    0,
665
                    0,
666
                    0,
667
                    0,
668
                    0,
669
                    0,
670
                    0,
671
                    3597.982
672
                  ],
673
                  [
674
                    1200,
675
                    379,
676
                    0,
677
                    159,
678
                    407,
679
                    0,
680
                    0,
681
                    0,
682
                    1176,
683
                    0,
684
                    0,
685
                    122,
686
                    0,
687
                    0,
688
                    110,
689
                    820,
690
                    0,
691
                    0,
692
                    8151
693
                  ]
694
                ],
695
                "subtotals_in_kgco2e_array": [
696
                  [
697
                    740324.064,
698
                    881029.28,
699
                    1510187.37488,
700
                    152417.504,
701
                    93910.816,
702
                    736286.336,
703
                    2552017.632,
704
                    830783.648,
705
                    1104062.016,
706
                    239569.696,
707
                    153637.824,
708
                    335406.112,
709
                    727023.04,
710
                    297011.968,
711
                    412224.096,
712
                    899789.728,
713
                    239997.504,
714
                    12128.96,
715
                    27515852.30048
716
                  ],
717
                  [
718
                    0,
719
                    323.05,
720
                    0,
721
                    0,
722
                    0,
723
                    0,
724
                    18539.43,
725
                    0,
726
                    669.76,
727
                    0,
728
                    18539.43,
729
                    0,
730
                    0,
731
                    0,
732
                    0,
733
                    0,
734
                    0,
735
                    0,
736
                    38071.67
737
                  ],
738
                  [
739
                    1200,
740
                    379,
741
                    0,
742
                    159,
743
                    407,
744
                    0,
745
                    0,
746
                    0,
747
                    1176,
748
                    0,
749
                    0,
750
                    122,
751
                    0,
752
                    0,
753
                    110,
754
                    820,
755
                    0,
756
                    0,
757
                    8151
758
                  ]
759
                ]
760
              });
761
              setDischargeData({
762
                "energy_category_names": [
763
                  "电",
764
                  "自来水",
765
                  "中水"
766
                ],
767
                "units": [
768
                  "CNY",
769
                  "CNY",
770
                  "CNY"
771
                ],
772
                "station_names_array": [
773
                  [
774
                    "市政府",
775
                    "办公楼",
776
                    "商场",
777
                    "酒店",
778
                    "博物馆",
779
                    "工厂",
780
                    "连锁门店",
781
                    "住宅小区",
782
                    "医院",
783
                    "大学",
784
                    "机场",
785
                    "火车站",
786
                    "养殖场",
787
                    "公寓",
788
                    "地铁站",
789
                    "体育场",
790
                    "公用动力",
791
                    "数据中心",
792
                    "调试空间"
793
                  ],
794
                  [
795
                    "市政府",
796
                    "办公楼",
797
                    "商场",
798
                    "酒店",
799
                    "博物馆",
800
                    "工厂",
801
                    "连锁门店",
802
                    "住宅小区",
803
                    "医院",
804
                    "大学",
805
                    "机场",
806
                    "火车站",
807
                    "养殖场",
808
                    "公寓",
809
                    "地铁站",
810
                    "体育场",
811
                    "公用动力",
812
                    "数据中心",
813
                    "调试空间"
814
                  ],
815
                  [
816
                    "市政府",
817
                    "办公楼",
818
                    "商场",
819
                    "酒店",
820
                    "博物馆",
821
                    "工厂",
822
                    "连锁门店",
823
                    "住宅小区",
824
                    "医院",
825
                    "大学",
826
                    "机场",
827
                    "火车站",
828
                    "养殖场",
829
                    "公寓",
830
                    "地铁站",
831
                    "体育场",
832
                    "公用动力",
833
                    "数据中心",
834
                    "调试空间"
835
                  ]
836
                ],
837
                "subtotals_array": [
838
                  [
839
                    [
840
                      199985.392,
841
                      222832.948,
842
                      218410.682,
843
                      3744.952
844
                    ],
845
                    [
846
                      250549.443,
847
                      250673.686,
848
                      239907.609,
849
                      4271.963
850
                    ],
851
                    [
852
                      328706.173,
853
                      432421.104,
854
                      495966.915,
855
                      8362.978
856
                    ],
857
                    [
858
                      43370.071,
859
                      38319.782,
860
                      41819.126,
861
                      736.997
862
                    ],
863
                    [
864
                      26496.059,
865
                      25738.397,
866
                      26719.486,
867
                      517.889
868
                    ],
869
                    [
870
                      209925.049,
871
                      195665.691,
872
                      220662.618,
873
                      4790.071
874
                    ],
875
                    [
876
                      716996.345,
877
                      715531.077,
878
                      721803.121,
879
                      12737.348
880
                    ],
881
                    [
882
                      230610.751,
883
                      233631.109,
884
                      227333.599,
885
                      3842.563
886
                    ],
887
                    [
888
                      315134.058,
889
                      325575.981,
890
                      308212.776,
891
                      5132.861
892
                    ],
893
                    [
894
                      71340.001,
895
                      74672.939,
896
                      67130.504,
897
                      976.905
898
                    ],
899
                    [
900
                      47337.487,
901
                      45985.79,
902
                      44277.017,
903
                      683.554
904
                    ],
905
                    [
906
                      96011.335,
907
                      88874.468,
908
                      93903.144,
909
                      1692.438
910
                    ],
911
                    [
912
                      211427.09,
913
                      216800.376,
914
                      205333.34,
915
                      3517.632
916
                    ],
917
                    [
918
                      87166.996,
919
                      82334.919,
920
                      83267.862,
921
                      1525.22
922
                    ],
923
                    [
924
                      116367.094,
925
                      118208.994,
926
                      112637.667,
927
                      1771.979
928
                    ],
929
                    [
930
                      242839.118,
931
                      258782.26,
932
                      258410.278,
933
                      4217.469
934
                    ],
935
                    [
936
                      58061.785,
937
                      52089.678,
938
                      97352.278,
939
                      2748.575
940
                    ],
941
                    [
942
                      139.216,
943
                      123.441,
944
                      9738.717,
945
                      738.781
946
                    ],
947
                    [
948
                      6784310.176,
949
                      7810058.137,
950
                      8632843.186,
951
                      160720.063
952
                    ]
953
                  ],
954
                  [
955
                    [
956
                      0,
957
                      0,
958
                      0,
959
                      0
960
                    ],
961
                    [
962
                      708.05,
963
                      642.6,
964
                      749.7,
965
                      11.9
966
                    ],
967
                    [
968
                      0,
969
                      0,
970
                      0,
971
                      0
972
                    ],
973
                    [
974
                      0,
975
                      0,
976
                      0,
977
                      0
978
                    ],
979
                    [
980
                      0,
981
                      0,
982
                      0,
983
                      0
984
                    ],
985
                    [
986
                      0,
987
                      0,
988
                      0,
989
                      0
990
                    ],
991
                    [
992
                      51848.3,
993
                      49640.85,
994
                      19730.2,
995
                      0
996
                    ],
997
                    [
998
                      0,
999
                      0,
1000
                      0,
1001
                      0
1002
                    ],
1003
                    [
1004
                      1576.75,
1005
                      1505.35,
1006
                      1279.25,
1007
                      17.85
1008
                    ],
1009
                    [
1010
                      0,
1011
                      0,
1012
                      0,
1013
                      0
1014
                    ],
1015
                    [
1016
                      51848.3,
1017
                      49640.85,
1018
                      19730.2,
1019
                      0
1020
                    ],
1021
                    [
1022
                      0,
1023
                      0,
1024
                      0,
1025
                      0
1026
                    ],
1027
                    [
1028
                      0,
1029
                      0,
1030
                      0,
1031
                      0
1032
                    ],
1033
                    [
1034
                      0,
1035
                      0,
1036
                      0,
1037
                      0
1038
                    ],
1039
                    [
1040
                      0,
1041
                      0,
1042
                      0,
1043
                      0
1044
                    ],
1045
                    [
1046
                      0,
1047
                      0,
1048
                      0,
1049
                      0
1050
                    ],
1051
                    [
1052
                      0,
1053
                      0,
1054
                      0,
1055
                      0
1056
                    ],
1057
                    [
1058
                      0,
1059
                      0,
1060
                      0,
1061
                      0
1062
                    ],
1063
                    [
1064
                      105981.4,
1065
                      101429.65,
1066
                      41489.35,
1067
                      29.75
1068
                    ]
1069
                  ],
1070
                  [
1071
                    [
1072
                      0,
1073
                      0,
1074
                      0,
1075
                      0
1076
                    ],
1077
                    [
1078
                      0,
1079
                      0,
1080
                      0,
1081
                      0
1082
                    ],
1083
                    [
1084
                      0,
1085
                      0,
1086
                      0,
1087
                      0
1088
                    ],
1089
                    [
1090
                      0,
1091
                      0,
1092
                      0,
1093
                      0
1094
                    ],
1095
                    [
1096
                      0,
1097
                      0,
1098
                      0,
1099
                      0
1100
                    ],
1101
                    [
1102
                      0,
1103
                      0,
1104
                      0,
1105
                      0
1106
                    ],
1107
                    [
1108
                      0,
1109
                      0,
1110
                      0,
1111
                      0
1112
                    ],
1113
                    [
1114
                      0,
1115
                      0,
1116
                      0,
1117
                      0
1118
                    ],
1119
                    [
1120
                      0,
1121
                      0,
1122
                      0,
1123
                      0
1124
                    ],
1125
                    [
1126
                      0,
1127
                      0,
1128
                      0,
1129
                      0
1130
                    ],
1131
                    [
1132
                      0,
1133
                      0,
1134
                      0,
1135
                      0
1136
                    ],
1137
                    [
1138
                      0,
1139
                      0,
1140
                      0,
1141
                      0
1142
                    ],
1143
                    [
1144
                      0,
1145
                      0,
1146
                      0,
1147
                      0
1148
                    ],
1149
                    [
1150
                      0,
1151
                      0,
1152
                      0,
1153
                      0
1154
                    ],
1155
                    [
1156
                      0,
1157
                      0,
1158
                      0,
1159
                      0
1160
                    ],
1161
                    [
1162
                      0,
1163
                      0,
1164
                      0,
1165
                      0
1166
                    ],
1167
                    [
1168
                      0,
1169
                      0,
1170
                      0,
1171
                      0
1172
                    ],
1173
                    [
1174
                      0,
1175
                      0,
1176
                      0,
1177
                      0
1178
                    ],
1179
                    [
1180
                      0,
1181
                      0,
1182
                      0,
1183
                      0
1184
                    ]
1185
                  ]
1186
                ]
1187
              });
1188
              setMonthLabels([
1189
                "2024-01",
1190
                "2024-02",
1191
                "2024-03",
1192
                "2024-04"
1193
              ]);
1194
              setStations([{ value: 'a1', label: '近7日' }, { value: 'a2', label: '本月' }, { value: 'a3', label: '本年' }]);
1195
            }
1196
          });
1197
      }
1198
    }
1199
  });
1200
1201
  useEffect(() => {
1202
    let timer = setInterval(() => {
1203
      let is_logged_in = getCookieValue('is_logged_in');
1204
      if (is_logged_in === null || !is_logged_in) {
1205
        setRedirectUrl(`/authentication/basic/login`);
1206
        setRedirect(true);
1207
      }
1208
    }, 1000);
1209
    return () => clearInterval(timer);
1210
  }, [setRedirect, setRedirectUrl]);
1211
1212
  useEffect(() => {
1213
    setLanguage(getItemFromStore('myems_web_ui_language'));
1214
  }, [getItemFromStore('myems_web_ui_language')]);
1215
1216
  return (
1217
    <Fragment>
1218
      <div className="card-deck">
1219
        <Spinner color="primary" hidden={spinnerHidden} />
1220
        <Spinner color="secondary" hidden={spinnerHidden} />
1221
        <Spinner color="success" hidden={spinnerHidden} />
1222
        <Spinner color="danger" hidden={spinnerHidden} />
1223
        <Spinner color="warning" hidden={spinnerHidden} />
1224
        <Spinner color="info" hidden={spinnerHidden} />
1225
        <Spinner color="light" hidden={spinnerHidden} />
1226
1227
        <CardSummary rate={''} title={t('Number of Power Stations')} footunit={''} color="powerStation">
1228
          {1 && <CountUp end={energyStoragePowerStationList.length} duration={2} prefix="" separator="," decimal="." decimals={0} />}
1229
        </CardSummary>
1230
        <CardSummary rate={''} title={t('Total Rated Capacity')} footunit={'kWh'} color="ratedCapacity">
1231
          {1 && <CountUp end={totalRatedCapacity} duration={2} prefix="" separator="," decimal="." decimals={2} />}
1232
        </CardSummary>
1233
        <CardSummary rate={''} title={t('Total Rated Power')} footunit={'kW'} color="ratedPower">
1234
          {1 && <CountUp end={totalRatedPower} duration={2} prefix="" separator="," decimal="." decimals={2} />}
1235
        </CardSummary>
1236
        <CardSummary rate={''} title={t('Total Charge')} footunit={'kWh'} color="electricity">
1237
          {1 && <CountUp end={totalCharge} duration={2} prefix="" separator="," decimal="." decimals={2} />}
1238
        </CardSummary>
1239
        <CardSummary rate={''} title={t('Total Discharge')} footunit={'kWh'} color="electricity">
1240
          {1 && <CountUp end={totalDischarge} duration={2} prefix="" separator="," decimal="." decimals={2} />}
1241
        </CardSummary>
1242
        <CardSummary rate={''} title={t('Total Revenue')} footunit={currency} color="income">
1243
          {1 && <CountUp end={totalRevenue} duration={2} prefix="" separator="," decimal="." decimals={2} />}
1244
        </CardSummary>
1245
      </div>
1246
1247
      <Row noGutters>
1248
        <Col lg={6} xl={6} className="mb-3 pr-lg-2">
1249
          <div className="mb-3 card" style={{ height: '100%' }}>
1250
            <Nav tabs>
1251
              <NavItem className="cursor-pointer">
1252
                <NavLink
1253
                  className={classNames({ active: activeTabLeft === '1' })}
1254
                  onClick={() => {
1255
                    toggleTabLeft('1');
1256
                  }}
1257
                >
1258
                  <h6>电量指标</h6>
1259
                </NavLink>
1260
              </NavItem>
1261
              <NavItem className="cursor-pointer">
1262
                <NavLink
1263
                  className={classNames({ active: activeTabLeft === '2' })}
1264
                  onClick={() => {
1265
                    toggleTabLeft('2');
1266
                  }}
1267
                >
1268
                  <h6>收益指标</h6>
1269
                </NavLink>
1270
              </NavItem>
1271
              <NavItem className="cursor-pointer">
1272
                <NavLink
1273
                  className={classNames({ active: activeTabLeft === '3' })}
1274
                  onClick={() => {
1275
                    toggleTabLeft('3');
1276
                  }}
1277
                >
1278
                  <h6>节能减排</h6>
1279
                </NavLink>
1280
              </NavItem>
1281
            </Nav>
1282
            <TabContent activeTab={activeTabLeft}>
1283
              <TabPane tabId="1">
1284
                <StackBarChart
1285
                  labels={monthLabels}
1286
                  chargeData={chargeData}
1287
                  dischargeData={dischargeData}
1288
                  stations={stations}
1289
                />
1290
              </TabPane>
1291
              <TabPane tabId="2">
1292
                <StackBarChart
1293
                  labels={monthLabels}
1294
                  chargeData={chargeData}
1295
                  dischargeData={dischargeData}
1296
                  stations={stations}
1297
                />
1298
              </TabPane>
1299
              <TabPane tabId="3">
1300
                <StackBarChart
1301
                  labels={monthLabels}
1302
                  chargeData={chargeData}
1303
                  dischargeData={dischargeData}
1304
                  stations={stations}
1305
                />
1306
              </TabPane>
1307
            </TabContent>
1308
          </div>
1309
        </Col>
1310
        <Col lg={6} xl={6} className="mb-3 pr-lg-2">
1311
          {settings.showOnlineMap ? (
1312
            <div className="mb-3 card" style={{ height: '100%' }}>
1313
              <CustomizeMapBox
1314
                Latitude={rootLatitude}
1315
                Longitude={rootLongitude}
1316
                Zoom={4}
1317
                Geojson={geojson['features']}
1318
              />
1319
            </div>
1320
          ) : (
1321
            <></>
1322
          )}
1323
        </Col>
1324
1325
      </Row>
1326
1327
      <EnergyStoragePowerStationTableCard energyStoragePowerStationList={energyStoragePowerStationList} />
1328
    </Fragment>
1329
  );
1330
};
1331
1332
export default withTranslation()(withRedirect(MultipleDashboard));
1333