Updated the JSON generator to output JSON that the main program can read.
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
class Expression:
|
class Expression:
|
||||||
expression = ""
|
# This object represents all the needed initial data about an expression that is to be parsed.
|
||||||
|
|
||||||
|
expression = "" # The formula to parse as a string.
|
||||||
# correct_response = 0
|
# correct_response = 0
|
||||||
wrong_response = 0
|
wrong_response = 0 # The incorrect response that was entered by the student.
|
||||||
variables = []
|
variables = [] # A list of Variable.
|
||||||
|
|
||||||
def __init__(self, expression_string, variables, wrong_response):
|
def __init__(self, expression_string, variables, wrong_response):
|
||||||
self.expression = expression_string
|
self.expression = expression_string
|
||||||
@@ -10,16 +12,21 @@ class Expression:
|
|||||||
self.wrong_response = wrong_response
|
self.wrong_response = wrong_response
|
||||||
|
|
||||||
class Variable:
|
class Variable:
|
||||||
|
# This object represents a variable that is found in the formula. It encodes the name, the type of variable
|
||||||
|
# and the starting point from which to look for mutations in the variable's value.
|
||||||
|
|
||||||
name = ""
|
name = ""
|
||||||
type = ""
|
type = ""
|
||||||
starting_point = 0
|
starting_point = 0
|
||||||
ending_point = 0
|
# ending_point = 0
|
||||||
|
|
||||||
VARIABLE_TYPES = {
|
VARIABLE_TYPES = {
|
||||||
"i" : "Interest",
|
"i" : "Interest",
|
||||||
"I" : "Interest",
|
"I" : "Interest",
|
||||||
"n" : "Time",
|
"n" : "Time",
|
||||||
"N" : "Time"
|
"N" : "Time",
|
||||||
|
"k" : "Installment",
|
||||||
|
"K" : "Installment"
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, name, type, starting_point = 0, ending_point = 0):
|
def __init__(self, name, type, starting_point = 0, ending_point = 0):
|
||||||
@@ -30,9 +37,12 @@ class Variable:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_variable_type(variable_name):
|
def get_variable_type(variable_name):
|
||||||
print(variable_name[0])
|
# Utilitie function to get the variable's type from it's name.
|
||||||
if len(variable_name) == 0:
|
# For example, a variable with 'i' in its name is an Interest type.
|
||||||
return "Unknown"
|
# Returns the variable's type as a string or 'Unknown' otherwise.
|
||||||
if not variable_name[0] in Variable.VARIABLE_TYPES:
|
if not variable_name[0] in Variable.VARIABLE_TYPES:
|
||||||
return "Unknown"
|
return "Unknown"
|
||||||
return Variable.VARIABLE_TYPES[variable_name[0]]
|
return Variable.VARIABLE_TYPES[variable_name[0]]
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "Name: %s Type: %s Start: %f" %(self.name, Variable.get_variable_type(self.name), self.starting_point)
|
||||||
|
|||||||
Reference in New Issue
Block a user