starting rendering, adding web sockets
This commit is contained in:
24
main.py
24
main.py
@@ -4,22 +4,23 @@
|
||||
from problem_generator import generate_problem
|
||||
from steps_generator import generate_steps
|
||||
from sympy import init_printing, sympify
|
||||
import time
|
||||
import json
|
||||
|
||||
#define the entry point to the programs
|
||||
def main():
|
||||
init_printing(order='lex')
|
||||
count = -1
|
||||
no_problem = True
|
||||
test=sympify('-2')
|
||||
while(no_problem):
|
||||
problem = generate_problem()
|
||||
steps = generate_steps(problem);
|
||||
|
||||
problem = generate_problem()
|
||||
problem["steps"] = generate_steps(problem);
|
||||
|
||||
print("Generated Problem:")
|
||||
print(problem)
|
||||
|
||||
print("Steps:")
|
||||
pretty_print_steps(steps)
|
||||
no_problem = check_solution(steps[-1]["after"], problem["solution"])
|
||||
|
||||
no_problem = check_solution(problem["steps"][-1]["after"], problem["solution"])
|
||||
if no_problem:
|
||||
with open("www/data/data.json", "w") as f:
|
||||
json.dump(problem, f)
|
||||
|
||||
def check_solution(got, solution):
|
||||
values = set([sympify(r.split("=")[1].strip()) for r in got.split(",")])
|
||||
@@ -29,7 +30,6 @@ def check_solution(got, solution):
|
||||
solutions_list = []
|
||||
solutions_list.append(sympify(solution))
|
||||
solutions = set(solutions_list)
|
||||
print(f"values:{values}, solutions:{solutions}")
|
||||
return solutions == values
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ def pretty_print_steps(steps):
|
||||
for key in step:
|
||||
if key not in ("before", "after"):
|
||||
print(f"{key.capitalize()}: {step[key]}")
|
||||
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
|
||||
def is_iterable(obj):
|
||||
|
||||
Reference in New Issue
Block a user