-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathanaxcel.py
323 lines (293 loc) · 12.9 KB
/
anaxcel.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
import functools
import os
import random
import sys
import time
import matplotlib.pyplot as plt
import openpyxl
import pandas as pd
import xlrd
import xlwt
from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.QtChart import QChart, QChartView, QPieSeries, QPieSlice
from PyQt5.QtCore import Qt, QTimer, QCoreApplication, QSettings
from PyQt5.QtGui import QPixmap, QPainter
from PyQt5.QtWidgets import QFileDialog, QTableWidgetItem, QGridLayout, QSplashScreen
from PyQt5.QtWidgets import QVBoxLayout
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.ticker import PercentFormatter
import anaxcelgui
import aboutmain
class anaxcelhandler(QtWidgets.QMainWindow, anaxcelgui.Ui_MainWindow):
def __init__(self, parent=None):
super(anaxcelhandler, self).__init__(parent)
if getattr(sys, 'frozen', False):
self.frozen = 'ever so'
self.bundle_dir = sys._MEIPASS
else:
self.bundle_dir = os.path.dirname(os.path.abspath(__file__))
self.setupUi(self)
self.setWindowIcon(QtGui.QIcon(self.bundle_dir + '/icons/icon.png'))
self.setStyleSheet(open("Dark/darkstyle.qss", "r").read())
self.listWidget.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.pushButtonbrowse.clicked.connect(self.openFileNamesDialog)
self.pushButtonclear.clicked.connect(self.clearwidget)
self.pushButtonselall.clicked.connect(self.selectall)
self.pushButtonload.clicked.connect(self.LoadProcess)
self.statusbar.showMessage('V 0.1')
self.actionExit.setShortcut('Ctrl+Q')
self.actionExit.triggered.connect(self.close_application)
self.actionExit.setStatusTip('Exit ')
self.pixmaplab = QPixmap('icons/excel48.png')
self.labelicon.setPixmap(self.pixmaplab)
self.labelicon.show()
self.label.setText("Loaded Excel File")
self.comboBoxfiletype.addItems(['xls', ' xlsx'])
self.pushButton_5.clicked.connect(self.analyseProcess)
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.toolbar = NavigationToolbar(self.canvas, self)
layoutx = QVBoxLayout()
layoutx.addWidget(self.toolbar)
layoutx.addWidget(self.canvas)
self.tab_6.setLayout(layoutx)
self.layoutdout = QGridLayout()
self.tab_4.setLayout(self.layoutdout)
self.chartView3 = QChartView()
self.layoutdout.addWidget(self.chartView3)
self.actionAdd_File.setShortcut('Ctrl+A')
self.actionAdd_File.triggered.connect(self.openFileNamesDialog)
self.actionAdd_File.setStatusTip('Add File ')
self.actionClear.setShortcut('Ctrl+C')
self.actionClear.triggered.connect(self.clearwidget)
self.actionClear.setStatusTip('Clear ')
self.actionSelect_All.setShortcut('Ctrl+S')
self.actionSelect_All.triggered.connect(self.selectall)
self.actionSelect_All.setStatusTip('Sellect All ')
self.actionLoad.setShortcut('Ctrl+L')
self.actionLoad.triggered.connect(self.LoadProcess)
self.actionLoad.setStatusTip('Load ')
self.actionAbout.setShortcut('Ctrl+I')
self.actionAbout.triggered.connect(self.showAbout)
self.actionAbout.setStatusTip('About ')
def showAbout(self):
self.window = aboutmain.abouthandel()
self.window.show()
def close_application(self):
choice = QtWidgets.QMessageBox.question(self, ' Confirm Exit ', "Are You Sure You want To Close Anaxcel ?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
if choice == QtWidgets.QMessageBox.Yes:
self.saveSettingstofilepackage()
sys.exit()
else:
pass
def openFileNamesDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
filterxls = "XLS (*.xls *.XLS)"
filterxlsx = "XLSX (*.xlsx *.XLSX)"
if self.comboBoxfiletype.currentIndex() == 0:
files, _ = QFileDialog.getOpenFileNames(self, "Select XLS Files", filter=filterxls, options=options)
if files:
for file in files:
self.listWidget.addItem(file)
elif self.comboBoxfiletype.currentIndex() == 1:
files, _ = QFileDialog.getOpenFileNames(self, "Select XLSX Files", filter=filterxlsx, options=options)
if files:
for file in files:
self.listWidget.addItem(file)
def clearwidget(self):
self.listWidget.clear()
self.tableWidget.clear()
self.label.setText("Loaded Excel File")
def selectall(self):
self.listWidget.selectAll()
# def CsvProcess(self):
# # merge csv files
# fout = open("combined.csv", "a")
# items = self.listWidget.selectedItems()
# xlsfiles = []
# for i in list(items):
# xlsfiles.append(str(i.text()))
# for line in open(xlsfiles[0]):
# fout.write(line)
# for index in xlsfiles[1:]:
# print(index)
# # now the rest:
# f = open(index)
# f.__next__() # skip the header
# for line in f:
# fout.write(line)
# f.close() # not really needed
# fout.close()
# f = open("folder/02-08-2017.CSV")
# for line in f:
# for x in line:
# if x == ';'
# line.split(';')
# print(line)
#
# f.close() # not really needed
def xlsProcess(self):
self.tableWidget.clear()
items = self.listWidget.selectedItems()
xlsfiles = []
for i in list(items):
xlsfiles.append(i.text())
wkbk = xlwt.Workbook()
outsheet = wkbk.add_sheet('Sheet1')
outrow_idx = 0
for f in xlsfiles:
insheet = xlrd.open_workbook(f).sheets()[0]
for row_idx in range(insheet.nrows):
for col_idx in range(insheet.ncols):
outsheet.write(outrow_idx, col_idx, insheet.cell_value(row_idx, col_idx))
outrow_idx += 1
wkbk.save(r'combined.xls')
# use on_demand=True to avoid loading worksheet data into memory
book = xlrd.open_workbook("combined.xls", on_demand=True)
sheet = book.sheet_by_index(0)
num_rows = sheet.nrows
num_col = sheet.ncols
self.tableWidget.setRowCount(num_rows)
self.tableWidget.setColumnCount(num_col)
for col in range(num_col):
for row in range(num_rows):
cell = sheet.cell(row, col)
if (not cell.value == "") and (not cell.value == " "):
self.tableWidget.setItem(row, col, QTableWidgetItem(str(cell.value)))
self.tableWidget.resizeColumnsToContents()
self.tableWidget.resizeRowsToContents()
def xlsxprocess(self):
self.tableWidget.clear()
items = self.listWidget.selectedItems()
xlsfiles = []
xlsoutput = []
c = 0
for i in list(items):
xlsfiles.append(str(i.text()))
for xlsx_item in xlsfiles:
wb = openpyxl.load_workbook(xlsx_item)
pathname = "file" + str(c) + ".xls"
wb.save(pathname)
c += 1
xlsoutput.append(str(pathname))
wkbk = xlwt.Workbook()
outsheet = wkbk.add_sheet('Sheet1')
outrow_idx = 0
for f in xlsoutput:
print(f)
insheet = xlrd.open_workbook(f).sheets()[0]
for row_idx in range(insheet.nrows):
for col_idx in range(insheet.ncols):
outsheet.write(outrow_idx, col_idx, insheet.cell_value(row_idx, col_idx))
outrow_idx += 1
wkbk.save(r'combined.xls')
df = pd.read_excel('combined.xls', header=0) # read file and set header row
self.tableWidget.setColumnCount(len(df.columns))
self.tableWidget.setRowCount(len(df.index))
for i in range(len(df.index)):
for j in range(len(df.columns)):
self.tableWidget.setItem(i, j, QTableWidgetItem(str(df.iat[i, j])))
self.tableWidget.resizeColumnsToContents()
self.tableWidget.resizeRowsToContents()
def LoadProcess(self):
if self.comboBoxfiletype.currentIndex() == 0: # xls
self.xlsProcess()
for colindex in range(self.tableWidget.columnCount()):
self.comboBoxabsc.addItem(str(colindex))
self.comboBoxordo.addItem(str(colindex))
elif self.comboBoxfiletype.currentIndex() == 1: # xlsx
self.xlsxprocess()
for colindex in range(self.tableWidget.columnCount()):
self.comboBoxabsc.addItem(str(colindex))
self.comboBoxordo.addItem(str(colindex))
def analyseProcess(self):
absc = []
ordo = []
absc.clear()
ordo.clear()
for tabrow in range(self.tableWidget.rowCount()):
abscitem = self.tableWidget.item(tabrow, self.comboBoxabsc.currentIndex())
ordoitem = self.tableWidget.item(tabrow, self.comboBoxordo.currentIndex())
absc.append(int(abscitem.text()))
ordo.append(str(ordoitem.text()))
df = pd.DataFrame({'data': absc})
df.index = ordo
df = df.sort_values(by='data', ascending=False)
df["cumpercentage"] = df["data"].cumsum() / df["data"].sum() * 100
self.figure.clear()
plt.ion()
ax = self.figure.add_subplot()
ax.bar(df.index, df["data"], color="C0")
ax2 = ax.twinx()
ax2.plot(df.index, df["cumpercentage"], color="C1", marker="D", ms=7)
ax2.yaxis.set_major_formatter(PercentFormatter())
ax.tick_params(axis="y", colors="C0")
ax2.tick_params(axis="y", colors="C1")
self.canvas.draw()
# donutchart***********************************
self.m_donuts = []
self.chartView3.setRenderHint(QPainter.Antialiasing)
self.chart3 = self.chartView3.chart()
self.chart3.legend().setVisible(True)
self.chart3.setTitle("Nested donuts Chart")
self.chart3.setAnimationOptions(QChart.AllAnimations)
minSize3 = 0.1
maxSize3 = 0.9
donutCount3 = 5
for i in range(donutCount3):
donut = QPieSeries()
sliceCount = random.randrange(3, 6)
# print(sliceCount)
for j in range(sliceCount):
value3 = random.randrange(0, 50)
slice_ = QPieSlice(str(value3), value3)
slice_.setLabelVisible(True)
slice_.setLabelColor(Qt.white)
slice_.setLabelPosition(QPieSlice.LabelInsideTangential)
slice_.hovered[bool].connect(functools.partial(self.explodeSlice, slice_=slice_))
donut.append(slice_)
donut.setHoleSize(minSize3 + i * (maxSize3 - minSize3) / donutCount3)
donut.setPieSize(minSize3 + (i + 1) * (maxSize3 - minSize3) / donutCount3)
self.m_donuts.append(donut)
self.chartView3.chart().addSeries(donut)
self.updateTimer = QTimer(self)
self.updateTimer.timeout.connect(self.updateRotation)
self.updateTimer.start(1250)
self.tabWidget.setCurrentIndex(2)
def updateRotation(self):
for donut in self.m_donuts:
phaseShift = random.randrange(-50, 100)
donut.setPieStartAngle(donut.pieStartAngle() + phaseShift)
donut.setPieEndAngle(donut.pieEndAngle() + phaseShift)
def explodeSlice(self, exploded, slice_):
if exploded:
self.updateTimer.stop()
sliceStartAngle = slice_.startAngle()
sliceEndAngle = slice_.startAngle() + slice_.angleSpan()
donut = slice_.series()
seriesIndex = self.m_donuts.index(donut)
for i in range(seriesIndex + 1, len(self.m_donuts)):
self.m_donuts[i].setPieStartAngle(sliceEndAngle)
self.m_donuts[i].setPieEndAngle(360 + sliceStartAngle)
else:
for donut in self.m_donuts:
donut.setPieStartAngle(0)
donut.setPieEndAngle(360)
self.updateTimer.start()
slice_.setExploded(exploded)
def main():
app = QtWidgets.QApplication(sys.argv)
# splash_pix = QPixmap('icons/splash.png')
# splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
# splash.setMask(splash_pix.mask())
# splash.show()
# time.sleep(2)
# splash.close()
window = anaxcelhandler()
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()