From 0d7fe949422c65a1eab6540121131bc44f551ca2 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Sun, 19 Apr 2020 23:49:27 -0500 Subject: [PATCH] Updated the Factor class with a new utility function. Fixed a few small bugs in it as well. --- factors.py | 24 ++++++++++++++++++++++-- main.py | 17 ++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/factors.py b/factors.py index f16a5be..324b483 100644 --- a/factors.py +++ b/factors.py @@ -1,4 +1,4 @@ -class Factor: +class Factor: simple_one = [] simple_two = [] compound_one = [] @@ -13,7 +13,7 @@ class Factor: self.base_list = base_list def calculate_factors(self, factor, include_compound = False, include_complex = False): - clear_factors_lists(self) + self.clear_factors_lists() for item in self.base_list: self.simple_one.append(factor / item) @@ -54,6 +54,26 @@ class Factor: print(self.complex_four) print() + def get_flat_factors_list(self): + flat_list = [] + for i in range(len(self.simple_one)): + flat_list.append(self.simple_one[i]) + flat_list.append(self.simple_two[i]) + + if len(self.compound_one) > 0: + for i in range(len(self.compound_one)): + flat_list.append(self.compound_one[i]) + flat_list.append(self.compound_two[i]) + + if len(self.complex_one) > 0: + for i in range(len(self.complex_one)): + flat_list.append(self.complex_one[i]) + flat_list.append(self.complex_two[i]) + flat_list.append(self.complex_three[i]) + flat_list.append(self.complex_four[i]) + + return flat_list + def clear_factors_lists(self): self.simple_one = [] self.simple_two = [] diff --git a/main.py b/main.py index 4d0c0fb..4074bd7 100755 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import expression import calc_engine import factors import jsonpickle +import itertools base_list = [2, 4, 6, 12] @@ -16,7 +17,6 @@ base_list = [2, 4, 6, 12] with open("expression.json", "r") as f: #j = json.load(f) exp = jsonpickle.decode(f.read()) - print(exp) #results = calc_engine.calculate_results(tokens.copy()) #print(results) @@ -28,9 +28,16 @@ tokens = tokenizer.get_tokens_from_expression_string(exp.expression) for v in exp.variables: factor = factors.Factor(v, base_list) - - calce_answers(factor, exp.variables[v].starting_point, exp.variables[v].type, exp.wrong_response) - + if exp.variables[v].type == "Interest": + factor.calculate_factors(exp.variables[v].starting_point, True, True) + else: + factor.calculate_factors(exp.variables[v].starting_point) + + #for result in calc_answers(f, m): + + calc_answers(factor, exp.variables[v].starting_point, exp.variables[v].type, exp.wrong_response) -#def calc_answers(factor_object, starting_point, variable_type, wrong_response): +def calc_answers(factor_object, starting_point, variable_type, wrong_response): + pass +