def run(args, hosted=False, state={}): parsed = parse_args(args, hosted, state) results = list(obscured.Application(**vars(parsed)).run()) if env.global_args.json: print(util.to_json(results)) return if not len(results): print("") print("No suitable systems") print("") return cow = ColumnObjectWriter(6, ['<', '<', '>', '>', '>']) print("") print("Alternative systems for route from {} to {}:".format( parsed.start, parsed.end)) print("") cow.add(['', 'System', 'Dev.', 'Dist. from', 'Dist. to']) cow.add(['', '', '']) for entry in results: cow.add([ ''.format(entry.system.name), '{}'.format(entry.system.name), '{:d}%'.format(min(100, int(entry.deviation))), '{}'.format(entry.distances.values()[0].to_string(True)), '{}'.format(entry.distances.values()[1].to_string(True)) ]) cow.add(['', '', '']) cow.out()
def run(args, hosted=False, state={}): parsed = parse_args(args, hosted, state) results = list(fuel_usage.Application(**vars(parsed)).run()) if env.global_args.json: print(util.to_json(results)) return headings = [' ', 'Distance', 'System'] padding = ['>', '>', '<', '>'] intra = [' ', ' ', ' ', ' '] refueling = False for entry in results: if entry.refuel is not None: refueling = True break if refueling: headings += ['Refuel', 'Percent'] headings += ['Fuel cost', 'Remaining'] cow = ColumnObjectWriter(len(headings), padding, intra) cow.add(headings) last_origin = None for entry in results: if entry.refuel is not None: row = ['', '', ''] if refueling: row += [ '{:.2f}T'.format(entry.refuel.amount), '{:.2f}%'.format(entry.refuel.percent) ] row += ['', '{:.2f}T'.format(entry.fuel.final)] cow.add(row) else: if last_origin is None: row = ['', '', entry.origin.system] if refueling: row += ['', ''] # This is the first row, so use the initial fuel available, not at the destination row += ['', '{:.2f}T'.format(entry.fuel.initial), ''] cow.add(row) row = [ '!' if not entry.ok else '*' if entry.is_long else '', entry.distance.to_string(True), entry.destination.system ] if refueling: row += ['', ''] row += [ '{:.2f}T'.format(entry.fuel.cost), '{:.2f}T'.format(entry.fuel.final) ] cow.add(row) last_origin = entry.origin.system print('') cow.out() print('')
def run(args, hosted = False, state = {}): parsed = parse_args(args, hosted, state) results = units.Application(**vars(parsed)).run() if env.global_args.json: print(util.to_json(list(results))) return for entry in results: print("") print(entry.distance.to_string(long = not parsed.short)) print("")
def api_v3(app): if app == 'raikogram': app = 'distance' if app not in [ 'close_to', 'coords', 'direction', 'distance', 'edts', 'find', 'fuel_usage', 'galmath', 'obscured', 'units' ]: return None module = importlib.import_module('edtslib.' + app) result = [] bottle.response.content_type = 'application/json' try: for entry in module.Application(**map_request(bottle.request)).run(): result.append(entry) except Exception as e: bottle.response.status = 500 return util.to_json({"error": e.message, "result": []}) if not len(result): result = None return util.to_json({"error": None, "result": result})
def run(args, hosted=False, state={}): results = galmath.Application( **vars(parse_args(args, hosted, state))).run() if env.global_args.json: print(util.to_json(list(results))) return for entry in results: print("") print( "Travelling {} with a {} jump range, at around {} from the core centre:" .format(entry.distance.to_string(True), entry.jump_range.to_string(True), entry.core_distance.to_string(True))) print("") print(" Maximum jump in range: {}".format( entry.low_max_dist.to_string(True))) print(" Plot between {} and {}".format( entry.plot_min.to_string(True), entry.plot_max.to_string(True))) print("")
def run(args, hosted=False, state={}): parsed = parse_args(args, hosted, state) results = coords.Application(**vars(parsed)).run() if env.global_args.json: print(util.to_json(list(results))) return fmt = '8g' if parsed.full_width else '8.2f' cow = ColumnObjectWriter(5, ['<', '>'], [' ', '']) for entry in results: position = [('{:' + fmt + '}').format(coord) for coord in entry.system.position] cow.add([ '', entry.system.name, ': [', position[0], ', ', position[1], ', ', position[2], ']', " +/- {0:.0f}LY in each axis".format(entry.system.uncertainty) if entry.system.uncertainty != 0.0 else "" ]) print("") cow.out() print("")
def run(args, hosted=False, state={}): parsed = parse_args(args, hosted, state) results = direction.Application(**vars(parsed)).run() if env.global_args.json: print(util.to_json(list(results))) return for entry in results: if parsed.check: if entry.check: print('OK {:0.2f}% deviation'.format(entry.deviation)) sys.exit(0) elif entry.opposite: print('NO opposite') else: print('NO {:0.2f}% deviation'.format(entry.deviation)) sys.exit(100) else: if parsed.bearing: n, u = util.get_as_bearing(entry.direction) if parsed.degrees: north = util.compass_degrees(n) up = util.compass_degrees(u) fmt = '{:03d}' else: north = util.compass_mils(n) up = util.compass_mils(u) fmt = '{:d}' print(' / '.join([fmt, fmt]).format(north, up)) elif parsed.angle: if entry.angle is not None: print( math.degrees(entry.angle) if parsed.degrees else entry. angle) else: print('INVALID') sys.exit(100) else: print(entry.direction)
def run(args, hosted=False, state={}): parsed = parse_args(args, hosted, state) indent = 8 stn_matches = [] sys_matches = [] results = find.Application(**vars(parsed)).run() if env.global_args.json: print(util.to_json(list(results))) return for entry in results: if entry.station is not None: stn_matches.append(entry) elif entry.system is not None: sys_matches.append(entry) if len(sys_matches) > 0: print("") print("Matching systems:") print("") cow = ColumnObjectWriter(4, ['<', '<', '>', '<']) for entry in sorted(sys_matches, key=lambda t: t.system.name): if parsed.show_ids or parsed.id64: id = " ({})".format( entry.system.pretty_id64(parsed.id64) if parsed. id64 else entry.system.id) else: id = "" cow.add([ '', '{}{}'.format(entry.system.name, id), '', entry.system.arrival_star.to_string(True) ]) for stn in entry.stations: cow.add([ '', '{}{}'.format(' ' * indent, stn.name), '({})'.format(stn.distance.to_string() if stn. distance is not None else '???'), stn.station_type if stn.station_type is not None else '???' ]) cow.out() print("") if len(stn_matches) > 0: print("") print("Matching stations:") print("") cow = ColumnObjectWriter(5, ['<', '<', '<', '>', '<'], [' ', ' ']) for entry in sorted(stn_matches, key=lambda t: t.station.name): if parsed.show_ids or parsed.id64: id = " ({})".format(entry.station.id) else: id = "" cow.add([ '', entry.station.system.to_string(), '{}{}'.format(entry.station.name, id), entry.station.distance.to_string() if entry.station.distance is not None else '???', entry.station.station_type if entry.station.station_type is not None else '???' ]) cow.out() print("") if len(sys_matches) == 0 and len(stn_matches) == 0: print("") print("No matches") print("")
def run(args, hosted=False, state={}): parsed = parse_args(args, hosted, state) results = list(edts.Application(**vars(parsed)).run()) if env.global_args.json: print(util.to_json(results)) return if not len(results): print("") print("No viable route found :(") print("") return print_summary = True show_cruise = False show_route = False show_jumps = parsed.ship is not None or parsed.jump_range is not None for entry in results: if entry.origin.station is not None or entry.destination.station is not None: show_cruise = True if not entry.summary: show_route = True if show_cruise and show_route: break origin = results[0].origin cow = None if parsed.format in ['long', 'summary']: headings = ['', '', 'Distance', '', 'System'] padding = ['<', '<', '>', '<', '<'] intra = [' ', ' ', ' ', ' '] if show_cruise: headings += ['Cruise', '', '', ''] padding += ['>', '>', '<', '<'] intra += [' ', ' ', ' ', ' ', ' '] else: intra += [' '] headings += [''] padding += ['<'] intra += [' '] if parsed.ship is not None and show_route: headings += ['Fuel', 'Fuel', 'range'] padding += ['<', '>', '<'] intra += [' ', ' ', ' '] if show_jumps: headings += ['Hop', 'dist.', 'Jumps'] padding += ['>', '<', '>'] intra += [' ', ' '] cow = ColumnObjectWriter(len(headings), padding, intra) cow.add(headings) cow.add([]) row = [ '', # Obscured '', # Long '', # Distance '>', origin.system.name ] if show_cruise: row += [ origin.station.distance.to_string() if origin.station is not None and origin.station.distance is not None else '', '', # Cruise time origin.station.name if origin.station is not None else '', origin.station.station_type if origin.station is not None and origin.station.station_type is not None else '' ] row += ['<'] cow.add(row) elif parsed.format == 'short': print("") sys.stdout.write( str(origin.station) if origin.station is not None else origin. system.name) elif parsed.format == 'csv': print(','.join([ origin.system.name, origin.station.name if origin.station is not None else '', str(0.0), origin.station.distance.to_string() if origin.station is not None and origin.station.distance is not None else '', '' ])) print_summary = False totaldist = 0.0 totaldist_sl = 0.0 totaljumps_min = 0 totaljumps_max = 0 total_fuel_cost = 0.0 totalsc = 0 totalsc_accurate = True est_time_min = 0 est_time_max = 0 for entry in results[1:]: if entry.waypoint is not None: totaldist += entry.waypoint.distance.lightyears totaldist_sl += entry.waypoint.direct.lightyears totaljumps_min += entry.waypoint.jumps.min totaljumps_max += entry.waypoint.jumps.max totalsc_accurate &= entry.waypoint.time.accurate if entry.destination.station is not None: if entry.destination.station.distance is not None: totalsc += entry.destination.station.distance.lightseconds if entry.waypoint.time.jumps is not None: est_time_min += entry.waypoint.time.jumps.min est_time_max += entry.waypoint.time.jumps.max if entry.waypoint.time.cruise is not None: est_time_min += entry.waypoint.time.cruise est_time_max += entry.waypoint.time.cruise if entry.fuel is not None and entry.fuel.cost is not None: total_fuel_cost += entry.fuel.cost if cow is not None: cow.add( format_leg(entry, show_cruise, show_route, show_jumps, parsed.ship is not None)) elif parsed.format == 'short': sys.stdout.write(', {}'.format( str(entry.destination.station) if entry.destination. station is not None else str(entry.destination.system))) elif parsed.format == 'csv': print(','.join([ entry.destination.system.name, entry.destination.station.name if entry.destination.station is not None else '', str(entry.distance.lightyears), str(entry.destination.station.distance) if entry.destination.station is not None and entry.destination.station.distance is not None else '', direction_hint(entry) ])) if cow is not None: cow.out() elif parsed.format == 'short': print("") if print_summary: totaldist_str = "{:.2f}LY ({:.2f}LY)".format( totaldist, totaldist_sl ) if totaldist >= totaldist_sl else "{:.2f}LY".format(totaldist_sl) totaljumps_str = "{:d}".format( totaljumps_max ) if totaljumps_min == totaljumps_max else "{:d} - {:d}".format( totaljumps_min, totaljumps_max) fuel_str = "; fuel cost: {:.2f}T".format( total_fuel_cost) if total_fuel_cost else '' est_time_min_m = math.floor(est_time_min / 60) est_time_min_s = int(est_time_min) % 60 est_time_str = "{:.0f}:{:02.0f}".format(est_time_min_m, est_time_min_s) if totaljumps_min != totaljumps_max: est_time_max_m = math.floor(est_time_max / 60) est_time_max_s = int(est_time_max) % 60 est_time_str += " - {:.0f}:{:02.0f}".format( est_time_max_m, est_time_max_s) print("") if show_jumps: print("Total distance: {}; total jumps: {}".format( totaldist_str, totaljumps_str)) print("Total SC distance: {:d}Ls{}; ETT: {}{}".format( int(totalsc), "+" if not totalsc_accurate else "", est_time_str, fuel_str)) else: print("Total distance: {}".format(totaldist_str)) print("")
def run(args, hosted=False, state={}): parsed = parse_args(args, hosted, state) results = distance.Application(**vars(parsed)).run() if env.global_args.json: print(util.to_json(list(results))) return cow = ColumnObjectWriter() raikogram_mode = False last_origin = None if parsed.route: # Route mode. cow.expand(4, ['<', '>', '<', '<'], [' ', ' ', ' ', ' ']) elif parsed.start is not None or len(parsed.systems) == 2: # Reference mode. cow.expand(6, ['<', '<', '>', '>', '<'], [' ', ' ']) else: # Raikogram. raikogram_mode = True header = [''] row = [] total = 0.0 shown_header = False cow.expand( len(parsed.systems) + (1 if not parsed.csv else 0), ['>'], [',' if parsed.csv else ' ']) for entry in results: if raikogram_mode: if entry.origin.system != last_origin: if len(row): if not shown_header: if parsed.csv: print(','.join(header)) else: cow.add(header) shown_header = True if parsed.csv: print(','.join(row)) else: cow.add(row) row = [entry.origin.system] total += entry.distance.lightyears if not shown_header: header.append(entry.destination.system) row.append( entry.distance.to_string(parsed.full_width) if entry.origin.system != entry.destination.system else '-') elif parsed.route: if last_origin is None: cow.add([ '', # Padding '', # Distance '', # > entry.origin.system.to_string(), '', # Extra ]) cow.add([ '', entry.distance.to_string(parsed.full_width), '>', entry.destination.system.to_string(), '+/- {}'.format( Lightyears(entry.origin.system.uncertainty3d + entry.destination.system.uncertainty3d). to_string(parsed.full_width)) if entry.origin.system.uncertainty3d != 0.0 or entry.destination.system.uncertainty3d != 0.0 else '' ]) else: cow.add([ '', # Padding entry.origin.system.to_string(), '>', entry.distance.to_string(parsed.full_width), '>', entry.destination.system.to_string(), '+/- {}'.format( Lightyears(entry.origin.system.uncertainty3d + entry.destination.system.uncertainty3d). to_string(parsed.full_width)) if entry.origin.system.uncertainty3d != 0.0 or entry.destination.system.uncertainty3d != 0.0 else '' ]) last_origin = entry.origin.system if raikogram_mode: if parsed.csv: print(','.join(row)) else: cow.add(row) if parsed.ordered: row = ['Total:', Lightyears(total).to_string(parsed.full_width)] if parsed.csv: print(','.join(row)) else: cow.add([]) cow.add(row) print('') cow.out() print('')