diff --git a/lasso/transit.py b/lasso/transit.py index 4e293d5..4e7a425 100644 --- a/lasso/transit.py +++ b/lasso/transit.py @@ -1151,21 +1151,49 @@ def shape_gtfs_to_cube(self, row, add_nntime = False): trip_stop_times_df["NNTIME"] = trip_stop_times_df["NNTIME"].round(2) trip_stop_times_df["NNTIME"].fillna(-1, inplace = True) + # ACCESS + def _access_type(x): + if (x.pickup_type in [1, "1"]): + return 2 + elif (x.drop_off_type in [1, "1"]): + return 1 + else: + return 0 + + trip_stop_times_df["ACCESS"] = trip_stop_times_df.apply(lambda x: _access_type(x), axis = 1) + # node list node_list_str = "" + stop_seq = 0 for nodeIdx in range(len(trip_node_list)): if trip_node_list[nodeIdx] in stop_node_id_list: - stop_seq = trip_stop_times_df.loc[ - trip_stop_times_df["model_node_id"] == trip_node_list[nodeIdx], "internal_stop_sequence"].iloc[0] + # in case a route stops at a stop more than once, e.g. circular route + stop_seq += 1 + if (add_nntime) & (stop_seq > 1): - nntime = ", NNTIME=%s" % (trip_stop_times_df.loc[ - trip_stop_times_df["model_node_id"] == trip_node_list[nodeIdx], "NNTIME"].iloc[0]) + if len(trip_stop_times_df[ + trip_stop_times_df["model_node_id"] == trip_node_list[nodeIdx]]) > 1: + nntime = ", NNTIME=%s" % (trip_stop_times_df.loc[ + (trip_stop_times_df["model_node_id"] == trip_node_list[nodeIdx]) & + (trip_stop_times_df["internal_stop_sequence"] == stop_seq), + "NNTIME"].iloc[0]) + else: + nntime = ", NNTIME=%s" % (trip_stop_times_df.loc[ + (trip_stop_times_df["model_node_id"] == trip_node_list[nodeIdx]),"NNTIME"].iloc[0]) else: nntime = "" - node_list_str += "\n %s%s" % (trip_node_list[nodeIdx], nntime) + + access_v = trip_stop_times_df.loc[ + (trip_stop_times_df["model_node_id"] == trip_node_list[nodeIdx]),"ACCESS"].iloc[0] + if access_v > 0: + access = ", ACCESS=%s" % (access_v) + else: + access = "" + + node_list_str += "\n %s%s%s" % (trip_node_list[nodeIdx], nntime, access) if nodeIdx < (len(trip_node_list) - 1): node_list_str += "," - if (add_nntime) & (stop_seq > 1): + if ((add_nntime) & (stop_seq > 1)) | (len(access) > 0): node_list_str += " N=" else: node_list_str += "\n -%s" % (trip_node_list[nodeIdx]) @@ -1174,6 +1202,7 @@ def shape_gtfs_to_cube(self, row, add_nntime = False): # remove NNTIME = 0 node_list_str = node_list_str.replace(" NNTIME=0.0, N=", "") + node_list_str = node_list_str.replace(" NNTIME=0.0,", "") return node_list_str