def Convert(sheet_id,fulldata=None,xlsfilename=u"calcul vk par scenarios_valeurs.xls"): start_t=time.time() time_ranges=["morning" , "day" , "evening","night"] time_ranges_lbl=["hpm_","hcj_","hps_","hcn_"] if fulldata is None: print u"Extract fields from XLS file.." fulldata=ParseXlsData(xlsfilename) print u"Fields extraction done." for choice in range(len(time_ranges_lbl)): day_time_to_extract=time_ranges[choice] traffic_saveto=time_ranges_lbl[choice]+"tron.dbf" print u"Filter %s time range.." % (day_time_to_extract) start_line=2 field_line=1 base_cols=[1,2,3,5,6,7,9,12,13] morning_first_col=15 day_first_col=19 evening_first_col=23 night_first_col=27 cols={ "morning" : [morning_first_col,morning_first_col+1,morning_first_col+3], "day" : [day_first_col,day_first_col+1,day_first_col+3], "evening" : [evening_first_col,evening_first_col+1,evening_first_col+3], "night" : [night_first_col,night_first_col+1,night_first_col+3] } col_label=["id_tronc","from_node","to_node","direction","surtype","rtype","length","capacity","speedmax","tv","pl","speedload"] fields,data=FilterXlsData(fulldata,sheet_id,start_line,base_cols+cols[day_time_to_extract],field_line) print u"Set default values in empty cells" data=SetDefaultValueWhereNone(data) print u"Save traffic to dbf file",traffic_saveto SaveArrayToDBF(traffic_saveto,col_label,data) print u"Extraction of data done in %g seconds." % (time.time()-start_t)
def Convert(day_time_to_extract, traffic_saveto, queue_saveto, fulldata=None, xlsfilename=u"tron�ons_calage_2002_v2.xls"): start_t = time.time() #day_time_to_extract= #morning,day,evening,night,average sheet_id = 1 start_line = 2 field_line = 1 base_cols = [1, 2, 3, 5, 6, 7, 9, 12, 13] morning_first_col = 15 day_first_col = 23 evening_first_col = 31 night_first_col = 39 avg_first_col = 47 cols = { "morning": [ morning_first_col + 2, morning_first_col + 3, morning_first_col + 5, morning_first_col + 7 ], "day": [ day_first_col + 2, day_first_col + 3, day_first_col + 5, day_first_col + 7 ], "evening": [ evening_first_col + 2, evening_first_col + 3, evening_first_col + 5, evening_first_col + 7 ], "night": [ night_first_col + 2, night_first_col + 3, night_first_col + 5, night_first_col + 7 ], "average": [ avg_first_col + 2, avg_first_col + 3, avg_first_col + 4, avg_first_col + 4 ] } col_label = [ "id_tronc", "from_node", "to_node", "direction", "surtype", "rtype", "length", "capacity", "speedmax", "tv", "pl", "speedload", "speedcross" ] if fulldata is None: print u"Extract %s fields from XLS file.." % (day_time_to_extract) fulldata = ParseXlsData(xlsfilename) fields, data = FilterXlsData(fulldata, sheet_id, start_line, base_cols + cols[day_time_to_extract], field_line) print u"Set default values in empty cells" data = SetDefaultValueWhereNone(data) print u"Save traffic to dbf file", traffic_saveto SaveArrayToDBF(traffic_saveto, col_label, data) print u"Save queue to dbf file :", queue_saveto extract_queue(fulldata, day_time_to_extract, queue_saveto) print u"Extraction of data done in %g seconds." % (time.time() - start_t)
def ConvertBusTram(day_time_to_extract, traffic_saveto, fulldata=None, xlsfilename=u"Services TC 2008.xls"): start_t = time.time() #day_time_to_extract= #morning,day,evening,night,average sheet_id = 0 start_line = 3 field_line = 2 base_cols = [0] morning_first_col = 1 day_first_col = 3 evening_first_col = 2 night_first_col = 4 #4: 20h-1h night2_first_col = 5 #5: 4h-6h avg_first_col = 6 cols = { "morning": [morning_first_col, morning_first_col + 6, morning_first_col + 12], "day": [day_first_col, day_first_col + 6, day_first_col + 12], "evening": [evening_first_col, evening_first_col + 6, evening_first_col + 12], "night": [night_first_col, night_first_col + 6, night_first_col + 12], "night2": [night2_first_col, night2_first_col + 6, night2_first_col + 12], "average": [avg_first_col, avg_first_col + 6, avg_first_col + 12] } col_label = ["id_tronc", "bus", "busway", "tramway"] if fulldata is None: print u"Extract %s fields from XLS file.." % (day_time_to_extract) fulldata = ParseXlsData(xlsfilename) fields, data = FilterXlsData(fulldata, sheet_id, start_line, base_cols + cols[day_time_to_extract], field_line) print u"Set default values in empty cells" data = SetDefaultValueWhereNone(data) print u"Save tramway and bus traffic to dbf file" SaveArrayToDBF(traffic_saveto, col_label, data) print u"Extraction of data done in %g seconds." % (time.time() - start_t)
def ConvertBusTramSpeed(speed_saveto, fulldata=None, xlsfilename=u"tps tc troncons.xls"): start_t = time.time() #day_time_to_extract= #morning,day,evening,night,average sheet_id = 0 start_line = 3 field_line = 2 base_cols = [0, 1, 2, 3, 5, 8, 9, 12, 14, 15, 18] col_label = [ "IDTRONC", "ORIG", "DEST", "ROAD_TYPE", "KM_LENGTH", "T_DUR_BUS", "T_DUR_BW", "T_DUR_TW", "C_SP_BUS", "C_SP_BW", "C_SP_TRAM" ] if fulldata is None: print u"Extract fields from XLS file.." fulldata = ParseXlsData(xlsfilename) fields, data = FilterXlsData(fulldata, sheet_id, start_line, base_cols, field_line) print u"Set default values in empty cells" data = SetDefaultValueWhereNone(data) print u"Save tramway and bus traffic to dbf file" SaveArrayToDBF(speed_saveto, col_label, data) print u"Extraction of data done in %g seconds." % (time.time() - start_t)