def find(self, location): """ Finds a location in the store, or return None if not present """ for v in self._visited: if same(v['system'], location['system']) and same( v['body'], location['body'] ) and v['lat'] == location['lat'] and v['lon'] == location['lon']: return v return None
def local( self, system, body): """ Returns all the locations on the given body that have not already been visited. Returns a list - can be empty, but not None """ locs = [] for m in self._materials: if same(m['system'], system) and same(m['body'], body) and not self._visited.is_visited(m): locs.append(m) return sorted(locs, key = lambda x : x['lat'])
def matches(self, loc): """ Returns the material location for this location, or None if this is not a known location. lat and lon are allowed to differ slightly We also allow for body names to be 'within' the system or for them to include the system name """ if self._visited.is_visited(loc): return None for m in self._materials: if same(m['system'], loc['system']) and same(m['body'], loc['body']) and math.fabs(m['lat'] - loc['lat']) < 3 and math.fabs(m['lon'] - loc['lon']) < 3: return m return None
def print_diff(t1, t2): sa, diff = util.same(t1, t2) if sa: print('There is no difference on linux config between two host.') return print('linux config difference between two host:\n') for k, v in diff.items(): _print_diff(k, v)
def print_diff(f1, f2): t1 = toml.loads(f1) t2 = toml.loads(f2) sa, diff = util.same(t1, t2) if sa: print('There is no difference on tidb config between two host.') return print('tidb config difference between two host:\n') for k, v in diff.items(): _print_diff(k, v)
def find_location(self, current_target=None): """ Finds where we should be heading based the current location state current_target is where we are currently headed, can be None """ debug("find_location - location is {}".format(self._location._loc)) if self._location.is_landed(): debug("Landed") target = self._materials.matches(self.location()) if target: debug("Found a resource on planet") mats = set(target['materials']).intersection( self._requirements) self._visited.set_visited(target) return ("Collect " + ", ".join(mats), target, False) if self._location.has_system(): distance, closest = self._materials.closest(self._location.pos(), self._requirements, types=self._types) if self._location.has_body(): # If we are already heading to a location then stick with it, # don't flip between targets on a body as they get close if current_target and not self._visited.is_visited( current_target): return ("Land at target", current_target, True) # See if there is another location on this body local = self._materials.local(self._location.system(), self._location.body()) if local: debug("More mats on same body") return ("Land at target", local[0], True) else: print("No more mats local to this body {}".format( self._location.body())) if closest and same(closest['system'], self._location.system()): debug("in correct system") return ("Supercruise to {} {}".format(closest['system'], closest['body']), closest, True) if closest: return ("Go to {} ({:1.0f} Ly)".format(closest['system'], distance), closest, False)
def on_correct_body(self, params, closest): return 'ShortBody' in params and same(closest['body'], params['ShortBody'])
def test_same(self): self.assertTrue(util.same("This", "This")) self.assertTrue(util.same("This", "THIS")) self.assertFalse(util.same("THIS", "THAT"))