forked from EDCD/EDMarketConnector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eddb.py
executable file
·116 lines (98 loc) · 4.09 KB
/
eddb.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
#!/usr/bin/python
#
# build databases from files systems.csv and stations.json from http://eddb.io/api
#
import cPickle
import csv
import json
import requests
def download(filename):
r = requests.get('https://eddb.io/archive/v6/' + filename, stream=True)
print '\n%s\t%dK' % (filename, len(r.content) / 1024)
return r
if __name__ == "__main__":
# Ellipsoid that encompasses most of the systems in the bubble (but not outliers like Sothis)
RX = RZ = 260
CY = -50
RY = 300
RX2 = RX * RX
RY2 = RY * RY
RZ2 = RZ * RZ
def inbubble(x, y, z):
return (x * x)/RX2 + ((y - CY) * (y - CY))/RY2 + (z * z)/RZ2 <= 1
# Sphere around Jaques
JX, JY, JZ = -9530.50000, -910.28125, 19808.12500
RJ2 = 80 * 80 # Furthest populated system is Pekoe at 50.16 Ly
def around_jaques(x, y, z):
return ((x - JX) * (x - JX) + (y - JY) * (y - JY) + (z - JZ) * (z - JZ)) <= RJ2
# Sphere around outliers
RO2 = 40 * 40
def around_outlier(cx, cy, cz, x, y, z):
return ((x - ox) * (x - ox) + (y - oy) * (y - oy) + (z - oz) * (z - oz)) <= RO2
systems = { int(s['id']) : {
'name' : s['name'].decode('utf-8'),
'x' : float(s['x']),
'y' : float(s['y']),
'z' : float(s['z']),
'is_populated' : int(s['is_populated']),
} for s in csv.DictReader(download('systems.csv').iter_lines()) }
#} for s in csv.DictReader(open('systems.csv')) }
print '%d\tsystems' % len(systems)
# (system_id, is_populated) by system_name (ignoring duplicate names)
system_ids = {
str(s['name']) : (k, s['is_populated'])
for k,s in systems.iteritems() if inbubble(s['x'], s['y'], s['z'])
}
print '%d\tsystems in bubble' % len(system_ids)
extra_ids = {
str(s['name']) : (k, s['is_populated'])
for k,s in systems.iteritems() if around_jaques(s['x'], s['y'], s['z'])
}
system_ids.update(extra_ids)
print '%d\tsystems in Colonia' % len(extra_ids)
cut = {
k : s for k, s in systems.iteritems()
if s['is_populated'] and s['name'] not in system_ids
}
print '%d\toutlying populated systems:' % len(cut)
extra_ids = {}
for k1,o in sorted(cut.iteritems()):
ox, oy, oz = o['x'], o['y'], o['z']
extra = {
str(s['name']) : (k, s['is_populated'])
for k,s in systems.iteritems() if around_outlier(ox, oy, oz, s['x'], s['y'], s['z'])
}
print '%-30s%7d %11.5f %11.5f %11.5f %4d' % (o['name'], k1, ox, oy, oz, len(extra))
extra_ids.update(extra)
print '\n%d\tsystems around outliers' % len(extra_ids)
system_ids.update(extra_ids)
cut = {
k : s
for k,s in systems.iteritems() if s['name'] in system_ids and system_ids[s['name']][0] != k
}
print '\n%d duplicate systems' % len(cut)
for k,s in sorted(cut.iteritems()):
print '%-20s%8d %8d %11.5f %11.5f %11.5f' % (s['name'], system_ids[s['name']][0], k, s['x'], s['y'], s['z'])
# Hack - ensure duplicate system names are pointing at the more interesting system
system_ids['Amo'] = (866, True)
system_ids['C Puppis'] = (25068, False)
system_ids['q Velorum'] = (15843, True)
system_ids['M Carinae'] = (22627, False)
system_ids['HH 17'] = (61275, False)
system_ids['K Carinae'] = (375886, False)
system_ids['d Velorum'] = (406476, False)
system_ids['L Velorum'] = (2016580, False)
system_ids['N Velorum'] = (3012033, False)
system_ids['i Velorum'] = (3387990, False)
with open('systems.p', 'wb') as h:
cPickle.dump(system_ids, h, protocol = cPickle.HIGHEST_PROTOCOL)
print '\n%d saved systems' % len(system_ids)
# station_id by (system_id, station_name)
stations = json.loads(download('stations.json').content) # let json do the utf-8 decode
station_ids = {
(x['system_id'], str(x['name'])) : x['id']
for x in stations if x['max_landing_pad_size']
}
with open('stations.p', 'wb') as h:
cPickle.dump(station_ids, h, protocol = cPickle.HIGHEST_PROTOCOL)
print '\n%d saved stations' % len(station_ids)