Beispiel #1
0
 def update_position(self, timestamp, coords, isLate, progressFraction,
                     T_segment_avg, T_trip_avg, fields):
     self.attrib['segment_actual'] = (timestamp -
                                      self.attrib['t_segment_start']) / 60.
     self.attrib['t_segment_stored'] = T_segment_avg / 60.
     if T_trip_avg == 0:
         lateFactor = 0.
     else:
         t_trip_late = self.attrib['duration_actual'] - T_trip_avg
         lateFactor = max(0., t_trip_late) / self.attrib['duration_actual']
     self.update_count += 1
     self.attrib['isLate'] = isLate
     self.attrib['t_late'] = max(
         0., (timestamp - self.attrib['sched_arrival']) / 60.)
     markerColor = _color_for_status(lateFactor)
     markerAlpha = 1.0
     if self.attrib['status'] == "inactive":
         markerAlpha = 0.0
     self.setPlotData(fields,\
                     [coords[0],\
                      coords[1],\
                      markerColor,\
                      float(12),\
                      markerAlpha,\
                     _make_string([(self['name'],["(unique id " + self['id'] + ")"]),\
                                   ("Time", [nice_time(timestamp, military=False)])]) +\
                         _make_table([\
                                      ["Approaching next stop:&nbsp&nbsp", station_names[self['next_stop']]],\
                                      ["Scheduled arrival&nbsp&nbsp", nice_time(self.attrib['sched_arrival'], military=False)],\
                                      ["Behind schedule by&nbsp&nbsp", "%.1f" % float(self.attrib['t_late']) + " mins"]]) +\
                         _make_table([\
                                      ["","actual","past performance"],\
                                      ["Time elapsed for this trip", "%.1f" % float(self.attrib['duration_actual']) + " mins", "%.1f" % float(T_trip_avg) + " mins"],\
                                      ["Time elapsed on this segment", "%.1f" % float(self.attrib['segment_actual']) + " mins", "%.1f" % float(progressFraction*T_segment_avg/60.) + " mins"]])
                                  ])
Beispiel #2
0
        def update_position(self, timestamp, coords, isLate, progressFraction, T_segment_avg, T_trip_avg, fields):
                self.attrib['segment_actual'] = (timestamp - self.attrib['t_segment_start'])/60.
                self.attrib['t_segment_stored'] = T_segment_avg/60.
                if T_trip_avg == 0:
                    lateFactor = 0.
                else:
                    t_trip_late = self.attrib['duration_actual'] - T_trip_avg
                    lateFactor = max(0.,t_trip_late)/self.attrib['duration_actual']
                self.update_count += 1
                self.attrib['isLate'] = isLate 
		self.attrib['t_late'] = max(0.,(timestamp - self.attrib['sched_arrival'])/60.)
                markerColor = _color_for_status(lateFactor)
                markerAlpha = 1.0
                if self.attrib['status'] == "inactive":
                        markerAlpha = 0.0
                self.setPlotData(fields,\
                                [coords[0],\
                                 coords[1],\
                                 markerColor,\
                                 float(12),\
                                 markerAlpha,\
                                _make_string([(self['name'],["(unique id " + self['id'] + ")"]),\
                                              ("Time", [nice_time(timestamp, military=False)])]) +\
                                    _make_table([\
                                                 ["Approaching next stop:&nbsp&nbsp", station_names[self['next_stop']]],\
                                                 ["Scheduled arrival&nbsp&nbsp", nice_time(self.attrib['sched_arrival'], military=False)],\
                                                 ["Behind schedule by&nbsp&nbsp", "%.1f" % float(self.attrib['t_late']) + " mins"]]) +\
                                    _make_table([\
                                                 ["","actual","past performance"],\
                                                 ["Time elapsed for this trip", "%.1f" % float(self.attrib['duration_actual']) + " mins", "%.1f" % float(T_trip_avg) + " mins"],\
                                                 ["Time elapsed on this segment", "%.1f" % float(self.attrib['segment_actual']) + " mins", "%.1f" % float(progressFraction*T_segment_avg/60.) + " mins"]])
                                             ])
