Esempio n. 1
0
    def _generate(self, force_calc):

        pro_file_name = PRO_FILE_NAME_PREFIX + self._index + INPUT_FILE_NAME_EXT

        if not force_calc:
            self._pro = read_input_file(pro_file_name)

        if not len(self._pro):

            for k in self._k:

                if k[TYPE_COL] == TYPE_1_COL:
                    cl_data = self._b1
                else:
                    cl_data = self._a2

                calc_lo_data, lo_pos = Pro.get_data_for_pro(
                    k[NAME_LO_COL], LO_P_RANGE, cl_data)

                calc_vi_data, vi_pos = Pro.get_data_for_pro(
                    k[NAME_VI_COL], VI_P_RANGE, cl_data)

                self._pro.append(combine_lo_vi(calc_lo_data, calc_vi_data))

            if self.generated:
                save_data_to_csv(pro_file_name, self._pro)
Esempio n. 2
0
File: pro.py Progetto: felgari/kuicl
 def _generate(self, force_calc):
     
     pro_file_name = PRO_FILE_NAME_PREFIX + self._index + INPUT_FILE_NAME_EXT
 
     if not force_calc:
         self._pro = read_input_file(pro_file_name)
     
     if not len(self._pro):
     
         for k in self._k:             
                    
             if k[TYPE_COL] == TYPE_1_COL:  
                 cl_data = self._b1
             else:
                 cl_data = self._a2
                 
             calc_lo_data, lo_pos = Pro.get_data_for_pro(k[NAME_LO_COL],
                                                         LO_P_RANGE,
                                                         cl_data)         
             
             calc_vi_data, vi_pos = Pro.get_data_for_pro(k[NAME_VI_COL],
                                                         VI_P_RANGE, 
                                                         cl_data) 
             
             self._pro.append(combine_lo_vi(calc_lo_data, calc_vi_data))
             
         if self.generated:
             save_data_to_csv(pro_file_name, self._pro)
Esempio n. 3
0
    def calculate(self):

        avpos = []

        # Compile files with cl.
        self._compile_cl()

        # Process the files sorted by name.
        files_sorted = sorted(self._cl_files_order)

        for fs in files_sorted:
            idx = self._cl_files_order.index(fs)

            clda = ClDat(NO_READ_INDEX)

            full_file_name = os.path.join(self._dir, self._cl_files[idx])

            clda.read_cldata(full_file_name)

            avpos = self._add_cl(avpos, clda.b1)
            avpos = self._add_cl(avpos, clda.a2)

        save_data_to_csv(AVPOS_FILE, avpos)

        for a in avpos:
            self._avpos.update({a[0]: a[1:]})
Esempio n. 4
0
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)
Esempio n. 5
0
def main():
    
    clda = ClDat()
    
    if clda.loaded:
    
        b1_res = read_res_file(B1_RES_FILE)
        a2_res = read_res_file(A2_RES_FILE)
        
        if len(b1_res) and len(a2_res):
            mdls_b1 = evaluate_all_models(clda.b1, b1_res)
            mdls_a2 = evaluate_all_models(clda.a2, a2_res)
            
            save_data_to_csv(MODELS_FILENAME, mdls_b1 + mdls_a2)
        else:
            print "Res data couldn't be read."
    else:
        print "Cl data couldn't be loaded."
Esempio n. 6
0
    def _calculate(self, force_calc):

        p_file_name = P_FILE_NAME_PREFIX + self._index + INPUT_FILE_NAME_EXT

        if not force_calc:
            self._p = read_input_file(p_file_name)

        if not len(self._p) or force_calc:

            for i in range(NUM_ROWS):

                p_value = PDat.calc_final_p(self._pro[i], self._pre[i],
                                            self._k[i][TYPE_COL])

                self._p.append(p_value)

            if self.generated:
                save_data_to_csv(p_file_name, self._p)
