-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCucumber_Main.py
More file actions
224 lines (202 loc) · 8.18 KB
/
Cucumber_Main.py
File metadata and controls
224 lines (202 loc) · 8.18 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import random
import numpy as np
from matplotlib import pyplot as plt
import operator
from lorem_text import lorem
import math
#testtest
#bruh
class GraphGen:
def __init__(self, *args, **kwargs):
super(GraphGen, self).__init__(*args, **kwargs)
self.figure, self.ax = plt.subplots()
self.units = ['meters (m)', 'seconds (s)', 'ampere (A)', 'candela (cd)',
'gram (g)', 'mole (mol)', 'kelvin (K)', 'radian (rad)', 'bit', 'count'
]
self.colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k']
self.lineStyles = ['-', '--', '-.', ':', 'None', ' ', '', 'solid', 'dashed', 'dashdot', 'dotted']
self.fontSizes = ['15px', '16px', '17px', '18px', '19px', '20px']
self.lineWidth = [0.2, 0.5, 1, 2, 3, 4, 5]
self.trueFalse = [True, False]
self.gridAxis = ['both', 'x', 'y']
self.gridWhich = ['major', 'minor', "both"]
self.dataRange = [-100, 100]
self.nbData = 100
self.plot = None
self.styles = None
self.SavePlot = None
self.coefficientRange = (-20, 20)
self.coefficientRangePositive = (2, 40)
self.Nb100 = np.linspace(self.dataRange[0], self.dataRange[1], self.nbData)
self.FunctionsListe = [self.constant, self.linear, self.quadratic, self.cubic,
self.quartic, self.quintic, self.sextic, self.rational,
self.square_root, self.cube_root, self.expo]
def randomize_data_range(self):
pass
def graph_gene(self):
name = lorem.words(1)
x, y = self.add_functions()
self.ax.grid(b=random.choice(self.trueFalse), which=random.choice(self.gridWhich),
axis=random.choice(self.gridAxis), color=random.choice(self.colors),
linestyle=random.choice(self.lineStyles), linewidth=random.choice(self.lineWidth))
# self.ax.set_facecolor(random.choice(self.colors))
self.ax.set_xlabel(random.choice(self.units))
self.ax.set_ylabel(random.choice(self.units))
self.ax.plot(x, y, color=random.choice(self.colors))
plt.savefig(fname='Graphs\Graph_{}'.format(name), dpi=random.randrange(100, 300))
self.ax.clear()
def add_functions(self):
listex = []
listey = []
nbparties = random.randrange(1, 11)
n = int(100 / nbparties)
dividedx = []
dividedy = []
for i in range(nbparties):
badx, bady = random.choice(self.FunctionsListe)()
x = list(badx)
y = list(bady)
print(y)
for j in x[i * n:(i + 1) * n]:
dividedx += j
for k in y[i * n:(i + 1) * n]:
dividedy.append(k)
return listex, listey
@staticmethod
def divide_chunks(l, n):
for i in range(0, len(l), n):
yield l[i:i + n]
def constant(self):
y = [random.randrange(-1000, 1000)] * 100
x = random.sample(list(self.Nb100), 100)
w = sorted(zip(x, y), key=operator.itemgetter(0))
x, y = list(zip(*w))
return x, y
def linear(self):
listeLinear = [0] * 2
for k, m in enumerate(listeLinear):
listeLinear[k] = random.randrange(*self.coefficientRange)
polyLinear = np.poly1d(listeLinear)
x = random.sample(list(self.Nb100), 100)
y = [0] * 100
for l in range(100):
y[l] += np.polyval(polyLinear, x[l])
w = sorted(zip(x, y), key=operator.itemgetter(0))
x, y = zip(*w)
return x, y
def quadratic(self):
listeQuadratic = [0] * 3
for k, m in enumerate(listeQuadratic):
listeQuadratic[k] = random.randrange(*self.coefficientRange)
while listeQuadratic[0] == 0:
listeQuadratic[0] = random.randrange(*self.coefficientRange)
polyQuadratic = np.poly1d(listeQuadratic)
x = random.sample(list(self.Nb100), 100)
y = [0] * 100
for l in range(100):
y[l] += np.polyval(polyQuadratic, x[l])
w = sorted(zip(x, y), key=operator.itemgetter(0))
x, y = zip(*w)
return x, y
def cubic(self):
listeCubic = [0] * 4
for k, m in enumerate(listeCubic):
listeCubic[k] = random.randrange(*self.coefficientRange)
polyCubic = np.poly1d(listeCubic)
x = random.sample(list(self.Nb100), 100)
y = [0] * 100
for l in range(100):
y[l] += np.polyval(polyCubic, x[l])
w = sorted(zip(x, y), key=operator.itemgetter(0))
x, y = zip(*w)
return x, y
def quartic(self):
listeQuartic = [0] * 5
for k, m in enumerate(listeQuartic):
listeQuartic[k] = random.randrange(*self.coefficientRange)
polyQuartic = np.poly1d(listeQuartic)
x = random.sample(list(self.Nb100), 100)
y = [0] * 100
for l in range(100):
y[l] += np.polyval(polyQuartic, x[l])
w = sorted(zip(x, y), key=operator.itemgetter(0))
x, y = zip(*w)
return x, y
def quintic(self):
listeQuintic = [0] * 6
for k, m in enumerate(listeQuintic):
listeQuintic[k] = random.randrange(*self.coefficientRange)
polyQuintic = np.poly1d(listeQuintic)
x = random.sample(list(self.Nb100), 100)
y = [0] * 100
for l in range(100):
y[l] += np.polyval(polyQuintic, x[l])
w = sorted(zip(x, y), key=operator.itemgetter(0))
x, y = zip(*w)
return x, y
def sextic(self):
listeSextic = [0] * 7
for k, m in enumerate(listeSextic):
listeSextic[k] = random.randrange(*self.coefficientRange)
polySextic = np.poly1d(listeSextic)
x = random.sample(list(self.Nb100), 100)
y = [0] * 100
for l in range(100):
y[l] += np.polyval(polySextic, x[l])
w = sorted(zip(x, y), key=operator.itemgetter(0))
x, y = zip(*w)
return x, y
def rational(self):
listeRational = [0] * 7
for k, m in enumerate(listeRational):
listeRational[k] = random.randrange(*self.coefficientRange)
listeRational2 = [0] * 7
for k, m in enumerate(listeRational2):
listeRational2[k] = random.randrange(*self.coefficientRange)
polyRational = np.poly1d(np.polydiv(listeRational, listeRational2))
x = random.sample(list(self.Nb100), 100)
y = [0] * 100
for l in range(100):
y[l] += np.polyval(polyRational, x[l])
w = sorted(zip(x, y), key=operator.itemgetter(0))
x, y = zip(*w)
return x, y
def square_root(self):
a = random.randrange(*self.coefficientRange)
while a == 0:
a = random.randrange(*self.coefficientRange)
b = random.randrange(*self.coefficientRange)
while b == 0:
b = random.randrange(*self.coefficientRange)
x = random.sample(list(self.Nb100), 100)
y = [0] * 100
for l in range(100):
mats = math.sqrt(b * x[l])
y[l] += a * mats
w = sorted(zip(x, y), key=operator.itemgetter(0))
x, y = zip(*w)
return x, y
def cube_root(self):
a = random.randrange(*self.coefficientRange)
while a == 0:
a = random.randrange(*self.coefficientRange)
x = random.sample(list(self.Nb100), 100)
y = [0] * 100
for l in range(100):
y[l] += a * (x[l] ** 3)
w = sorted(zip(x, y), key=operator.itemgetter(0))
x, y = zip(*w)
return x, y
def expo(self):
a = random.randrange(*self.coefficientRange)
b = random.randrange(*self.coefficientRange)
c = random.randrange(*self.coefficientRangePositive)
x = random.sample(list(self.Nb100), 100)
y = [0] * 100
for l in range(100):
y[l] += a * (c ** (b * x[l]))
w = sorted(zip(x, y), key=operator.itemgetter(0))
x, y = zip(*w)
return x, y
a = GraphGen()
a.add_functions()