コード例 #1
0
    def run(self, db_url, tracker_id, start, end):
        # Perform a database query
        db_url = self.local_db_url(db_url)
        s = DBSession(db_url)()
        tid = Speed.device_info_serial
        dt = Speed.date_time
        q = s.query(tid, func.count(tid))
        q = q.filter(tid.in_(tracker_id))
        q = q.filter(dt.between(start, end))
        q = q.filter(Speed.userflag == 0)
        q = q.filter(Speed.longitude != None)
        q = q.group_by(tid)
        r = q.all()
        msg = json.dumps(r)

        s.close()

        # Write results to text files
        fn = os.path.join(self.output_dir(), "result.txt")
        with open(fn, "w") as f:
            f.write(msg)

        result = {}
        result["query"] = {"start": start, "end": end, "tracker_id": tracker_id}

        return result
コード例 #2
0
    def run(self, db_url, trackers, start, end,
            shape, size, sizebyalt, colorby,
            speedthreshold1, speedthreshold2, speedthreshold3,
            alpha, altitudemode):
        self.update_state(state="RUNNING")
        start = iso8601.parse_date(start)
        end = iso8601.parse_date(end)
        db_url = self.local_db_url(db_url)
        session = DBSession(db_url)()

        trackers_list = "_".join([str(t['id']) for t in trackers])
        filename_tpl = "t{trackers}-s{start}-e{end}.kmz"
        filename = filename_tpl.format(start=start.strftime('%Y%m%d%H%M'),
                                       end=end.strftime('%Y%m%d%H%M'),
                                       trackers=trackers_list,
                                       )
        fn = os.path.join(self.output_dir(), filename)
        kml = simplekml.Kml(open=0)

        self.pointstylecache = {}
        style = {'shape': shape,
                 'size': size,
                 'sizebyalt': sizebyalt,
                 'colorby': colorby,
                 'speedthresholds': [speedthreshold1,
                                     speedthreshold2,
                                     speedthreshold3,
                                     ],
                 'alpha': alpha,
                 'altitudemode': altitudemode,
                 }
        self.addIcons2kml(kml)
        for tracker in trackers:
            self.track2kml(kml, session,
                           start, end,
                           tracker,
                           style)

        session.close()
        kml.savekmz(fn)

        result = {}
        result['query'] = {'start': start.isoformat(),
                           'end': end.isoformat(),
                           'trackers': trackers,
                           'style': style,
                           }
        return result
コード例 #3
0
    def run(self, db_url, tracker_id, start, end):
        self.update_state(state="RUNNING")
        start = iso8601.parse_date(start)
        end = iso8601.parse_date(end)
        db_url = self.local_db_url(db_url)
        session = DBSession(db_url)()

        rows = self.query2rows(session, tracker_id, start, end)
        doc = self.track2gpx(tracker_id, rows)
        fn = self.getOutputFileName(tracker_id, start, end)
        doc.writeGPX(fn)

        session.close()

        result = {}
        result['query'] = {'start': start.isoformat(),
                           'end': end.isoformat(),
                           'tracker_id': tracker_id,
                           }
        return result