-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.py
764 lines (649 loc) · 34.4 KB
/
App.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
import sys
import os
import subprocess
import re
from datetime import datetime
from PyQt6 import QtCore
from PyQt6.QtWidgets import (QApplication, QMainWindow, QFileDialog, QMessageBox, QLabel)
from PyQt6.QtGui import (QPixmap, QScreen)
from CSV_Parser import csvParser
from Plotter import (PlotterSelective, PlotterCollective)
from UI_Main import Ui_MainWindow
from UI_RangeForm import Ui_RangeForm
dataList = {'Renewable Energy Sources [g]':'0100', 'Hydrolic Powers [g]':'0200', 'Solar Thermal Powers [g]':'0300', 'Combined Steam & Heat Production [g]':'0400', 'Geothermal Heat Production [g]':'0500', 'Power Plants Electricity Production [g]':'0600', 'Nuclear [g]':'0700', 'Pump Consumption [g]':'0800', 'Turbine Production [g]':'0900', 'Pump Storage [g]':'1000', 'Electrolyser Gr.2 [g]':'1100', 'Electrolyser Gr.3 [g]':'1200', 'EV & V2G (Transport) [g]':'1300', 'Nordpool Prices [g]':'1400', 'Market Prices [g]':'1500', 'Exports Payment [g]':'1600', 'Individual Heat 1 [g]':'1700', 'Individual Electricity [g]':'1800', 'Individual Heat 2 [g]':'1900', 'Transports Heat 2 [g]':'2000', 'District Cooling [g]':'2100', 'Desalination [g]':'2200', 'Gas Grid Demand & Balance [g]':'2300', 'Electr. Demand':'0001', 'Elec.dem Cooling':'0002', 'Fixed Exp/Imp':'0003', 'DH Demand':'0004', 'Wind Electr.':'0101', 'Offshore Electr.':'0102', 'PV Electr.':'0103', 'CSP Electr.':'0104', 'River Electr.':'0105', 'Wave Electr.':'0106', 'Tidal Electr.':'0107', 'CSP2 Electr.':'0108', 'CSP2 Storage':'0109', 'CSP2 loss':'0110', 'Hydro Electr.':'0201', 'Hydro pump':'0202', 'Hydro storage':'0203', 'Hydro Wat-Sup':'0204', 'Hydro Wat-Loss':'0205', 'Solar Heat':'0301', 'CSHP 1 Heat':'0401', 'Waste 1 Heat':'0402', 'Boiler 1 Heat':'0005', 'Solar 1 Heat':'0302', 'Sol1 Str Heat':'0303', 'CSHP 2 Heat':'0403', 'Waste 2 Heat':'0404', 'Geoth 2 Heat':'0501', 'Geoth 2 Steam':'0502', 'Geoth 2 Storage':'0503', 'CHP 2 Heat':'0006', 'HP 2 Heat':'0007', 'Boiler 2 Heat':'0008', 'EH 2 Heat':'0009', 'ELT 2 Heat':'0010', 'Solar2 Heat':'0304', 'Sol2 Str Heat':'0305', 'Storage2 Heat':'0011', 'Balance2 Heat':'0012', 'CSHP 3 Heat':'0405', 'Waste 3 Heat':'0406', 'Geoth 3 Heat':'0504', 'Geoth 3 Steam':'0505', 'Geoth 3 Storage':'0506', 'CHP 3 Heat':'0013', 'HP 3 Heat':'0014', 'Boiler 3 Heat':'0015', 'EH 3 Heat':'0016', 'ELT 3 Heat':'0017', 'Solar3 Heat':'0306', 'Sol3 Str Heat':'0307', 'Storage3 Heat':'0018', 'Balance3 Heat':'0019', 'Flexible Electr.':'0020', 'HP Electr.':'0021', 'CSHP Electr.':'0022', 'CHP Electr.':'0023', 'PP Electr.':'0601', 'PP2 Electr.':'0602', 'Nuclear Electr.':'0701', 'Geother. Electr.':'0702', 'Pump Electr.':'0801', 'Turbine Electr.':'0901', 'Pumped Storage':'1001', 'Pump2 Electr.':'0802', 'Turbine2 Electr.':'0902', 'Pumped2 Storage':'1002', 'Rock in Electr.':'0903', 'Rock out Steam':'0904', 'Rock str Storage':'0905', 'ELT 2 Electr.':'1101', 'ELT 2 H2 ELT 2':'1102', 'ELT 3 Electr.':'1201', 'ELT 3 H2 ELT 3':'1202', 'V2G Demand':'1301', 'V2G Charge':'1302', 'V2G Discha.':'1303', 'V2G Storage':'1304', 'H2 Electr.':'2001', 'H2 Storage':'2002', 'CO2Hydro Electr.':'2003', 'NH3Hydro Electr.':'2004', 'CO2Hydro liq.fuel':'2005', 'NH3Hydro Ammonia':'2006', 'HH-CHP Electr.':'1801', 'HH-HP Electr.':'1802', 'HH-HP/EB Electr.':'1803', 'HH-EB Electr.':'1804', 'HH-H2 Electr.':'1901', 'HH-H2 Storage':'1902', 'HH-H2 Prices':'1903', 'HH Dem. Heat':'1701', 'HH CHP+HP Heat':'1702', 'HH Boil. Heat':'1703', 'HH Solar Heat':'1704', 'HH Store Heat':'1705', 'HH Balan Heat':'1706', 'Stabil. LoadPercent':'0024', 'Import Electr.':'0025', 'Export Electr.':'0026', 'CEEP Electr.':'0027', 'EEEP Electr.':'0028', 'ExMarket Prices':'1401', 'ExMarket Prod':'1402', 'System Prices':'1501', 'InMarket Prices':'1502', 'Btl-neck Prices':'1503', 'Import Payment':'0029', 'Export Payment':'1601', 'Blt-neck Payment':'1602', 'Add-exp Payment':'0030', 'Boilers ':'2301', 'CHP2+3 ':'2302', 'PP CAES':'2303', 'Indi- vidual':'2304', 'Transp. ':'2305', 'Indust. Various':'2306', 'Demand Sum':'2307', 'Biogas ':'2308', 'Syngas ':'2309', 'CO2HyGas ':'2310', 'SynHyGas ':'2311', 'SynFuel ':'2312', 'Storage ':'2313', 'Storage Content':'2314', 'Sum ':'2315', 'Import Gas':'2316', 'Export Gas':'2317', 'FreshW Demand':'2201', 'FreshW Storage':'2202', 'SaltW Demand':'2203', 'Brine Prod.':'2204', 'Brine Storage':'2205', 'Desal.Pl Electr.':'2206', 'FWPump Electr.':'2207', 'Turbine Electr.':'2208', 'Pump Electr.':'2209', 'CoolGr1 Demand':'2101', 'CoolGr2 Demand':'2102', 'CoolGr3 Demand':'2103', 'Cool-El Demand':'2104', 'CoolGr1 Natural':'2105', 'CoolGr2 Natural':'2106', 'CoolGr3 Natural':'2107', 'Cooling DHgr1':'2108', 'Cooling DHgr2':'2109', 'Cooling DHgr3':'2110', 'Cooling Electr.':'2111'}
monthList = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
figList, pltList, stdList, xRangelist = [], [], [], []
figID, pltID, stdID = 1, 1, 1
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.InitialData()
self.SwitchHandelers()
self.Connections()
def InitialData(self):
self.cb_FileFormat.addItems(['image', 'html', 'json'])
self.cb_FileFormat.setCurrentIndex(0)
self.SelectiveAnalysis()
def SwitchHandelers(self):
self.rb_Selective.toggled.connect(self.SelectiveAnalysis)
self.rb_Collective.toggled.connect(self.CollectiveAnalysis)
self.rb_HourlyVal.toggled.connect(self.UpdateDataType)
self.rb_MonthlyVal.toggled.connect(self.UpdateDataType)
self.rb_AnnualVal.toggled.connect(self.UpdateDataType)
self.cb_Trace.currentIndexChanged.connect(self.UpdateTrace)
self.lw_FigList.currentRowChanged.connect(self.UpdateFigSlct)
self.lw_PltList.currentRowChanged.connect(self.UpdatePltSlct)
self.lw_StdList.currentRowChanged.connect(self.UpdateStdSlct)
self.cb_TicksX.stateChanged.connect(self.UpdateTickStateX)
self.cb_TicksY.stateChanged.connect(self.UpdateTickStateY)
self.cb_Xdata.currentTextChanged.connect(self.UpdateXdata)
def SelectiveAnalysis(self):
self.rb_HourlyVal.setEnabled(True)
self.rb_MonthlyVal.setEnabled(True)
self.rb_AnnualVal.setEnabled(True)
self.rb_HourlyVal.setChecked(True)
self.btn_Xrange.setEnabled(False)
self.UpdateDataType()
def CollectiveAnalysis(self):
self.rb_HourlyVal.setEnabled(False)
self.rb_MonthlyVal.setEnabled(False)
self.rb_AnnualVal.setEnabled(True)
self.rb_AnnualVal.setChecked(True)
self.btn_Xrange.setEnabled(True)
self.UpdateDataType()
def UpdateDataType(self):
if self.rb_HourlyVal.isEnabled and self.rb_HourlyVal.isChecked():
self.cb_Trace.clear()
self.cb_Trace.addItems(['Scatter Plot'])
self.cb_Trace.setCurrentIndex(0)
self.rb_Xtime.setEnabled(True)
self.rb_Xtime.setChecked(True)
self.cb_Xstart.setEnabled(True)
self.cb_Xstart.clear()
self.cb_Xend.setEnabled(True)
self.cb_Xend.clear()
self.cb_Ydata.clear()
self.cb_Ydata.setEnabled(True)
self.cb_Ydata.addItems(dataList.keys())
self.cb_Ydata.insertSeparator(23)
self.cb_Xdata.clear()
self.cb_Xdata.addItems(dataList.keys())
self.cb_Xdata.insertSeparator(23)
if self.rb_MonthlyVal.isEnabled and self.rb_MonthlyVal.isChecked():
self.cb_Trace.clear()
self.cb_Trace.addItems(['Scatter Plot', 'Bar Chart'])
self.cb_Trace.setCurrentIndex(0)
self.rb_Xtime.setEnabled(True)
self.rb_Xtime.setChecked(True)
self.cb_Xstart.setEnabled(True)
self.cb_Xstart.clear()
self.cb_Xstart.addItems(monthList)
self.cb_Xstart.setCurrentIndex(0)
self.cb_Xend.setEnabled(True)
self.cb_Xend.clear()
self.cb_Xend.addItems(monthList)
self.cb_Xend.setCurrentIndex(11)
self.cb_Ydata.clear()
self.cb_Ydata.setEnabled(True)
self.cb_Ydata.addItems(dataList.keys())
self.cb_Ydata.insertSeparator(23)
self.cb_Xdata.clear()
self.cb_Xdata.addItems(dataList.keys())
self.cb_Xdata.insertSeparator(23)
if self.rb_AnnualVal.isEnabled and self.rb_AnnualVal.isChecked():
if self.rb_Selective.isChecked():
self.cb_Trace.clear()
self.cb_Trace.addItems(['Bar Chart', 'Pie Chart'])
self.cb_Trace.setCurrentIndex(0)
self.rb_Xdata.setChecked(True)
self.rb_Xtime.setEnabled(False)
self.cb_Xstart.setEnabled(False)
self.cb_Xend.setEnabled(False)
self.cb_Ydata.clear()
self.cb_Ydata.setEnabled(False)
self.cb_Ydata.addItems(dataList.keys())
self.cb_Ydata.insertSeparator(23)
self.cb_Xdata.clear()
if self.rb_Collective.isChecked():
self.cb_Trace.clear()
self.cb_Trace.addItems(['Box Plot'])
self.cb_Trace.setCurrentIndex(0)
self.rb_Xdata.setChecked(True)
self.rb_Xtime.setEnabled(False)
self.cb_Xstart.setEnabled(False)
self.cb_Xend.setEnabled(False)
self.sb_Col.setEnabled(False)
self.sb_Row.setEnabled(False)
self.cb_Ydata.clear()
self.cb_Ydata.setEnabled(False)
self.cb_Xdata.clear()
self.UpdateTrace()
def UpdateTrace(self):
if self.cb_Trace.currentText() == 'Scatter Plot':
self.cb_Style.clear()
self.cb_Style.addItems(['Lines + Markers', 'Lines Only', 'Markers Only', 'Smooth Linear'])
self.cb_Style.setCurrentIndex(0)
self.cb_FillArea.setEnabled(True)
self.cb_TicksX.setEnabled(True)
self.cb_TicksY.setEnabled(True)
self.cb_StatMean.setEnabled(True)
self.cb_StatMedian.setEnabled(True)
self.cb_OnlyStats.setEnabled(True)
self.cb_StackLines.setChecked(False)
self.cb_StackLines.setEnabled(False)
elif self.cb_Trace.currentText() == 'Bar Chart':
self.cb_Style.clear()
self.cb_Style.addItems(['Stacked', 'Grouped'])
self.cb_Style.setCurrentIndex(0)
self.cb_FillArea.setEnabled(False)
self.cb_TicksX.setEnabled(False)
self.cb_TicksY.setEnabled(False)
self.cb_StatMean.setEnabled(True)
self.cb_StatMedian.setEnabled(True)
self.cb_OnlyStats.setEnabled(True)
self.cb_StackLines.setChecked(False)
self.cb_StackLines.setEnabled(False)
if self.rb_AnnualVal.isChecked():
self.cb_Xdata.clear()
self.cb_Xdata.addItems(['Energy Balance', 'Power Values - Totals', 'Power Values - Annual Average', 'Power Values - Annual Maximum', 'Power Values - Annual Minimum', 'Investment Costs - Total', 'Investment Costs - Annual', 'Investment Costs - O & M', 'Total Elect. Demand', 'Total Heat Demand', 'VRES (Renewable Fuel Balance)', 'Electricity Consumption', 'Electricity Production', 'Electricity Balance', 'District Heat Production', 'District Heat Gr.1', 'District Heat Gr.2', 'District Heat Gr.3', 'Individual (HH) Heating Production', 'Heat Balance'])
elif self.cb_Trace.currentText() == 'Pie Chart':
self.cb_Style.clear()
self.cb_Style.addItems(['Domain', 'Domain Spaced'])
self.cb_Style.setCurrentIndex(0)
self.cb_FillArea.setEnabled(False)
self.cb_TicksX.setEnabled(False)
self.cb_TicksY.setEnabled(False)
self.cb_StatMean.setEnabled(False)
self.cb_StatMedian.setEnabled(False)
self.cb_OnlyStats.setEnabled(False)
self.cb_StackLines.setEnabled(False)
if self.rb_AnnualVal.isChecked():
self.cb_Xdata.clear()
self.cb_Xdata.addItems(['Annual CO2 Emissions', 'Annual Fuel Consumptions', 'Share of RES', 'Total Elect. Demand', 'Total Heat Demand', 'VRES (Renewable Fuel Balance)', 'Electricity Consumption', 'Electricity Production', 'Electricity Balance', 'District Heat Production', 'District Heat Gr.1', 'District Heat Gr.2', 'District Heat Gr.3', 'Individual (HH) Heating Production', 'Heat Balance'])
elif self.cb_Trace.currentText() == 'Box Plot':
self.cb_Style.clear()
self.cb_Style.addItems(['Whiskers', 'OutLiers', 'Whiskers & Points', 'Whiskers & OutLiers'])
self.cb_Style.setCurrentIndex(0)
self.cb_FillArea.setEnabled(False)
self.cb_TicksX.setEnabled(False)
self.cb_TicksY.setEnabled(False)
self.cb_StatMean.setEnabled(False)
self.cb_StatMedian.setEnabled(False)
self.cb_OnlyStats.setEnabled(False)
self.cb_StackLines.setEnabled(False)
if self.rb_AnnualVal.isChecked():
self.cb_Xdata.clear()
self.cb_Xdata.addItems(['Energy Balance (per Index)', 'Installed Capacities (per Index)', 'Total Elect. Demand', 'Total Heat Demand'])
def UpdateXdata(self):
global xDataMode
xDataMode = self.cb_Xdata.currentText()
def UpdateTickStateX(self):
if self.cb_TicksX.isChecked():
self.txt_TicksX.setEnabled(False)
else:
self.txt_TicksX.setEnabled(True)
def UpdateTickStateY(self):
if self.cb_TicksY.isChecked():
self.txt_TicksY.setEnabled(False)
else:
self.txt_TicksY.setEnabled(True)
def UpdateFigSlct(self):
if self.lw_FigList.currentRow() == -1:
self.lbl_SlctFig.setText('none')
self.lbl_SlctFig.setStyleSheet('border-bottom-width: 1px; border-bottom-style: solid; border-radius: 0px; color: red;')
else:
self.lbl_SlctFig.setText(self.lw_FigList.currentItem().text())
self.lbl_SlctFig.setStyleSheet('border-bottom-width: 1px; border-bottom-style: solid; border-radius: 0px; color: green;')
def UpdatePltSlct(self):
if self.lw_PltList.currentRow() == -1:
self.lbl_SlctPlt.setText('none')
self.lbl_SlctPlt.setStyleSheet('border-bottom-width: 1px; border-bottom-style: solid; border-radius: 0px; color: red;')
else:
self.lbl_SlctPlt.setText(self.lw_PltList.currentItem().text())
self.lbl_SlctPlt.setStyleSheet('border-bottom-width: 1px; border-bottom-style: solid; border-radius: 0px; color: green;')
def UpdateStdSlct(self):
if self.lw_StdList.currentRow() == -1:
self.lbl_SlctStd.setText('none')
self.lbl_SlctStd.setStyleSheet('border-bottom-width: 1px; border-bottom-style: solid; border-radius: 0px; color: red;')
else:
self.lbl_SlctStd.setText(self.lw_StdList.currentItem().text())
self.lbl_SlctStd.setStyleSheet('border-bottom-width: 1px; border-bottom-style: solid; border-radius: 0px; color: green;')
def Connections(self):
self.actionExit.triggered.connect(self.close)
self.actionAbout.triggered.connect(self.openAboutDialog)
self.btn_Page.clicked.connect(self.ChangePage)
self.btn_ExePath.clicked.connect(self.SelectExePath)
self.btn_IPF.clicked.connect(self.SelectIPF)
self.btn_OPD.clicked.connect(self.SelectOPD)
self.btn_Exec.clicked.connect(self.ProcessFile)
self.btn_StdLoad.clicked.connect(self.AddStudy)
self.btn_StdRemove.clicked.connect(self.RemoveStudy)
self.btn_FigAdd.clicked.connect(self.AddFigure)
self.btn_FigDlt.clicked.connect(self.RemoveFigure)
self.btn_PltNew.clicked.connect(self.AddPlot)
self.btn_PltDlt.clicked.connect(self.RemovePlot)
self.btn_FigSave.clicked.connect(self.SaveFigure)
self.btn_FigView.clicked.connect(self.PreviewFigure)
self.btn_Xrange.clicked.connect(self.OpenRangeWindow)
def openAboutDialog(self):
QMessageBox.about(self, 'About', 'Developed by Load Tafran & Shahm Barmada')
def ChangePage(self):
if self.stackedWidget.currentIndex() == 0:
self.stackedWidget.setCurrentIndex(1)
else:
self.stackedWidget.setCurrentIndex(0)
def SelectExePath(self):
try:
filePath = QFileDialog.getOpenFileName(self, 'Select EneryPLAN.exe file', filter='energyPLAN.exe')
self.txt_ExePath.setText(filePath[0])
except:
pass
def SelectIPF(self):
try:
filePath = QFileDialog.getOpenFileName(self, 'Select Input file', filter= '*.txt')
self.txt_IPF.setText(filePath[0])
except:
pass
def SelectOPD(self):
global path_OPD
try:
path_OPD = QFileDialog.getExistingDirectory(self, 'Select ouput directory', '', options= QFileDialog.Option.ShowDirsOnly)
self.txt_OPD.setText(path_OPD)
except:
pass
def ProcessFile(self):
global stdID
timeStamp = datetime.now().strftime('%y%m%d%H%M%S')
if self.txt_ExePath.text() != '' and self.txt_IPF.text() != '' and self.txt_OPD.text() != '':
path_OPD = self.txt_OPD.text()
subprocess.run([self.txt_ExePath.text(), "-i", self.txt_IPF.text(), "-ascii", path_OPD + '/ops.txt'])
stdParsed = csvParser(self.txt_IPF.text(), path_OPD + '/ops.txt', timeStamp)
if self.cb_OpenOPD.isChecked():
subprocess.run(['explorer', os.path.realpath(path_OPD)])
if self.cb_LoadVis.isChecked():
stdName = stdParsed
stdName = stdName[stdName.rfind('/') +1:stdName.rfind('.')]
stdCard = {
'id': 'std' + str(stdID).zfill(2),
'name': stdName,
'path': stdParsed}
stdID += 1
stdList.append(stdCard)
self.lw_StdList.addItem(stdName)
else:
QMessageBox.critical(self, 'Error', 'Error')
def AddStudy(self):
global stdID
numbering = 1
i = 0
filePath = QFileDialog.getOpenFileNames(self, 'Select Input file', filter='*.csv')
if len(filePath[0]) != 0:
for i in range(len(filePath[0])):
stdName = filePath[0][i]
stdName = stdName[stdName.rfind('/') +1:stdName.rfind('.')]
while len(self.lw_StdList.findItems(stdName, QtCore.Qt.MatchFlag.MatchExactly)) > 0:
if re.fullmatch(r'_\d{2}', stdName[-3:]) is not None:
stdName = stdName[:-3] + '_' + str(numbering).zfill(2)
else:
stdName = stdName + '_' + str(numbering).zfill(2)
numbering += 1
stdCard = {
'id': 'std' + str(stdID).zfill(2),
'name': stdName,
'path': filePath[0][i]}
stdID += 1
stdList.append(stdCard)
self.lw_StdList.addItem(stdName)
self.lw_StdList.setCurrentRow(self.lw_StdList.count() -1)
self.lw_StdList.sortItems()
def RemoveStudy(self):
removeIndex = self.lw_StdList.currentRow()
if self.lw_StdList.currentItem() is not None:
removeName = self.lw_StdList.currentItem().text()
self.lw_StdList.takeItem(removeIndex)
for i in range(len(stdList)):
if stdList[i]['name'] == removeName:
del stdList[i]
break
else:
next
def AddFigure(self):
global figID
numbering = 1
figName = re.sub(r'\s+', r' ', self.txt_FigName.text().strip())
if re.fullmatch(r'(?=.)[\w[|]\s][^<>:"/|?*\\]', figName) is None:
if re.match(r'\w|\w+', figName):
while len(self.lw_FigList.findItems(figName, QtCore.Qt.MatchFlag.MatchExactly)) > 0:
if re.fullmatch(r'_\d{2}', figName[-3:]) is not None:
figName = figName[:-3] + '_' + str(numbering).zfill(2)
else:
figName = figName + '_' + str(numbering).zfill(2)
numbering += 1
if int(self.txt_FigHeight.text()) != 0 and int(self.txt_FigWidth.text()) != 0:
figCard = {
'id': 'fig' + str(figID).zfill(2),
'name': figName,
'width': int(self.txt_FigWidth.text()),
'height': int(self.txt_FigHeight.text()),
'rows': int(self.sb_FigRows.text()),
'cols': int(self.sb_FigCols.text()),
'font': int(self.sb_FontSize.text())}
figID += 1
figList.append(figCard)
self.lw_FigList.addItem(figName)
self.lw_FigList.setCurrentRow(self.lw_FigList.count() -1)
self.lw_FigList.sortItems()
else:
print('error 1')
pass
else:
print('error 2')
pass
def RemoveFigure(self):
removeIndex = self.lw_FigList.currentRow()
if self.lw_FigList.currentItem() is not None:
removeName = self.lw_FigList.currentItem().text()
self.lw_FigList.takeItem(removeIndex)
for i in range(len(figList)):
if figList[i]['name'] == removeName:
del figList[i]
break
else:
next
def AddPlot(self):
global pltID
numbering = 1
if self.lw_StdList.currentRow() == -1:
pass
else:
dataSrc = self.lw_StdList.currentItem().text()
for i in range(len(stdList)):
if stdList[i]['name'] == self.lw_StdList.currentItem().text():
dataSrc = stdList[i]
if self.lw_FigList.currentRow() == -1:
pass
else:
pltSrcName = self.lw_FigList.currentItem().text()
for i in range(len(figList)):
if figList[i]['name'] == pltSrcName:
pltSrcID = figList[i]['id']
pltName = 'Fig(' + pltSrcName + ')_' + str(numbering).zfill(2)
while len(self.lw_PltList.findItems(pltName, QtCore.Qt.MatchFlag.MatchExactly)) > 0:
numbering += 1
pltName = 'Fig(' + pltSrcName + ')_' + str(numbering).zfill(2)
if self.rb_HourlyVal.isChecked():
pltType = 'hourly'
if self.rb_Xtime.isChecked():
xType = 'time'
elif self.rb_Xdata.isChecked():
xType = 'data'
for i, key in enumerate(dataList.keys()):
if key == self.cb_Xdata.currentText():
xData = dataList[key]
xTitle = key
next
if key == self.cb_Ydata.currentText():
yData = dataList[key]
yTitle = key
next
elif self.rb_MonthlyVal.isChecked():
pltType = 'monthly'
if self.rb_Xtime.isChecked():
xType = 'time'
elif self.rb_Xdata.isChecked():
xType = 'data'
for i, key in enumerate(dataList.keys()):
if key == self.cb_Xdata.currentText():
xData = dataList[key]
xTitle = key
next
if key == self.cb_Ydata.currentText():
yData = dataList[key]
yTitle = key
next
elif self.rb_AnnualVal.isChecked():
pltType = 'annual'
xType = 'data'
xData = self.cb_Xdata.currentText()
xTitle = 'Annual Values'
for i, key in enumerate(dataList.keys()):
if key == self.cb_Ydata.currentText():
yData = dataList[key]
yTitle = key
next
traceType = self.cb_Trace.currentText()
traceStyle = self.cb_Style.currentText()
if self.cb_FillArea.isEnabled():
if self.cb_FillArea.isChecked():
traceFill = True
else:
traceFill = False
else:
traceFill = False
if self.cb_TicksX.isChecked():
xTick = 'auto'
xStep = 0
else:
xTick = 'linear'
xStep = int(self.txt_TicksX.text())
if self.cb_TicksY.isChecked():
yTick = 'auto'
yStep = 0
else:
yTick = 'linear'
yStep = int(self.txt_TicksX.text())
xTimeStart = self.cb_Xstart.currentText()
xTimeEnd = self.cb_Xend.currentText()
pltCard = {
'id': 'plt' + str(pltID).zfill(2),
'name': pltName,
'figid': pltSrcID,
'figname': pltSrcName,
'datasrc': dataSrc,
'datatype': pltType,
'tracetype': traceType,
'tracestyle': traceStyle,
'tracefill': traceFill,
'pos': (int(self.sb_Row.text()) * 10) + int(self.sb_Col.text()),
'rowspan': int(self.sb_RowSpan.text()),
'colspan': int(self.sb_ColSpan.text()),
'xstart': xTimeStart,
'xend': xTimeEnd,
'xdata': xData,
'xtitle': xTitle,
'xtype': xType,
'xtick': xTick,
'xstep': xStep,
'ydata': yData,
'ytitle': yTitle,
'ytick': yTick,
'ystep': yStep,
'median': self.cb_StatMedian.isChecked(),
'mean': self.cb_StatMean.isChecked(),
'statonly': self.cb_OnlyStats.isChecked(),
'stack': self.cb_StackLines.isChecked()}
pltID += 1
pltList.append(pltCard)
self.lw_PltList.addItem(pltName)
self.lw_PltList.setCurrentRow(self.lw_PltList.count() -1)
self.lw_PltList.sortItems()
def RemovePlot(self):
removeIndex = self.lw_PltList.currentRow()
if self.lw_PltList.currentItem() is not None:
removeName = self.lw_PltList.currentItem().text()
self.lw_PltList.takeItem(removeIndex)
for i in range(len(pltList)):
if pltList[i]['name'] == removeName:
del pltList[i]
break
else:
next
def PrepareFigure(self):
global figure
showLegend = self.cb_Legend.isChecked()
showTitle = self.cb_StudiesNames.isChecked()
if self.rb_Selective.isChecked():
# get selected figure card
slctFig = self.lbl_SlctFig.text()
for i in range(len(figList)):
if figList[i]['name'] == slctFig:
slctFig = figList[i]
slctFigID = figList[i]['id']
break
else:
next
# generate sub-plots list of cards
slctPlt = []
for i in range(len(pltList)):
if pltList[i]['figid'] == slctFigID:
slctPlt.append(pltList[i])
next
else:
next
# process figure in plotter
figure = PlotterSelective(slctFig, slctPlt, showLegend, showTitle)
if self.rb_Collective.isChecked():
# get selected figure card
slctFig = self.lbl_SlctFig.text()
for i in range(len(figList)):
if figList[i]['name'] == slctFig:
slctFig = figList[i]
break
else:
next
# get studies list:
slctStd = []
for i in range(len(stdList)):
slctStd.append(stdList[i])
# get X data series:
xData = self.cb_Xdata.currentText()
xRange = xRangelist
traceStyle = self.cb_Style.currentText()
# process figure in plotter
figure = PlotterCollective(slctFig, slctStd, xData, xRange, traceStyle, showLegend, showTitle)
def SaveFigure(self):
try:
self.PrepareFigure()
if self.cb_FileFormat.currentText() == 'image':
savePath = QFileDialog.getSaveFileName(self, 'Save File', filter='*.png;;*.jpg;;*.svg')
figure.write_image(file= savePath[0], scale= 3, engine= 'kaleido')
elif self.cb_FileFormat.currentText() == 'html':
savePath = QFileDialog.getSaveFileName(self, 'Save File', filter='*.html')
figure.write_html(file= savePath[0])
elif self.cb_FileFormat.currentText() == 'json':
savePath = QFileDialog.getSaveFileName(self, 'Save File', filter='*.json')
figure.write_json(file= savePath[0], engine= 'json')
except:
pass
def PreviewFigure(self):
self.PrepareFigure()
try:
figure.write_image(file= './preview.jpg', scale= 1)
self.PreviewWindowDialog = PreviewWindow(self)
self.PreviewWindowDialog.show()
except:
pass
def OpenRangeWindow(self):
self.RangeDialog = RangeWindow(self)
self.RangeDialog.show()
class PreviewWindow(QMainWindow):
def __init__(self, parent= None):
super(PreviewWindow, self).__init__(parent)
self.setWindowTitle('Figure Preview')
self.resize(100, 100)
imageHolder = QPixmap('./preview.jpg')
if imageHolder.width() > int(QScreen.availableGeometry(QApplication.primaryScreen()).width() * 0.95):
imageWidth = int(QScreen.availableGeometry(QApplication.primaryScreen()).width() / 1.2)
imageHeight = int(imageHolder.height() * (imageWidth / imageHolder.width()))
elif imageHolder.height() > int(QScreen.availableGeometry(QApplication.primaryScreen()).height() * 0.95):
imageHeight = int(QScreen.availableGeometry(QApplication.primaryScreen()).height() / 1.2)
imageWidth = int(imageHolder.width() * (imageHeight / imageHolder.height()))
else:
imageWidth = imageHolder.width()
imageHeight = imageHolder.height()
self.setMinimumSize(imageWidth, imageHeight)
self.setMaximumSize(imageWidth, imageHeight)
self.imageLable = QLabel()
self.imageLable.setPixmap(imageHolder)
self.imageLable.setScaledContents(True)
self.setCentralWidget(self.imageLable)
os.remove('./preview.jpg')
class RangeWindow(QMainWindow, Ui_RangeForm):
def __init__(self, parent= MainWindow):
super(RangeWindow, self).__init__(parent)
self.setupUi(self)
self.UpdateStack()
self.pushButton.clicked.connect(self.GenerateList)
def UpdateStack(self):
if xDataMode == 'Energy Balance (per Index)':
self.groupBox.setVisible(True)
self.groupBox_2.setVisible(False)
elif xDataMode == 'Installed Capacities (per Index)':
self.groupBox.setVisible(False)
self.groupBox_2.setVisible(True)
def GenerateList(self):
xRangelist.clear()
if self.groupBox.isVisible():
if self.checkBox_1.isChecked():
xRangelist.append(self.checkBox_1.text())
if self.checkBox_2.isChecked():
xRangelist.append(self.checkBox_2.text())
if self.checkBox_3.isChecked():
xRangelist.append(self.checkBox_3.text())
if self.checkBox_4.isChecked():
xRangelist.append(self.checkBox_4.text())
if self.checkBox_5.isChecked():
xRangelist.append(self.checkBox_5.text())
elif self.groupBox_2.isVisible():
if self.checkBox_6.isChecked():
xRangelist.append(self.checkBox_6.text())
if self.checkBox_7.isChecked():
xRangelist.append(self.checkBox_7.text())
if self.checkBox_8.isChecked():
xRangelist.append(self.checkBox_8.text())
if self.checkBox_9.isChecked():
xRangelist.append(self.checkBox_9.text())
if self.checkBox_10.isChecked():
xRangelist.append(self.checkBox_10.text())
if self.checkBox_11.isChecked():
xRangelist.append(self.checkBox_11.text())
if self.checkBox_12.isChecked():
xRangelist.append(self.checkBox_12.text())
if self.checkBox_13.isChecked():
xRangelist.append(self.checkBox_13.text())
if self.checkBox_14.isChecked():
xRangelist.append(self.checkBox_14.text())
if self.checkBox_15.isChecked():
xRangelist.append(self.checkBox_15.text())
if self.checkBox_16.isChecked():
xRangelist.append(self.checkBox_16.text())
if self.checkBox_17.isChecked():
xRangelist.append(self.checkBox_17.text())
if self.checkBox_18.isChecked():
xRangelist.append(self.checkBox_18.text())
if self.checkBox_19.isChecked():
xRangelist.append(self.checkBox_19.text())
if self.checkBox_20.isChecked():
xRangelist.append(self.checkBox_20.text())
if self.checkBox_21.isChecked():
xRangelist.append(self.checkBox_21.text())
if self.checkBox_22.isChecked():
xRangelist.append(self.checkBox_22.text())
if self.checkBox_23.isChecked():
xRangelist.append(self.checkBox_23.text())
if self.checkBox_24.isChecked():
xRangelist.append(self.checkBox_24.text())
if self.checkBox_26.isChecked():
xRangelist.append(self.checkBox_26.text())
if self.checkBox_27.isChecked():
xRangelist.append(self.checkBox_27.text())
if self.checkBox_29.isChecked():
xRangelist.append(self.checkBox_29.text())
if self.checkBox_31.isChecked():
xRangelist.append(self.checkBox_31.text())
self.close()
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec())