-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataGenFunctions.py
More file actions
154 lines (131 loc) · 5.29 KB
/
dataGenFunctions.py
File metadata and controls
154 lines (131 loc) · 5.29 KB
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
# ============================
# DATA GENERATION FUNCTIONS
# ============================
from datetime import datetime, timedelta
import random
class DataGenFunctions:
def __init__(self, data_store=None):
self.data_store = data_store
def from_list(self, params):
values = params.get("values", [])
return random.choice(values) if values else ""
def date(self, params):
start_year = params.get("start_year", 1970)
end_year = params.get("end_year", 2020)
start = datetime(start_year, 1, 1)
end = datetime(end_year, 12, 31)
d = start + timedelta(days=random.randint(0, (end - start).days))
return d.strftime("%d.%m.%Y")
def checkbox_binary(self, params):
p = params.get("true_prob", 0.5)
return random.random() < p
def checkbox_group_random(self, params):
children = params.get("children", [])
mode = params.get("mode", "single")
missing_prob = params.get("missing_prob", 0.0)
if not children:
return []
if random.random() < missing_prob:
return []
names = [c["name"] for c in children]
if mode == "single":
return [random.choice(names)]
k = random.randint(1, len(names))
return random.sample(names, k)
# ============================
# STAMP CONTENT GENERATORS
# ============================
def doctor_name(self, params):
first_names = params.get("first_names", ["Anna", "Max", "Julia", "Leon", "Nina", "David"])
last_names = params.get("last_names", ["Schmidt", "Mueller", "Weber", "Braun", "Fischer", "Klein"])
return f"{random.choice(first_names)} {random.choice(last_names)}"
def doctor_specialty(self, params):
specialties = params.get(
"specialties",
[
"Allgemeinmedizin",
"Innere Medizin",
"Orthopaedie",
"Dermatologie",
"Neurologie",
"Kardiologie",
],
)
return random.choice(specialties)
def doctor_bsnr(self, params):
min_value = int(params.get("bsnr_min", 100000000))
max_value = int(params.get("bsnr_max", 999999999))
return str(random.randint(min_value, max_value))
def doctor_lanr(self, params):
min_value = int(params.get("lanr_min", 100000000))
max_value = int(params.get("lanr_max", 999999999))
return str(random.randint(min_value, max_value))
def doctor_phone(self, params):
area_codes = params.get("area_codes", ["030", "040", "0221", "089", "069", "0711"])
area = random.choice(area_codes)
body_a = random.randint(100, 999)
body_b = random.randint(10000, 99999)
return f"{area} {body_a}{body_b}"
def handwritten_note(self, params):
notes = params.get(
"values",
["gez.", "i.A.", "ok", "dringend", "eilig", "heute", datetime.now().strftime("%d.%m.%y")],
)
return random.choice(notes)
def doctor_stamp_lines(self, params):
first_names = params.get("first_names", ["Anna", "Max", "Julia", "Leon", "Nina", "David"])
last_names = params.get("last_names", ["Schmidt", "Mueller", "Weber", "Braun", "Fischer", "Klein"])
specialties = params.get(
"specialties",
["Allgemeinmedizin", "Innere Medizin", "Orthopaedie", "Dermatologie"],
)
cities = params.get("cities", ["Berlin", "Koeln", "Hamburg", "Muenchen", "Bonn"])
streets = params.get("streets", ["Hauptstrasse", "Bahnhofstrasse", "Gartenweg", "Lindenweg"])
first = random.choice(first_names)
last = random.choice(last_names)
doctor_title = random.choice(params.get("titles", ["Dr. med.", "Dr.", "PD Dr."]))
specialty = random.choice(specialties)
city = random.choice(cities)
street = random.choice(streets)
payload = {
"full_name": f"{first} {last}",
"doctor_name": f"{doctor_title} {first} {last}",
"specialty": specialty,
"city": city,
"street": f"{street} {random.randint(1, 90)}",
"postcode": str(random.randint(10000, 99999)),
"phone": self.doctor_phone(params),
"bsnr": self.doctor_bsnr(params),
"lanr": self.doctor_lanr(params),
}
line_template = params.get(
"line_template",
[
"{doctor_name}",
"Facharzt fuer {specialty}",
"{street}",
"{postcode} {city}",
"Tel.: {phone}",
"BSNR: {bsnr}",
],
)
lines = []
for idx, template in enumerate(line_template):
try:
txt = str(template).format(**payload)
except (KeyError, ValueError):
txt = str(template)
if not txt:
continue
lines.append(
{
"text": txt,
"section_id": f"line_{idx}",
"font_size": int(params.get("font_size", 28)),
}
)
return {
"preset": params.get("preset", "medical_with_black_signature"),
"lines": lines,
"fields": payload,
}