1
|
|
|
""" |
2
|
|
|
Kerapu |
3
|
|
|
""" |
4
|
1 |
|
import csv |
5
|
1 |
|
from typing import Optional |
6
|
|
|
|
7
|
1 |
|
from kerapu import clean_code, clean_date, clean_str, LEN_SPECIALISME_CODE |
8
|
|
|
|
9
|
|
|
|
10
|
1 |
|
class Specialisme: |
11
|
|
|
""" |
12
|
|
|
Klasse voor specialismen. |
13
|
|
|
""" |
14
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
15
|
1 |
|
_specialisme_tabel = {} |
16
|
|
|
""" |
17
|
|
|
De specialismen referentietabel. |
18
|
|
|
|
19
|
|
|
:type: dict[str,list[dict[str,str]]] |
20
|
|
|
""" |
21
|
|
|
|
22
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
23
|
1 |
|
def __init__(self, specialisme_code: str): |
24
|
|
|
""" |
25
|
|
|
Object constructor. |
26
|
|
|
|
27
|
|
|
:param str specialisme_code: De code van het specialisme. |
28
|
|
|
""" |
29
|
1 |
|
self.__specialisme_code = clean_code(specialisme_code, LEN_SPECIALISME_CODE) |
30
|
1 |
|
""" |
31
|
|
|
De code van het uitvoerend specialisme. |
32
|
|
|
|
33
|
|
|
:type: str |
34
|
|
|
""" |
35
|
|
|
|
36
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
37
|
1 |
|
@staticmethod |
38
|
1 |
|
def __lees_specialisme_tabel(folder: str): |
39
|
|
|
""" |
40
|
|
|
Leest de specialisme referentietabel (opgeslagen in CSV). |
41
|
|
|
|
42
|
|
|
:param str folder: De folder met alle goupertabellen. |
43
|
|
|
""" |
44
|
1 |
|
with open(folder + '/Specialismen.csv', encoding='utf-8') as csv_file: |
45
|
1 |
|
reader = csv.reader(csv_file, ) |
46
|
1 |
|
regel_nummer = 0 |
47
|
1 |
|
for regel in reader: |
48
|
1 |
|
regel_nummer += 1 |
49
|
|
|
|
50
|
|
|
# Sla de eerste regel met koppen over. |
51
|
1 |
|
if regel_nummer == 1: |
52
|
1 |
|
continue |
53
|
|
|
|
54
|
1 |
|
specialisme_code = clean_code(regel[0], LEN_SPECIALISME_CODE) |
55
|
1 |
|
specialisme_cluster1 = clean_str(regel[4]) |
56
|
1 |
|
specialisme_cluster2 = clean_str(regel[5]) |
57
|
1 |
|
begin_datum = clean_date(regel[7]) |
58
|
1 |
|
eind_datum = clean_date(regel[8]) |
59
|
|
|
|
60
|
1 |
|
rij = {'specialisme_code': specialisme_code, |
61
|
|
|
'specialisme_cluster1': specialisme_cluster1, |
62
|
|
|
'specialisme_cluster2': specialisme_cluster2, |
63
|
|
|
'begin_datum': begin_datum, |
64
|
|
|
'eind_datum': eind_datum} |
65
|
|
|
|
66
|
1 |
|
if specialisme_code not in Specialisme._specialisme_tabel: |
67
|
1 |
|
Specialisme._specialisme_tabel[specialisme_code] = [] |
68
|
|
|
|
69
|
1 |
|
Specialisme._specialisme_tabel[specialisme_code].append(rij) |
70
|
|
|
|
71
|
1 |
|
print("Aantal specialismen: %d" % (regel_nummer - 1)) |
72
|
|
|
|
73
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
74
|
1 |
|
@staticmethod |
75
|
1 |
|
def init_static(folder: str): |
76
|
|
|
""" |
77
|
|
|
Initialiseert alle statistische data. |
78
|
|
|
|
79
|
|
|
:param str folder: De folder met alle goupertabellen. |
80
|
|
|
""" |
81
|
1 |
|
Specialisme.__lees_specialisme_tabel(folder) |
82
|
|
|
|
83
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
84
|
1 |
|
def __get_specialisme_referentie(self, datum: str) -> Optional[dict]: |
85
|
|
|
""" |
86
|
|
|
Zoekt de referentie data voor deze specialisme in de specialismen referentietabel. |
87
|
|
|
|
88
|
|
|
:param str datum: De begindatum van het subtraject. |
89
|
|
|
|
90
|
|
|
:rtype: dict[str,str] |
91
|
|
|
""" |
92
|
1 |
|
if self.__specialisme_code in self._specialisme_tabel: |
93
|
1 |
|
for referentie in self._specialisme_tabel[self.__specialisme_code]: |
94
|
1 |
|
if referentie['begin_datum'] <= datum <= referentie['eind_datum']: |
95
|
|
|
# Een geldige referentie rij gevonden. |
96
|
1 |
|
return referentie |
97
|
|
|
|
98
|
|
|
# Er is geen geldige referentie rij gevonden. |
99
|
|
|
return None |
100
|
|
|
|
101
|
|
|
else: |
102
|
|
|
return None |
103
|
|
|
|
104
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
105
|
1 |
|
def specialisme_aantal(self, specialisme_code: str, datum: str) -> int: |
106
|
|
|
""" |
107
|
|
|
Geeft het aantal malen (d.w.z. 0 of 1) dat dit specialisme voldoet aan een attributecode op een gegeven datum |
108
|
|
|
. |
109
|
|
|
:param str specialisme_code: De attribuutcode waaraan voldaan moet worden. |
110
|
|
|
:param str datum: De datum. |
111
|
|
|
|
112
|
|
|
:rtype: int |
113
|
|
|
""" |
114
|
1 |
|
referentie = self.__get_specialisme_referentie(datum) |
115
|
|
|
|
116
|
1 |
|
if not referentie: |
117
|
|
|
# Het specialisme komt niet voor in de referentie tabel. Geef 0 terug. |
118
|
|
|
return 0 |
119
|
|
|
|
120
|
1 |
|
if referentie['specialisme_code'] == clean_code(specialisme_code, LEN_SPECIALISME_CODE): |
121
|
1 |
|
return 1 |
122
|
|
|
|
123
|
1 |
|
return 0 |
124
|
|
|
|
125
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
126
|
1 |
|
def specialisme_cluster_aantal(self, cluster_code: str, cluster_nummer: int, datum: str) -> int: |
127
|
|
|
""" |
128
|
|
|
Geeft het aantal malen (d.w.z. 0 of 1) dat dit specialisme voldoet aan een clustercode op een gegeven datum. |
129
|
|
|
|
130
|
|
|
:param str cluster_code: De clustercode waaraan voldaan moet worden. |
131
|
|
|
:param int cluster_nummer: Het clusternummer. |
132
|
|
|
:param str datum: De datum. |
133
|
|
|
|
134
|
|
|
:rtype: int |
135
|
|
|
""" |
136
|
1 |
|
referentie = self.__get_specialisme_referentie(datum) |
137
|
|
|
|
138
|
1 |
|
if not referentie: |
139
|
|
|
# Het specialisme komt niet voor in de referentie tabel. Geef 0 terug. |
140
|
|
|
return 0 |
141
|
|
|
|
142
|
1 |
|
if cluster_nummer == 0: |
143
|
|
|
return 1 |
144
|
|
|
|
145
|
1 |
|
if 1 <= cluster_nummer <= 2: |
146
|
1 |
|
if referentie['specialisme_cluster%d' % cluster_nummer] == cluster_code: |
147
|
|
|
# Dit specialisme komt voor in het gevraagde cluster. |
148
|
1 |
|
return 1 |
149
|
|
|
|
150
|
1 |
|
return 0 |
151
|
|
|
|
152
|
|
|
raise RuntimeError("Onbekend clusternummer %d." % cluster_nummer) |
153
|
|
|
|
154
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
155
|
|
|
|