2023-06-13 07:27:13 +00:00
|
|
|
from nullptr.models.marketplace import Marketplace
|
2023-06-13 14:33:22 +00:00
|
|
|
from nullptr.models.jumpgate import Jumpgate
|
|
|
|
from nullptr.models.system import System
|
2023-06-13 07:27:13 +00:00
|
|
|
|
|
|
|
class Analyzer:
|
|
|
|
def __init__(self, store):
|
|
|
|
self.store = store
|
|
|
|
|
|
|
|
def find_markets(self, resource, sellbuy, location):
|
|
|
|
for m in self.store.all(Marketplace):
|
|
|
|
resources = m.imports if sellbuy == 'sell' else m.exports
|
|
|
|
if resource in resources:
|
|
|
|
yield m
|
2023-06-13 14:33:22 +00:00
|
|
|
|
|
|
|
def find_path(self, orig, to):
|
|
|
|
if orig == to: return []
|
|
|
|
jg = self.store.get(Jumpgate, orig.symbol)
|
|
|
|
if jg is None: return None
|
|
|
|
best_distance = orig.distance(to)
|
|
|
|
best_hop = None
|
|
|
|
for hop_str in jg.systems:
|
|
|
|
hop = self.store.get(System, hop_str)
|
|
|
|
if hop is None: continue
|
|
|
|
dist = hop.distance(to)
|
|
|
|
if dist < best_distance:
|
|
|
|
best_distance = dist
|
|
|
|
best_hop = hop
|
|
|
|
if best_hop is None: return None
|
|
|
|
tail = self.find_path(best_hop, to)
|
|
|
|
if tail is None: return None
|
|
|
|
return [best_hop] + tail
|