def main(): argv = parse_arguments() tdenv = tradeenv.TradeEnv(properties=argv) tdb = tradedb.TradeDB(tdenv) system, tdbSys = get_system(argv, tdb) if argv.pick: argv.destinations.extend(pick_destinations(argv, tdb)) if argv.destinations: process_destinations(argv, tdb) return print("Add EDSC Star Distances for \"{}\"".format(system)) print() print("You will now be prompted for distances to various stars.") print() print( "At each prompt, the star name will be copied into your paste buffer. " "You should alt-tab into the game and paste the name into the Galaxy " "Map's search box. Then alt-tab back and enter the distance value.") print() print("At each prompt enter a ly distance (e.g. 123.45), q to stop, " "or leave the line empty if you don't want to enter data for " "this star.") print("5 distances are required for EDSC to make a first guess at a " "star's location. You can submit more to increase the accuracy " "but the only time you need to submit more than 10 is when you " "are trying to submit corrections.") print() clip = SystemNameClip() print() print(""" =================================================== STANDARD STARS: (q to skip to the next section) These are stars with well-known positions. =================================================== """) distances, term = get_distances(argv, clip, standardStars) if distances: send_and_check_distances(argv, tdb, clip, distances) outliers = get_outliers(argv) if outliers: print(""" =================================================== EXTRA STARS: (q to skip to the next section) Stars from {}. =================================================== """.format(argv.extraFile)) distances, term = get_distances(argv, clip, outliers) if distances: send_and_check_distances(argv, tdb, clip, distances) print(""" =================================================== CHOOSE YOUR OWN: (q to stop) Specify additional stars. Prefix names with a '+' to add them to {}. =================================================== """.format(argv.extraFile)) distances = [] newOutliers = [] while True: star = input("Enter star name: ") star = star.strip().upper() if not star or star == 'Q': break # Remove surrounding quotes save = False if star.startswith('+'): save = True star = star[1:].strip() star = re.sub(r'\s+', ' ', star) star = re.sub(r"''+", "'", star) star = re.sub(r'^("|\')+\s*(.*)\s*\1+', r'\2', star) if star.find('"') >= 0: print("Invalid star name") continue if star.startswith('+'): save = True star = star[1:].strip() for ref in distances: if ref['name'] == star: print("'{}' is already listed.") continue check_system(argv, tdb, tdbSys, star) extras, term = get_distances(argv, clip, [star]) if term != 'q' and len(extras) > 0: distances.extend(extras) if save and star not in outliers and star not in newOutliers: newOutliers.append(star) if send_and_check_distances(argv, tdb, clip, distances): add_extra_stars(argv, newOutliers)
def main(): doDeletions = False parser = argparse.ArgumentParser( description='Check for prices that are outside reasonable bounds.' ) parser.add_argument( '--percentile', help='Set cutoff percentile', type=float, default=2, ) parser.add_argument( '--selling', help='Check the StationSelling table instead of StationBuying', action='store_true', ) parser.add_argument( '--delete', help='Remove bad elements from the local .db immediately', action='store_true', default=False, ) parser.add_argument( '--db', help='Specify location of the SQLite database.', default=None, dest='dbFilename', type=str, ) parser.add_argument( '--debug', '-w', help='Enable/raise level of diagnostic output.', default=0, required=False, action='count', ) parser.add_argument( '--detail', '-v', help='Increase level of detail in output.', default=0, required=False, action='count', ) parser.add_argument( '--quiet', '-q', help='Reduce level of detail in output.', default=0, required=False, action='count', ) parser.add_argument( '--margin', help='Adjust the error margin.', type=int, default=25, ) parser.add_argument( '--ignore', help='Ignore items.', action='append', default=list(), ) filters = parser.add_mutually_exclusive_group() filters.add_argument( '--dumb', help='Limit to "DUMB" items (<11cr).', dest='filters', action='store_const', const='DUMB', ) filters.add_argument( '--high', help='Limit to "HIGH" items.', dest='filters', action='store_const', const='HIGH', ) filters.add_argument( '--low', help='Limit to "LOW" items.', dest='filters', action='store_const', const='LOW', ) argv = parser.parse_args(sys.argv[1:]) argv.ignore = [ ignore.upper() for ignore in argv.ignore ] table = "StationSelling" if argv.selling else "StationBuying" tdenv = tradeenv.TradeEnv(properties=argv) tdb = tradedb.TradeDB(tdenv) tdenv.NOTE( "Checking {}, margin={}", table, argv.margin, ) errorFilter = getattr(argv, "filters", None) check_price_bounds( tdb, table, margin=argv.margin, doDeletions=argv.delete, percentile=argv.percentile, errorFilter=errorFilter, )
def main(): argv = parse_arguments() tdenv = tradeenv.TradeEnv(properties=argv) tdb = tradedb.TradeDB(tdenv) if not argv.summary: try: argv.startSys = tdb.lookupSystem(argv.refSystem) except (LookupError, tradedb.AmbiguityError): raise UsageError( "Unrecognized system '{}'. Reference System must be an " "*exact* name for a system that TD already knows.\n" "Did you forget to put double-quotes around the reference " "system name?".format(argv.refSystem)) print("start date: {}".format(argv.date)) edsq = misc.edsc.StarQuery( test=argv.test, confidence=argv.confidence, date=argv.date, ) data = edsq.fetch() if edsq.status['statusnum'] != 0: raise Exception("Query failed: {} ({})".format( edsq.status['msg'], edsq.status['statusnum'], )) date = data['date'] systems = data['systems'] print("{} results".format(len(systems))) # Filter out systems we already know that match the EDSC data. systems = [sysinfo for sysinfo in systems if is_change(tdb, sysinfo)] print("{} deltas".format(len(systems))) if argv.summary or len(systems) <= 0: return systems = [sysinfo for sysinfo in systems if 'coord' in sysinfo] if argv.random: num = min(len(systems), argv.maxSystems) systems = random.sample(systems, num) if argv.refSys: refSys = tdb.lookupPlace(argv.refSys) else: refSys = None startSys = argv.startSys for sysinfo in systems: x, y, z = sysinfo['coord'] sysinfo['distance'] = get_distance(tdb, startSys, x, y, z) if refSys: sysinfo['refdist'] = get_distance(tdb, refSys, x, y, z) else: sysinfo['refdist'] = None if argv.distance: if refSys: systems.sort(key=lambda sysinfo: sysinfo['refdist']) else: systems.sort(key=lambda sysinfo: sysinfo['distance']) systems = systems[:argv.maxSystems] if argv.splash: print( "\n" "===============================================================\n" "\n" " The tool will now take you through the stars returned by EDSC\n" " that are new or different from your local System.csv.\n" "\n" " You will be prompted with the name and predicted distance from\n" " your current system so you can check for mistakes.\n" "\n" " The name will be copied into your clipboard so you can alt-tab\n" " into the game and paste the name into the Galaxy Map's SEARCH\n" " box (under NAVIGATION). Let the map zoom to the system.\n" "\n" " Check the name and distance, then use the appropriate action.\n" "\n" " (Use the -NS option to skip this text in future)\n" "\n" "===============================================================\n" "\n") input("Hit enter to continue: ") print("""At the prompt enter: q to indicate you've suffered enough, y to accept the name/value and confirm with EDSC, n (or anything else) to skip the name/value (no confirmation), =name (e.g. =SOL) to accept the distance but correct spelling, ~dist (e.g. ~104.49) to submit a distance correction for the system, """) print() extras = get_extras() clip = misc.clipboard.SystemNameClip() total = len(systems) current = 0 with open("tmp/new.systems.csv", "w", encoding="utf-8") as output: for sysinfo in systems: current += 1 name = sysinfo['name'] created = sysinfo['createdate'] x, y, z = sysinfo['coord'] print("\n" "-----------------------------------------------\n" "{syidlab:.<12}: {syid}\n" "{conflab:.<12}: {conf}\n" "{crealab:.<12}: {crcm} {crts}\n" "{updtlab:.<12}: {upcm} {upts}\n".format( syidlab="ID", conflab="Confidence", crealab="Created", updtlab="Updated", syid=sysinfo['id'], conf=sysinfo['cr'], crcm=sysinfo['commandercreate'], crts=created, upcm=sysinfo.get('commanderupdate', '[never]'), upts=sysinfo.get('updatedate', ''), )) if refSys: print("{reflab:.<12}: {refdist}ly\n".format( reflab="Ref Dist", refdist=sysinfo['refdist'], )) check_database(tdb, name, x, y, z) change = has_position_changed(sysinfo['place'], name, x, y, z) if change: oldDist = startSys.distanceTo(sysinfo['place']) print("Old Distance: {:.2f}ly".format(oldDist)) distance = sysinfo['distance'] clip.copy_text(name) prompt = "{}/{}: '{}': {:.2f}ly? ".format( current, total, name, distance, ) ok = input(prompt) if ok.lower() == 'q': break if ok.startswith('~'): correction = float(ok[1:]) submit_distance(argv, name, correction) if not name.upper() in extras: add_to_extras(argv, name) continue if ok.startswith('='): name = ok[1:].strip().upper() if not name in extras: add_to_extras(argv, name) ok = 'y' if ok.lower() != 'y': continue if argv.add: tdb.addLocalSystem(name, x, y, z, added='Release 1.00-EDStar', modified=created, commit=True) print("'{}',{},{},{},'Release 1.00-EDStar','{}'".format( name, x, y, z, created, ), file=output) submit_distance(argv, name, distance)
def main(): argv = parse_arguments() tdenv = tradeenv.TradeEnv(properties=argv) tdenv.quiet = 1 tdb = tradedb.TradeDB(tdenv) if not argv.summary: try: argv.startSys = tdb.lookupSystem(argv.refSystem) except (LookupError, tradedb.AmbiguityError): raise UsageError( "Unrecognized system '{}'. Reference System must be an " "*exact* name for a system that TD already knows.\n" "Did you forget to put double-quotes around the reference " "system name?".format(argv.refSystem)) if not argv.date: argv.date = tdb.query("SELECT MAX(modified) FROM System").fetchone()[0] dateRe = re.compile( r'^20\d\d-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01]) ([01]\d|2[0123]):[0-5]\d:[0-5]\d$' ) if not dateRe.match(argv.date): raise UsageError( "Invalid date: '{}', expecting YYYY-MM-DD HH:MM:SS format.".format( argv.date)) print("start date: {}".format(argv.date)) edsq = misc.edsm.StarQueryMulti( log=argv.logEDSM, startDateTime=argv.date, submitted=1, showId=1, ) data = edsq.fetch() systems = data print("{} results".format(len(systems))) # Filter out systems we already know that match the EDSM data. systems = [sysinfo for sysinfo in systems if is_change(tdb, sysinfo)] print("{} deltas".format(len(systems))) if argv.summary or len(systems) <= 0: return systems = [sysinfo for sysinfo in systems if 'coords' in sysinfo] if argv.random: num = min(len(systems), argv.maxSystems) systems = random.sample(systems, num) if argv.refSys: refSys = tdb.lookupPlace(argv.refSys) else: refSys = None startSys = argv.startSys for sysinfo in systems: x = sysinfo['coords']['x'] y = sysinfo['coords']['y'] z = sysinfo['coords']['z'] sysinfo['distance'] = get_distance(tdb, startSys, x, y, z) if refSys: sysinfo['refdist'] = get_distance(tdb, refSys, x, y, z) else: sysinfo['refdist'] = None if argv.distance: if argv.maxLy > 0: if refSys: systems = [ sysinfo for sysinfo in systems if sysinfo['refdist'] <= argv.maxLy ] else: systems = [ sysinfo for sysinfo in systems if sysinfo['distance'] <= argv.maxLy ] else: if refSys: systems.sort(key=lambda sysinfo: sysinfo['refdist']) else: systems.sort(key=lambda sysinfo: sysinfo['distance']) systems = systems[:argv.maxSystems] if argv.splash and not argv.autoOK: print( "\n" "===============================================================\n" "\n" " The tool will now take you through the stars returned by EDSM\n" " that are new or different from your local System.csv.\n" "\n" " You will be prompted with the name and predicted distance from\n" " your current system so you can check for mistakes.\n" "\n" " The name will be copied into your clipboard so you can alt-tab\n" " into the game and paste the name into the Galaxy Map's SEARCH\n" " box (under NAVIGATION). Let the map zoom to the system.\n" "\n" " Check the name and distance, then use the appropriate action.\n" "\n" " (Use the -NS option to skip this text in future)\n" "\n" "===============================================================\n" "\n") input("Hit enter to continue: ") if not argv.autoOK: print("""At the prompt enter: q to indicate you've suffered enough, y to accept the name/value, n (or anything else) to skip the name/value (no confirmation), =name (e.g. =SOL) to accept the distance but correct spelling, """) print() extras = get_extras() clip = misc.clipboard.SystemNameClip() total = len(systems) current = 0 with open("tmp/new.systems.csv", "w", encoding="utf-8") as output: if argv.autoOK: commit = False else: commit = True for sysinfo in systems: current += 1 name = sysinfo['name'] created = sysinfo['date'] x = sysinfo['coords']['x'] y = sysinfo['coords']['y'] z = sysinfo['coords']['z'] if not argv.autoOK: print("\n" "-----------------------------------------------\n" "{syidlab:.<12}: {syid}\n" "{crealab:.<12}: {crts}\n".format( syidlab="ID", crealab="Created", syid=sysinfo['id'], crts=created, )) if refSys: print("{reflab:.<12}: {refdist}ly\n".format( reflab="Ref Dist", refdist=sysinfo['refdist'], )) check_database(tdb, name, x, y, z) change = has_position_changed(sysinfo['place'], name, x, y, z) if change: oldDist = startSys.distanceTo(sysinfo['place']) print("Old Distance: {:.2f}ly".format(oldDist)) distance = sysinfo['distance'] clip.copy_text(name) prompt = "{}/{}: '{}': {:.2f}ly? ".format( current, total, name, distance, ) if argv.autoOK: if change: ok = "n" else: ok = "y" else: ok = input(prompt) if ok.lower() == 'q': break if ok.startswith('='): name = ok[1:].strip().upper() if not name in extras: add_to_extras(argv, name) ok = 'y' if ok.lower() != 'y': continue if argv.add: print("Add {:>6}: {:>12} {} {}".format(current, sysinfo['id'], created, name)) tdb.addLocalSystem(name, x, y, z, added='EDSM', modified=created, commit=commit) print("'{}',{},{},{},'EDSM','{}'".format( name, x, y, z, created, ), file=output) if argv.add and not commit: tdb.getDB().commit()
options += ',fallback' trade.main(('trade.py', 'import', '-P', 'eddblink', '-O', options)) # Check to see if plugin updated database. with tdb.sqlPath.open('r', encoding="utf-8") as fh: tmpFile = fh.read() if tmpFile.find("type_id INTEGER DEFAULT 0 NOT NULL,") == -1: sys.exit( "EDDBlink plugin must be updated for listener to work correctly.") update_busy = False process_ack = False export_ack = False export_busy = False dataPath = os.environ.get('TD_CSV') or Path( tradeenv.TradeEnv().dataDir).resolve() eddbPath = plugins.eddblink_plug.ImportPlugin( tdb, tradeenv.TradeEnv()).dataPath.resolve() debugPath = eddbPath / Path("debug.txt") db_name, item_ids, system_ids, station_ids = update_dicts() print("Press CTRL-C at any time to quit gracefully.") try: update_thread.start() # Give the update checker enough time to see if an update is needed, # before starting the message processor and listings exporter. time.sleep(5) process_thread.start() export_thread.start()