mathjson-solver 1.6.1__tar.gz → 1.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mathjson-solver-1.6.1/src/mathjson_solver.egg-info → mathjson_solver-1.7.0}/PKG-INFO +1 -1
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/setup.cfg +1 -1
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/setup.py +1 -1
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/src/mathjson_solver/__main__.py +17 -2
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0/src/mathjson_solver.egg-info}/PKG-INFO +1 -1
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/tests/test_with_pytest.py +4 -0
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/LICENSE +0 -0
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/README.md +0 -0
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/pyproject.toml +0 -0
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/src/mathjson_solver/__init__.py +0 -0
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/src/mathjson_solver.egg-info/SOURCES.txt +0 -0
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/src/mathjson_solver.egg-info/dependency_links.txt +0 -0
- {mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/src/mathjson_solver.egg-info/top_level.txt +0 -0
|
@@ -3,6 +3,8 @@ from functools import reduce
|
|
|
3
3
|
import math
|
|
4
4
|
from copy import deepcopy
|
|
5
5
|
from statistics import median
|
|
6
|
+
import logging
|
|
7
|
+
import traceback
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
class MathJSONException(Exception):
|
|
@@ -123,8 +125,19 @@ def create_mathjson_solver(solver_parameters):
|
|
|
123
125
|
for x in s[1:-1]:
|
|
124
126
|
if len(x) != 2:
|
|
125
127
|
raise ValueError(f"Wrong if or elif in 'If'")
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
try:
|
|
129
|
+
if f(x[0], c):
|
|
130
|
+
try:
|
|
131
|
+
return f(x[1], c)
|
|
132
|
+
except MathJSONException as e:
|
|
133
|
+
logging.error(
|
|
134
|
+
"MathJSONException: %s", traceback.format_exc()
|
|
135
|
+
)
|
|
136
|
+
continue
|
|
137
|
+
except MathJSONException as e:
|
|
138
|
+
logging.error("MathJSONException: %s", traceback.format_exc())
|
|
139
|
+
return f(s[-1], c) # return default value (else)
|
|
140
|
+
|
|
128
141
|
return f(s[-1], c)
|
|
129
142
|
|
|
130
143
|
def In(s):
|
|
@@ -237,6 +250,7 @@ def create_mathjson_solver(solver_parameters):
|
|
|
237
250
|
"Float": Float,
|
|
238
251
|
"Str": Str,
|
|
239
252
|
"Not": Not,
|
|
253
|
+
"IsDefined": lambda s: s[1] in c,
|
|
240
254
|
}
|
|
241
255
|
if s[0] in constructs:
|
|
242
256
|
try:
|
|
@@ -253,6 +267,7 @@ def create_mathjson_solver(solver_parameters):
|
|
|
253
267
|
elif s in c:
|
|
254
268
|
return f(c[s], c)
|
|
255
269
|
else:
|
|
270
|
+
# raise KeyError(f"Parameter '{s}' is not defined")
|
|
256
271
|
return s
|
|
257
272
|
|
|
258
273
|
return f
|
|
@@ -45,6 +45,10 @@ from mathjson_solver import create_solver, MathJSONException
|
|
|
45
45
|
({"color": "green"}, ["Switch", "color", 0, ["blue", 10], ["red", 30]], 0),
|
|
46
46
|
({"color": "green"}, ["Switch", "undefined", 0, ["blue", 10], ["red", 30]], 0),
|
|
47
47
|
({}, ["If", [["Equal", 1, 0], 10], [["Equal", 2, 2], 20], 9000], 20),
|
|
48
|
+
({"a": 10, "b": 10}, ["If", [["Equal", "a", "b"], 10], 9000], 10),
|
|
49
|
+
({"a": 10, "b": 20}, ["If", [["Equal", "a", "b"], 10], 9000], 9000),
|
|
50
|
+
({"a": 10}, ["If", [["Equal", "a", "b"], 10], 9000], 9000),
|
|
51
|
+
({"a": 10}, ["If", [["Equal", "a", ["Sum", 1, "b"]], 10], 9000], 9000),
|
|
48
52
|
({}, ["Array", 1, 2, 3, 5, 2], ["Array", 1, 2, 3, 5, 2]),
|
|
49
53
|
({}, ["Max", ["Array", 1, 2, 3, 5, 2]], 5),
|
|
50
54
|
({}, ["Max", ["Array", 1, 2, ["Sum", 2, 4, 3], 5, 2]], 9),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mathjson-solver-1.6.1 → mathjson_solver-1.7.0}/src/mathjson_solver.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|