def get_data_for_pre(name, cl_data, res_data, is_lo): pre_data = [] if is_lo: col = R_NAME_1_COL col_other = R_NAME_2_COL the_range = LO_D_RANGE the_other_range = VI_D_RANGE else: col = R_NAME_2_COL col_other = R_NAME_1_COL the_range = VI_D_RANGE the_other_range = LO_D_RANGE cl = get_cl_data_for_name(name, cl_data) final_cl = [cl[i] for i in the_range] for res_d in res_data: if res_d[col] == name: cl_other = get_cl_data_for_name(res_d[col_other], cl_data) final_cl_other = [cl_other[i] for i in the_other_range] new_row = [cl_other[CL_POS_COL]] new_row.extend(final_cl_other) new_row.extend([res_d[RES_ELT_COL]]) pre_data.append(new_row) return pre_data, [cl[CL_POS_COL]] + final_cl
def get_data_for_pre(name, cl_data, res_data, is_lo): pre_data = [] if is_lo: col = R_NAME_1_COL col_other = R_NAME_2_COL the_range = LO_D_RANGE the_other_range = VI_D_RANGE else: col = R_NAME_2_COL col_other = R_NAME_1_COL the_range = VI_D_RANGE the_other_range = LO_D_RANGE cl = get_cl_data_for_name(name, cl_data) final_cl = [cl[i] for i in the_range] for res_d in res_data: if res_d[col] == name: cl_other = get_cl_data_for_name(res_d[col_other], cl_data) final_cl_other = [cl_other[i] for i in the_other_range] new_row = [ cl_other[CL_POS_COL] ] new_row.extend(final_cl_other) new_row.extend([res_d[RES_ELT_COL]]) pre_data.append(new_row) return pre_data, [cl[CL_POS_COL]] + final_cl
def generate_final_hist(index, b1_hist, a2_hist, k, pro_data, pre_data, p_data, cldat): hist = b1_hist + a2_hist for i, k_elt in enumerate(k): if k_elt[K_TYPE_COL] == TYPE_1_COL: cl = cldat.b1 else: cl = cldat.a2 new_row = [int(k_elt[TYPE_COL]), ''] if HIST_TYPE: new_row.extend(pro_data[i]) new_row.extend(pre_data[i]) new_row.extend(p_data[i]) else: cl_lo = get_cl_data_for_name(k_elt[NAME_LO_COL], cl) new_row.extend([cl_lo[i] for i in LO_D_RANGE]) cl_vi = get_cl_data_for_name(k_elt[NAME_VI_COL], cl) new_row.extend([cl_vi[i] for i in VI_D_RANGE]) new_row.extend([k_elt[NAME_LO_COL], k_elt[NAME_VI_COL]]) hist.append(new_row) save_data_to_csv(AP_HIST_FILE, hist)
def gen_hist(res, cl, file_name, p_type): print "Generating historical data for: %s" % file_name hist = read_input_file(file_name) j_res_max = max([ int(r[R_J_COL]) for r in res if int(r[R_J_COL]) >= FIRST_ENTRY_HIST]) for j in range(FIRST_ENTRY_HIST, j_res_max + 1): res_j = [ r for r in res if int(r[R_J_COL]) == j ] res_data = [ r for r in res if int(r[R_J_COL]) < j ] for r in res_j: new_row = [int(p_type), r[R_M_COL]] if HIST_TYPE: pro_data = calc_pro_data(r, cl) pre_data = calc_pre_data(r, cl, res_data) p_data = PDat.calc_final_p(pro_data, pre_data, p_type) new_row = [int(p_type), r[R_M_COL]] new_row.extend(pro_data) new_row.extend(pre_data) new_row.extend(p_data) new_row.extend([r[R_NAME_1_COL], r[R_NAME_2_COL]]) else: cl_lo = get_cl_data_for_name(r[R_NAME_1_COL], cl) new_row.extend([cl_lo[i] for i in LO_D_RANGE]) cl_vi = get_cl_data_for_name(r[R_NAME_2_COL], cl) new_row.extend([cl_vi[i] for i in VI_D_RANGE]) new_row.extend([r[R_NAME_1_COL], r[R_NAME_2_COL]]) hist.append(new_row) save_data_to_csv(file_name, hist) return hist
def get_data_for_pro(name_col, p_range, cl_data): data_from_name = get_cl_data_for_name(name_col, cl_data) """ print name_col print data_from_name print CL_POS_COL """ pos = int(data_from_name[CL_POS_COL]) data_from_range = [int(data_from_name[i]) for i in p_range] data_for_calc = Pro._calculate_pro_data(data_from_range) return data_for_calc, pos