-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathZFunAna.py
1009 lines (870 loc) · 44.3 KB
/
ZFunAna.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
765
766
767
768
769
770
771
772
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
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#在列表中显示元素
#删除项目
from PySide2.QtUiTools import QUiLoader
from PySide2.QtCore import *
from PySide2.QtWidgets import *
from PySide2.QtGui import QCursor
from PySide2.QtCharts import QtCharts
from PySide2 import QtWidgets
import numpy,keyboard
import pyecharts.options as opts
from pyecharts.charts import Bar3D
import Zplot
import ZfinanceCfg
import os
import pandas as pd
import ZBaseFunc,ZfinanceCfg,ZFavorEditor
class FunAnaProc:
def __init__(self,GlobalUI,APP):
self.GlobalAPP = APP
self.GlobalMainUI = GlobalUI
self.SortListDict = dict()
self.SortListvsCnt = []
self.SortListvsCnt_IntelRecomd = []
self.SortListvsCnt_Orginal = []
self.TickersInfoDataBase = ZBaseFunc.GetTickersInfo()
self.GlobalMainUI.PreviewLevelNum.setMaximum(10)
self.GlobalMainUI.PreviewLevelNum.setMinimum(1)
self.GlobalMainUI.PreviewDensity.setMaximum(20)
self.GlobalMainUI.PreviewDensity.setMinimum(1)
self.GlobalMainUI.PreviewPeriod.setMaximum(9)
self.GlobalMainUI.PreviewPeriod.setMinimum(0)
self.GlobalMainUI.ValueRatio_PieChart.setContentsMargins(0, 0, 0, 0)
self.ValueRatio_PieChartLay = QtWidgets.QVBoxLayout(self.GlobalMainUI.ValueRatio_PieChart)
self.ValueRatio_PieChartLay.setContentsMargins(0, 0, 0, 0)
self.GlobalMainUI.RaiseRatio_BarChart.setContentsMargins(0, 0, 0, 0)
self.RaiseRatio_BarChartLay = QtWidgets.QVBoxLayout(self.GlobalMainUI.RaiseRatio_BarChart)
self.RaiseRatio_BarChartLay.setContentsMargins(0, 0, 0, 0)
self.GlobalMainUI.MarketCapTrend_LineChart.setContentsMargins(0, 0, 0, 0)
self.MarketCapTrend_LineChartLay = QtWidgets.QVBoxLayout(self.GlobalMainUI.MarketCapTrend_LineChart)
self.MarketCapTrend_LineChartLay.setContentsMargins(0, 0, 0, 0)
self.GlobalMainUI.PreGroup.clicked.connect(self.HandlePreGroup)
#self.GlobalMainUI.StartSortingAnalyse.clicked.connect(self.HandleStartSortingAnalyse)
self.GlobalMainUI.FunAnaFilterInput.textChanged.connect(self.HandleInputChanged)
self.GlobalMainUI.ColumeList.setContextMenuPolicy(Qt.CustomContextMenu)
self.GlobalMainUI.ColumeList.customContextMenuRequested[QPoint].connect(self.ColumeListMenu)
self.GlobalMainUI.ColumeList.clicked.connect(self.HandleExplanSorts)
self.GlobalMainUI.SortingResultTree.setColumnCount(1)
self.GlobalMainUI.SortingResultTree.setHeaderLabels(['Cluster'],)
self.GlobalMainUI.SortingResultTree.setContextMenuPolicy(Qt.CustomContextMenu)
self.GlobalMainUI.SortingResultTree.customContextMenuRequested[QPoint].connect(self.SortingResultMenu)
self.GlobalMainUI.SortingResultTree.clicked.connect(self.HandlePreview)
self.GlobalMainUI.CompareGroupTree.setColumnCount(len(['Cluster','IPO']))
self.GlobalMainUI.CompareGroupTree.setHeaderLabels(['Cluster','IPO'])
self.GlobalMainUI.CompareGroupTree.setContextMenuPolicy(Qt.CustomContextMenu)
self.GlobalMainUI.CompareGroupTree.customContextMenuRequested[QPoint].connect(self.handleCompareClusterMenu)
#self.GlobalMainUI.CompareGroupTree.clicked.connect(self.HandlePreview)
self.GlobalMainUI.PreviewLevelNum.sliderReleased.connect(self.HandlePreviewLevelNum)
self.GlobalMainUI.PreviewLevelNum.valueChanged.connect(self.HandlePreviewLevelNumLabel)
self.GlobalMainUI.PreviewDensity.sliderReleased.connect(self.HandlePreviewDensity)
self.GlobalMainUI.PreviewDensity.valueChanged.connect(self.HandlePreviewDensityLabel)
self.GlobalMainUI.PreviewPeriod.sliderReleased.connect(self.HandlePreviewPeriod)
self.GlobalMainUI.PreviewPeriod.valueChanged.connect(self.HandlePreviewPeriodLabel)
self.GlobalMainUI.IntelRecom.clicked.connect(self.HandleIntelligentRecommendation)
try:
Temp= pd.read_csv('Data\\03_IntermediateData\TickersInfo.csv',sep=',',index_col='symbol',low_memory=False)
InfoDataBase = Temp[~numpy.isnan(Temp['sharesOutstanding'])]
ZBaseFunc.SetTickersInfo(IN=InfoDataBase)
except:
ZBaseFunc.Log2LogBox("TickersInfo.csv missing")
self.ValueRatioPreviewFlag = True
self.RaiseRatioPreviewFlag = True
self.MarketCapTrendPreviewFlag = True
self.GlobalMainUI.PreProcess.clicked.connect(self.HandlePreProcess)
self.PreProcessUI = QUiLoader().load('UIDesign\PreProcess.ui')
# self.PreProcessUI.LoadExist.clicked.connect(self.HandleLoadExist)
self.PreProcessUI.ReloadNew.clicked.connect(self.HandleReloadNew)
self.DCFavorEditorFavorUI = ZFavorEditor.FavorEditorUIProc()
self.GlobalAPP = APP
# self.HandlePreGroup()
def HandlePreProcess(self):
self.PreProcessUI.show()
self.PreProcessUI.PreProcessProgressBar.setValue(0)
def HandleReloadNew(self):
global GlobalAPP
ZBaseFunc.Log2LogBox('Reload Ticker info Start')
DataBasePath = os.getcwd() + '\\Data\\01_TickerDatabase'
InfoDataBase = pd.DataFrame()
try:
TickerFolders = os.listdir(DataBasePath)
except:
QMessageBox.information(None, "警告", "没有下载好的数据,请先去“数据下载”模块进行数据下载", QMessageBox.Yes,
QMessageBox.Yes)
os.mkdir(DataBasePath)
TickerFolders = []
Mnt = len(TickerFolders)
if Mnt == 0:
QMessageBox.information(None, "警告", "没有下载好的数据,请先去“数据下载”模块进行数据下载", QMessageBox.Yes,QMessageBox.Yes)
self.PreProcessUI.close()
return
cnt = 0
TemplastProgress = 0
for TickerFolder in TickerFolders:
cnt += 1
TempInfPath = DataBasePath+'/'+TickerFolder+'/'+TickerFolder+'_inf.csv'
FileName = ZBaseFunc.GetCompleteFileName('Data/01_TickerDatabase/' + TickerFolder + '/' + TickerFolder + '_1d')
if FileName == None:
StartDate = ''
else:
Tempdf = pd.read_csv('Data/01_TickerDatabase/' + TickerFolder + '/' + FileName, sep=',', index_col='DateTime')
StartDate = Tempdf.index[0]
try:
TempInfo = pd.read_csv(TempInfPath,sep=',',index_col='symbol')
TempInfo['DownloadStartDate'] = StartDate
InfoDataBase = InfoDataBase.append(TempInfo)
except:
pass
if (cnt/Mnt - TemplastProgress >=0.005):
TemplastProgress = cnt/Mnt
self.PreProcessUI.PreProcessProgressBar.setValue(TemplastProgress*100)
self.GlobalAPP.processEvents()
InfoDataBase.to_csv('Data\\03_IntermediateData\\TickersInfo.csv',sep=',',index_label='symbol')
InfoDataBase = InfoDataBase[~numpy.isnan(InfoDataBase['sharesOutstanding'])]
ZBaseFunc.SetTickersInfo(InfoDataBase)
ZBaseFunc.SetTickersInfo(IN=InfoDataBase)
ZBaseFunc.Log2LogBox('Reload Ticker info Finished')
self.PreProcessUI.close()
return
def HandleIntelligentRecommendation(self):
if self.GlobalMainUI.IntelRecom.isChecked():
self.SortListvsCnt = self.SortListvsCnt_IntelRecomd
else:
self.SortListvsCnt = self.SortListvsCnt_Orginal
slm = QStringListModel()
slm.setStringList(self.SortListvsCnt)
self.GlobalMainUI.ColumeList.setModel(slm)
def HandlePreviewLevelNumLabel(self):
self.GlobalMainUI.LevelLabel.setText('分级: '+ str(self.GlobalMainUI.PreviewLevelNum.value()))
def HandlePreviewDensityLabel(self):
self.GlobalMainUI.DensityLabel.setText('颗粒度: '+str(self.GlobalMainUI.PreviewDensity.value()))
def HandlePreviewPeriodLabel(self):
if ZfinanceCfg.PreviewPeriodList[self.GlobalMainUI.PreviewPeriod.value()] == -1:
self.GlobalMainUI.PeriodLabel.setText('周期: Max')
else:
self.GlobalMainUI.PeriodLabel.setText('周期: '+str(int(ZfinanceCfg.PreviewPeriodList[self.GlobalMainUI.PreviewPeriod.value()]/5))+' wks')
def HandlePreviewLevelNum(self):
self.GlobalMainUI.LevelLabel.setText('分级: '+ str(self.GlobalMainUI.PreviewLevelNum.value()))
if(self.GlobalMainUI.SortingResultTree.currentItem() != None):
self.HandlePreview()
def HandlePreviewDensity(self):
self.GlobalMainUI.DensityLabel.setText('颗粒度: '+str(self.GlobalMainUI.PreviewDensity.value()))
if(self.GlobalMainUI.SortingResultTree.currentItem() != None):
self.HandlePreview()
def HandlePreviewPeriod(self):
if ZfinanceCfg.PreviewPeriodList[self.GlobalMainUI.PreviewPeriod.value()] == -1:
self.GlobalMainUI.PeriodLabel.setText('周期: Max')
else:
self.GlobalMainUI.PeriodLabel.setText('周期: '+str(int(ZfinanceCfg.PreviewPeriodList[self.GlobalMainUI.PreviewPeriod.value()]/5))+' wks')
if(self.GlobalMainUI.SortingResultTree.currentItem() != None):
self.HandlePreview()
def HandleRatioPreview(self,TempDataframe=pd.DataFrame()):#Pie
ZBaseFunc.Log2LogBox('start Draw')
RootDir = 'Data/01_TickerDatabase/'
LevelNum = self.GlobalMainUI.PreviewLevelNum.value()
EarlyDaysNum = ZfinanceCfg.PreviewPeriodList[self.GlobalMainUI.PreviewPeriod.value()]
LastLevelNum = 0
if len(TempDataframe)<=LevelNum:
LevelNum = len(TempDataframe)
PerLevelNum = 1
else:
PerLevelNum = int(len(TempDataframe)/LevelNum)
if(PerLevelNum == 0):
LevelNum = 1
PerLevelNum = len(TempDataframe)
else:
LastLevelNum = int(len(TempDataframe)-PerLevelNum*LevelNum)
if(LastLevelNum != 0):
LevelNum +=1
Temp = TempDataframe.sort_values('marketCap', ascending=False)
TickerListSortByMartetvalue = Temp.index.tolist()
TickerLevelGroup = dict()
if (LastLevelNum != 0):
for i in range(LevelNum-1):
templist=[]
for j in range(PerLevelNum):
templist.append(TickerListSortByMartetvalue.pop(0))
TickerLevelGroup['Level'+str(i+1)] = templist
TickerLevelGroup['LevelLast'] = TickerListSortByMartetvalue
else:
for i in range(LevelNum):
templist=[]
for j in range(PerLevelNum):
templist.append(TickerListSortByMartetvalue.pop(0))
TickerLevelGroup['Level'+str(i+1)] = templist
TickerLevelGroupMarketCap=dict()
TotalSum_Now = 0
TotalSum_Early = 0
TempCnt = 0
ProcessCntSum = len(Temp.index)
##############################################加载到内存########################
LevelDataframeDict = dict()
MinLastDay = 99999999
for Key, Value in TickerLevelGroup.items():
TempLevelDF = pd.DataFrame()
MaxLen = 0
for i in Value:
FileName_1d = ZBaseFunc.GetCompleteFileName(RootDir+'/'+i+'/'+i+'_1d_')
if(FileName_1d == None):
continue
TempDF = pd.read_csv(RootDir+'/'+i+'/'+FileName_1d,index_col='DateTime')
LastDay = int(FileName_1d.split('_')[3])
if(LastDay<MinLastDay):
MinLastDay = LastDay
LastDayIndex = TempDF.index[-1]
if(len(TempDF)>MaxLen):
TempLevelDF = TempLevelDF.reindex(TempDF.index.tolist())
MaxLen = len(TempDF)
TempLevelDF[i+'_Close'] = TempDF['Close']
TempCnt+=1
self.GlobalMainUI.FunAnaGroupProgressBar.setValue(TempCnt / ProcessCntSum * 100)
self.GlobalAPP.processEvents()
LevelDataframeDict[Key] = TempLevelDF
self.GlobalMainUI.FunAnaGroupProgressBar.setValue(100)
self.GlobalAPP.processEvents()
TempDFlist=[]
for Key, Value in LevelDataframeDict.items():
Sum_Now = 0
Sum_Early = 0
for i in TickerLevelGroup[Key]:
Shareamount= TempDataframe.loc[i, 'sharesOutstanding']
try:
TempClosePrice = Value[i+'_Close']
except:
continue
TempClosePrice.dropna(inplace=True)
MarketCap_Now = TempClosePrice.iloc[-1] * Shareamount
if (len(TempClosePrice) <= EarlyDaysNum-1) or EarlyDaysNum == -1:
MarketCap_Early = TempClosePrice.iloc[0] * Shareamount
else:
MarketCap_Early = TempClosePrice.iloc[-EarlyDaysNum] * Shareamount
Sum_Now = Sum_Now + MarketCap_Now
Sum_Early = Sum_Early + MarketCap_Early
TickerLevelGroupMarketCap[Key] = [Sum_Now, Sum_Early]
TotalSum_Now = TotalSum_Now + Sum_Now
TotalSum_Early = TotalSum_Early + Sum_Early
TempDFlist.append(Value)
TempGroupDataframe = pd.concat(TempDFlist,axis=1)
TempGroupDataframe = TempGroupDataframe[:LastDayIndex]
Density = self.GlobalMainUI.PreviewDensity.value()
TempIndex = []
TempGroupDataframe = TempGroupDataframe.iloc[-(EarlyDaysNum+1):-1]
for i in range(0,len(TempGroupDataframe),Density):
TempIndex.append(i)
TempGroupDataframe = pd.DataFrame(TempGroupDataframe.iloc[TempIndex]).fillna(0)
TempGroupDataframe_MC = pd.DataFrame()
for i in TempGroupDataframe.columns.values.tolist():
Ticker = i.split('_')[0]
TempGroupDataframe_MC[Ticker+'_MarketCap'] = TempGroupDataframe[Ticker+'_Close']*TempDataframe.loc[Ticker, 'sharesOutstanding']/1000000000
TempGroupDataframe_MC['MarketCap_sum'] = TempGroupDataframe_MC.apply(lambda x: x.sum(), axis=1)
Lines = dict()
self.MarkerCapRatioPreview(TickerLevelGroupMarketCap,TotalSum_Now)
self.RaiseRatioPreview(TickerLevelGroupMarketCap)
Lines['sum'] = TempGroupDataframe_MC['MarketCap_sum'].tolist()
self.MarketcapSumTrendPreview(Lines)
ZBaseFunc.Log2LogBox('end Draw')
def MarkerCapRatioPreview(self, TickerLevelGroupMarketCap=dict(),TotalSum_Now = None):
if self.ValueRatioPreviewFlag == False:
self.ValueRatio_PieChartLay.removeWidget(self.ValueRatio_PieChartView)
pieseries = QtCharts.QPieSeries()
for Key, Value in TickerLevelGroupMarketCap.items():
pieseries.append(Key,Value[0]/TotalSum_Now)
pieseries.setPieSize(2.5)
chart = QtCharts.QChart()
chart.setTitle("MarketCap Ratio")
chart.addSeries(pieseries)
chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations)
chart.legend().hide()
#############################################
self.ValueRatio_PieChartView = QtCharts.QChartView(chart, self.GlobalMainUI)
self.ValueRatio_PieChartView.setContentsMargins(0, 0, 0, 0)
self.ValueRatio_PieChartLay.addWidget(self.ValueRatio_PieChartView)
self.ValueRatio_PieChartView.setGeometry(0, 0, self.GlobalMainUI.width(), self.GlobalMainUI.height())
self.ValueRatioPreviewFlag = False
def RaiseRatioPreview(self, TickerLevelGroupMarketCap=dict()):
if self.RaiseRatioPreviewFlag == False:
self.RaiseRatio_BarChartLay.removeWidget(self.RaiseRatio_BarChartView)
# we want to create percent bar series
barseries = QtCharts.QBarSeries()
Max = 0
for Key, Value in TickerLevelGroupMarketCap.items():
TempLevel = QtCharts.QBarSet(Key)
RaiseRate = Value[0]/Value[1]
TempLevel.append(RaiseRate)
barseries.append(TempLevel)
if (RaiseRate>Max):
Max = RaiseRate
chart = QtCharts.QChart()
chart.addSeries(barseries)
chart.setTitle("Raise Ratio")
chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations)
# chart.setTheme(QtCharts.QChart.ChartThemeDark)
axisX = QtCharts.QValueAxis()
axisX.setRange(-0.25, 0.25)
chart.setAxisX(axisX, barseries)
axisY = QtCharts.QValueAxis()
axisY.setRange(0, int(Max)+1)
chart.setAxisY(axisY, barseries)
#chart.removeAxis(axisY)
chart.removeAxis(axisX)
# chart.createDefaultAxes()
chart.legend().setVisible(False)
# create chartview and add the chart in the chartview
self.RaiseRatio_BarChartView = QtCharts.QChartView(chart, self.GlobalMainUI)
self.RaiseRatio_BarChartView.setContentsMargins(0, 0, 0, 0)
self.RaiseRatio_BarChartLay.addWidget(self.RaiseRatio_BarChartView)
self.RaiseRatio_BarChartView.setGeometry(0, 0, self.GlobalMainUI.width(), self.GlobalMainUI.height())
self.RaiseRatioPreviewFlag = False
def MarketcapSumTrendPreview(self,Lines=dict()):#Line
if self.MarketCapTrendPreviewFlag == False:
self.MarketCapTrend_LineChartLay.removeWidget(self.MarketCapTrend_LineChartView)
MaxMarketcapSum = max(Lines['sum'])
MinMarketcapSum = min(Lines['sum'])
MarketcapSumLen = len(Lines['sum'])
chart = QtCharts.QChart()
Lineseries = QtCharts.QLineSeries()
chart.addSeries(Lineseries)
dtaxisX = QtCharts.QValueAxis()
vlaxisY = QtCharts.QValueAxis()
#设置坐标轴显示范围
dtaxisX.setMin(0)
dtaxisX.setMax(MarketcapSumLen)
vlaxisY.setMin(MinMarketcapSum)
vlaxisY.setMax(MaxMarketcapSum)
chart.setTitle("MarketCap : B$")
# self.dtaxisX.setTickCount(6)
# self.vlaxisY.setTickCount(11)
#设置网格不显示
vlaxisY.setGridLineVisible(True)
#把坐标轴添加到chart中
chart.addAxis(dtaxisX,Qt.AlignBottom)
chart.addAxis(vlaxisY,Qt.AlignLeft)
#把曲线关联到坐标轴
Lineseries.attachAxis(dtaxisX)
Lineseries.attachAxis(vlaxisY)
chart.removeAxis(dtaxisX)
#self.chart.removeAxis(self.vlaxisY)
chart.legend().hide()
#self.setChart(self.chart)
x = 0
for i in Lines['sum']:
Lineseries.append(x ,i)
x += 1
self.MarketCapTrend_LineChartView = QtCharts.QChartView(chart, self.GlobalMainUI)
self.MarketCapTrend_LineChartView.setContentsMargins(0, 0, 0, 0)
self.MarketCapTrend_LineChartLay.addWidget(self.MarketCapTrend_LineChartView)
self.MarketCapTrend_LineChartView.setGeometry(0, 0, self.GlobalMainUI.width(), self.GlobalMainUI.height())
self.MarketCapTrendPreviewFlag = False
return
def HandlePreview(self):
TempDataframe = self.TickersInfoDataBase
TempLink = self.GlobalMainUI.SortingResultTree.currentItem()
if TempLink.parent() == None:
return
LinkCol = [TempLink.text(0)]
while TempLink.parent() != None:
TempLink = TempLink.parent()
LinkCol.insert(0, TempLink.text(0))
print(LinkCol)
t = 0
for i in range(len(LinkCol) - 2):
t += 1
Cluster = LinkCol[i].split(':')[1]
ClusterMember = LinkCol[i + 1].split('[')[0]
TempDataframe = TempDataframe[TempDataframe[Cluster].isin([ClusterMember])]
Cluster = LinkCol[t].split(':')[1]
ClusterMember = self.GlobalMainUI.SortingResultTree.currentItem().text(0).split('[')[0]
TempDataframe = TempDataframe[TempDataframe[Cluster].isin([ClusterMember])]
TickerList = []
for i in TempDataframe.index.tolist():
TickerList.append(i+':'+str(TempDataframe.loc[i,'shortName']))
if TickerList == []:
return
Temp = QStringListModel()
Temp.setStringList(TickerList)
self.GlobalMainUI.GroupList.setModel(Temp)
if self.GlobalMainUI.RatioPreview.isChecked() :
self.HandleRatioPreview(TempDataframe)
def HandlePreGroup(self):
self.TickersInfoDataBase = ZBaseFunc.GetTickersInfo()
try:
if self.TickersInfoDataBase == None:
QMessageBox.information(None, "警告", "没有找到预处理好的数据,请先“导入数据”", QMessageBox.Yes,
QMessageBox.Yes)
return
except:
pass
SortList = self.TickersInfoDataBase.columns.values.tolist()
TotalTickerNum = len(self.TickersInfoDataBase)
ProcessCntSum = len(SortList)*2
SortListDict=dict()
TempCnt = 0
for Sort_i in SortList:
SortListDict[Sort_i] = len(self.TickersInfoDataBase.groupby(Sort_i).count())
TempCnt += 1
self.GlobalMainUI.FunAnaGroupProgressBar.setValue(TempCnt/ProcessCntSum*100)
self.GlobalAPP.processEvents()
SortListvsNum= sorted(SortListDict.items(), key=lambda item: item[1], reverse=False)
self.SortListvsCnt_Orginal=[]
self.SortListvsCnt_IntelRecomd = []
SortListvsCnt_ReC = []
SortListvsCnt_ReO = []
for SortListDict_i in SortListvsNum:
ClusterGroupNum = SortListDict_i[1]
ClusterAvailableDataNum = len(self.TickersInfoDataBase[SortListDict_i[0]].dropna())
self.SortListDict[SortListDict_i[0]] = self.TickersInfoDataBase.groupby(SortListDict_i[0]).count().index.tolist()
Sign = 'X'
if ClusterAvailableDataNum >0.75*TotalTickerNum and \
ClusterGroupNum <0.3 *TotalTickerNum and\
ClusterGroupNum>=6 and \
type(self.TickersInfoDataBase[SortListDict_i[0]].iloc[0]) == type('numpy.float64(0)'):
Sign = 'C'
SortListvsCnt_ReC.append('[' + str(SortListDict_i[1]) + '/' + str(
len(self.TickersInfoDataBase[SortListDict_i[0]].dropna())) + '/' + Sign + ']:' + SortListDict_i[0])
if ClusterAvailableDataNum >0.9*TotalTickerNum and \
ClusterGroupNum >0.6*TotalTickerNum and \
type(self.TickersInfoDataBase[SortListDict_i[0]].iloc[0]) != type('numpy.float64(0)'):
Sign = 'O'
SortListvsCnt_ReO.append('[' + str(SortListDict_i[1]) + '/' + str(
len(self.TickersInfoDataBase[SortListDict_i[0]].dropna())) + '/' + Sign + ']:' + SortListDict_i[0])
self.SortListvsCnt_Orginal.append('['+str(SortListDict_i[1])+'/'+str(len(self.TickersInfoDataBase[SortListDict_i[0]].dropna())) +'/'+Sign+']:'+SortListDict_i[0])
TempCnt += 1
self.GlobalMainUI.FunAnaGroupProgressBar.setValue(TempCnt / ProcessCntSum * 100)
self.GlobalAPP.processEvents()
self.SortListvsCnt_IntelRecomd = SortListvsCnt_ReC+SortListvsCnt_ReO
if self.GlobalMainUI.IntelRecom.isChecked():
self.SortListvsCnt = self.SortListvsCnt_IntelRecomd
else:
self.SortListvsCnt = self.SortListvsCnt_Orginal
slm = QStringListModel()
slm.setStringList(self.SortListvsCnt)
self.GlobalMainUI.ColumeList.setModel(slm)
def HandleInputChanged(self):
VagueText = self.GlobalMainUI.FunAnaFilterInput.text()
slm = QStringListModel()
self.FliteredList=list(filter(lambda x: VagueText in x, self.SortListvsCnt))
slm.setStringList(self.FliteredList)
self.GlobalMainUI.ColumeList.setModel(slm)
def HandleExplanSorts(self,index):
self.GlobalMainUI.ColumeList.selectionModel().selectedIndexes()[0].data()
SelectedCol = self.GlobalMainUI.ColumeList.selectionModel().selectedIndexes()[0].data().split(':')[1]
Temp = QStringListModel()
Temp.setStringList(str(x) for x in self.SortListDict[SelectedCol])
self.GlobalMainUI.GroupList.setModel(Temp)
print(index)
def EventRank(self,Tree = None):
TempCol = Tree.currentColumn()
cursor = QTreeWidgetItemIterator(Tree)
while cursor.value():
TempStr = ZBaseFunc.SortTrick(cursor.value().text(TempCol))
cursor.value().setText(TempCol,TempStr)
cursor = cursor.__iadd__(1)
Tree.setSortingEnabled(True)
Tree.sortByColumn(Tree.currentColumn(),)
Tree.setSortingEnabled(False)
cursor = QTreeWidgetItemIterator(Tree)
while cursor.value():
TempStr = cursor.value().text(TempCol)
try:
TempStr = TempStr.split('*')[1]
except:
try:
TempStr = '-'+TempStr.split('-')[1]
except:
pass
cursor.value().setText(TempCol,TempStr)
cursor = cursor.__iadd__(1)
def EventDeleteZero(self):
cursor = QTreeWidgetItemIterator(self.GlobalMainUI.SortingResultTree)
DeleteList = []
while cursor.value():
if('[0]' in cursor.value().text(0) ):
DeleteList.insert(0,cursor.value())
cursor = cursor.__iadd__(1)
for i in DeleteList:
i.parent().removeChild(i)
print(self.GlobalMainUI.SortingResultTree.currentColumn())
def EventDeleteOp(self):
if self.GlobalMainUI.SortingResultTree.currentColumn() == 0:
return
HeaderLabel = []
for i in range(self.GlobalMainUI.SortingResultTree.columnCount()):
HeaderLabel.append(self.GlobalMainUI.SortingResultTree.headerItem().text(i))
HeaderLabel.pop(self.GlobalMainUI.SortingResultTree.currentColumn())
self.GlobalMainUI.SortingResultTree.setColumnCount(len(HeaderLabel))
self.GlobalMainUI.SortingResultTree.setHeaderLabels((HeaderLabel))
print(self.GlobalMainUI.SortingResultTree.currentColumn())
def EventDeleteFatherLevel(self):
print(self.GlobalMainUI.SortingResultTree.currentItem().text(0))
def EventDeleteThisItem(self,Tree = None):
currNode = Tree.currentItem()
TempParent = currNode.parent()
if TempParent == None:
Tree.takeTopLevelItem(Tree.indexOfTopLevelItem(currNode))
else:
TempParent.removeChild(currNode)
def EventAddToCompare(self):
IterationNode = currNode = self.GlobalMainUI.SortingResultTree.currentItem()
TempParent = currNode.parent()
if TempParent != None:
TempStr = []
while IterationNode.parent() !=None:
TempStr.insert(0,IterationNode.text(0))
IterationNode = IterationNode.parent()
CompareClusterName = IterationNode.text(0).split(':')[1]
for i in TempStr:
CompareClusterName = CompareClusterName+':'+i.split('[')[0]
root = QTreeWidgetItem(self.GlobalMainUI.CompareGroupTree)
root.setText(0, CompareClusterName)
for i in range(2,self.GlobalMainUI.CompareGroupTree.columnCount()):
root.setCheckState(i, Qt.Checked)
model = self.GlobalMainUI.GroupList.model()
ProcessCntSum = model.rowCount()
TempCnt = 0
for row in range(model.rowCount()):
index = model.index(row, 0)
item = model.data(index, Qt.DisplayRole)
Ticker = item.split(':')[0]
StartDate = self.TickersInfoDataBase.loc[Ticker, 'DownloadStartDate'].replace('-','')
child = QTreeWidgetItem(root)
child.setText(0, Ticker)
child.setText(1, StartDate)
TempCnt += 1
self.GlobalMainUI.FunAnaGroupProgressBar.setValue(TempCnt / ProcessCntSum * 100)
self.GlobalAPP.processEvents()
pass
def EventAddToFavorList(self):
IterationNode = currNode = self.GlobalMainUI.SortingResultTree.currentItem()
TempParent = currNode.parent()
if TempParent != None:
TempStr = []
while IterationNode.parent() !=None:
TempStr.insert(0,IterationNode.text(0))
IterationNode = IterationNode.parent()
NewAddFavorName = IterationNode.text(0).split(':')[1]
for i in TempStr:
NewAddFavorName = NewAddFavorName+':'+i.split('[')[0]
model = self.GlobalMainUI.GroupList.model()
TempList = []
for row in range(model.rowCount()):
index = model.index(row, 0)
item = model.data(index, Qt.DisplayRole)
TempList.append(item.split(':')[0])
self.DCFavorEditorFavorUI.handleFavorEditor(SelectList=TempList, NewClass=NewAddFavorName)
pass
def handleCompareClusterMenu(self):
popMenu = QMenu()
if self.GlobalMainUI.CompareGroupTree.currentColumn() == 0:
DeleteThisItem = popMenu.addAction('删除该项')
DeleteThisItem.triggered.connect(lambda :self.EventDeleteThisItem(self.GlobalMainUI.CompareGroupTree))
LoadRawData = popMenu.addAction('加载所有列数据')
LoadRawData.triggered.connect(self.EventLoadRawData)
elif self.GlobalMainUI.CompareGroupTree.currentColumn() == 1:
Rank = popMenu.addAction('上市时间排序')
Rank.triggered.connect(lambda :self.EventRank(self.GlobalMainUI.CompareGroupTree))
# OutputInPlotly = popMenu.addAction('出图')
# OutputInPlotly.triggered.connect(self.HandleOutputInPlotly)
else:
DeleteEmptyTicker = popMenu.addAction('删除本列为空的Ticker')
# DeleteEmptyTicker.triggered.connect(self.EventDeleteEmptyTicker)
Rank = popMenu.addAction('从大到小排序')
Rank.triggered.connect(lambda: self.EventRank(self.GlobalMainUI.CompareGroupTree))
# DeleteEmptyTicker.triggered.connect(self.EventDeleteEmptyTicker)
popMenu.exec_(QCursor.pos())
pass
def SortingResultMenu(self, point):
self.HandlePreview()
popMenu = QMenu()
if self.GlobalMainUI.SortingResultTree.currentColumn() == 0:
DeleteThisItem = popMenu.addAction('删除该项')
DeleteThisItem.triggered.connect(lambda :self.EventDeleteThisItem(self.GlobalMainUI.SortingResultTree))
DeleteZero = popMenu.addAction('删除0项')
DeleteZero.triggered.connect(self.EventDeleteZero)
AnaCalc = popMenu.addAction('分析计算')
AnaCalc.triggered.connect(self.HandleStartSortingAnalyse)
AddToCompare = popMenu.addAction('添加到比较')
AddToCompare.triggered.connect(self.EventAddToCompare)
AddToFavorList = popMenu.addAction('添加到喜好列表')
AddToFavorList.triggered.connect(self.EventAddToFavorList)
else:
Rank = popMenu.addAction("从大小排序")
Rank.triggered.connect(lambda :self.EventRank(self.GlobalMainUI.SortingResultTree))
DeleteOp = popMenu.addAction('删除算子')
DeleteOp.triggered.connect(self.EventDeleteOp)
DrawInWebbrowser = popMenu.addAction('浏览器出图')
DrawInWebbrowser.triggered.connect(self.EventDrawInWebbrowser)
popMenu.exec_(QCursor.pos())
def EventDrawInWebbrowser(self):
ChildCnt = self.GlobalMainUI.SortingResultTree.currentItem().childCount()
if ChildCnt == 0:
ZBaseFunc.Log2LogBox('iChildCnt = 0')
return
ResultList = []
PlotItem={'Count':[]}
for i in range(1, self.GlobalMainUI.SortingResultTree.columnCount()):
ItemStr = self.GlobalMainUI.SortingResultTree.headerItem().text(i).replace('\n', ' ')
PlotItem[ItemStr]=[]
for i in range(ChildCnt):
iChild = self.GlobalMainUI.SortingResultTree.currentItem().child(i)
iChildCnt = iChild.childCount()
XaxisLabel = iChild.text(0).split('[')[0]
for j in range(iChildCnt):
jChild = iChild.child(j)
YaxisLabel = jChild.text(0).split('[')[0]
for k in range(0,self.GlobalMainUI.SortingResultTree.columnCount()):
if k == 0:
TempVal = int(iChild.child(j).text(0).split('[')[1].split(']')[0])
ItemStr = 'Count'
else:
TempVal = float(iChild.child(j).text(k))
ItemStr = self.GlobalMainUI.SortingResultTree.headerItem().text(k).replace('\n',' ')
PlotItem[ItemStr].append([XaxisLabel,YaxisLabel,TempVal])
Zplot.ZBar3D(PlotItem)
return
XAxisList = []
YAxisList = []
for i in ResultList:
if not i[0] in XAxisList:
XAxisList.append(i[0])
if not i[1] in YAxisList:
YAxisList.append(i[1])
Bar1 = (
Bar3D(init_opts=opts.InitOpts(width='960px', height='720px'))
.add(
series_name='bbb',
data=ResultList,
xaxis3d_opts=opts.Axis3DOpts(type_='category', data=XAxisList),
yaxis3d_opts=opts.Axis3DOpts(type_='category', data=YAxisList),
zaxis3d_opts=opts.Axis3DOpts(type_='value'),
grid3d_opts=opts.Grid3DOpts(width=len(XAxisList)*6, height=100, depth=len(YAxisList)*6),
)
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(
max_=1000000000000,
range_color=[
'#313695',
'#4575b4',
'#74add1',
'#abd9e9',
'#e0f3f8',
'#ffffbf',
'#fee090',
'#fdae61',
'#f46d43',
'#d73027',
'#a50026',
],
)
)
)
Bar2 =(
Bar3D(init_opts=opts.InitOpts(width='960px', height='720px'))
.add(
series_name='aaa',
data=ResultList,
xaxis3d_opts=opts.Axis3DOpts(type_='category', data=XAxisList),
yaxis3d_opts=opts.Axis3DOpts(type_='category', data=YAxisList),
zaxis3d_opts=opts.Axis3DOpts(type_='value'),
grid3d_opts=opts.Grid3DOpts(width=len(XAxisList) * 6, height=100, depth=len(YAxisList) * 6),
)
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(
max_=1000000000000,
range_color=[
'#313695',
'#4575b4',
'#74add1',
'#abd9e9',
'#e0f3f8',
'#ffffbf',
'#fee090',
'#fdae61',
'#f46d43',
'#d73027',
'#a50026',
],
)
)
)
from pyecharts.charts import Bar, Geo, Grid,Page
page = Page()
page.add(
Bar1(),
Bar2(),
)
page.render("page_default_layout.html")
def ColumeListMenu(self, point):
popMenu = QMenu()
try:
self.record = self.GlobalMainUI.ColumeList.selectionModel().selectedIndexes()[0]
except:
pass
SelectedColNumInfo = self.record.data().split(':')[0]
SelectedColNumKey = self.record.data().split(':')[1]
if keyboard.is_pressed('ctrl'):
Compare_SUM = popMenu.addAction("求总值")
Compare_AVG = popMenu.addAction('求平均值')
Compare_SUMvsxShare = popMenu.addAction('求总股本积和')
Compare_AVGvsxShare = popMenu.addAction('求总股本积平均')
Compare_SUMperShare = popMenu.addAction('每股平摊总值')
Compare_AVGperShare = popMenu.addAction('每股平摊均值')
Compare_SUM.triggered.connect(lambda :self.AddCompareValue('∑X\n'+SelectedColNumKey))
Compare_AVG.triggered.connect(lambda :self.AddCompareValue('(∑X)/n\n'+SelectedColNumKey))
Compare_SUMvsxShare.triggered.connect(lambda :self.AddCompareValue('∑(Share*X)\n'+SelectedColNumKey))
Compare_AVGvsxShare.triggered.connect(lambda :self.AddCompareValue('∑(Share*X)/n\n'+SelectedColNumKey))
Compare_SUMperShare.triggered.connect(lambda :self.AddCompareValue('∑(X/Share)\n'+SelectedColNumKey))
Compare_AVGperShare.triggered.connect(lambda :self.AddCompareValue('∑(X/Share)/n\n'+SelectedColNumKey))
else:
if SelectedColNumInfo.split('/')[2] =='O]':
Operator = popMenu.addMenu('添加算子')
AddOpSum = Operator.addAction('求和')
AddOpAverage = Operator.addAction('求均值')
AddCluster = popMenu.addAction("添加分类项")
else:
AddCluster = popMenu.addAction("添加分类项")
Operator = popMenu.addMenu('添加算子')
AddOpSum = Operator.addAction('求和')
AddOpAverage = Operator.addAction('求均值')
AddCluster.triggered.connect(self.EventAddCluster)
AddOpSum.triggered.connect(self.EventAddOpSum)
AddOpAverage.triggered.connect(self.EventAddOpAverage)
popMenu.exec_(QCursor.pos())
return
def EventLoadRawData(self):
cursor = QTreeWidgetItemIterator(self.GlobalMainUI.CompareGroupTree)
while cursor.value():
TempChild = cursor.value()
if TempChild.parent() != None:
for i in range(2,self.GlobalMainUI.CompareGroupTree.columnCount()):
ColIndex = self.GlobalMainUI.CompareGroupTree.headerItem().text(i).split('\n')[1]
Value = self.TickersInfoDataBase.loc[TempChild.text(0),ColIndex]
TempChild.setText(i, str(Value))
cursor = cursor.__iadd__(1)
pass
def EventAddCluster(self):
SelectedCol = self.GlobalMainUI.ColumeList.selectionModel().selectedIndexes()[0].data().split(':')[1]
TempDataframe = self.TickersInfoDataBase
if(self.GlobalMainUI.SortingResultTree.currentIndex().parent().row() == -1):
root = QTreeWidgetItem(self.GlobalMainUI.SortingResultTree)
for i in self.SortListDict[SelectedCol]:
Num = len(TempDataframe[TempDataframe[SelectedCol].isin([i])])
Temp=str(i)+'['+str(Num)+']'
child = QTreeWidgetItem(root)
child.setText(0, Temp)
root.setText(0, 'INFO:'+SelectedCol)
else:
if self.GlobalMainUI.SortingResultTree.currentItem().childCount() != 0:
return
TempLink = self.GlobalMainUI.SortingResultTree.currentItem()
LinkCol = [TempLink.text(0)]
while TempLink.parent() != None:
TempLink = TempLink.parent()
LinkCol.insert(0,TempLink.text(0))
t= 0
for i in range(len(LinkCol)-2):
t+=1
Cluster = LinkCol[i].split(':')[1]
ClusterMember = LinkCol[i+1].split('[')[0]
TempDataframe = TempDataframe[TempDataframe[Cluster].isin([ClusterMember])]
Cluster = LinkCol[t].split(':')[1]
cursor = QTreeWidgetItemIterator(self.GlobalMainUI.SortingResultTree.currentItem().parent())
ChildCnt = cursor.value().childCount()
cursor = cursor.__iadd__(1)
TempCnt = 0
ProcessCntSum = ChildCnt
for i in range(ChildCnt):
TempRoot = cursor.value()
TempRootName = TempRoot.text(0)+':'+SelectedCol
ClusterMember =TempRoot.text(0).split('[')[0]
TempDataframex = TempDataframe[TempDataframe[Cluster].isin([ClusterMember])]
TempRoot.setText(0,TempRootName)
cursor = cursor.__iadd__(1)
for j in self.SortListDict[SelectedCol]:
Num = len(TempDataframex[TempDataframex[SelectedCol].isin([j])])
Temp = str(j) + '[' + str(Num) + ']'
child = QTreeWidgetItem(TempRoot)
child.setText(0, Temp)
TempCnt+=1
self.GlobalMainUI.FunAnaGroupProgressBar.setValue(TempCnt / ProcessCntSum * 100)
self.GlobalAPP.processEvents()
print('not root')
pass
def AddCompareValue(self,SelectedCluster = None):
HeaderLabel = []
Temp = SelectedCluster
for i in range(self.GlobalMainUI.CompareGroupTree.columnCount()):
HeaderLabel.append(self.GlobalMainUI.CompareGroupTree.headerItem().text(i))
if self.GlobalMainUI.CompareGroupTree.headerItem().text(i) == Temp:
return
HeaderLabel.append(Temp)
self.GlobalMainUI.CompareGroupTree.setColumnCount(len(HeaderLabel))
self.GlobalMainUI.CompareGroupTree.setHeaderLabels((HeaderLabel))
cursor = QTreeWidgetItemIterator(self.GlobalMainUI.CompareGroupTree)
while cursor.value():
if cursor.value().parent() == None:
cursor.value().setCheckState(i+1, Qt.Checked)
cursor = cursor.__iadd__(1)
def EventAddOpSum(self):
HeaderLabel = []
SelectedCluster = self.GlobalMainUI.ColumeList.selectionModel().selectedIndexes()[0].data().split(':')[1]
Temp = SelectedCluster + '\n--SUM'
for i in range(self.GlobalMainUI.SortingResultTree.columnCount()):
HeaderLabel.append(self.GlobalMainUI.SortingResultTree.headerItem().text(i))
if self.GlobalMainUI.SortingResultTree.headerItem().text(i) == Temp:
return
HeaderLabel.append(Temp)
self.GlobalMainUI.SortingResultTree.setColumnCount(len(HeaderLabel))
self.GlobalMainUI.SortingResultTree.setHeaderLabels((HeaderLabel))
def EventAddOpAverage(self):
HeaderLabel = []
SelectedCluster = self.GlobalMainUI.ColumeList.selectionModel().selectedIndexes()[0].data().split(':')[1]
Temp = SelectedCluster + '\n--AVG'
for i in range(self.GlobalMainUI.SortingResultTree.columnCount()):
HeaderLabel.append(self.GlobalMainUI.SortingResultTree.headerItem().text(i))
if self.GlobalMainUI.SortingResultTree.headerItem().text(i) == Temp:
return
HeaderLabel.append(Temp)
self.GlobalMainUI.SortingResultTree.setColumnCount(len(HeaderLabel))
self.GlobalMainUI.SortingResultTree.setHeaderLabels((HeaderLabel))
pass
def HandleStartSortingAnalyse(self):
OperatorList = []
self.GlobalMainUI.SortingResultTree.setSortingEnabled(False)
for i in range(1,self.GlobalMainUI.SortingResultTree.columnCount()):
OperatorList.append({'col':self.GlobalMainUI.SortingResultTree.headerItem().text(i).split('\n--')[0],
'Op':self.GlobalMainUI.SortingResultTree.headerItem().text(i).split('\n--')[1]})
cursor = QTreeWidgetItemIterator(self.GlobalMainUI.SortingResultTree)
ProcessCntSum = 0
rootcnt = 0
while cursor.value():
cursor = cursor.__iadd__(1)
ProcessCntSum +=1
cursor = QTreeWidgetItemIterator(self.GlobalMainUI.SortingResultTree)
ProcessCnt = 0
while cursor.value():
Temp = cursor.value()
TempDataframe = self.TickersInfoDataBase
TempChild = Temp
if(Temp.parent() != None):
while Temp.parent() != None:
Cluster = Temp.parent().text(0).split(':')[1]
ClusterMember = Temp.text(0).split('[')[0]
TempDataframe = TempDataframe[TempDataframe[Cluster].isin([ClusterMember])]
Temp = Temp.parent()
Tempcnt = 1
for i in OperatorList:
if(i['Op'] == 'SUM'):
TempResult = round(TempDataframe[i['col']].sum(),4)
if (i['Op'] == 'AVG'):
if len(TempDataframe) == 0:
TempResult = 'NA'
else:
TempResult = round(TempDataframe[i['col']].sum()/len(TempDataframe),4)
TempChild.setText(Tempcnt,str(TempResult))