85 lines
2.2 KiB
Python
85 lines
2.2 KiB
Python
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]
|