-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPieChartTab.py
164 lines (134 loc) · 6.77 KB
/
PieChartTab.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
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import pandas as pd
import sys
import PieChartWidget
import FilterationWidgets
class wdgPieChartTab(QWidget):
def __init__(self, data):
super().__init__()
self.data = data
self.setupUI()
def setupUI(self):
# GroupBox of Type
self.gbxType = QGroupBox()
self.lytType = QHBoxLayout()
self.gbxType.setTitle("Type of Chart")
self.rbtDrillDown = QRadioButton('DrillDown')
self.rbtDrillDown.setChecked(True)
self.rbtStacked = QRadioButton('Stacked')
self.lytType.addWidget(self.rbtDrillDown)
self.lytType.addWidget(self.rbtStacked)
self.gbxType.setLayout(self.lytType)
self.lytComboBoxes = QFormLayout()
self.lytComboBoxes.setFormAlignment(Qt.AlignCenter)
self.lytComboBoxes.setLabelAlignment(Qt.AlignRight)
self.cmbAccording = QComboBox()
self.cmbAccording.addItems(getCategoryColumnNames(self.data, ['Time', 'Date', 'Summary of Operations']))
self.cmbBreakDown = QComboBox()
self.cmbBreakDown.addItems(getCategoryColumnNames(self.data, ['Time', 'Date', 'Summary of Operations']))
self.cmbBreakDown.setCurrentIndex(1)
self.cmbFiltration = QComboBox()
self.filtrationSeries = getAllColNamesAndTypes(self.data, ['Summary of Operations'])
self.cmbFiltration.addItem('None')
self.cmbFiltration.addItems(self.filtrationSeries.index)
self.cmbFiltration.currentTextChanged.connect(self.evt_cmbFiltrationChanged)
self.lytComboBoxes.addRow("According to", self.cmbAccording)
self.lytComboBoxes.addRow("Break Down", self.cmbBreakDown)
self.lytComboBoxes.addRow("Filtered By", self.cmbFiltration)
self.lytFiltration = QVBoxLayout()
self.btnSubmit = QPushButton('Submit')
self.lytLeft = QVBoxLayout()
self.lytLeft.addWidget(self.gbxType, 3)
self.lytLeft.addLayout(self.lytComboBoxes, 40)
self.lytLeft.addLayout(self.lytFiltration, 50)
self.lytLeft.addWidget(self.btnSubmit, 3)
self.lytRight = QVBoxLayout()
self.btnSubmit.clicked.connect(self.evt_btnSubmitClicked)
self.lytMain = QHBoxLayout()
self.lytMain.addLayout(self.lytLeft, 1)
self.lytMain.addLayout(self.lytRight, 9)
self.setLayout(self.lytMain)
def evt_cmbFiltrationChanged(self, text):
# remove the previous Filtration Widget
while self.lytFiltration.count():
child = self.lytFiltration.takeAt(0)
if child.widget():
child.widget().deleteLater()
if text == 'None':
pass
elif 'Time' in text or 'time' in text:
self.wdgFiltration = FilterationWidgets.TimeFiltrationWidget(self.data, text)
self.lytFiltration.addWidget(self.wdgFiltration)
elif 'Date' in text or 'date' in text:
self.wdgFiltration = FilterationWidgets.DateFiltrationWidget(self.data, text)
self.lytFiltration.addWidget(self.wdgFiltration)
elif self.filtrationSeries[text] == 'object':
self.wdgFiltration = FilterationWidgets.CategoryFiltrationWidget(self.data, text)
self.wdgFiltration.btnEnter.setDefault(True)
self.btnSubmit.setDefault(False)
self.lytFiltration.addWidget(self.wdgFiltration)
elif "int" in str(self.filtrationSeries[text]) or "float" in str(self.filtrationSeries[text]):
self.wdgFiltration = FilterationWidgets.NumericFiltrationWidget(self.data, text)
self.lytFiltration.addWidget(self.wdgFiltration)
def checkInputData(self):
string = ""
if self.cmbAccording.currentText() == self.cmbBreakDown.currentText():
string += "-The Main column and Breakdown column are the same.\n"
if self.cmbFiltration.currentText() == 'None':
pass
elif self.filtrationSeries[self.cmbFiltration.currentText()] == 'object':
if "Time" in self.cmbFiltration.currentText() or "time" in self.cmbFiltration.currentText():
if self.wdgFiltration.timeFrom.time() > self.wdgFiltration.timeTo.time():
string += "-Wrong Input Time\n"
elif "Date" in self.cmbFiltration.currentText() or "date" in self.cmbFiltration.currentText():
if self.wdgFiltration.dateFrom.date() > self.wdgFiltration.dateTo.date():
string += "-Wrong Input Date\n"
elif self.wdgFiltration.lstWidget.count() == 0:
string += "-Nothing is selected in the filtration.\n"
elif "int" in str(self.filtrationSeries[self.cmbFiltration.currentText()]) or "float" in str(self.filtrationSeries[self.cmbFiltration.currentText()]):
if self.wdgFiltration.spinMin.value() > self.wdgFiltration.spinMax.value():
string += "-Wrong input in filtration.\n"
return string
def evt_btnSubmitClicked(self):
# remove the previous Chart Widget
while self.lytRight.count():
child = self.lytRight.takeAt(0)
if child.widget():
child.widget().deleteLater()
errors = self.checkInputData()
if errors == "":
if self.rbtDrillDown.isChecked():
type = 'DrillDown'
else:
type = 'Stacked'
mainCol = self.cmbAccording.currentText()
breakDownCol = self.cmbBreakDown.currentText()
if self.cmbFiltration.currentText() == 'None':
data = self.data
else:
data = self.wdgFiltration.getFilteredData()
# check if the data is empty or not
if data.empty:
QMessageBox.critical(self, "Error", "There is no Data because of Filtration")
else:
wdgChart = PieChartWidget.wdgPieChart(type, mainCol, breakDownCol, data)
self.lytRight.addWidget(wdgChart)
else:
QMessageBox.critical(self, 'Error', errors)
def getAllColNamesAndTypes(data: pd.DataFrame, ExcludedCols: list) -> pd.Series:
dataTypes = data.dtypes
for col in ExcludedCols:
# check first if the column is in the data
if col in dataTypes.index:
dataTypes.drop(labels=col, inplace=True)
return dataTypes
def getCategoryColumnNames(data: pd.DataFrame, ExcludedCols: list) -> list:
dataTypes = data.dtypes
colNames = []
for type in dataTypes.index:
if type not in ExcludedCols and dataTypes[type] == 'object':
colNames.append(type)
return colNames
## excluded: 'Time', 'Date', 'Summary of Operations'