示例#1
0
def init_globals(in_path):

    gl.n_r = 0
    gl.n_o = 0
    gl.out_list = []
    u.init_sl_time()
    gl.fields = u.get_csv_fields_dict(in_path)
示例#2
0
def comp(in1, in2, out):
    from .init import init_compare

    (l1, l2) = init_compare(in1, in2)
    u.init_sl_time()
    while compare_elt(l1, l2) != " ":
        (l1, l2) = compare_equal(l1, l2, in1, in2, out)
        (l1, l2) = compare_inf(l1, l2, in1, out)
        (l1, l2) = compare_sup(l1, l2, in2, out)
示例#3
0
def gen_out_file(out_path):
    # Generating output file in the case of only one temporary list
    from .init import init_prev_elt
    from .functions import write_min_elt

    with open(out_path, 'a', encoding='utf-8') as out_file:
        gl.c_tot_out = 1
        u.init_sl_time()
        init_prev_elt(gl.cur_list)
        for elt in gl.cur_list:
            write_min_elt(elt, out_file)
示例#4
0
def gen_img_dict(in_path):
    s = f"Generating parse dictionary from file '{in_path}'..."
    u.log(s)
    gl.parse_dict = {}
    with open(in_path, 'r', encoding='utf-8', errors='ignore') as in_file:
        gl.N_READ = 0
        line = read_one_line(in_file)
        fill_parse_dict(line)
        u.init_sl_time()
        while line != '':
            line = read_one_line(in_file)
            fill_parse_dict(line)

    even_dict()
    u.log(f"Parse dictionary generated ({gl.N_READ} lines processed)")
示例#5
0
def save_img_dict(out_path):
    u.log('Saving parse dictionary as csv...')
    header = []
    for elt in gl.parse_dict:
        header.append(elt)

    with open(out_path, 'w', encoding='utf-8') as out_file:
        u.write_csv_line(header, out_file)
        u.init_sl_time()
        gl.N_WRITE = 0
        while gl.N_WRITE < gl.N_ROW:
            cur_row = []
            for elt in gl.parse_dict:
                cur_row.append(gl.parse_dict[elt][gl.N_WRITE])
            u.write_csv_line(cur_row, out_file)
            gl.N_WRITE += 1
            u.step_log(gl.N_WRITE, gl.SL_STEP_WRITE, what='lines written')

    u.log(f"csv file saved in {out_path}")
示例#6
0
def gen_sorted_temp_files(in_path, out_path):
    # Generation of sorted temporary files

    has_header = u.has_header(in_path)
    u.log("Generating first list to be sorted...")
    u.init_sl_time()
    with open(in_path, 'r', encoding='utf-8') as in_file:
        first_line = in_file.readline()
        if not has_header:
            gl.cur_list.append(u.csv_to_list(first_line))
        gl.c_sf_read = 1
        for line in in_file:
            gl.c_sf_read += 1
            gl.cur_list.append(u.csv_to_list(line))
            s = "lines read"
            u.step_log(gl.c_sf_read, gl.SL_STEP, s)
            check_max_row(gl.c_sf_read)
    gen_last_file(out_path)
    del gl.cur_list
示例#7
0
def empty_array_list(out_path):
    from .init import init_prev_elt
    from .functions import write_min_elt

    s = "Emptying buffer array in output file (and removing dupes)..."
    u.log(s)
    n_col = len(gl.array_list)
    with open(out_path, 'a', encoding='utf-8') as out_file:
        u.init_sl_time()
        # cursor variable represents a reading cursor for gl.array_list
        (cursor, max_cursor, void_cursor) = init_cursors()
        init_prev_elt(gl.array_list[0])
        while cursor != void_cursor:
            (min_elt, min_col) = get_min_elt(cursor, n_col)
            write_min_elt(min_elt, out_file)
            if cursor[min_col] == max_cursor[min_col] - 1:
                # If one of the lists has entirely been read, array of lists
                # is generated again without the elements already extracted
                # in the output file and while loop is broken (return)
                cursor[min_col] += 1
                for i, l in enumerate(gl.array_list):
                    gl.array_list[i] = l[cursor[i]:]
                return
            cursor[min_col] += 1
示例#8
0
# This script shows you simple examples of use for the log and step_log functions

import time
import partools.utils as u

u.log("This won't be logged in a file")
u.init_log('test')
u.log("This will be logged in a file")

out_list = []
u.init_sl_time()
for i in range(1, 21):
    time.sleep(0.05)  # simulates io / calculation
    out_list.append(i)
    u.step_log(i, 5, "elements appended")

u.log_print(f'out_list: {out_list}')