def api_sector_name(x, y, z): v = vector3.Vector3(x, y, z) result = {'names': [], 'position': vec3_to_dict(v)} sect = pgnames.get_sector(v, allow_ha=True) if sect is not None and isinstance(sect, sector.HASector): result['names'].append({'name': sect.name, 'type': sect.sector_class}) sect = pgnames.get_sector(v, allow_ha=False) if sect is not None: result['names'] += [{'name': sect.name, 'type': sect.sector_class}] if not any(result['names']): bottle.response.status = 400 result = None bottle.response.content_type = 'application/json' return {'result': result}
def test_sector_positions(self): test1 = pgnames.get_sector("Wregoe") self.assertEqual(test1.name, "Wregoe") self.assertEqual(test1.centre, v3.Vector3(-65.0, -25.0, -1065.0) + (640, 640, 640)) self.assertEqual(test1.size, 1280.0) test2 = pgnames.get_sector("GRIA EAEC") self.assertEqual(test2.name, "Gria Eaec") self.assertEqual( test2.centre, v3.Vector3(-2625.0, -1305.0, 15575.0) + (640, 640, 640)) self.assertEqual(test2.size, 1280.0) test2 = pgnames.get_sector("core sys sector") self.assertEqual(test2.name, "Core Sys Sector") self.assertEqual(test2.centre, v3.Vector3(0, 0, 0)) self.assertEqual(test2.size, 50.0)
def api_sector_position(name): sect = pgnames.get_sector(name) if sect is not None: if isinstance(sect, sector.HASector): result = { 'name': pgnames.get_canonical_name(name), 'type': 'ha', 'centre': vec3_to_dict(sect.centre), 'radius': sect.radius } else: result = { 'name': pgnames.get_canonical_name(name), 'type': 'pg', 'origin': vec3_to_dict(sect.origin), 'centre': vec3_to_dict(sect.centre), 'size': sect.size } else: bottle.response.status = 400 result = None bottle.response.content_type = 'application/json' return {'result': result}
def run_test(it): teststart = time.clock() alls = 0 ok1 = 0 ok2 = 0 okha = 0 okhaname = 0 bad1 = 0 bad2 = 0 badha = 0 badhaname = 0 none1 = 0 none2 = 0 noneha = 0 notpg = 0 for system in it: alls += 1 sysname = pgnames.get_canonical_name(system.name) if sysname is not None: m = pgdata.pg_system_regex.match(sysname) if m is not None: if m.group("sector").lower() in pgdata.ha_regions: sect = pgdata.ha_regions[m.group("sector").lower()] is_noneha = False if sect.contains(system.position): rp, rpe = pgnames._get_relpos_from_sysid(*m.group("l1", "l2", "l3", "mcode", "n1", "n2")) if rp is None or rpe is None: log.info("BadRelPos: could not calculate relative position for {}", system.name) badha += 1 continue elif any([s > (sector.sector_size + rpe) for s in rp]): log.info("BadRelPos: invalid relpos for {}", system.name) badha += 1 continue so = sect.get_origin(rpe * 2) coords = so + rp dx = abs(coords.x - system.position.x) dy = abs(coords.y - system.position.y) dz = abs(coords.z - system.position.z) realdist = (coords - system.position).length if dx <= rpe and dy <= rpe and dz <= rpe: okha += 1 else: badha += 1 absdiff = abs(coords - system.position) log.info("BadHA{5}: {4}, {0} not close enough to {1} with {2:.0f}LY/axis uncertainty, actually {3}", coords, system.position, rpe, absdiff, system.name, " (minor)" if absdiff.x < (dist+1) and absdiff.y < (dist+1) and absdiff.z < (dist+1) else "") else: noneha += 1 is_noneha = True log.info("NoneHA: {0} @ {1} not in {2}", system.name, system.position, sect) if not is_noneha: ha_name = pgnames._ha_get_name(system.position) if ha_name == m.group("sector"): okhaname += 1 else: badhaname += 1 if ha_name is not None: log.info("BadHAName: {} ({}LY) was predicted to be in {} ({}LY)", system.name, sect.size, ha_name, pgdata.ha_regions[ha_name.lower()].size) else: log.info("BadHAName: {} ({}LY) was predicted to not be in an HA sector", system.name, sect.size) else: cls = pgnames._get_sector_class(m.group("sector")) if isinstance(cls, int): cls = "c{}".format(cls) sect = pgnames.get_sector(m.group("sector")) if sect is not None: cls = sect.sector_class pos_sect = pgnames.get_sector(system.position, allow_ha=False) if sect == pos_sect: coords, dist = pgnames._get_coords_from_name(system.name) if coords is None or dist is None: log.warning("BadName: could not get coords for {0}", system.name) if cls == 'c2': bad2 += 1 elif cls == 'c1': bad1 += 1 continue dx = abs(coords.x - system.position.x) dy = abs(coords.y - system.position.y) dz = abs(coords.z - system.position.z) realdist = (coords - system.position).length if dx <= dist and dy <= dist and dz <= dist: if cls == 'c2': ok2 += 1 elif cls == 'c1': ok1 += 1 else: if cls == 'c2': bad2 += 1 elif cls == 'c1': bad1 += 1 absdiff = abs(coords - system.position) log.info("Bad position{5}: {4}, {0} not close enough to {1} with {2:.0f}LY/axis uncertainty, actually {3}", coords, system.position, dist, absdiff, system.name, " (minor)" if absdiff.x < (dist+1) and absdiff.y < (dist+1) and absdiff.z < (dist+1) else "") else: if cls == 'c2': bad2 += 1 elif cls == 'c1': bad1 += 1 log.info("Bad sector: {0} @ {1} is not in {2}", system.name, system.position, sect) else: if cls == 'c2': none2 += 1 log.info("None2: {0} @ {1}", system.name, system.position) elif cls == 'c1': none1 += 1 log.info("None1: {0} @ {1}", system.name, system.position) else: log.info("InvalidName: {0} @ {1}", system.name, system.position) else: notpg += 1 else: notpg += 1 duration = time.clock() - teststart log.info("Totals: All = {}, OK1 = {}, OK2 = {}, OKHA = {}, OKHAName = {}, Bad1 = {}, Bad2 = {}, BadHA = {}, BadHAName = {}, None1 = {}, None2 = {}, NoneHA = {}, notPG = {}", alls, ok1, ok2, okha, okhaname, bad1, bad2, badha, badhaname, none1, none2, noneha, notpg) log.info("Time: {0:.6f}s, {1:.6f}s per system", duration, duration / alls)
if y >= 8: y = -8 z += 1 if count + 1 > limit: break count += 1 print("Count: {0}, OK: {1}, bad: {2}".format(count, ok, bad)) elif sys.argv[1] == "search2": input = sys.argv[2] syst = pgnames.get_system(input) if syst is not None: coords, relpos_confidence = syst.position, syst.uncertainty print("Est. position of {0}: {1} (+/- {2}LY)".format(input, coords, int(relpos_confidence))) else: sect = pgnames.get_sector(input) if sect is not None: print("{0} is {1}, has origin {2}".format(input, str(sect), sect.origin)) else: print("Could not find sector or system") elif sys.argv[1] == "localdatatest": env.set_verbosity(2) with env.use() as envdata: run_test(envdata.find_all_systems()) elif sys.argv[1] == "id64datatest": env.set_verbosity(2) env.start() import id64data for name, id64 in id64data.known_systems.items():