A python library for fast parser used in naoTimes bot.
- Python 3.10+
- Rust 1.80.0+
parse_timestringparse_timestring_as_timedelta
A quick an easy timestring parsing, easily convert text like
1h30m into a proper timedelta object.
from fastnomicon import parse_timestring_as_timedelta
t_delta = parse_timestring_as_timedelta("1h30m") # or you can also write it with space
print(t_delta) # -> 1:30:00The standard parse_timestring will be a custom class called TimeTuple which contains the stack information about each timestring (e.g. 1h30m will be [TimeTuple(time=1, scale=Hours), TimeTuple(time=30, scale=Minutes)]).
execute_math_expr(available withmathfeature)
A quick and easy way to parse complex mathematical expression using Shunting-yard algorithm.
from fastnomicon import execute_math_expr
result = execute_math_expr("6/2*(1+2)") # or you can also write it with space
print(result) # -> 9.0The following function are supported in the expression, extending the standard PEMDAS expression:
abs(x)— Absolute number of xatan2(x, y)— 2-argument arctangentcos(x)— Cosinelog(x)— Logarithmic 10max(x, y, z, ...)— Largest number, can be repeatedmin(x, y, z, ...)— Smallest number, can be repeatednCr(x, y)— Combination (order not important)nMCr(x, y)— Multi combinationnMPr(x, y)— Power of number (order not important)nPr(x, y)— Permutationrand(x)— Random number multiplied by xsin(x)— Sinenormal(mu, sigma)— Normal distributionuniform(mu, sigma)— Uniform distributionlognormal(mu, sigma)— Log-normal distribution
We also provide the following approximation constants:
pi—3.141592653589793, Archimedes' constant (π)tau—6.283185307179586, The full circle constant (τ)e—2.718281828459045, The Euler's number constant (e)
The fastnomicon crate and python bindings are licensed under the MPL 2.0 license.