Exemplo n.º 1
0
def Convert(xlspath, saveto, day_time_to_extract):
    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]
    morningcol = 16
    daycol = 19
    eveningcol = 22
    nightcol = 25
    avgcol = 28
    speed_column = 31
    cols = {
        "morning": [morningcol, morningcol + 1, speed_column],
        "day": [daycol, daycol + 1, speed_column],
        "evening": [eveningcol, eveningcol + 1, speed_column],
        "night": [nightcol, nightcol + 1, speed_column],
        "average": [avgcol, avgcol + 1, speed_column]
    }
    col_label = ["num_zone", "vl", "pl", "speed"]
    fields, data = ExtractXlsData(xlspath, sheet_id, start_line,
                                  base_cols + cols[day_time_to_extract],
                                  field_line)  #+cols[day_time_to_extract]
    data = data[:-1]  #remove the sum
    print u"Set default values in empty cells"
    data = SetDefaultValueWhereNone(data)
    print u"Save to dbf file"
    SaveArrayToDBF(saveto, col_label, data)
    print u"Extraction of data done in %g seconds." % (time.time() - start_t)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
def Convert(saveto):
    start_t=time.time()
    #day_time_to_extract= #morning,day,evening,night,average
    sheet_id=0
    start_line=1
    field_line=0
    base_cols=[1]
    col_label=["id_tronc"]
    fields,data=ExtractXlsData("liste_troncons_ponts_100713.xls",sheet_id,start_line,base_cols,field_line)
    print u"Set default values in empty cells"
    data=SetDefaultValueWhereNone(data)
    print u"Save to dbf file"
    SaveArrayToDBF(saveto,col_label,data)
    print u"Extraction of data done in %g seconds." % (time.time()-start_t)
Exemplo n.º 5
0
def extract_queue(xlsdata, day_time_to_extract, queue_saveto):
    sheet_id = 2
    start_line = 2
    field_line = 1
    base_cols = [1, 2, 3, 7]
    morning_first_col = 8
    day_first_col = 11
    evening_first_col = 14
    night_first_col = 17
    morning_second_col = 20
    day_second_col = 23
    evening_second_col = 26
    night_second_col = 29
    cols = {
        "morning": [
            morning_first_col, morning_first_col + 1, morning_first_col + 2,
            morning_second_col, morning_second_col + 1
        ],
        "day": [
            day_first_col, day_first_col + 1, day_first_col + 2,
            day_second_col, day_second_col + 1
        ],
        "evening": [
            evening_first_col, evening_first_col + 1, evening_first_col + 2,
            evening_second_col, evening_second_col + 1
        ],
        "night": [
            night_first_col, night_first_col + 1, night_first_col + 2,
            night_second_col, night_second_col + 1
        ]
    }
    if not day_time_to_extract in cols.keys():
        return
    col_label = [
        "id_tronc", "from_node", "to_node", "speed_max", "speed_load",
        "time_cross", "sd_cross", "sd_cross_i", "queue_len"
    ]
    fields, data = FilterXlsData(xlsdata, sheet_id, start_line,
                                 base_cols + cols[day_time_to_extract],
                                 field_line)
    data = SetDefaultValueWhereNone(data)
    SaveArrayToDBF(queue_saveto, col_label, data)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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)