def splitList(dbconn, start_time, end_time, hex_or_flight, date, debug, reporter, logToDB, printJSON, quiet, numRecs): orderSql = "order by %s, report_epoch" % hex_or_flight cur = pr.queryReportsDB(dbconn, myStartTime=start_time, myEndTime=end_time, postSql=orderSql, printQuery=debug, myReporter=reporter) data = pr.readReportsDB(cur, numRecs) oldplane = None eventlist = [] # # Split up into a separate list for each flight # while data: for plane in data: if not oldplane or getattr(oldplane, hex_or_flight) != getattr(plane, hex_or_flight): if oldplane: pl = buildRec(eventlist, dbconn, hex_or_flight, date) if not quiet: if printJSON: print(pl.to_JSON()) else: first_ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(pl.time_first_seen)) last_ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(pl.time_last_seen)) print(getattr(pl, hex_or_flight), " seen between ", first_ts, " and ", last_ts) if logToDB: pl.logToDB(dbconn, debug) dbconn.commit() eventlist = [] eventlist.append(plane) oldplane = plane else: eventlist.append(plane) data = pr.readReportsDB(cur, numRecs) if eventlist: pl = buildRec(eventlist, dbconn, hex_or_flight, date) if not quiet: if printJSON: print(pl.to_JSON()) else: first_ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(pl.time_first_seen)) last_ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(pl.time_last_seen)) print(getattr(pl, hex_or_flight), " seen between ", first_ts, " and ", last_ts) if logToDB: pl.logToDB(dbconn, debug) dbconn.commit()
mytype=None, lon=None, lat=None, url=None, location=None) cur = pr.queryReportsDB(dbconn, myhex=args.hexcodes, myStartTime=args.start_time, myEndTime=args.end_time, myflight=args.flights, minDistance=args.minDistance, maxDistance=args.maxDistance, minAltitude=args.minAltitude, maxAltitude=args.maxAltitude, minSpeed=args.minSpeed, maxSpeed=args.maxSpeed, minRssi=args.minRssi, maxRssi=args.maxRssi, minNucp=args.minNucp, maxNucp=args.maxNucp, myReporter=args.reporter, reporterLocation=reporter.location, printQuery=args.debug, postSql=" order by report_epoch") data = pr.readReportsDB(cur) while data: for plane in data: print(plane.to_JSON()) data = pr.readReportsDB(cur, args.numRecs)
else: yesterday = datetime.date.today() - timedelta(1) dbconn = pr.connDB(args.db_conf) reporter = pr.readReporter(dbconn, args.reporter) if not args.start_time: args.start_time = yesterday.strftime("%F") + " 00:00:00" if not args.end_time: args.end_time = yesterday.strftime("%F") + " 23:59:59" postSql = " or altitude < 0 or speed > %s " % args.maxSpeed cur = pr.queryReportsDB(dbconn, myhex=args.hexcodes, myStartTime=args.start_time, myEndTime=args.end_time, myflight=args.flights, minDistance=args.minDistance, maxDistance=args.maxDistance, myReporter=args.reporter, reporterLocation=reporter.location, printQuery=args.debug, postSql=postSql) data = pr.readReportsDB(cur, args.numRecs) while data: for plane in data: if args.debug or args.list: print("Deleting distance problem " + plane.to_JSON()) if not args.list: plane.delFromDB(dbconn, printQuery=args.debug) del_count += 1 data = pr.readReportsDB(cur, args.numRecs) dbconn.commit()
exit(1) else: if not args.start_time: args.start_time = datetime.date.today().strftime("%F") + " 00:00:00" dbconn = pr.connDB(args.db_conf) reporter = pr.readReporter(dbconn, args.reporter, printQuery=args.debug) airport = pr.readAirport(dbconn, args.airport, printQuery=args.debug) runways = pr.readRunways(dbconn, args.airport, printQuery=args.debug) for runway in runways: if args.debug: print(runway.to_JSON()) if not args.runways or args.runways == runway.name: cur = pr.queryReportsDB(dbconn, myhex=args.hexcodes, myStartTime=args.start_time, \ myEndTime=args.end_time, myflight=args.flights, maxAltitude=( int(args.committed_height) + airport.altitude), minAltitude=(airport.altitude - 150), myReporter=args.reporter, reporterLocation=reporter.location, printQuery=args.debug, \ runways=runway.runway_area, postSql=" order by hex, report_epoch") data = pr.readReportsDB(cur, numRecs=10000) oldplane = None eventlist = [] # # Split up into a separate list for each plane # while data: for plane in data: if args.debug: print(plane.to_JSON()) if not oldplane: eventlist.append(plane)
and b.report_epoch <= date_part('epoch', timestamp with time zone '%s 23:59:59')::int;''' % ( pr.RPTR_FMT.format(args.reporter), args.date, args.date) cur = dbconn.cursor(cursor_factory=RealDictCursor) if args.debug: print(cur.mogrify(sql)) cur.execute(sql) maxes = cur.fetchone() cur.close() print(maxes) cur = pr.queryReportsDB(dbconn, myStartTime=args.date + " 00:00:00", myEndTime=args.date + " 23:59:59", myReporter=args.reporter, minDistance=maxes['max_dist'], maxDistance=maxes['max_dist'], reporterLocation=reporter.location, printQuery=args.debug) max_dist_rec = cur.fetchone() cur.close() plane_dist = pr.PlaneReport(**max_dist_rec) print(plane_dist.to_JSON()) cur = pr.queryReportsDB(dbconn, myStartTime=args.date + " 00:00:00", myEndTime=args.date + " 23:59:59", myReporter=args.reporter, minAltitude=maxes['max_alt'], maxAltitude=maxes['max_alt'],