Exemplo n.º 1
0
def build_formula(var_name, equations_list):
    """Returns a string like 'x(t-1) + 1' as a formula.""" 
    # DONE:          I consider splitting 'equations_list' into 'formulas_dict' a common task 
    #                for both parsers, but in concept this does not really belong to 'xl_fill.py'
    #                
    #                May later move strip_timeindex(str_), test_parse_to_formula_dict() and 
    #                parse_to_formula_dict(equations) to a separate module, callable either by two parsers OR
    #                at stage where we evaluate user-defined input. 
    import equations_preparser as eq_pp
    formulas_dict     = eq_pp.parse_to_formula_dict(equations_list)
    return eq_pp.get_formula(var_name, formulas_dict)
Exemplo n.º 2
0
 target_ar = get_target_ar()
 
 print(target_ar) 
 # end task formulation   
 
 # Solution:
 print("\n******* Solution flow:")    
 print("*** Array before equations:")
 df = get_dataframe_before_equations(data_df, controls_df, var_label_list)
 ar = get_array_before_equations(df)
 print(ar)
 
 print("\n***  Split formulas:")
 
 import equations_preparser as eq_pp
 formulas_dict = eq_pp.parse_to_formula_dict(equations_list)
 pprint(formulas_dict)
 
 print("\n***  Assign variables to array rows:")
 variable_to_row_dict = get_variable_rows_as_dict(ar)
 pprint(variable_to_row_dict)
 
 print("\n***  Iterate over NaN in data area + fill with formulas:")    
 ar = fill_array_with_excel_formulas(ar, equations_list)    
 print("\n Resulting array:")
 print(ar)
      
 print("\n*** Must be like:")    
 print(target_ar)    
 is_equal = np.array_equal(ar, target_ar)