-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
48 lines (37 loc) · 1.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import inspect
import pycel
from concurrent.futures import ThreadPoolExecutor
from pycel.types import CelBool, CelInt, CelFloat, CelString, CelList, CelMap
def test_basic():
expressions = [
'b && (c == "string") && f >= 3.14 && a in g && o.id == d',
'b && c == "string" && f >= 3.14',
'c == "string" && b && f >= 3.14',
]
for expression in expressions:
# Compile expression
program = pycel.CelProgram(expression)
# Evaluate expression
result = program.evaluate({
"a": CelInt(1),
"d": CelInt(2),
"b": CelBool(True),
"c": CelString("string"),
"f": CelFloat(3.15),
"g": CelList([CelInt(1)]),
"o": CelMap({"id": CelInt(2)}),
})
print(inspect.signature(program.evaluate))
# Print results
print(f"{result} <= {expression}")
def test_multithreading():
with ThreadPoolExecutor(max_workers=10) as executor:
expression = "1 == 1"
program = pycel.CelProgram(expression)
def evaluate(value: int):
result = program.evaluate({})
return result
for result in executor.map(evaluate, range(10)):
print(result)
test_basic()
test_multithreading()