-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.py
283 lines (229 loc) · 10 KB
/
Test.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
from openpyxl import load_workbook
import matplotlib.pyplot as plt
import wx
import wx.grid as gridlib
from collections import defaultdict
global istodersoll
istodersoll = 1
global istodersoll_text
istodersoll_text = ""
class MyGrid(wx.Frame):
def __init__(self, new_dict_template):
wx.Frame.__init__(self, parent = None, title = "Auswahlraster", size=(500, 250))
panel = wx.Panel(self)
myRaster = gridlib.Grid(panel)
myRaster.CreateGrid(150, 7)
myRaster.EnableEditing(False)
'''Überschriften'''
spalte = 0
for key in new_dict_template:
myRaster.SetCellValue(0, spalte, key)
myRaster.SetCellFont(0, spalte, wx.Font(16, wx.ROMAN, wx.NORMAL, wx.BOLD))
myRaster.SetCellBackgroundColour(0, spalte, wx.LIGHT_GREY)
spalte = spalte + 1
'''Zeilen füllen'''
y = 0
for key in new_dict_template:
x = 2
for value in new_dict_template[key]:
myRaster.SetCellValue(x, y, value)
myRaster.SetCellFont(x, y, wx.Font(14, wx.ROMAN, wx.NORMAL, wx.NORMAL))
x = x + 1
y = y + 1
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(myRaster)
panel.SetSizer(sizer)
class AuswahlBox(wx.Frame):
def __init__(self, parent, title):
super(AuswahlBox, self).__init__(parent, title=title, size=(250, 200))
panel = wx.Panel(self)
box = wx.BoxSizer(wx.VERTICAL)
auswahl = ["Auswahl treffen", "IST", "SOLL"]
self.label = wx.StaticText(panel, label="IST oder SOLL?", style=wx.ALIGN_CENTER)
box.Add(self.label, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 15)
self.combo = wx.ComboBox(panel, choices=auswahl)
box.Add(self.combo, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 20)
self.combo.Bind(wx.EVT_COMBOBOX, self.bei_Auswahl)
self.button = wx.Button(panel, label="Okay", style=wx.ALIGN_CENTER_HORIZONTAL)
box.Add(self.button, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 20)
self.button.Bind(wx.EVT_BUTTON, self.bei_Click)
panel.SetSizer(box)
self.Center()
self.Show()
def bei_Auswahl(self, event):
global istodersoll
global istodersoll_text
if self.combo.GetValue() == "IST":
self.label.SetLabel("Es wurde " + self.combo.GetValue() + " ausgewählt")
istodersoll = 1
istodersoll_text = " (IST-Werte)"
elif self.combo.GetValue() == "SOLL":
self.label.SetLabel("Es wurde " + self.combo.GetValue() + " ausgewählt")
istodersoll = 2
istodersoll_text = " (SOLL-Werte)"
else:
self.label.SetLabel("Bitte IST oder SOLL auswählen")
istodersoll = 0
print("Bitte IST oder SOLL auswählen")
def bei_Click(self, event):
self.Close()
class Template_Cell:
def __init__(self, row, column, value, color, sheet):
self.row = row
self.column = column
self.value = value
self.color = color
self.sheet = sheet
#self.konzepte = konzepte #später kommt noch self.konzepte dazu
class Cell:
def __init__(self, row, column, value, year, sheet, istodersoll):
self.row = row
self.column = column
self.value = value
self.year = year
self.sheet = sheet
if istodersoll == 1:
self.istodersoll = "IST"
elif istodersoll == 2:
self.istodersoll = "SOLL"
def ausgabe(self):
print("Mappe: " + str(self.sheet))
print("Jahr: " + str(self.year))
print(str(self.istodersoll) + "-Wert")
print("Spalte: " +str(self.column))
print("Zeile: " + str(self.row))
print("Wert: " + str(self.value))
def gettemplate():
file_location = "/Users/mzichert/Documents/PycharmProjects/FE-Versuche/Haushaltsbücher_MPI_Template.xlsx"
wb = load_workbook(file_location, data_only=True)
template_cells = []
dict_template = defaultdict(list)
for sheet in range(len(wb.sheetnames)):
if wb.sheetnames[sheet] != "Synthese":
wb.active = sheet
spalte = 1
for zeile in range(10, 200):
inhalt = wb.active.cell(row = zeile, column = spalte)
if not inhalt.value:
continue
else:
template_cells.append(Template_Cell(zeile, spalte, inhalt.value, getattr(inhalt.fill.fgColor, inhalt.fill.fgColor.type), wb.sheetnames[sheet]))
dict_template[wb.sheetnames[sheet]].append(inhalt.value)
return template_cells, dict_template
def getdata(wanted):
wb = load_workbook(filename, data_only=True)
global istodersoll
data = []
years = []
cells = []
g = gen_years()
for sheet in range(len(wb.sheetnames)):
if wb.sheetnames[sheet] == "1954-1963":
wb.active = sheet
for zeile in range(1, 100):
cell = wb.active.cell(row=zeile + 1, column=1)
if cell.value == wanted:
for spalte in range(0, 20, 2):
inhalt = wb.active.cell(row=zeile + 1, column= istodersoll + spalte + 1)
data.append(inhalt.value)
year = next(g)
cells.append(Cell(zeile, spalte, inhalt.value/1000, year, wb.sheetnames[sheet], istodersoll))
elif wb.sheetnames[sheet] == "1964-1966":
wb.active = sheet
for zeile in range(1, 150):
cell = wb.active.cell(row=zeile + 1, column=1)
if cell.value == wanted:
for spalte in range(0, 4, 2):
inhalt = wb.active.cell(row=zeile + 1, column=istodersoll + spalte + 1)
data.append(inhalt.value)
year = next(g)
cells.append(Cell(zeile, spalte, inhalt.value/1000, year, wb.sheetnames[sheet], istodersoll))
for spalte in range(4, 6, 2):
inhalt = wb.active.cell(row=zeile + 1, column=istodersoll + spalte + 1)
data.append(inhalt.value)
year = next(g)
cells.append(Cell(zeile, spalte, inhalt.value, year, wb.sheetnames[sheet], istodersoll))
elif wb.sheetnames[sheet] == "1967":
wb.active = sheet
for zeile in range(1, 150):
cell = wb.active.cell(row=zeile + 1, column=1)
if cell.value == wanted:
for spalte in range(0, 2, 2):
inhalt = wb.active.cell(row=zeile + 1, column=istodersoll + spalte + 1)
data.append(inhalt.value)
year = next(g)
cells.append(Cell(zeile, spalte, inhalt.value, year, wb.sheetnames[sheet], istodersoll))
elif wb.sheetnames[sheet] == "1968-1972":
wb.active = sheet
for zeile in range(1, 150):
cell = wb.active.cell(row=zeile + 1, column=1)
if cell.value == wanted:
for spalte in range(0, 10, 2):
inhalt = wb.active.cell(row=zeile + 1, column=istodersoll + spalte + 1)
data.append(inhalt.value)
year = next(g)
cells.append(Cell(zeile, spalte, inhalt.value, year, wb.sheetnames[sheet], istodersoll))
elif wb.sheetnames[sheet] == "1973-1986":
wb.active = sheet
for zeile in range(1, 200):
cell = wb.active.cell(row=zeile + 1, column=1)
if cell.value == wanted:
for spalte in range(0, 28, 2):
inhalt = wb.active.cell(row=zeile + 1, column=istodersoll + spalte + 1)
data.append(inhalt.value)
year = next(g)
cells.append(Cell(zeile, spalte, inhalt.value, year, wb.sheetnames[sheet], istodersoll))
elif wb.sheetnames[sheet] == "1987-1997":
wb.active = sheet
for zeile in range(1, 200):
cell = wb.active.cell(row=zeile + 1, column=1)
if cell.value == wanted:
for spalte in range(0, 22, 2):
inhalt = wb.active.cell(row=zeile + 1, column=istodersoll + spalte + 1)
data.append(inhalt.value)
year = next(g)
cells.append(Cell(zeile, spalte, inhalt.value, year, wb.sheetnames[sheet], istodersoll))
elif wb.sheetnames[sheet] == "1998-2002":
wb.active = sheet
for zeile in range(1, 200):
cell = wb.active.cell(row=zeile + 1, column=1)
if cell.value == wanted:
for spalte in range(0, 10, 2):
inhalt = wb.active.cell(row=zeile + 1, column=istodersoll + spalte + 1)
data.append(inhalt.value)
year = next(g)
cells.append(Cell(zeile, spalte, inhalt.value, year, wb.sheetnames[sheet], istodersoll))
return cells
def gen_years():
for x in range(1954, 2003):
yield x
def plot_matplot(new_cells):
years = []
data = []
for cell in new_cells:
years.append(cell.year)
data.append(cell.value)
plt.plot(years, data, "m")
plt.title("Haushaltsplan" + istodersoll_text)
plt.ylabel("Einnahmen/Ausgaben")
plt.xlabel("Jahre")
plt.text(60, .025, "Hallo")
plt.show()
filename = "/Users/mzichert/Documents/PycharmProjects/FE-Versuche/Haushaltsbücher_MPG_Test.xlsx"
wanted = "Test"
#app = wx.App()
#AuswahlBox(None, 'Auswahlmenü')
#app.MainLoop()
#new_cells = getdata(wanted)
#plot_matplot(new_cells)
new_template_cells, new_dict_template = gettemplate()
#for cell in new_template_cells:
#if cell.sheet == "1998-2002":
#print(cell.value)
#for cell in new_cells:
#cell.ausgabe()
#break
app = wx.App()
frame = MyGrid(new_dict_template)
frame.Show()
app.MainLoop()