Updated the Factor class with a new utility function. Fixed a few small bugs in it as well.

This commit is contained in:
2020-04-19 23:49:27 -05:00
parent ca47912d05
commit 0d7fe94942
2 changed files with 34 additions and 7 deletions
+22 -2
View File
@@ -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 = []
+12 -5
View File
@@ -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