-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_create.py
80 lines (70 loc) · 3.18 KB
/
db_create.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
# db_create.py
import os
import sqlite3
def main():
"""
Generates the following files:
- system_description.csv
- system_jumps.csv
from the SDE database (https://developers.eveonline.com/resource/resources)
Place "universeDataDx.db" in the database resource directory for this script to run
:return:
"""
db_dir = os.path.join("resources", "database")
eve_db_file = os.path.join(db_dir, "universeDataDx.db")
system_jumps_file = os.path.join(db_dir, "system_jumps.csv")
system_description_file = os.path.join(db_dir, "system_description.csv")
print(db_dir)
# read Eve SQL databse
with sqlite3.connect(eve_db_file) as sql_con:
cursor = sql_con.cursor()
# write solar system jumps file (gate connections)
result = cursor.execute('SELECT fromSolarSystemID, toSolarSystemID FROM mapSolarSystemJumps')
with open(system_jumps_file, "w") as f_out:
for row in result.fetchall():
f_out.write("{};{}\n".format(row[0], row[1]))
# write solar system description file (id, name, security class, security value)
result = cursor.execute('SELECT regionID, solarSystemID, solarSystemName, security FROM mapSolarSystems')
with open(system_description_file, "w") as f_out:
for row in result.fetchall():
region_id = row[0]
system_id = row[1]
system_name = row[2]
security = float(row[3])
# try and compute wormhole class or k-space class (HS, LS, NS)
query = cursor.execute(
'SELECT wormholeClassID FROM mapLocationWormholeClasses WHERE locationID=?',
(region_id, )
)
system_class = query.fetchone()
if system_class:
system_class = system_class[0]
else:
query = cursor.execute(
'SELECT wormholeClassID FROM mapLocationWormholeClasses WHERE locationID=?',
(system_id, )
)
system_class = query.fetchone()
if system_class:
system_class = system_class[0]
else:
system_class = "Unknown"
if system_class != "Unknown":
if system_class in [1, 2, 3, 4, 5, 6, 12, 13, 14, 15, 16, 17, 18]:
system_class = "C{}".format(system_class)
else:
if 0.45 <= security:
system_class = "HS"
elif 0 <= security < 0.45:
system_class = "LS"
else:
system_class = "NS"
if security < 0:
security_format = "{:.2f}".format(security)
elif 0 <= security <= 0.1:
security_format = "0.1"
else:
security_format = "{:.1f}".format(security)
f_out.write("{};{};{};{}\n".format(system_id, system_name, system_class, security_format))
if __name__ == "__main__":
main()