-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_setup.py
More file actions
53 lines (42 loc) · 1.14 KB
/
db_setup.py
File metadata and controls
53 lines (42 loc) · 1.14 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
# ---------------------------------------------------------------------
#
# This script needs to be executed before playing the game for the first time
import json
import pandas as pd
def getSchwierigkeit(ewz) -> str:
ewz = int(ewz)
match ewz:
case _ if ewz < 65000:
return "extrem"
case _ if ewz < 90000:
return "schwer"
case _ if ewz < 180000:
return "mittel"
case _ if ewz >= 180000:
return "leicht"
case _:
return ""
# Auslesen der csv-Datei
df = pd.read_csv('ort.csv')
# Initialize the data structure with empty dictionaries for each difficulty level
data = {
"highscore": {},
"staedte": {
"extrem": {},
"schwer": {},
"mittel": {},
"leicht": {},
}
}
for index, row in df.iterrows():
name = row['Name']
land = row['Land']
ewz = row['Einwohner']
laenge = row['Laenge']
breite = row['Breite']
schwierigkeit = getSchwierigkeit(ewz)
data["staedte"][schwierigkeit][name] = [land, ewz, laenge, breite]
print(data)
with open('./db.json', 'w') as f:
json.dump(data, f, indent=4)
print("Finished inserting cities into db.json. READY TO PLAY!")