def render_top_k_summary(source_path: str, prefix: str, epoch_index: int): """ Show top-k summary plot. Args: source_path (str): The root path of the dumped snapshots data for the corresponding experiment. prefix (str): Prefix of data folders. epoch_index (int): The index of selected epoch. """ helper.render_h3_title("Cike Bike Top K") data = helper.read_detail_csv( os.path.join( source_path, f"{prefix}{epoch_index}", GlobalFileNames.stations_sum ) ) # Convert index to station name. index_name_conversion = helper.read_detail_csv(os.path.join(source_path, GlobalFileNames.name_convert)) data["station name"] = list( map( lambda x: index_name_conversion.loc[int(x[9:])][0], data["name"] ) ) # Generate top summary. top_number = st.select_slider( "Select Top K", list(range(1, 6)) ) top_attributes = ["bikes", "trip_requirement", "fulfillment", "fulfillment_ratio"] for item in top_attributes: helper.generate_by_snapshot_top_summary("station name", data, int(top_number), item)
def render_intra_view(source_path: str, epoch_num: int, prefix: str): """Show CIM intra-view plot. Args: source_path (str): The root path of the dumped snapshots data for the corresponding experiment. epoch_num (int) : Total number of epoches, i.e. the total number of data folders since there is a folder per epoch. prefix (str): Prefix of data folders. """ selected_epoch = st.sidebar.select_slider( label="Choose an Epoch:", options=list(range(0, epoch_num)) ) # Get data of selected epoch. data_ports = helper.read_detail_csv(os.path.join(source_path, f"{prefix}{selected_epoch}", "ports.csv")) data_ports["remaining_space"] = list( map( lambda x, y, z: x - y - z, data_ports["capacity"], data_ports["full"], data_ports["empty"] ) ) # Basic data. ports_num = len(data_ports["name"].unique()) ports_index = np.arange(ports_num).tolist() snapshot_num = len(data_ports["frame_index"].unique()) snapshots_index = np.arange(snapshot_num).tolist() # Items for user to select. attribute_option_candidates = ( CIMItemOption.quick_info + CIMItemOption.booking_info + CIMItemOption.port_info ) # Name conversion. index_name_conversion = helper.read_detail_csv(os.path.join(source_path, GlobalFileNames.name_convert)) st.sidebar.markdown("***") option_view = st.sidebar.selectbox( label="By ports/snapshot:", options=CIMIntraViewChoice._member_names_ ) if option_view == CIMIntraViewChoice.by_port.name: _render_intra_view_by_ports( data_ports, ports_index, index_name_conversion, attribute_option_candidates, snapshot_num ) elif option_view == CIMIntraViewChoice.by_snapshot.name: _render_intra_view_by_snapshot( source_path, selected_epoch, data_ports, snapshots_index, index_name_conversion, attribute_option_candidates, ports_num, prefix )
def render_inter_view(source_path: str, epoch_num: int): """Render the cross-epoch infomartion chart of Citi Bike data. This part would be displayed only if epoch_num > 1. Args: source_path (str): The root path of the dumped snapshots data for the corresponding experiment. epoch_num (int): Total number of epoches, i.e. the total number of data folders since there is a folder per epoch. """ helper.render_h1_title("Citi Bike Inter Epoch Data") sample_ratio = helper.get_sample_ratio_selection_list(epoch_num) # Get epoch sample number. down_pooling_range = helper._get_sampled_epoch_range(epoch_num, sample_ratio) attribute_option_candidates = ( CITIBIKEItemOption.quick_info + CITIBIKEItemOption.requirement_info + CITIBIKEItemOption.station_info ) # Generate data. data_summary = helper.read_detail_csv( os.path.join(source_path, GlobalFileNames.stations_sum) ).iloc[down_pooling_range] # Get formula and selected data. data_formula = helper.get_filtered_formula_and_data( GlobalScenarios.CITI_BIKE, data_summary, attribute_option_candidates ) _generate_inter_view_panel( data_formula["data"][data_formula["attribute_option"]], down_pooling_range )
def render_inter_view(source_path: str, epoch_num: int): """Show CIM inter-view plot. Args: source_path (str): The root path of the dumped snapshots data for the corresponding experiment. epoch_num (int): Total number of epoches, i.e. the total number of data folders since there is a folder per epoch. """ helper.render_h1_title("CIM Inter Epoch Data") sample_ratio = helper.get_sample_ratio_selection_list(epoch_num) # Get epoch sample list. down_pooling_range = helper._get_sampled_epoch_range(epoch_num, sample_ratio) attribute_option_candidates = ( CIMItemOption.quick_info + CIMItemOption.port_info + CIMItemOption.booking_info ) # Generate data. data = helper.read_detail_csv(os.path.join(source_path, GlobalFileNames.ports_sum)).iloc[down_pooling_range] data["remaining_space"] = list( map( lambda x, y, z: x - y - z, data["capacity"], data["full"], data["empty"] ) ) # Get formula and selected data. data_formula = helper.get_filtered_formula_and_data(GlobalScenarios.CIM, data, attribute_option_candidates) _generate_inter_view_panel( data_formula["data"][data_formula["attribute_option"]], down_pooling_range )
def render_intra_view(source_path: str, epoch_num: int, prefix: str): """Show Citi Bike intra-view plot. Args: source_path (str): The root path of the dumped snapshots data for the corresponding experiment. epoch_num (int): Total number of epoches, i.e. the total number of data folders since there is a folder per epoch. prefix (str): Prefix of data folders. """ selected_epoch = 0 if epoch_num > 1: selected_epoch = st.sidebar.select_slider( label="Choose an Epoch:", options=list(range(0, epoch_num)) ) helper.render_h1_title("Citi Bike Intra Epoch Data") data_stations = pd.read_csv(os.path.join(source_path, f"{prefix}{selected_epoch}", "stations.csv")) view_option = st.sidebar.selectbox( label="By station/snapshot:", options=CitiBikeIntraViewChoice._member_names_ ) stations_num = len(data_stations["id"].unique()) stations_index = np.arange(stations_num).tolist() snapshot_num = len(data_stations["frame_index"].unique()) snapshots_index = np.arange(snapshot_num).tolist() index_name_conversion = helper.read_detail_csv( os.path.join( source_path, GlobalFileNames.name_convert ) ) attribute_option_candidates = ( CITIBIKEItemOption.quick_info + CITIBIKEItemOption.requirement_info + CITIBIKEItemOption.station_info ) st.sidebar.markdown("***") # Filter by station index. # Display the change of snapshot within 1 station. render_top_k_summary(source_path, prefix, selected_epoch) if view_option == CitiBikeIntraViewChoice.by_station.name: _generate_intra_view_by_station( data_stations, index_name_conversion, attribute_option_candidates, stations_index, snapshot_num ) # Filter by snapshot index. # Display all station information within 1 snapshot. elif view_option == CitiBikeIntraViewChoice.by_snapshot.name: _generate_intra_view_by_snapshot( data_stations, index_name_conversion, attribute_option_candidates, snapshots_index, snapshot_num, stations_num )
def _render_intra_panel_vessel(source_path: str, prefix: str, option_epoch: int, snapshot_index: int): """Show vessel info of selected snapshot. Args: source_path (str): The root path of the dumped snapshots data for the corresponding experiment. prefix (str): Prefix of data folders. option_epoch (int): Selected index of epoch. snapshot_index (int): Index of selected snapshot folder. """ data_vessel = helper.read_detail_csv( os.path.join(source_path, f"{prefix}{option_epoch}", "vessels.csv")) vessels_num = len(data_vessel["name"].unique()) _generate_intra_panel_vessel(data_vessel, snapshot_index, vessels_num)