def fill_array_with_excel_formulas(ar, equations_dict, pivot_col = 0):    
    pivot_labels = equations_dict.keys()
    var_dict = get_variable_rows_as_dict(ar, pivot_col)    
    for i, j, var_name in yield_cell_coords_for_filling(ar, pivot_labels, pivot_col):
        formula_as_string = equations_dict[var_name]
        time_period = j 
        ar[i, j] = parse_equation_to_xl_formula(formula_as_string, 
                                                var_dict, time_period)
    return ar
Esempio n. 2
0
def get_xl_formula(cell, var_name, equations_list, variables_dict):
    """Returns a valid Excel formula as string, eg '=A2*C3'.   """ 
    # LATER:  - we currently do not check formulas: 
    #            * Only current period vars ьгые иу allowed on left side. Valid: "x(t)= x(t-1)". Not Valid: "x(t+1) = x(t)"
    #            * 0,5 or 0.5
    #            * All required varables must be covered by formulas
    #            * What happens if there is a variable that is created from other variables, but not listed in data or controls?
    #          - cross-dependencies of 'TIME_INDEX_VARIABLES'       
    
    # get formula to work with
    formula_as_string =  build_formula(var_name, equations_list)
    
    # use sympy parser
    # from eqcell_core import parse_equation_to_xl_formula
    # use regex parser
    from formula_parser import parse_equation_to_xl_formula
    
    time_period = cell[1]
    return parse_equation_to_xl_formula(formula_as_string, variables_dict, time_period)