Ejemplo n.º 1
0
def trace2csv(tracefile, reader):
    """ Use the specified reader to convert the given
        tracefile to a csv file
    """
    out_path = os.path.splitext(tracefile)[0] + ".csv"
    data_keys = core.get_data_keys(reader)
    data_key_order = core.get_data_key_order(reader)

    infile = core.open_tracefile(tracefile, reader)
    outfile = open(out_path, "w")

    if data_key_order is not None:
        outfile.write(",".join([key for key in data_key_order]) + "\n")
    else:
        outfile.write(",".join([key for key in data_keys]) + "\n")

    for packet in infile:
        out_str = packet2csv_row(packet, num_fields=len(data_keys), data_key_order=data_key_order)
        outfile.write(out_str)

    outfile.close()
Ejemplo n.º 2
0
def _tracefile_to_data_arrays(tracefile, reader, include_errors=False):
    """ Return a tracefile's data as arrays of data
        indexed by the data's key
    """
    data_arrays = {}
    data_keys = core.get_data_keys(reader)
    for key in data_keys:
        data_arrays[key] = []

    infile = core.open_tracefile(tracefile, reader)

    for sample in infile:
        if 'data_errors' in sample:
            if not include_errors:
                continue
        for key in data_keys:
            if key in sample:
                data_arrays[key].append(sample[key])
            else:
                data_arrays[key].append(0)

    return data_arrays
Ejemplo n.º 3
0
def trace2csv(tracefile, reader):
    """ Use the specified reader to convert the given
        tracefile to a csv file
    """
    out_path = os.path.splitext(tracefile)[0] + '.csv'
    data_keys = core.get_data_keys(reader)
    data_key_order = core.get_data_key_order(reader)

    infile = core.open_tracefile(tracefile, reader)
    outfile = open(out_path, 'w')

    if data_key_order is not None:
        outfile.write(','.join([key for key in data_key_order]) + '\n')
    else:
        outfile.write(','.join([key for key in data_keys]) + '\n')

    for packet in infile:
        out_str = packet2csv_row(packet,
                                 num_fields=len(data_keys),
                                 data_key_order=data_key_order)
        outfile.write(out_str)

    outfile.close()