-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logic.py
79 lines (66 loc) · 1.93 KB
/
Logic.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
74
75
76
77
78
79
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.lines as lines
def f(function, xInterval):
try:
F_X = np.zeros(xInterval.shape)
function = function.lower()
index = 0
for x in xInterval:
F_X[index] = eval(function)
index += 1
return F_X
except:
return "Invalid Process"
def Validate(Function="", minX="", maxX=""):
if Function == "" or minX == "" or maxX == "":
return "Empty Data"
try:
float(minX)
except:
return "Enter a numeric value for minX"
try:
float(maxX)
except:
return "Enter a numeric value for maxX"
if float(minX) > float(maxX):
return "minX can't be greater than maxX"
elif float(maxX) == float(minX):
return "minX can't be equal to to maxX"
else:
return "OK"
def Submit(
ErrorMessageLabel="",
Function="",
minX="",
maxX="",
nbins="100",
plotGraph=None,
plotFigure=None,
):
Function_Value = Function.text().replace("^", "**")
minX_Value = minX.text()
maxX_Value = maxX.text()
ValidationResult = Validate(Function_Value, minX_Value, maxX_Value)
if ValidationResult == "minX can't be greater than maxX":
ErrorMessageLabel.setText(ValidationResult + ".\nThey will be swaped")
temp = minX_Value
minX.setText(maxX_Value)
maxX.setText(temp)
# temp = minX
# minX = maxX
# maxX = temp
elif ValidationResult != "OK":
ErrorMessageLabel.setText(ValidationResult)
return
else:
ErrorMessageLabel.setText("")
xAxis = np.linspace(float(minX_Value), float(maxX_Value), int(nbins))
yAxis = f(Function_Value, xAxis)
if yAxis == "Invalid Process":
ErrorMessageLabel.setText("Invalid Process")
return
plotFigure.clear()
ax = plotFigure.add_subplot(111)
ax.plot(xAxis, yAxis)
plotGraph.draw()