Beispiel #1
0
 def __init__(self, session, compu_method: model.CompuMethod):
     conversionType = compu_method.conversionType
     if conversionType == "IDENTICAL":
         self.evaluator = Identical()
     elif conversionType == "FORM":
         pass
     elif conversionType == "LINEAR":
         coeffs = compu_method.coeffs_linear
         if coeffs is None:
             raise exceptions.StructuralError(
                 "'LINEAR' requires a coefficients (COEFFS_LINEAR).")
         self.evaluator = Linear(coeffs)
     elif conversionType == "RAT_FUNC":
         coeffs = compu_method.coeffs
         if coeffs is None:
             raise exceptions.StructuralError(
                 "'RAT_FUNC' requires a coefficients (COEFFS).")
         self.evaluator = RatFunc(coeffs)
     elif conversionType == "TAB_INTP":
         pass
     elif conversionType == "TAB_NOINTP":
         pass
     elif conversionType == "TAB_VERB":
         table_name = compu_method.compu_tab_ref.conversionTable
         table = session.query(model.CompuVtab).filter(
             model.CompuVtab.name == table_name).first()
         if table is None:
             raise exceptions.StructuralError(
                 "'TAB_VERB' requires a conversation table.")
         pairs = [(p.inVal, p.outVal) for p in table.pairs]
         default = table.default_value.display_string if table.default_value else None
         self.evaluator = TabVerb(pairs, default)
     else:
         raise ValueError(
             "Unknown conversation type '{}'.".format(conversionType))
Beispiel #2
0
 def __init__(self, session, compu_method: model.CompuMethod):
     conversionType = compu_method.conversionType
     if conversionType == "IDENTICAL":
         self.evaluator = Identical()
     elif conversionType == "FORM":
         formula = compu_method.formula.f_x
         formula_inv = compu_method.formula.formula_inv.g_x if compu_method.formula.formula_inv else None
         system_constants = []
         constants_text = session.query(model.SystemConstant).all()
         for cons in constants_text:
             name = cons.name
             text = cons.value
             try:
                 value = float(text)
             except ValueError:
                 value = text
             system_constants.append((name, value, ))
         self.evaluator = Formula(formula, formula_inv, system_constants)
     elif conversionType == "LINEAR":
         coeffs = compu_method.coeffs_linear
         if coeffs is None:
             raise exceptions.StructuralError("'LINEAR' requires coefficients (COEFFS_LINEAR).")
         self.evaluator = Linear(coeffs)
     elif conversionType == "RAT_FUNC":
         coeffs = compu_method.coeffs
         if coeffs is None:
             raise exceptions.StructuralError("'RAT_FUNC' requires coefficients (COEFFS).")
         self.evaluator = RatFunc(coeffs)
     elif conversionType in ("TAB_INTP", "TAB_NOINTP"):
         klass = InterpolatedTable if conversionType == "TAB_INTP" else LookupTable
         table_name = compu_method.compu_tab_ref.conversionTable
         table = session.query(model.CompuTab).filter(model.CompuTab.name == table_name).first()
         if table is None:
             raise exceptions.StructuralError("'TAB_INTP' and 'TAB_NOINTP requires a conversation table.")
         pairs = [(p.inVal, p.outVal) for p in table.pairs]
         default_numeric = table.default_value_numeric.display_value if table.default_value_numeric else None
         default = table.default_value.display_string if table.default_value else None
         if default_numeric and default:
             raise exceptions.StructuralError("Cannot use both DEFAULT_VALUE and DEFAULT_VALUE_NUMERIC.")
         default = default_numeric if not default_numeric is None else default
         self.evaluator = klass(pairs, default)
     elif conversionType == "TAB_VERB":
         table_name = compu_method.compu_tab_ref.conversionTable
         table = session.query(model.CompuVtab).filter(model.CompuVtab.name == table_name).first()
         if table is None:
             table = session.query(model.CompuVtabRange).filter(model.CompuVtabRange.name == table_name).first()
             if table is None:
                 raise exceptions.StructuralError("'TAB_VERB' requires a conversation table.")
             triples = [(p.inValMin, p.inValMax, p.outVal) for p in table.triples]
             default = table.default_value.display_string if table.default_value else None
             # TODO: datatype !?
             self.evaluator = LookupTableWithRanges(triples, default)
         else:
             pairs = [(p.inVal, p.outVal) for p in table.pairs]
             default = table.default_value.display_string if table.default_value else None
             self.evaluator = LookupTable(pairs, default)
     else:
         raise ValueError("Unknown conversation type '{}'.".format(conversionType))
Beispiel #3
0
 def __init__(self, session, compu_method: model.CompuMethod):
     conversionType = compu_method.conversionType
     if conversionType == "IDENTICAL":
         self.evaluator = Identical()
     elif conversionType == "FORM":
         formula = compu_method.formula["formula"]
         formula_inv = compu_method.formula["formula_inv"]
         system_constants = []
         constants_text = session.query(model.SystemConstant).all()
         for cons in constants_text:
             name = cons.name
             text = cons.value
             try:
                 value = float(text)
             except ValueError:
                 value = text
             system_constants.append((
                 name,
                 value,
             ))
         self.evaluator = Formula(formula, formula_inv, system_constants)
     elif conversionType == "LINEAR":
         coeffs = compu_method.coeffs_linear
         if coeffs is None:
             raise exceptions.StructuralError(
                 "'LINEAR' requires coefficients (COEFFS_LINEAR).")
         self.evaluator = Linear(coeffs)
     elif conversionType == "RAT_FUNC":
         coeffs = compu_method.coeffs
         if coeffs is None:
             raise exceptions.StructuralError(
                 "'RAT_FUNC' requires coefficients (COEFFS).")
         self.evaluator = RatFunc(coeffs)
     elif conversionType in ("TAB_INTP", "TAB_NOINTP"):
         klass = InterpolatedTable if compu_method.tab[
             "interpolation"] else LookupTable
         pairs = zip(compu_method.tab["in_values"],
                     compu_method.tab["out_values"])
         default = compu_method.tab["default_value"]
         self.evaluator = klass(pairs, default)
     elif conversionType == "TAB_VERB":
         default = compu_method.tab_verb["default_value"]
         if compu_method.tab_verb["ranges"]:
             triples = zip(compu_method.tab_verb["lower_values"],
                           compu_method.tab_verb["upper_values"],
                           compu_method.tab_verb["text_values"])
             self.evaluator = LookupTableWithRanges(triples, default)
         else:
             pairs = zip(compu_method.tab_verb["in_values"],
                         compu_method.tab_verb["text_values"])
             self.evaluator = LookupTable(pairs, default)
     else:
         raise ValueError(
             "Unknown conversation type '{}'.".format(conversionType))