Merged the factoring engine into the project. Un-sure if this object approach will work however. Most likely will need to be redesigned in the future.
This commit is contained in:
+84
@@ -0,0 +1,84 @@
|
|||||||
|
class Factor:
|
||||||
|
simple_one = []
|
||||||
|
simple_two = []
|
||||||
|
compound_one = []
|
||||||
|
compound_two = []
|
||||||
|
complex_one = []
|
||||||
|
complex_two = []
|
||||||
|
complex_three = []
|
||||||
|
complex_four = []
|
||||||
|
|
||||||
|
def __init__(self, variable_name, factors, factor_type):
|
||||||
|
self.variable_name = varianle_name
|
||||||
|
self.factors = factors
|
||||||
|
self.factor_type = factor_type
|
||||||
|
|
||||||
|
def calculate_factors(self, factor, base_list, include_compound = False, include_complex = False):
|
||||||
|
clear_factors_lists(self)
|
||||||
|
|
||||||
|
for item in base_list:
|
||||||
|
simple_one.append(factor / item)
|
||||||
|
simple_two.append(factor * item)
|
||||||
|
|
||||||
|
if include_compound:
|
||||||
|
for item in base_list:
|
||||||
|
compound_one.append(((1 + factor) ** (1 / item)) - 1)
|
||||||
|
compound_two.append(((1 + factor) ** item) - 1)
|
||||||
|
|
||||||
|
if include_complex:
|
||||||
|
for item in base_list:
|
||||||
|
complex_one.append(item * (((1 + factor) ** (1 / item)) - 1))
|
||||||
|
complex_two.append(1 / item * (((1 + factor) ** (1 / item)) - 1))
|
||||||
|
complex_three.append(item * (((1 + factor) ** item) - 1 ))
|
||||||
|
complex_four.append(1 / item * (((1 + factor) ** item) - 1))
|
||||||
|
|
||||||
|
def print_factors(self, include_simple = True, include_compound = True, include_complex = True):
|
||||||
|
print("Factors for %s." %(self.variable_name))
|
||||||
|
|
||||||
|
if include_simple and self.simple_one:
|
||||||
|
print("Simple Factors:")
|
||||||
|
print(self.simple_one)
|
||||||
|
print(self.simple_two)
|
||||||
|
print()
|
||||||
|
|
||||||
|
if include_compound and self.compound_one:
|
||||||
|
print("Compound Factors:")
|
||||||
|
print(self.compound_one)
|
||||||
|
print(self.compound_two)
|
||||||
|
print()
|
||||||
|
|
||||||
|
if include_complex and self.complex_one:
|
||||||
|
print("Complex Factors:")
|
||||||
|
print(self.complex_one)
|
||||||
|
print(self.complex_two)
|
||||||
|
print(self.complex_three)
|
||||||
|
print(self.complex_four)
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
def clear_factors_lists(self):
|
||||||
|
self.simple_one = []
|
||||||
|
self.simple_two = []
|
||||||
|
self.compound_one = []
|
||||||
|
self.compound_two = []
|
||||||
|
self.complex_one = []
|
||||||
|
self.complex_two = []
|
||||||
|
self.complex_three = []
|
||||||
|
self.complex_four = []
|
||||||
|
|
||||||
|
class FactorTypes:
|
||||||
|
simple = 0
|
||||||
|
compound = 1
|
||||||
|
complex = 2
|
||||||
|
|
||||||
|
FACTOR_TYPES = {
|
||||||
|
0 : "Simple",
|
||||||
|
1 : "Compound",
|
||||||
|
2 : "Complex"
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_factor_type_name(factor_type):
|
||||||
|
if not factor_type in FACTOR_TYPES:
|
||||||
|
raise ValueError("The factor types is invalid.", "factor_type")
|
||||||
|
return FACTOR_TYPES[factor_type]
|
||||||
@@ -8,5 +8,5 @@ results = calc_engine.calculate_results(tokens)
|
|||||||
print(results)
|
print(results)
|
||||||
|
|
||||||
#for t in tokens:
|
#for t in tokens:
|
||||||
# print("%s (%s) " %(t.value, token.TokenType.get_operator_name(t.type)), end = "")
|
# print("%s (%s) " %(t.value, token.TokenType.get_token_type_name(t.type)), end = "")
|
||||||
#print()
|
#print()
|
||||||
|
|||||||
Reference in New Issue
Block a user