Beispiel #1
0
def cve2lines(cvedirn, station_conv, llfn):

    railstation_fn = os.path.join(cvedirn, 'railstation_master.txt')

    # railstation -> 路線 - 駅名リスト
    # {(cve路線ID, cve路線名): ジョルダン駅名, ...}
    railstation_data = mk_railstation_data(railstation_fn, station_conv)

    # Lines instance
    lines = Lines()
    for lineID, linename, *stations_j in railstation_data:
        chk = lines.add_line(lineID, linename, stations_j)
        if type(chk) is int and chk < 0:
            print('railstation err: {0}: {1} {2}'.format(
                chk, lineID, linename))
            sys.exit()

    # 路線リスト
    lines_list = lines.line_list()
    with open(llfn, 'w', encoding='utf-8') as f:
        f.write(''.join(['\t'.join(l) + '\n' for l in lines_list]))

    return lines
Beispiel #2
0
    header = ['tt路線', 'tt方面', 'i', '入力駅', 'tt時刻', 'tt文字列1', 'tt文字列2', \
                'rt_on駅', 'rt路線', 'rt行き先', 'rt方面', '列車no', 'flg', 'cve路線ID', 'cve路線名']

    def writedata(fn, data, header):
        with open(fn, 'w', encoding='utf-8') as f:
            f.write('\t'.join(header) + '\n')
            for l in data:
                f.write('\t'.join(l) + '\n')

    writedata(okfn, ok_data, header)
    writedata(osngfn, osng_data, header + ['途中始発', '途中終着', '-> 各駅'])
    writedata(pasfn, pas_data, header + ['new路線ID', '途中始発', '途中終着', '-> 各駅'])
    writedata(errfn, err_data, header + ['-> ng駅'])

    # 路線リスト
    line_list_data = lines.line_list()

    with open(llfn, 'w', encoding='utf-8') as llf:
        llf.write(''.join(
            ['\t'.join([str(x) for x in l]) + '\n' for l in line_list_data]))

    # pickle
    pickledirn = os.path.join(wkdirn, 'pickle')
    if not os.path.isdir(pickledirn):
        os.mkdir(pickledirn)
    vpfn = os.path.join(pickledirn, 'vehicles.pickle')
    pickle.dump(vehicles, open(vpfn, 'wb'))
    lpfn = os.path.join(pickledirn, 'lines.pickle')
    pickle.dump(lines, open(lpfn, 'wb'))