-
Notifications
You must be signed in to change notification settings - Fork 0
/
values.py
73 lines (60 loc) · 2.41 KB
/
values.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import string
from selenium import webdriver
from selenium.webdriver.common.by import By
from dotenv import load_dotenv
import os
load_dotenv(".env")
class Number:
def __init__(self, constant, variables) -> None:
self.constant = constant
if variables is None:
self.variables = []
else:
self.variables = variables
def __repr__(self):
if self.constant % 1 == 0.0 and self.constant != 0.0:
result = str(int(self.constant))
else:
result = str(self.constant) if self.constant != 0.0 else ''
for variable in self.variables:
if variable is not None:
result += str(variable)
if result.startswith(" + "):
return result[3:]
return result
def render(self, filename="render") -> None:
option = webdriver.ChromeOptions()
option.binary_location = os.environ['CHROME_PATH']
option.add_argument("--headless")
browser = webdriver.Chrome(executable_path=os.environ['CHROME_DRIVER_PATH'], chrome_options=option)
browser.get(os.environ['PROJECT_PATH'] + "generation_page/index.html?expression=" + self.generate_latex())
element=browser.find_element(By.ID,"expression_container")
element.screenshot(filename + ".png")
def generate_latex(self):
return str(self).replace(" ", "").replace("+", "è")
class Variables:
def get_name(variables: list) -> string:
return ''.join(variables.keys())
def __init__(self, coef: float or int, variables: list) -> None:
self.coef = coef
self.variables = variables
self.name = ''.join(sorted(variables.keys()))
def __repr__(self) -> str:
result = ''
if self.coef != 0 or self.coef != 0.0:
if self.coef == 1:
result += ' + '
elif self.coef == -1:
result += ' - '
else:
if self.coef % 1 == 0.0:
result += ' + ' + str(int(self.coef)) if (self.coef >= 0) else ' - ' + str(int(self.coef)*-1)
else:
result += ' + ' + str(self.coef) if (self.coef >= 0) else ' - ' + str(self.coef*-1)
for x in self.name:
result += f'{x}^' + str(self.variables[x]) if self.variables[x] != 1 else x
else:
return
if result == "":
return "0"
return result