Esempio n. 7
0
File: pre.py Progetto: felgari/kuicl
 def _generate(self, force_calc):  
     
     pre_file_name = PRE_FILE_NAME_PREFIX + self._index + INPUT_FILE_NAME_EXT
     
     if not force_calc:
         self._pre = read_input_file(pre_file_name)
     
     if not len(self._pre):
     
         b1_res = read_res_file(B1_RES_FILE)
         a2_res = read_res_file(A2_RES_FILE)
         
         for k in self._k:
             if k[TYPE_COL] == TYPE_1_COL:  
                 cl_data = self._b1
                 res_data = b1_res
             else:
                 cl_data = self._a2
                 res_data = a2_res
                 
             lo_data, lo_target_data = Pre.get_data_for_pre(k[NAME_LO_COL], 
                                                            cl_data,
                                                            res_data, True) 
                 
             lo_mdl = Pre.get_mdl(k[NAME_LO_COL]) 
             
             vi_data, vi_target_data = Pre.get_data_for_pre(k[NAME_VI_COL], 
                                                            cl_data,
                                                            res_data, False)
                 
             vi_mdl = Pre.get_mdl(k[NAME_VI_COL]) 
                 
             print "Predicting: %s - %s" % (k[NAME_LO_COL], k[NAME_VI_COL])
             
             lo_pre = self.get_pre_values(lo_data, lo_target_data, 
                                          lo_mdl.lo_mdls)             
 
             vi_pre = self.get_pre_values(vi_data, vi_target_data, 
                                          vi_mdl.vi_mdls)
             
             self._pre.append(combine_lo_vi(lo_pre, vi_pre))
             
         if self.generated:
             save_data_to_csv(pre_file_name, self._pre)
Esempio n. 8
0
 def _calculate(self, force_calc):
     
     p_file_name = P_FILE_NAME_PREFIX + self._index + INPUT_FILE_NAME_EXT
     
     if not force_calc:
         self._p = read_input_file(p_file_name)
     
     if not len(self._p) or force_calc:
     
         for i in range(NUM_ROWS):  
             
             p_value = PDat.calc_final_p(self._pro[i],
                                         self._pre[i],
                                         self._k[i][TYPE_COL])
             
             self._p.append(p_value)
         
         if self.generated:
             save_data_to_csv(p_file_name, self._p)
Esempio n. 9
0
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
Esempio n. 10
0
File: pre.py Progetto: felgari/kuicl
    def _generate(self, force_calc):

        pre_file_name = PRE_FILE_NAME_PREFIX + self._index + INPUT_FILE_NAME_EXT

        if not force_calc:
            self._pre = read_input_file(pre_file_name)

        if not len(self._pre):

            b1_res = read_res_file(B1_RES_FILE)
            a2_res = read_res_file(A2_RES_FILE)

            for k in self._k:
                if k[TYPE_COL] == TYPE_1_COL:
                    cl_data = self._b1
                    res_data = b1_res
                else:
                    cl_data = self._a2
                    res_data = a2_res

                lo_data, lo_target_data = Pre.get_data_for_pre(
                    k[NAME_LO_COL], cl_data, res_data, True)

                lo_mdl = Pre.get_mdl(k[NAME_LO_COL])

                vi_data, vi_target_data = Pre.get_data_for_pre(
                    k[NAME_VI_COL], cl_data, res_data, False)

                vi_mdl = Pre.get_mdl(k[NAME_VI_COL])

                print "Predicting: %s - %s" % (k[NAME_LO_COL], k[NAME_VI_COL])

                lo_pre = self.get_pre_values(lo_data, lo_target_data,
                                             lo_mdl.lo_mdls)

                vi_pre = self.get_pre_values(vi_data, vi_target_data,
                                             vi_mdl.vi_mdls)

                self._pre.append(combine_lo_vi(lo_pre, vi_pre))

            if self.generated:
                save_data_to_csv(pre_file_name, self._pre)
Esempio n. 11
0
 def _save_mean(self):
     
     output_file = MEAN_FILE_NAME_PREFIX + self._index + OUTPUT_FILE_NAME_EXT
     
     save_data_to_csv(output_file, self._mean)
Esempio n. 12
0
    def _save_mean(self):

        output_file = MEAN_FILE_NAME_PREFIX + self._index + OUTPUT_FILE_NAME_EXT

        save_data_to_csv(output_file, self._mean)