예제 #1
0
def main():
    tt.TurtleScreen._RUNNING = True
    n_steps =10
    step_time_delay = 5
    s = tt.Screen() 
    s.clear()
    s.setup(width=700, height=700, starty = 0)
    s.setworldcoordinates(-14000, -14000, 14000, 14000)
    s.tracer(60, 0)  #FIRST ARGUMENT DETERMINES SPEED OF ANIMATION
    s.colormode(255)
    fleet = [x for x in btr.getAllVehiclesGTFS() if x['type'] == 'bus']
    buses = dict([(b['id'], BusBall(.2, b['xcoord'], b['ycoord'], b['id'])) for b in fleet])
    # creates a dictionary of just the buses of the form { id : BusBall}
    s.tracer(False)
    for i in range(n_steps):
        s.update()
        time.sleep(step_time_delay)
        fleet = [x for x in btr.getAllVehiclesGTFS() if x['type'] == 'bus']
        print 'step', i + 1, 'of', n_steps, 'current fleet size:', len(fleet)
        for b in fleet: #for each bus in the retrieved fleet, 
            if b['id'] in buses:  #see whether it is in the current list of buses
                if buses[b['id']].ycoord != b['ycoord']: #if yes, see whether it has a new position
                    buses[b['id']].move(b['xcoord'], b['ycoord']) #if yes, move it
            else:
                buses[b['id']] = BusBall(.2, b['xcoord'], b['ycoord'], b['id']) #add it to the current bus list
                print 'NEW BUS!!!', b['id']
 def updateData(self):
     self.counter += 1
     if self.counter % unsch_update_period_factor == 1:
         self.supplement = dict()
         self.supplement_by_veh = dict()
     self.vehicles = btr.getAllVehiclesGTFS()
     self.trips = btr.getAllTripsGTFS()
     self.timestamp = long(time.time())
     self.addDestAndDir()
     threading.Timer(veh_update_period, self.updateData).start()
예제 #3
0
 def updateData(self):
     self.counter += 1
     if self.counter % unsch_update_period_factor == 1:
         self.supplement_by_trip = dict()
         self.supplement_by_veh = dict()
     self.vehicles = btr.getAllVehiclesGTFS()
     self.trips = btr.getAllTripsGTFS()
     self.timestamp = long(time.time())
     self.addDestDirShape()
     #print self.supplement_by_trip
     threading.Timer(veh_update_period, self.updateData).start()