mathjson-solver 1.9.0__tar.gz → 1.10.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.9.0/src/mathjson_solver.egg-info → mathjson_solver-1.10.0}/PKG-INFO +11 -2
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/setup.cfg +1 -1
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/setup.py +1 -1
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/src/mathjson_solver/__main__.py +68 -1
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0/src/mathjson_solver.egg-info}/PKG-INFO +11 -2
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/tests/test_with_pytest.py +22 -0
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/LICENSE +0 -0
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/README.md +0 -0
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/pyproject.toml +0 -0
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/src/mathjson_solver/__init__.py +0 -0
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/src/mathjson_solver.egg-info/SOURCES.txt +0 -0
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/src/mathjson_solver.egg-info/dependency_links.txt +0 -0
- {mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/src/mathjson_solver.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: mathjson-solver
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.10.0
|
|
4
4
|
Summary: Utilities for MathJSON evaluation
|
|
5
5
|
Home-page: https://github.com/LongenesisLtd/mathjson-solver
|
|
6
6
|
Author: Martins Mednis
|
|
@@ -12,6 +12,15 @@ Classifier: Operating System :: OS Independent
|
|
|
12
12
|
Requires-Python: >=3.6
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: author-email
|
|
17
|
+
Dynamic: classifier
|
|
18
|
+
Dynamic: description
|
|
19
|
+
Dynamic: description-content-type
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: project-url
|
|
22
|
+
Dynamic: requires-python
|
|
23
|
+
Dynamic: summary
|
|
15
24
|
|
|
16
25
|
# MathJSON Solver
|
|
17
26
|
|
|
@@ -6,6 +6,7 @@ from copy import deepcopy
|
|
|
6
6
|
from statistics import median
|
|
7
7
|
import logging
|
|
8
8
|
import traceback
|
|
9
|
+
import datetime
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class MathJSONException(Exception):
|
|
@@ -141,6 +142,31 @@ def create_mathjson_solver(solver_parameters):
|
|
|
141
142
|
def Arr(s):
|
|
142
143
|
return s
|
|
143
144
|
|
|
145
|
+
def Add(s):
|
|
146
|
+
l_res = []
|
|
147
|
+
tmp = 0
|
|
148
|
+
for i, x in enumerate(s[1:]):
|
|
149
|
+
res = f(x, c)
|
|
150
|
+
if i ==0:
|
|
151
|
+
tmp = res
|
|
152
|
+
else:
|
|
153
|
+
tmp = tmp + res
|
|
154
|
+
|
|
155
|
+
# if isinstance(res, list):
|
|
156
|
+
# l_res.append(sum([xx for xx in res[1:]]))
|
|
157
|
+
# else:
|
|
158
|
+
# l_res.append(res)
|
|
159
|
+
|
|
160
|
+
return tmp
|
|
161
|
+
|
|
162
|
+
# tmp = 0
|
|
163
|
+
# for i, x in enumerate(l):
|
|
164
|
+
# if i == 0:
|
|
165
|
+
# tmp = x
|
|
166
|
+
# else:
|
|
167
|
+
# tmp = tmp + x
|
|
168
|
+
# return tmp
|
|
169
|
+
|
|
144
170
|
def Sum(s):
|
|
145
171
|
l_res = []
|
|
146
172
|
for x in s[1:]:
|
|
@@ -343,9 +369,37 @@ def create_mathjson_solver(solver_parameters):
|
|
|
343
369
|
conditions=conditions,
|
|
344
370
|
)
|
|
345
371
|
|
|
372
|
+
def Strptime(s):
|
|
373
|
+
datetime_str = f(s[1], c)
|
|
374
|
+
parameters = f(s[2], c)
|
|
375
|
+
return datetime.datetime.strptime(datetime_str, parameters)
|
|
376
|
+
|
|
377
|
+
def Strftime(s):
|
|
378
|
+
dt = f(s[1], c)
|
|
379
|
+
parameters = f(s[2], c)
|
|
380
|
+
return dt.strftime(parameters)
|
|
381
|
+
|
|
382
|
+
def Now(s):
|
|
383
|
+
return datetime.datetime.now()
|
|
384
|
+
|
|
385
|
+
def Today(s):
|
|
386
|
+
return datetime.date.today()
|
|
387
|
+
|
|
388
|
+
def TimeDeltaDays(s):
|
|
389
|
+
return datetime.timedelta(days=f(s[1], c))
|
|
390
|
+
|
|
391
|
+
def TimeDeltaMinutes(s):
|
|
392
|
+
return datetime.timedelta(minutes=f(s[1], c))
|
|
393
|
+
|
|
394
|
+
def TimeDeltaHours(s):
|
|
395
|
+
return datetime.timedelta(hours=f(s[1], c))
|
|
396
|
+
|
|
397
|
+
def TimeDeltaWeeks(s):
|
|
398
|
+
return datetime.timedelta(weeks=f(s[1], c))
|
|
399
|
+
|
|
346
400
|
constructs = {
|
|
347
401
|
"Sum": Sum,
|
|
348
|
-
"Add":
|
|
402
|
+
"Add": Add,
|
|
349
403
|
"Subtract": lambda s: reduce(
|
|
350
404
|
lambda a, b: a - b, [f(x, c) for x in s[1:]]
|
|
351
405
|
),
|
|
@@ -401,6 +455,14 @@ def create_mathjson_solver(solver_parameters):
|
|
|
401
455
|
"IsDefined": lambda s: s[1] in c,
|
|
402
456
|
"Map": Map,
|
|
403
457
|
"HasMatchingSublist": HasMatchingSublist,
|
|
458
|
+
"Strptime": Strptime,
|
|
459
|
+
"Strftime": Strftime,
|
|
460
|
+
"Today": Today,
|
|
461
|
+
"Now": Now,
|
|
462
|
+
"TimeDeltaWeeks": TimeDeltaWeeks,
|
|
463
|
+
"TimeDeltaHours": TimeDeltaHours,
|
|
464
|
+
"TimeDeltaMinutes": TimeDeltaMinutes,
|
|
465
|
+
"TimeDeltaDays": TimeDeltaDays,
|
|
404
466
|
}
|
|
405
467
|
if s[0] in constructs:
|
|
406
468
|
try:
|
|
@@ -487,6 +549,11 @@ def extract_variables(s: Union[list, int, float, str], li: set, ignore_list: set
|
|
|
487
549
|
ignore_list.add(x[0])
|
|
488
550
|
li.update(extract_variables(x[1], li, ignore_list))
|
|
489
551
|
li.update(extract_variables(x[-1], li, ignore_list))
|
|
552
|
+
elif s[0] == "If":
|
|
553
|
+
for elif_block in s[1:-1]: # s[1] is list
|
|
554
|
+
for x in elif_block:
|
|
555
|
+
li.update(extract_variables(x, li, ignore_list))
|
|
556
|
+
li.update(extract_variables(s[-1], li, ignore_list))
|
|
490
557
|
else:
|
|
491
558
|
for x in s[1:]:
|
|
492
559
|
li.update(extract_variables(x, li, ignore_list))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: mathjson-solver
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.10.0
|
|
4
4
|
Summary: Utilities for MathJSON evaluation
|
|
5
5
|
Home-page: https://github.com/LongenesisLtd/mathjson-solver
|
|
6
6
|
Author: Martins Mednis
|
|
@@ -12,6 +12,15 @@ Classifier: Operating System :: OS Independent
|
|
|
12
12
|
Requires-Python: >=3.6
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: author-email
|
|
17
|
+
Dynamic: classifier
|
|
18
|
+
Dynamic: description
|
|
19
|
+
Dynamic: description-content-type
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: project-url
|
|
22
|
+
Dynamic: requires-python
|
|
23
|
+
Dynamic: summary
|
|
15
24
|
|
|
16
25
|
# MathJSON Solver
|
|
17
26
|
|
|
@@ -259,6 +259,13 @@ from mathjson_solver import create_solver, MathJSONException, extract_variables
|
|
|
259
259
|
],
|
|
260
260
|
False,
|
|
261
261
|
),
|
|
262
|
+
({}, ["Strftime", ["Strptime", "2025-01-10T10:05", "%Y-%m-%dT%H:%M"], "%Y"], "2025"),
|
|
263
|
+
({}, ["Strftime", ["Today"], "%Y"], "2025"),
|
|
264
|
+
({}, ["Strftime", ["Now"], "%Y"], "2025"),
|
|
265
|
+
({}, ["Strftime", ["Add", ["Strptime", "2025-01-10T10:05", "%Y-%m-%dT%H:%M"], ["TimeDeltaDays", 3]], "%d"], "13"),
|
|
266
|
+
({}, ["Strftime", ["Add", ["Strptime", "2025-01-10T10:05", "%Y-%m-%dT%H:%M"], ["TimeDeltaMinutes", 5]], "%M"], "10"),
|
|
267
|
+
({}, ["Strftime", ["Add", ["Strptime", "2025-01-10T10:05", "%Y-%m-%dT%H:%M"], ["TimeDeltaHours", 2]], "%H"], "12"),
|
|
268
|
+
({}, ["Strftime", ["Add", ["Strptime", "2025-01-10T10:05", "%Y-%m-%dT%H:%M"], ["TimeDeltaWeeks", 1]], "%d"], "17"),
|
|
262
269
|
],
|
|
263
270
|
)
|
|
264
271
|
def test_solver_simple(parameters, expression, expected_result):
|
|
@@ -319,6 +326,21 @@ def test_handle_exception():
|
|
|
319
326
|
["Add", "[slug1][0][question1]", "y", 4, "[slug1][-3:-1][question1]"],
|
|
320
327
|
set(["[slug1][0][question1]", "y", "[slug1][-3:-1][question1]"]),
|
|
321
328
|
),
|
|
329
|
+
(
|
|
330
|
+
{},
|
|
331
|
+
["If", [["Equal", "[uzwuoy][-1][question1]", 200], 200], 1],
|
|
332
|
+
set(["[uzwuoy][-1][question1]"]),
|
|
333
|
+
),
|
|
334
|
+
(
|
|
335
|
+
{},
|
|
336
|
+
[
|
|
337
|
+
"If",
|
|
338
|
+
[["Equal", "[uzwuoy][-1][question1]", 200], 201],
|
|
339
|
+
[["Equal", "[uzwuoy][-2][question1]", 100], 101],
|
|
340
|
+
1,
|
|
341
|
+
],
|
|
342
|
+
set(["[uzwuoy][-1][question1]", "[uzwuoy][-2][question1]"]),
|
|
343
|
+
),
|
|
322
344
|
],
|
|
323
345
|
)
|
|
324
346
|
def test_extract_variables(parameters, expression, expected_result):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mathjson_solver-1.9.0 → mathjson_solver-1.10.0}/src/mathjson_solver.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|