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()
Esempio n. 2
0
                               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)
 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)
                 elif oldplane.hex == plane.hex:
                     eventlist.append(plane)
                 else:
                     splitList(eventlist,