-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
37 lines (28 loc) · 1.06 KB
/
controller.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
from numpy import arange
from errors import Error
from errorStorage import ErrorStorage
from postfix.calculator import calculate
from postfix.postfix import Postfix
from tokens.parser import Parser
from tokens.token import TokenType
def calculate_values(expression, x_min, x_max, precision) -> list or None:
if not expression:
return None
tokens = Parser(expression).parse()
if tokens is None:
return None
postfix = Postfix().create_postfix(tokens)
if len(postfix) == 1:
return fill_values(x_min, x_max, precision, postfix[0])
result = calculate(postfix, x_min, x_max, precision)
return result
# ------------------------------- INTERNAL ----------------------------------- #
def fill_values(x_min, x_max, precision, token) -> list or None:
data = arange(x_min, x_max + precision, precision)
if token.type is TokenType.X:
return data
if token.type is TokenType.NUMBER:
data.fill(token.data)
return data
ErrorStorage.put_error(Error.INTERNAL_EXCEPTION_SINGLE_TOKEN)
return None