diff --git a/eddb.py b/eddb.py index 6312b57f..f157122f 100755 --- a/eddb.py +++ b/eddb.py @@ -15,15 +15,89 @@ def download(filename): if __name__ == "__main__": - # system_id by system_name - systems = json.loads(download('systems_populated.json').content) # let json do the utf-8 decode + # 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']) : s['id'] - for s in systems + 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 - system_ids['K Carinae'] = 375886 # both unpopulated + system_ids['Amo'] = (866, True) + 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) diff --git a/plugins/eddb.py b/plugins/eddb.py index 0d864800..4a654b69 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -16,29 +16,39 @@ STATION_UNDOCKED = u'×' # "Station" name to display when not docked = U+00D7 this = sys.modules[__name__] # For holding module globals +# (system_id, is_populated) by system_name with open(join(config.respath, 'systems.p'), 'rb') as h: this.system_ids = cPickle.load(h) +# station_id by (system_id, station_name) with open(join(config.respath, 'stations.p'), 'rb') as h: this.station_ids = cPickle.load(h) # Main window clicks -def station_url(system_name, station_name): - if station_id(system_name, station_name): - return 'https://eddb.io/station/%d' % station_id(system_name, station_name) - elif system_id(system_name): +def system_url(system_name): + if system_id(system_name): return 'https://eddb.io/system/%d' % system_id(system_name) else: return None +def station_url(system_name, station_name): + if station_id(system_name, station_name): + return 'https://eddb.io/station/%d' % station_id(system_name, station_name) + else: + return system_url(system_name) + # system_name -> system_id or 0 def system_id(system_name): - return this.system_ids.get(system_name, 0) # return 0 on failure (0 is not a valid id) + return this.system_ids.get(system_name, [0, False])[0] + +# system_name -> is_populated +def system_populated(system_name): + return this.system_ids.get(system_name, [0, False])[1] # (system_name, station_name) -> station_id or 0 def station_id(system_name, station_name): - return this.station_ids.get((this.system_ids.get(system_name), station_name), 0) + return this.station_ids.get((system_id(system_name), station_name), 0) def plugin_start(): @@ -50,10 +60,10 @@ def plugin_app(parent): def journal_entry(cmdr, is_beta, system, station, entry, state): this.system = system - this.station['text'] = station or (system_id(system) and STATION_UNDOCKED or '') + this.station['text'] = station or (system_populated(system) and STATION_UNDOCKED or '') this.station.update_idletasks() def cmdr_data(data, is_beta): this.system = data['lastSystem']['name'] - this.station['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (system_id(data['lastSystem']['name']) and STATION_UNDOCKED or '') + this.station['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (system_populated(data['lastSystem']['name']) and STATION_UNDOCKED or '') this.station.update_idletasks() diff --git a/stations.p b/stations.p index e84291f9..d617497b 100644 Binary files a/stations.p and b/stations.p differ diff --git a/systems.p b/systems.p index 0a04a3c8..802ec312 100644 Binary files a/systems.p and b/systems.p differ