def convert_time_columns(row): out_row = row[:] # copy for idx in time_column_idxs: field = row[idx].strip() if check_time_str(field): out_row[idx] = hms.str2sec(field) elif field == '': msg = u"GTFS dataset " + GTFSdir + u" contains empty \ values for arrival_time or departure_time in stop_times.txt. Although the \ GTFS spec allows empty values for these fields, this toolbox \ requires exact time values for all stops. You will not be able to use this \ dataset for your analysis." Errors_To_Return.append(msg) raise CustomError else: try: out_row[idx] = float(field) except ValueError: msg = u'Column "' + col_names[ idx] + u'" in file ' + os.path.join( GTFSdir, fname) + u' has an invalid value:' + field + u'.' Errors_To_Return.append(msg) raise CustomError return out_row
def convert_time_columns(row): out_row = row[:] # copy for idx in time_column_idxs: field = row[idx].strip() if check_time_str(field): out_row[idx] = hms.str2sec(field) elif field == "": msg = ( u"GTFS dataset " + GTFSdir + u" contains empty \ values for arrival_time or departure_time in stop_times.txt. Although the \ GTFS spec allows empty values for these fields, this toolbox \ requires exact time values for all stops. You will not be able to use this \ dataset for your analysis." ) Errors_To_Return.append(msg) raise CustomError else: try: out_row[idx] = float(field) except ValueError: msg = ( u'Column "' + col_names[idx] + u'" in file ' + os.path.join(GTFSdir, fname) + u" has an invalid value:" + field + u"." ) Errors_To_Return.append(msg) raise CustomError return out_row
def interpolate_times(time_point_1, time_point_2, blank_times): ''' Simple interpolation method. Assume stop times are evenly spaced between time points.''' # [arrival_time, departure_time, id] num_blank_stops = len(blank_times) # Find the total number of seconds between departing the first time point and arriving at the second time point. total_time_interval_secs = hms.hmsdiff(time_point_2[0], time_point_1[1]) # Find the interval size that divides the total time evenly. time_between_stops_secs = total_time_interval_secs / float(num_blank_stops + 1) # Increment the interval and assign values to the blank stops current_secs = hms.str2sec(time_point_1[1]) for blank_time in blank_times: current_secs += time_between_stops_secs blank_time[0] = hms.sec2str(current_secs) # Set arrival_time and departure_time to the same value. blank_time[1] = blank_time[0] return blank_times
def interpolate_times(time_point_1, time_point_2, blank_times): ''' Simple interpolation method. Assume stop times are evenly spaced between time points.''' # [arrival_time, departure_time, id] num_blank_stops = len(blank_times) # Find the total number of seconds between departing the first time point and arriving at the second time point. total_time_interval_secs = hms.hmsdiff(time_point_2[0], time_point_1[1]) # Find the interval size that divides the total time evenly. time_between_stops_secs = total_time_interval_secs / float( num_blank_stops + 1) # Increment the interval and assign values to the blank stops current_secs = hms.str2sec(time_point_1[1]) for blank_time in blank_times: current_secs += time_between_stops_secs blank_time[0] = hms.sec2str(current_secs) # Set arrival_time and departure_time to the same value. blank_time[1] = blank_time[0] return blank_times
def convert_time_columns(row): out_row = row[:] # copy for idx in time_column_idxs: field = row[idx].strip() if check_time_str(field): out_row[idx] = hms.str2sec(field) elif field == '': msg = "GTFS dataset " + GTFSdir + " contains empty \ values for arrival_time or departure_time in stop_times.txt. Although the \ GTFS spec allows empty values for these fields, this toolbox \ requires exact time values for all stops. You will not be able to use this \ dataset for your analysis." arcpy.AddError(msg) raise BBB_SharedFunctions.CustomError else: try: out_row[idx] = float (field) except ValueError: msg = 'Column "' + col_names[idx] + '" in file ' + os.path.join(GTFSdir, fname) + ' has an invalid value: ' + field + '.' arcpy.AddError(msg) raise BBB_SharedFunctions.CustomError return out_row
GTFS spec allows empty values for these fields, this toolbox \ requires exact time values for all stops. You will not be able to use this \ dataset for your analysis." arcpy.AddError(msg) raise CustomError if not sqlize_csv.check_time_str( arrival_time) or not sqlize_csv.check_time_str( departure_time): msg = u"GTFS dataset " + os.path.basename( gtfs_dir) + u" contains invalid \ values for arrival_time or departure_time in stop_times.txt that are not in HH:MM:SS format." arcpy.AddError(msg) else: arrival_time = hms.str2sec(arrival_time) departure_time = hms.str2sec(departure_time) datarow = [ stop_id, int(row[idx_stop_sequence]), arrival_time, departure_time ] stop_times_dict.setdefault(trip_id, []).append(datarow) # For each trip, select stops in the trip, put them in order, and get pairs # of directly-connected stops for trip in stop_times_dict.keys(): selectedstops = stop_times_dict[trip] selectedstops.sort(key=operator.itemgetter(1)) for x in range(0, len(selectedstops) - 1): start_stop = selectedstops[x][0] end_stop = selectedstops[x + 1][0]
arcpy.AddField_management(outtable,'dep_t_str',"TEXT") #delete unwanted field arcpy.DeleteField_management(outtable, 'Field1') #loop through all the entries in txt with arcpy.da.InsertCursor(outtable, ['trip_id', 'arrival_t', 'depart_t', 'stop_id', 'stop_seq', 's_headsign', 'pickup_t', 'dropoff_t', 'shapetrav', 'timepoint','arr_t_str','dep_t_str']) as ICursor: with open(stopTime_table, 'rb') as f: next(f) reader = csv.reader(f) for row in reader: trip_id = row[0] arrival_t = hms.str2sec(row[1]) depart_t = hms.str2sec(row[2]) stop_id = row[3] stop_seq = row[4] s_headsign = row[5] pickup_t = row[6] dropoff_t = row[7] shapetrav = row[8] timepoint = row[9] arr_t_str = row[1] dep_t_str = row[2] ICursor.insertRow((trip_id, arrival_t, depart_t, stop_id, stop_seq, s_headsign, pickup_t, dropoff_t, shapetrav, timepoint, arr_t_str, dep_t_str)) print 'done'
arrival_time = row[idx_arrival_time] departure_time = row[idx_departure_time] if arrival_time == '' or departure_time == '': msg = u"GTFS dataset " + os.path.basename(gtfs_dir) + u" contains empty \ values for arrival_time or departure_time in stop_times.txt. Although the \ GTFS spec allows empty values for these fields, this toolbox \ requires exact time values for all stops. You will not be able to use this \ dataset for your analysis." arcpy.AddError(msg) raise CustomError if not sqlize_csv.check_time_str(arrival_time) or not sqlize_csv.check_time_str(departure_time): msg = u"GTFS dataset " + os.path.basename(gtfs_dir) + u" contains invalid \ values for arrival_time or departure_time in stop_times.txt that are not in HH:MM:SS format." arcpy.AddError(msg) else: arrival_time = hms.str2sec(arrival_time) departure_time = hms.str2sec(departure_time) datarow = [stop_id, int(row[idx_stop_sequence]), arrival_time, departure_time] stop_times_dict.setdefault(trip_id, []).append(datarow) # For each trip, select stops in the trip, put them in order, and get pairs # of directly-connected stops for trip in stop_times_dict.keys(): selectedstops = stop_times_dict[trip] selectedstops.sort(key=operator.itemgetter(1)) for x in range(0, len(selectedstops)-1): start_stop = selectedstops[x][0] end_stop = selectedstops[x+1][0] SourceOIDkey = "%s , %s , %s" % (start_stop, end_stop, str(trip_routetype_dict[trip])) # This stop pair needs a line feature linefeature_dict[SourceOIDkey] = True
# First row is column names: columns = [name.strip() for name in reader.next()] # locate each field in each rows idx_trip_id = columns.index("trip_id") idx_stop_id = columns.index("stop_id") idx_stop_sequence = columns.index("stop_sequence") idx_arrival_time = columns.index("arrival_time") idx_departure_time = columns.index("departure_time") for row in reader: trip_id = row[idx_trip_id] stop_id = row[idx_stop_id] stop_sequence = int(row[idx_stop_sequence]) arrival_time = hms.str2sec(row[idx_arrival_time]) departure_time = hms.str2sec(row[idx_departure_time]) datarow = [stop_id, stop_sequence, arrival_time, departure_time] stop_times_dict.setdefault(trip_id, []).append(datarow) # for each trip, select stops in the trip, put them in order and get pairs # of directly-connected stops for trip in stop_times_dict.keys(): selectedstops = stop_times_dict[trip] selectedstops.sort(key=operator.itemgetter(1)) for x in range(0, len(selectedstops) - 1): start_stop = selectedstops[x][0] end_stop = selectedstops[x + 1][0] SourceOIDkey = "%s, %s" % (start_stop, end_stop)