def _write_stats(self): G = GTFS(self.day_db_path) net = combined_stop_to_stop_transit_network(G) sections = net.edges(data=True) n_links = len(sections) section_lengths = [] vehicle_kilometers_per_section = [] for from_I, to_I, data in sections: section_lengths.append(data['d']) vehicle_kilometers_per_section.append(data['n_vehicles'] * data['d'] / 1000.) stats = {"n_stops": len(G.stops(require_reference_in_stop_times=True)), "n_connections": len(G.get_transit_events()), "n_links": n_links, "network_length_m": sum(section_lengths), "link_distance_avg_m": int(sum(section_lengths) / len(section_lengths)), "vehicle_kilometers": sum(vehicle_kilometers_per_section), "buffer_center_lat": self.lat, "buffer_center_lon": self.lon, "buffer_radius_km": self.buffer_distance, "extract_start_date": self.get_weekly_extract_start_date().strftime("%Y-%m-%d") } self.__verify_stats(stats) df = pandas.DataFrame.from_dict({key:[value] for key, value in stats.items()}) df.to_csv(self.stats_fname, sep=";", columns=list(sorted(stats.keys())), index=False)
license = license.replace("_", " ") city_data_dict["License"] = license feeds = get_feeds_from_to_publish_tuple(city_data) pipeline = ExtractPipeline(city_data, feeds) try: day_G = GTFS(pipeline.day_db_path) trip_counts_per_day = day_G.get_trip_counts_per_day() print(trip_counts_per_day) assert len(trip_counts_per_day) <= 3 city_data_dict["Extract date"] = str(trip_counts_per_day.loc[ trip_counts_per_day['trip_counts'] == max( trip_counts_per_day['trip_counts'])].iloc[0]['date']) print(city_data_dict["Extract date"].replace(" 00:00:00", "")) city_data_dict["n_stops"] = len( day_G.stops(require_reference_in_stop_times=True)) city_data_dict["n_connections"] = len(day_G.get_transit_events()) n_links = len( combined_stop_to_stop_transit_network(day_G).edges(data=True)) city_data_dict["n_links"] = int(n_links) except FileNotFoundError as e: print("File " + pipeline.day_db_path + " was not found") city_data_dict["Extract date"] = "NaN" cities.append(city_data_dict) pickle.dump(cities, open(pickle_cache_file, 'wb'), -1) def spaces(x): try: num_as_str_reversed = str(int(x))[::-1] num_with_spaces = ',\\'.join( num_as_str_reversed[i:i + 3]