示例#1
0
  def updateVehicles(self, xml = None):
    if xml is None:
      update = route_scraper.get_updated_routes(None)
    else:
      update = route_scraper.parse_xml(routes=None,xmldata=xml)

    for vehicle in update:
      vid = vehicle['id']
      now = vehicle['update_time'] #datetime
      delay = datetime.timedelta(seconds=int(vehicle['secsSinceReport']))
      update_time = now-delay

      report = GPSDataTools.VehicleReport(
        id = vid,
        lat = vehicle['lat'],
        lon = vehicle['lon'],
        routetag = vehicle['routeTag'],
        dirtag = vehicle['dirTag'],
        reported_update_time = update_time
        );
      
      trk = self.vehicles.get( vid )
      if not trk:
        trk = GPSTrackState(vid)
        self.vehicles[vid] = trk

      gtfs_match = trk.updateTrack(report)
      return gtfs_match
示例#2
0
    def updateVehicles(self, xml=None):
        if xml is None:
            update = route_scraper.get_updated_routes(None)
        else:
            update = route_scraper.parse_xml(routes=None, xmldata=xml)

        for vehicle in update:
            vid = vehicle['id']
            now = vehicle['update_time']  #datetime
            delay = datetime.timedelta(seconds=int(vehicle['secsSinceReport']))
            update_time = now - delay

            report = GPSDataTools.VehicleReport(
                id=vid,
                lat=vehicle['lat'],
                lon=vehicle['lon'],
                routetag=vehicle['routeTag'],
                dirtag=vehicle['dirTag'],
                reported_update_time=update_time)

            trk = self.vehicles.get(vid)
            if not trk:
                trk = GPSTrackState(vid)
                self.vehicles[vid] = trk

            gtfs_match = trk.updateTrack(report)
            return gtfs_match
示例#3
0
def save_data(xmlfile):
  f = open(xmlfile,'r')
  lines = "\n".join(f.readlines())
  f.close()
  xmlfile = path.basename(xmlfile)
  time_retrieved = xmlfile[:xmlfile.find(".")]
  vals = parse_xml(None,lines,time_retrieved=time_retrieved)
  db.update_routes(vals)
  db.commit()
示例#4
0
def save_data(xmlfile):
    f = open(xmlfile, "r")
    lines = "\n".join(f.readlines())
    f.close()
    xmlfile = path.basename(xmlfile)
    time_retrieved = xmlfile[: xmlfile.find(".")]
    vals = parse_xml(None, lines, time_retrieved=time_retrieved)
    db.update_routes(vals)
    db.commit()