-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinanzexplorer_model.py
executable file
·195 lines (143 loc) · 5.38 KB
/
Finanzexplorer_model.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
import csv
from collections import OrderedDict
RECHNUNGSTYP = ""
superkategorien = []
# Define colours
WHITE = "#ffffff"
dct_Kategorien = {}
dct_Posten = {}
dct_categorierelations = OrderedDict()
dct_Schemata = OrderedDict()
dct_cells = {}
class Konzept:
def __init__(self, name, color):
self.rechnungstyp = RECHNUNGSTYP
self.name = name
self.color = color
self.cells = [] # not the real cell_objects, just the position as (row, col)
def __str__(self):
return self.name
class Cell:
def __init__(self, cellrow, cellcol, value, jahr): # value = (kategorie, "--..", oberkategorie)
self.row = cellrow
self.col = cellcol
self.value = value
self.active = False
self.jahr = jahr
self.posten = dct_Posten[(self.value[0].id, self.jahr)]
self.color = WHITE
self.konzept = None
self.zwischensumme = False
self.oberkategorie = self.value[2]
self.unterkategorien = []
for s in dct_Schemata.values():
if s.jahr == self.jahr:
for c in s.cells:
if self.oberkategorie:
if self.oberkategorie.id == c.value[0].id:
c.unterkategorien.append(self)
c.zwischensumme = True
def calculate_zwischensumme(self):
if self.zwischensumme and self.posten.geldbetrag == 0:
for k in self.unterkategorien:
self.posten.geldbetrag += k.posten.geldbetrag
def get_pos(self):
return self.row, self.col
class KategorieRelation:
def __init__(self, lst):
self.id = int(lst[0])
self.origin_id = int(lst[1])
self.skos_typ = lst[2]
self.target_id = int(lst[3])
self.schema_id = int(lst[4])
self.order_in_schema = lst[5]
self.origin_kategorie = dct_Kategorien[self.origin_id]
self.target_kategorie = dct_Kategorien[self.target_id]
class Kategorie:
def __init__(self, lst):
self.id = int(lst[0])
self.bezeichnung = lst[1]
self.spezifizierung = lst[2]
self.hoere_oberkategorie = lst[3]
def get_id(self):
return self.id
class Schema:
def __init__(self, lst):
self.id = int(lst[0])
self.bezeichnung = lst[1]
self.typ = lst[1].split("_")[1]
self.jahr = int(lst[1].split("_")[2][:4])
self.KategorieRelationen = [] # list of obj(KategorieRelation)
self.kategorien_hierarchisch = []
for r in dct_categorierelations.values():
if r.schema_id == self.id:
self.KategorieRelationen.append(r)
self.cells = set()
class Posten:
def __init__(self, lst):
self.kategorie_id = int(lst[0])
self.rechnungskategorie = lst[1]
# self.jahr_id = int(lst[2])
self.jahr = int(lst[3])
self.id = int(lst[4])
if lst[5] in [None, 'None', '', ' ']:
self.geldbetrag = 0.00
else:
self.geldbetrag = float(lst[5])
def import_csv(filename, sep=","):
with open(filename + ".csv", newline='', encoding="utf-8-sig") as f1:
filelist = list(csv.reader(f1, delimiter=sep))
result = []
for it in filelist:
result.append(it)
return result[1:]
def import_kategorien():
global dct_Kategorien
for x in import_csv("Finanz_ID-Kategorie"):
dct_Kategorien[int(x[0])] = Kategorie(x)
def import_posten():
global dct_Posten
for x in import_csv("Finanz_Posten-Jahr-Betrag"): # http://gmpg-intern.mpiwg-berlin.mpg.de:8888/explorer/525/
dct_Posten[(int(x[0]), int(x[3]))] = Posten(x) # dict_key: (Kat_id, year)
def import_kategorierelations():
global dct_categorierelations
lst_categorierelations = []
for x in import_csv("Finanz_Kategorie_Relation"): # http://gmpg-intern.mpiwg-berlin.mpg.de:8888/explorer/526/
if x[5]:
x[5] = int(x[5].split(".")[0])
else:
x[5] = 0
lst_categorierelations.append(KategorieRelation(x))
lst_categorierelations.sort(key=lambda kat: kat.order_in_schema)
for y in lst_categorierelations:
dct_categorierelations[int(y.id)] = y
lst_categorierelations.clear()
def import_schemata():
global dct_Schemata
for x in import_csv("Finanz_ID-Schema"):
# um nur die Daten zu laden, die auch dem gewählten Rechnungstypen entsprechen
if x[1].split("_")[1] == RECHNUNGSTYP:
dct_Schemata[int(x[0])] = Schema(x)
def get_dct_kategorien():
return dct_Kategorien
def get_dct_posten():
return dct_Posten
def get_dct_categorierelations():
return dct_categorierelations
def get_dct_schemata():
return dct_Schemata
def get_dct_cells():
return dct_cells
def populate_cells(): # Class Cells vielleicht lieber im View, da hauptsächlich (nur?!) dort genutzt
col = -1
for year in range(1948, 2006):
for schema in dct_Schemata.values():
if schema.jahr == year:
row = 0
col += 1
myView.frame.myGrid.SetColLabelValue(col, str(schema.jahr))
for kategorie_in_Hierarchie in schema.kategorien_hierarchisch:
row += 1
temp = Cell(row, col, kategorie_in_Hierarchie, schema.jahr)
dct_cells[(row, col)] = temp
dct_Schemata[schema.id].cells.add(temp)