Beispiel #3
0
    def run(self, use_T0=None):
        self.T = time.time()
        if use_T0:
                self.T = use_T0
        self.Tend = self.T + self.Tend
	T_last_update = 0.
	T_last_plot = 0.
	initPlot = False

        while self.T < self.Tend:
	    if not initPlot:
	        self.plotMgr.init_area(self.mgr.plot_boundaries())
		initPlot = True

	    if self.T - T_last_update > self.updateDataInterval:
		T_last_update = self.T
            	t_update, updateDF = self.streamMgr.read(self.T, self.T+self.updateDataInterval)
                if len(updateDF)>0:
            	        self.mgr.streamUpdate(updateDF)
                else:
                        print "Skipped processing DF of length ZERO"
	    	t_lag = time.time() - t_update
                print nice_time(t_update), nice_time(self.T), "lag between current wall-clock time and real-time feed update:","%.1f" % t_lag, "seconds"

            self.T = time.time()
            if self.T - T_last_plot > self.refreshPlotInterval:
		t_plot = t_update + self.T - T_last_update
                self.mgr.evolve(t_plot, t_update)
                stationData, trainData, routeData, fields, hoverFields = self.mgr.drawSystem(t_plot)
		scatterData = pd.concat([stationData, trainData], axis=0)
                self.plotMgr.plot(scatterData, routeData, fields, hoverFields, t_plot)
		T_last_plot = self.T

	    #time.sleep((1./self.acceleration)*self.refreshPlotInterval)
            self.T = time.time()#t_plot + self.refreshPlotInterval
Beispiel #4
0
 def _purgeStalled(self, t_current, t_wait_mins):
     for train_id in self.activeTrains.keys():
         t_last_update = self.activeTrains[train_id].attrib['time_of_update']
         if (t_current - t_last_update)/60. > t_wait_mins:
             routeID = self.activeTrains[train_id].attrib['routeID']
             print nice_time(t_current), "Purging stalled train",train_id, "after", (t_current-t_last_update)/60.,"mins inactive on route",routeID
             self._getRoute(train_id, routeID).clearTrain(train_id, t_current)
             self.activeTrains.pop(train_id)
             self.drawTrainData = self.drawTrainData.drop(train_id, axis=0)
Beispiel #5
0
 def _purgeStalled(self, t_current, t_wait_mins):
     for train_id in self.activeTrains.keys():
         t_last_update = self.activeTrains[train_id].attrib[
             'time_of_update']
         if (t_current - t_last_update) / 60. > t_wait_mins:
             routeID = self.activeTrains[train_id].attrib['routeID']
             print nice_time(
                 t_current), "Purging stalled train", train_id, "after", (
                     t_current -
                     t_last_update) / 60., "mins inactive on route", routeID
             self._getRoute(train_id,
                            routeID).clearTrain(train_id, t_current)
             self.activeTrains.pop(train_id)
             self.drawTrainData = self.drawTrainData.drop(train_id, axis=0)
Beispiel #6
0
 def _listApproaching(self, t_now):
     strings = []
     t_late = 0.
     for (ll,dd) in self.routes.keys():
         trainsDict = self.routes[(ll,dd)]
         listTrains = "; ".join([nice_time(t[1], military=False) for t in trainsDict.values()])
         for t_data in trainsDict.values():
             t_late = t_late + max(0., t_now-t_data[1])
         direction_tag = {"N":"Uptown","S":"Downtown"}
         if len(listTrains) > 0:
             strings.append((str(ll) + " " + direction_tag[dd] + " due", listTrains))
     return t_late, strings
Beispiel #7
0
 def updateProgress(self, timestamp, fields):
         t_late_approaching, trains_approaching_string = self._listApproaching(timestamp)
         self.setPlotData(fields=fields,\
                          data=[float(self.attrib['lon']),\
                                float(self.attrib['lat']),\
                                _stop_color_for_status(t_late_approaching/60.),\
                                float(7),\
                                float(1.0),\
                                _make_string([("Station", [str(self['name'])]),\
                                              ("Time", [nice_time(time.time(), military=False)]),\
                                              ("Trains approaching", trains_approaching_string),\
                                              ("Arrival Stats", [""])]) +\
                                _make_table(self._listStopData(timestamp))])
Beispiel #8
0
 def _listApproaching(self, t_now):
     strings = []
     t_late = 0.
     for (ll, dd) in self.routes.keys():
         trainsDict = self.routes[(ll, dd)]
         listTrains = "; ".join(
             [nice_time(t[1], military=False) for t in trainsDict.values()])
         for t_data in trainsDict.values():
             t_late = t_late + max(0., t_now - t_data[1])
         direction_tag = {"N": "Uptown", "S": "Downtown"}
         if len(listTrains) > 0:
             strings.append(
                 (str(ll) + " " + direction_tag[dd] + " due", listTrains))
     return t_late, strings
Beispiel #9
0
 def updateProgress(self, timestamp, fields):
     t_late_approaching, trains_approaching_string = self._listApproaching(
         timestamp)
     self.setPlotData(fields=fields,\
                      data=[float(self.attrib['lon']),\
                            float(self.attrib['lat']),\
                            _stop_color_for_status(t_late_approaching/60.),\
                            float(7),\
                            float(1.0),\
                            _make_string([("Station", [str(self['name'])]),\
                                          ("Time", [nice_time(time.time(), military=False)]),\
                                          ("Trains approaching", trains_approaching_string),\
                                          ("Arrival Stats", [""])]) +\
                            _make_table(self._listStopData(timestamp))])