コード例 #1
0
# Add extra headers
rows[0] = rows[0][:49] + [
    'w_games_perc.', 'l_games_perc.', 'w_service_games_perc.',
    'l_service_games_perc.', 'w_points_perc.', 'l_points_perc.',
    'w_service_points_perc.', 'l_service_points_perc.', 'w_combined_perc.',
    'l_combined_perc.', 'w_combined_service_perc.', 'l_combined_service_perc.'
]

# Add contents of extra columns
for row in rows[1:]:
    w_games_perc, l_games_perc = get_game_percentages(row)
    w_service_games_perc, l_service_games_perc = get_service_game_percentages(
        row)
    w_points_perc, l_points_perc = get_point_percentages(row)
    w_service_points_perc, l_service_points_perc = get_service_point_percentages(
        row)
    w_combined_percentage, l_combined_percentage = get_combined_percentages(
        row)
    w_combined_serve_percentage, l_combined_serve_percentage = get_combined_service_percentages(
        row)
    row = row[:49] + [
        w_games_perc, l_games_perc, w_service_games_perc, l_service_games_perc,
        w_points_perc, l_points_perc, w_service_points_perc,
        l_service_points_perc, w_combined_percentage, l_combined_percentage,
        w_combined_serve_percentage, l_combined_serve_percentage
    ]

# re-write file with extra information
os.remove(input_file)
out.append_csv_rows(rows, input_file)
コード例 #2
0
if __name__ == "__main__":

    # Create queues and process pool
    q_out = mp.Queue()
    q_in = mp.Queue()
    pool = mp.Pool(10, worker, (
        q_in,
        q_out,
    ))

    # Fill queues of work, with max 50 items in input queue
    for i, item in enumerate(provider_model.data_provider):
        q_in.put(item)
        if i > 50:
            output_lines = q_out.get()
            out.append_csv_rows(output_lines, output_file)

    # Handle final 50 items of output que
    for i in range(50):
        try:
            output_lines = q_out.get(
                block=True,
                timeout=300)  # If idle for 5 minutes assume finished
            out.append_csv_rows(output_lines, output_file)
        except Queue.Empty:
            break

    # Close ques and pool
    pool.terminate()
    q_in.close()
    q_out.close()
コード例 #3
0
    q_in = mp.Queue()
    pool = mp.Pool(25, worker, (
        q_in,
        q_out1,
        q_out2,
        q_out3,
        q_out4,
    ))

    # Fill queues of work, with max 50 items in input queue
    for i, item in enumerate(provider_model.data_provider):
        q_in.put(item)
        if i > 50:
            output_lines = q_out1.get()
            out.append_csv_rows(output_lines, output_file1)
            output_lines = q_out2.get()
            out.append_csv_rows(output_lines, output_file2)
            output_lines = q_out3.get()
            out.append_csv_rows(output_lines, output_file3)
            output_lines = q_out4.get()
            out.append_csv_rows(output_lines, output_file4)
            if i % 50 == 0:
                print('Iteration {0}'.format(i))

    # Handle final 150 items of output queue
    for i in range(50):
        try:
            output_lines = q_out1.get(
                block=True,
                timeout=300)  # If idle for 5 minutes assume job finished