mathjson-solver 2.3.0__py3-none-any.whl → 2.4.0__py3-none-any.whl
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/__main__.py +15 -0
- mathjson_solver/_datetime_constructs.py +62 -0
- {mathjson_solver-2.3.0.dist-info → mathjson_solver-2.4.0.dist-info}/METADATA +1 -3
- {mathjson_solver-2.3.0.dist-info → mathjson_solver-2.4.0.dist-info}/RECORD +6 -6
- {mathjson_solver-2.3.0.dist-info → mathjson_solver-2.4.0.dist-info}/WHEEL +1 -1
- {mathjson_solver-2.3.0.dist-info → mathjson_solver-2.4.0.dist-info}/licenses/LICENSE +0 -0
mathjson_solver/__main__.py
CHANGED
|
@@ -192,6 +192,11 @@ from ._datetime_constructs import (
|
|
|
192
192
|
TimeDeltaMinutes,
|
|
193
193
|
TimeDeltaHours,
|
|
194
194
|
TimeDeltaWeeks,
|
|
195
|
+
DateDiffSeconds,
|
|
196
|
+
DateDiffMinutes,
|
|
197
|
+
DateDiffHours,
|
|
198
|
+
DateDiffDays,
|
|
199
|
+
DateDiffYears,
|
|
195
200
|
)
|
|
196
201
|
from ._functional_constructs import (
|
|
197
202
|
Fold,
|
|
@@ -496,6 +501,11 @@ constructs = {
|
|
|
496
501
|
"TimeDeltaHours": TimeDeltaHours,
|
|
497
502
|
"TimeDeltaMinutes": TimeDeltaMinutes,
|
|
498
503
|
"TimeDeltaDays": TimeDeltaDays,
|
|
504
|
+
"DateDiffSeconds": DateDiffSeconds,
|
|
505
|
+
"DateDiffMinutes": DateDiffMinutes,
|
|
506
|
+
"DateDiffHours": DateDiffHours,
|
|
507
|
+
"DateDiffDays": DateDiffDays,
|
|
508
|
+
"DateDiffYears": DateDiffYears,
|
|
499
509
|
"Function": Function,
|
|
500
510
|
"Variable": Variable,
|
|
501
511
|
"MultiplyByScalar": MultiplyByScalar,
|
|
@@ -974,6 +984,11 @@ def extract_variables(
|
|
|
974
984
|
"TimeDeltaHours",
|
|
975
985
|
"TimeDeltaMinutes",
|
|
976
986
|
"TimeDeltaDays",
|
|
987
|
+
"DateDiffSeconds",
|
|
988
|
+
"DateDiffMinutes",
|
|
989
|
+
"DateDiffHours",
|
|
990
|
+
"DateDiffDays",
|
|
991
|
+
"DateDiffYears",
|
|
977
992
|
"Function",
|
|
978
993
|
"Variable",
|
|
979
994
|
"MultiplyByScalar",
|
|
@@ -44,3 +44,65 @@ def TimeDeltaHours(f, c, solver_parameters, s):
|
|
|
44
44
|
|
|
45
45
|
def TimeDeltaWeeks(f, c, solver_parameters, s):
|
|
46
46
|
return datetime.timedelta(weeks=f(s[1], c))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _to_datetime(value, name):
|
|
50
|
+
dt = _try_parse_datetime(value)
|
|
51
|
+
if isinstance(dt, datetime.datetime):
|
|
52
|
+
return dt
|
|
53
|
+
if isinstance(dt, datetime.date):
|
|
54
|
+
return datetime.datetime(dt.year, dt.month, dt.day)
|
|
55
|
+
raise ValueError(f"{name}: could not parse input as datetime: {value!r}")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _datediff_seconds(f, c, s, name):
|
|
59
|
+
start = _to_datetime(f(s[1], c), name)
|
|
60
|
+
end = _to_datetime(f(s[2], c), name)
|
|
61
|
+
try:
|
|
62
|
+
return (end - start).total_seconds()
|
|
63
|
+
except TypeError:
|
|
64
|
+
raise ValueError(
|
|
65
|
+
f"{name}: cannot mix timezone-aware and timezone-naive datetimes"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _whole_if_integral(x):
|
|
70
|
+
return int(x) if float(x).is_integer() else x
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def DateDiffSeconds(f, c, solver_parameters, s):
|
|
74
|
+
return _whole_if_integral(_datediff_seconds(f, c, s, "DateDiffSeconds"))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def DateDiffMinutes(f, c, solver_parameters, s):
|
|
78
|
+
return _whole_if_integral(_datediff_seconds(f, c, s, "DateDiffMinutes") / 60)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def DateDiffHours(f, c, solver_parameters, s):
|
|
82
|
+
return _whole_if_integral(_datediff_seconds(f, c, s, "DateDiffHours") / 3600)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def DateDiffDays(f, c, solver_parameters, s):
|
|
86
|
+
return _whole_if_integral(_datediff_seconds(f, c, s, "DateDiffDays") / 86400)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def DateDiffYears(f, c, solver_parameters, s):
|
|
90
|
+
"""Number of complete calendar years from s[1] to s[2] (negative if reversed)."""
|
|
91
|
+
start = _to_datetime(f(s[1], c), "DateDiffYears")
|
|
92
|
+
end = _to_datetime(f(s[2], c), "DateDiffYears")
|
|
93
|
+
if (start.tzinfo is None) != (end.tzinfo is None):
|
|
94
|
+
raise ValueError(
|
|
95
|
+
"DateDiffYears: cannot mix timezone-aware and timezone-naive datetimes"
|
|
96
|
+
)
|
|
97
|
+
sign = 1
|
|
98
|
+
if end < start:
|
|
99
|
+
start, end = end, start
|
|
100
|
+
sign = -1
|
|
101
|
+
|
|
102
|
+
def anniversary_key(dt):
|
|
103
|
+
return (dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond)
|
|
104
|
+
|
|
105
|
+
years = end.year - start.year
|
|
106
|
+
if anniversary_key(end) < anniversary_key(start):
|
|
107
|
+
years -= 1
|
|
108
|
+
return sign * years
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: mathjson-solver
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: Utilities for MathJSON evaluation
|
|
5
5
|
Project-URL: Homepage, https://github.com/LongenesisLtd/mathjson-solver
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/LongenesisLtd/mathjson-solver/issues
|
|
@@ -53,8 +53,6 @@ Coming from 1.x? Version 2 changed `Log`'s meaning — see [Migrating from 1.x](
|
|
|
53
53
|
* **Data Processing:** Apply mathematical transformations to datasets
|
|
54
54
|
* **Health Applications:** Calculate medical scores, dosages, or risk assessments
|
|
55
55
|
|
|
56
|
-
**What's still missing:** a ready-to-use, user-facing editor for authoring MathJSON itself — today, the expressions have to come from somewhere else (a form builder, a generated JSON structure, hand-written JSON). CortexJS ships [MathLive's mathfield](https://mathlive.io/mathfield/) for entering math, but it's built for typing LaTeX-style notation (e-learning quizzes, scientific computing, calculators) — not for assembling a formula that references named fields from a form. Worth evaluating on its own merits rather than assumed to transfer.
|
|
57
|
-
|
|
58
56
|
## Installation
|
|
59
57
|
|
|
60
58
|
```bash
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
mathjson_solver/__init__.py,sha256=09fRBSoObQ-chsHOTNjWe05QiOljufWSCA-nmYfMJpo,165
|
|
2
|
-
mathjson_solver/__main__.py,sha256=
|
|
2
|
+
mathjson_solver/__main__.py,sha256=BvSL7ocJW1QcCkAYTocFleL3mFQqyfA1WPqYpP-HL18,38804
|
|
3
3
|
mathjson_solver/_arithmetic_constructs.py,sha256=LYJaCA9vyItchKtcaZxJbNh_J6BPAZpvSjH-FSgLo2I,6430
|
|
4
4
|
mathjson_solver/_array_arithmetic_constructs.py,sha256=g2BVecvD0hfpPryd1SUchIf8E7XRH7cS6E3p-SDg7LE,8996
|
|
5
5
|
mathjson_solver/_array_helpers.py,sha256=75FEIfF4Wo4xmiOqKn42SMdfptAY154utmKAF-EId74,1375
|
|
@@ -11,7 +11,7 @@ mathjson_solver/_comparison_constructs.py,sha256=5pxug4YEAhOwfSVx8rIv9P2hxs2GweF
|
|
|
11
11
|
mathjson_solver/_construct_shared.py,sha256=j2I37VLMaYuBw2xniJ0OC9PahKyFCJ1cX_mI7Yf2nNE,2228
|
|
12
12
|
mathjson_solver/_control_flow_constructs.py,sha256=7gpXcYglat802rOHtcipN6S0bRKAKOsw9MJDBR2y5Ec,3327
|
|
13
13
|
mathjson_solver/_core_constructs.py,sha256=UtqOvEF_X29YX16VONBOBRzifs0neBQQO-wDkgpit3E,2084
|
|
14
|
-
mathjson_solver/_datetime_constructs.py,sha256=
|
|
14
|
+
mathjson_solver/_datetime_constructs.py,sha256=bB4mVR27W3sHimaDheHKfZ0VDOnb-kM7XJtrhAzuVQI,3095
|
|
15
15
|
mathjson_solver/_exceptions.py,sha256=t_zD7ANElfk3tBCW0xyhmWFScs-peczdTOtMLp8gRew,1717
|
|
16
16
|
mathjson_solver/_functional_constructs.py,sha256=T2SnYVvN77Z5w931g7DIpozeIO6t-tRvSV0JQAio4qw,4508
|
|
17
17
|
mathjson_solver/_interpolation.py,sha256=zNEXVs3b67WpkrbI-JkSredKleFD4MJhzmWu1fY85zc,2354
|
|
@@ -22,7 +22,7 @@ mathjson_solver/_special_functions.py,sha256=76CvW3AvrHn67p23Sb6guJqWyJP_qO76Blc
|
|
|
22
22
|
mathjson_solver/_statistics_constructs.py,sha256=Vtop7z9MdfCdXLCIAmgIuOnqU-Ji3f4C87eLKrs_BAo,15759
|
|
23
23
|
mathjson_solver/_string_constructs.py,sha256=OUlejq7FL-z6pJ3J-5u-4LMMqqU_UXW32vUsqOcRo5I,11848
|
|
24
24
|
mathjson_solver/_trig_constructs.py,sha256=R0kkawqjMFcYG1p78bXnbDmArpvg4iT9fkjFsb2RQlQ,602
|
|
25
|
-
mathjson_solver-2.
|
|
26
|
-
mathjson_solver-2.
|
|
27
|
-
mathjson_solver-2.
|
|
28
|
-
mathjson_solver-2.
|
|
25
|
+
mathjson_solver-2.4.0.dist-info/METADATA,sha256=nOGgWE0sLMlVSc6Y6nocPhtTkTAICEPedjEQDx2ClDc,12576
|
|
26
|
+
mathjson_solver-2.4.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
27
|
+
mathjson_solver-2.4.0.dist-info/licenses/LICENSE,sha256=uWXG6XqeqlBciRTAN8ZPXcNrZnzq1V5Dc7QzB2VGCjY,1071
|
|
28
|
+
mathjson_solver-2.4.0.dist-info/RECORD,,
|
|
File without changes
|