def update(self): # Check if the locally cached vehicle list has gotten stale. if len(self.passengers) != len(common.passengers): self.passengers = common.passengers.values() self.passengers.sort() lines = [] for pax in self.passengers: assert isinstance(pax, Passenger) lines.append([str(pax.ID), "%.3f" % pax.time, str(pax.src_station.ID), str(pax.dest_station.ID), str(pax.loc.ID), self.type_str(pax.loc), sec_to_hms(pax.wait_time), sec_to_hms(pax.walk_time), sec_to_hms(pax.ride_time), sec_to_hms(pax.total_time), str(pax.trip_success), str(pax.mass), str(pax.will_share), str(pax.unload_delay), str(pax.load_delay), pax.src_station.label, pax.dest_station.label, pax.loc.label]) self._lines = lines
def update(self): if len(self.s_list) != len(common.stations): self.s_list = common.stations.values() self.s_list.sort() lines = [] for s in self.s_list: assert isinstance(s, Station) berths, unload, load, unload_load, queue = 0, 0, 0, 0, 0 for platform in s.platforms: for berth in platform.berths: berths += 1 if berth.unloading and berth.loading: unload_load += 1 elif berth.unloading: unload += 1 elif berth.loading: load += 1 else: # no loading or unloading capability queue += 1 pax_wait_times = s.all_pax_wait_times() if pax_wait_times: min_pax_wait = sec_to_hms(min(pax_wait_times)) mean_pax_wait = sec_to_hms(sum(pax_wait_times)/len(pax_wait_times)) max_pax_wait = sec_to_hms(max(pax_wait_times)) else: min_pax_wait = "N/A" mean_pax_wait = "N/A" max_pax_wait = "N/A" lines.append(["%d" % s.ID, s.label, "%d" % len(s.platforms), "%d" % berths, "%d" % unload, "%d" % load, "%d" % unload_load, "%d" % queue, "%d" % len(s._passengers), "%d" % sum(1 for pax in s._all_passengers if pax.src_station is s), "%d" % s._pax_arrivals_count, "%d" % s._pax_departures_count, min_pax_wait, mean_pax_wait, max_pax_wait, "inc", # TODO: Vehicle-related stats "inc", "inc", "inc"]) self._lines = lines
def _get_unload_delay_text(self): return sec_to_hms(self.item.unload_delay)
def _get_total_time_text(self): return sec_to_hms(self.item.total_time)
def _get_walk_time_text(self): return sec_to_hms(self.item.walk_time)
def _get_ride_time_text(self): return sec_to_hms(self.item.ride_time)
def update(self, pax_report, vehicle_report, station_report, power_report): """Returns a list of strings containing summary info.""" assert isinstance(pax_report, PaxReport) assert isinstance(vehicle_report, VehicleReport) assert isinstance(station_report, StationReport) assert isinstance(power_report, PowerReport) KM_TO_MILES = 0.621371192 lines = [] lines.append("Minutes Simulated:\t %.1f" % (Sim.now()/60.)) lines.append("") # Passenger summary statistics if common.passengers: # some passengers were simulated pax_list = common.passengers.values() success_rate = sum(1 for p in pax_list if p.trip_success)/len(pax_list) * 100 lines.append("Passenger Statistics") lines.append("Number of Passengers: %d" % len(pax_list)) min_t, max_t, sum_t = 0, 0, 0 for p in pax_list: t = p.wait_time if t < min_t: min_t = t if t > max_t: max_t = t sum_t += t lines.append("Wait times (Min/Mean/Max):\t%s\t%s\t%s" % \ (sec_to_hms(min_t), sec_to_hms(sum_t/len(pax_list)), sec_to_hms(max_t))) min_t, max_t, sum_t = 0, 0, 0 for p in pax_list: t = p.walk_time if t < min_t: min_t = t if t > max_t: max_t = t sum_t += t lines.append("Walk times (Min/Mean/Max):\t%s\t%s\t%s" % \ (sec_to_hms(min_t), sec_to_hms(sum_t/len(pax_list)), sec_to_hms(max_t))) min_t, max_t, sum_t = 0, 0, 0 for p in pax_list: t = p.ride_time if t < min_t: min_t = t if t > max_t: max_t = t sum_t += t lines.append("Ride times (Min/Mean/Max):\t%s\t%s\t%s" % \ (sec_to_hms(min_t), sec_to_hms(sum_t/len(pax_list)), sec_to_hms(max_t))) min_t, max_t, sum_t = 0, 0, 0 for p in pax_list: t = p.total_time if t < min_t: min_t = t if t > max_t: max_t = t sum_t += t lines.append("Total times (Min/Mean/Max):\t%s\t%s\t%s" % \ (sec_to_hms(min_t), sec_to_hms(sum_t/len(pax_list)), sec_to_hms(max_t))) lines.append("%% Trip success:\t%5d" % success_rate) lines.append("") else: lines.append("No passengers simulated.") lines.append("") # Vehicle summary statistics distances = [v.get_dist_travelled() for v in common.vehicle_list] operational_times = [v.get_operational_time() for v in common.vehicle_list] nonempty_distances = [v.get_nonempty_dist() for v in common.vehicle_list] nonempty_times = [v.get_nonempty_time() for v in common.vehicle_list] pax_distances = [v.get_pax_dist() for v in common.vehicle_list] pax_counts = [v.total_pax for v in common.vehicle_list] total_dist = sum(distances) total_km = total_dist/1000. total_miles = total_km * KM_TO_MILES total_nonempty_dist = sum(nonempty_distances) total_nonempty_km = total_nonempty_dist/1000. total_nonempty_miles = total_nonempty_km * KM_TO_MILES total_pax_dist = sum(pax_distances) total_pax_km = total_pax_dist/1000. total_pax_miles = total_pax_km * KM_TO_MILES total_time = sum(operational_times) # seconds total_time_hours = total_time/3600. total_nonempty_time = sum(nonempty_times) # seconds total_nonempty_time_hours = total_nonempty_time/3600. mean_km = total_km/len(common.vehicle_list) mean_miles = mean_km * KM_TO_MILES max_km = max(distances)/1000. max_miles = max_km * KM_TO_MILES min_km = min(distances)/1000. min_miles = min_km * KM_TO_MILES try: mean_vel_kph = total_km/total_time_hours mean_vel_mph = total_miles/total_time_hours except ZeroDivisionError: mean_vel_kph = 0 mean_vel_mph = 0 try: mean_pax_vel_kph = total_nonempty_km/total_nonempty_time_hours mean_pax_vel_mph = total_nonempty_miles/total_nonempty_time_hours except ZeroDivisionError: mean_pax_vel_kph = 0 mean_pax_vel_mph = 0 total_pax = sum(pax_counts) min_pax = min(pax_counts) mean_pax = total_pax/len(common.vehicle_list) max_pax = max(pax_counts) lines.append("Vehicle statistics") lines.append("Number of Vehicles:\t%d" % len(common.vehicle_list)) lines.append("Total vehicle km travelled:\t%10.3f\t(%.3f miles)" % (total_km, total_miles)) lines.append("Vehicle km travelled (Min/Mean/Max):\t%9.3f\t%9.3f\t%9.3f" % (min_km, mean_km, max_km)) lines.append("Vehicle miles travelled (Min/Mean/Max):\t%9.3f\t%9.3f\t%9.3f" % (min_miles, mean_miles, max_miles)) lines.append("Mean velocity:\t%10d km/hr\t(%d mph)" % (mean_vel_kph, mean_vel_mph)) lines.append("Mean velocity w/ passengers:\t%10d km/hr\t(%d mph)" % (mean_pax_vel_kph, mean_pax_vel_mph)) lines.append("Total passengers carried:\t%10d" % total_pax) lines.append("Pax carried per vehicle (Min/Mean/Max):\t%9d\t%9.3f\t%9d" % (min_pax, mean_pax, max_pax)) lines.append("Passenger km travelled: %.1f\t(%.1f miles)" % (total_pax_km, total_pax_miles)) lines.append("") # Station summary statistics lines.append("Station statistics") lines.append("Number of stations:\t%d" % len(common.station_list)) lines.append("") # Power summary statistics try: lines.append("Power statistics") total_energy = power_report.plot_data.get_data('total_energy').get_data()[-1] lines.append("Total Energy:\t%.1f KW-hrs" % total_energy) lines.append("Energy/Distance:\t%.1f Watt-hrs/km\t (%.1f Watt-hrs/mile)" \ % ((total_energy*1000.)/total_km, (total_energy*1000.)/total_miles)) except (IndexError, ZeroDivisionError): pass self._lines = lines self._text = self.LINE_DELIMETER.join(self._lines)
def _get_max_all_pax_wait_text(self): return sec_to_hms(self.item.max_all_pax_wait)
def _get_mean_curr_pax_wait_text(self): return sec_to_hms(self.item.mean_curr_pax_wait)
def station_selection_handler(self, object, name, new): """This handler method will get called every time the metadata of the datasourcse get updated. We'll just dump out the contents of that metadata to screen. In this case, it is the index of the point directly under the mouse, and the index of the last point the mouse clicked on (indicated by "selection"). name is 'metadata changed' new is 'True' """ metadata = object.metadata selected = [] if "hover" in metadata: # and not self.data_label_index: # print "Hover:", metadata["hover"][0] select = metadata['hover'][0] point = (self.plot_data.get_data('stat_x')[select], self.plot_data.get_data('stat_y')[select]) # print "Point:", point stat = common.station_list[select] stat_name = stat.label num_pax = len(stat._passengers) now = SimPy.now() wait_times = [pax.wait_time for pax in stat._passengers] if wait_times: max_wait = utility.sec_to_hms(max(wait_times)) avg_wait = utility.sec_to_hms( sum(wait_times) / len(wait_times)) else: max_wait = utility.sec_to_hms(0) avg_wait = utility.sec_to_hms(0) # print "stuff", stat_name, num_pax, max_wait, avg_wait self._stat_label = chaco.DataLabel(component=self.plot, data_point=point, lines=[ '%s' % stat_name, 'sID: %d' % stat.ID, 'PAX Waiting: %d' % num_pax, 'max wait: %s' % max_wait, 'avg wait: %s' % avg_wait ]) self.plot.overlays.append(self._stat_label) # Ahh, the hackery work of a hack. Suck. # An explanation: It seems like the metadata is being updated twice, # but only on the first time the mouse hovers over any station. Rather # than trying to figure out what's up, I'm just deleting all DataLabels # whenever the mouse moves. Better long term soln is probably to write # my own version of a scatter_inspector that handles the DataLabels # internally. else: to_delete = [] for idx, overlay in enumerate(self.plot.overlays): if isinstance(overlay, chaco.DataLabel): to_delete.append(idx) for x in reversed(to_delete): del self.plot.overlays[x] if "selections" in metadata: # print metadata["selections"] try: for select in metadata["selections"]: stat = common.station_list[select] stat.edit_traits() del metadata["selections"] # clear the selection list except IndexError: pass