Repository navigation
Expand file tree
/
Copy pathproj3.py
More file actions
504 lines (504 loc) · 14.9 KB
/
Copy pathproj3.py
File metadata and controls
504 lines (504 loc) · 14.9 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
def warn(*args,**kwargs):
pass
import warnings
warnings.warn=warn
from sklearn.linear_model import LinearRegression
import pymysql
import numpy
v=[0,0,0,0]
i=[0,0,0,0]
i_limit=[200,500,1500,2000]
p4_num=0
p4_den=0
p3_num=0
p3_den=0
p21_num=0
p21_den=0
p22_num=0
p22_den=0
p11_num=0
p11_den=0
p12_num=0
p12_den=0
def get_input():
print("enter voltage values")
for j in range(4):
v[j]=int(input())
print("enter current values")
for j in range(4):
i[j]=int(input())
def curve4(v):
#db=pymysql.connect("localhost","root","","esp")
#cur=db.cursor()
x=[35,37,39,41]
y=[790,810,830,850]
#cur.execute("SELECT * FROM crv4")
#c=cur.fetchall()
#for row in c:
# x.append(row[0])
# y.append(row[1])
xn=numpy.array(x)
yn=numpy.array(y)
model=LinearRegression()
model.fit(numpy.transpose(numpy.matrix(yn)),numpy.transpose(numpy.matrix(xn)))
k=[v[3]]
y_predict=model.predict(k)
print(y_predict)
return y_predict
def actionX():
print("Do internal inspection for misalignment of electrodes, ash deposits, failure of rapping system components")
def power_down_rapping():
print("Perform power down rapping")
def reduce_charge_ratio():
print("Charge reduction by 25% required")
def update4(val):
global p4_num
global p4_den
p4_num+=val
p4_den+=1
def success_4():
global p4_num
global p4_den
#db=pymysql.connect("localhost","root","","esp")
#cur=db.cursor()
#cur.execute("SELECT * FROM prob4")
#c=cur.fetchall()
x=[9,15]
for row in c:
x.append(row[0])
x.append(row[1])
prob=(x[0]+p4_num)/(x[1]+p4_den)
return prob
def up4():
global p4_num
global p4_den
db=pymysql.connect("localhost","root","","esp")
cur=db.cursor()
cur.execute("SELECT * FROM prob4")
c=cur.fetchall()
x=[]
for row in c:
x.append(row[0])
x.append(row[1])
cur.execute("UPDATE prob4 SET num=%d, den=%d"%(x[0]+p4_num,x[1]+p4_den))
db.commit()
def opt_stage4(v,i,i_limit):
flag=0
if v[3]<30 or i[3]>=0.95*i_limit[3]:
bound=curve4()
prob=success_4()
print(bound,prob)
if i[3]>1.25*bound:
print("current greater than 1.25 times expected value")
power_down_rapping()
return(0)
elif i[3]>1.1*bound:
print("current greater than 1.1 times expected value")
if prob>0.25:
print("success rate of charge reduction is >25%")
reduce_charge_ratio()
#get_input()
if v[3]>30 and i[3]<0.95*i_limit[3]:
print("field 4 optimised")
update4(1)
return(1)
else:
print("action unsuccessful")
update4(0)
flag=-1
return(2)
else:
print("success rate of charge reduction is <25%")
power_down_rapping()
return(3)
else:
print("current less than 1.1 times expected value and greater than 0.95 times current limit")
if flag==0:
reduce_charge_ratio()
#get_input()
if v[3]>30 and i[3]<0.95*i_limit[3]:
print("field 4 optimised")
update4(1)
return(4)
else:
print("field 4 not optimised by charge reduction")
update4(0)
return(5)
else:
print("previous action was charge reduction which was unsuccessful")
power_down_rapping()
return(6)
#get_input()
if v[3]<30 or i[3]>=0.95*i_limit[3]:
print("field 4 is still not optimised")
actionX()
return(7)
else:
print("field 4 is optimised")
return(8)
#up4()
def up3():
global p3_num
global p3_den
db=pymysql.connect("localhost","root","","esp")
cur=db.cursor()
cur.execute("SELECT * FROM prob3")
c=cur.fetchall()
x=[]
for row in c:
x.append(row[0])
x.append(row[1])
cur.execute("UPDATE prob3 SET num=%d, den=%d"%(x[0]+p3_num,x[1]+p3_den))
db.commit()
def curve3(v):
#db=pymysql.connect("localhost","root","","esp")
#cur=db.cursor()
x=[35,37,39,41]
y=[790,810,830,850]
#cur.execute("SELECT * FROM crv3")
#c=cur.fetchall()
#for row in c:
# x.append(row[0])
# y.append(row[1])
xn=numpy.array(x)
yn=numpy.array(y)
model=LinearRegression()
model.fit(numpy.transpose(numpy.matrix(yn)),numpy.transpose(numpy.matrix(xn)))
k=[v[2]]
y_predict=model.predict(k)
print(y_predict)
return y_predict
def update3(val):
global p3_num
global p3_den
p3_num+=val
p3_den+=1
def success_3():
global p3_num
global p3_den
#db=pymysql.connect("localhost","root","","esp")
#cur=db.cursor()
#cur.execute("SELECT * FROM prob3")
#c=cur.fetchall()
x=[9,15]
#for row in c:
# x.append(row[0])
# x.append(row[1])
prob=(x[0]+p3_num)/(x[1]+p3_den)
return prob
def opt_stage3(v,i,i_limit):
flag=0
if v[2]<30 or i[2]>=0.95*i_limit[2]:
bound=curve3(v)
prob=success_3()
print(bound,prob)
if i[2]>1.25*bound:
print("current greater than 1.25 times expected value")
power_down_rapping()
return(0)
elif i[2]>1.1*bound:
print("current greater than 1.1 times expected value")
if prob>0.25:
print("success rate of charge reduction is >25%")
reduce_charge_ratio()
#get_input()
if v[2]>30 and i[2]<0.95*i_limit[2]:
print("field 3 optimised")
update3(1)
return(1)
else:
print("action unsuccessful")
update3(0)
flag=-1
return(2)
else:
print("success rate of charge reduction is <25%")
power_down_rapping()
return(3)
else:
print("current less than 1.1 times expected value and greater than 0.95 times current limit")
if flag==0:
reduce_charge_ratio()
#get_input()
if v[2]>30 and i[2]<0.95*i_limit[2]:
print("field 3 optimised")
update3(1)
return(4)
else:
print("field 3 not optimised by charge reduction")
update3(0)
return(5)
else:
print("previous action was charge reduction which was unsuccessful")
power_down_rapping()
return(6)
#get_input()
if v[2]<30 or i[2]>=0.95*i_limit[2]:
print("field 3 is still not optimised")
actionX()
return(7)
else:
print("field 3 is optimised")
return(8)
def update22(val):
global p22_num
global p22_den
p22_num+=val
p22_den+=1
def up21():
global p21_num
global p21_den
db=pymysql.connect("localhost","root","","esp")
cur=db.cursor()
cur.execute("SELECT * FROM prob21")
c=cur.fetchall()
x=[]
for row in c:
x.append(row[0])
x.append(row[1])
cur.execute("UPDATE prob21 SET num=%d, den=%d"%(x[0]+p21_num,x[1]+p21_den))
db.commit()
def up22():
global p22_num
global p22_den
db=pymysql.connect("localhost","root","","esp")
cur=db.cursor()
cur.execute("SELECT * FROM prob22")
c=cur.fetchall()
x=[]
for row in c:
x.append(row[0])
x.append(row[1])
cur.execute("UPDATE prob22 SET num=%d, den=%d"%(x[0]+p22_num,x[1]+p22_den))
db.commit()
def update21(val):
global p21_num
global p21_den
p21_num+=val
p21_den+=1
def success_21():
global p21_num
global p21_den
#db=pymysql.connect("localhost","root","","esp")
#cur=db.cursor()
#cur.execute("SELECT * FROM prob21")
#c=cur.fetchall()
x=[9,15]
#for row in c:
# x.append(row[0])
# x.append(row[1])
prob=(x[0]+p21_num)/(x[1]+p21_den)
#cur.execute("UPDATE prob21 SET num=%d, den=%d"%(x[0]+p21_num,x[1]+p21_den))
p21_num=0
p21_den=0
#db.commit()
return prob
def success_22():
global p22_num
global p22_den
#db=pymysql.connect("localhost","root","","esp")
#cur=db.cursor()
#cur.execute("SELECT * FROM prob22")
#c=cur.fetchall()
x=[9,15]
#for row in c:
# x.append(row[0])
# x.append(row[1])
prob=(x[0]+p22_num)/(x[1]+p22_den)
#cur.execute("UPDATE prob3 SET num=%d, den=%d"%(x[0]+p22_num,x[1]+p22_den))
p22_num=0
p22_den=0
#db.commit()
return prob
def opt_stage2(v,i,i_limit):
global p21_num
global p21_den
if v[1]>30 and i[1]<=200:
print("increase limit by 25%")
i_limit[1]=1.25*i_limit[1]
#get_input()
return(0)
flag=0
if v[1]<30 or i[1]>0.95*i_limit[1]:
prob1=success_21()
prob2=success_22()
print(prob1,prob2)
if (prob1<0.25 or prob2<0.5) and flag==-1:
print("set limit of current for field 2 as 200")
i_limit[1]=200
#get_input()
return(0)
else:
flag=-1
print("lower value of current limit for field 2 by 25%")
i_limit[1]=0.75*i_limit[1]
#get_input()
if v[1]>30 and i[1]<=0.95*i_limit[1]:
print("field 1 optimised")
print("updating probability values of action 1...")
update21(1)
return(1)
else:
print("action unsuccessful")
print("again reduce value of current for field 2 by 25%")
update21(0)
i_limit[1]=0.75*i_limit[1]
#get_input()
if v[1]>30 and i[1]<=0.95*i_limit[1]:
print("field 2 optimised")
print("updating probability of action 2...")
update22(1)
return(2)
else:
print("now reduce value of current limit of field 2 by 200")
update22(0)
i_limit[1]=i_limit[1]-200
return(3)
if v[1]<30 and i[1]>0.95*i_limit[1]:
print("field 2 is still not optimised")
actionX()
return(4)
else:
print("field 2 is optimised")
return(5)
#up21()
#up22()
def update12(val):
global p12_num
global p12_den
p12_num+=val
p12_den+=1
def up11():
global p12_num
global p12_den
db=pymysql.connect("localhost","root","","esp")
cur=db.cursor()
cur.execute("SELECT * FROM prob11")
c=cur.fetchall()
x=[]
for row in c:
x.append(row[0])
x.append(row[1])
cur.execute("UPDATE prob11 SET num=%d, den=%d"%(x[0]+p11_num,x[1]+p11_den))
db.commit()
def up12():
global p11_num
global p11_den
db=pymysql.connect("localhost","root","","esp")
cur=db.cursor()
cur.execute("SELECT * FROM prob12")
c=cur.fetchall()
x=[]
for row in c:
x.append(row[0])
x.append(row[1])
cur.execute("UPDATE prob12 SET num=%d, den=%d"%(x[0]+p12_num,x[1]+p12_den))
db.commit()
def update11(val):
global p11_num
global p11_den
p11_num+=val
p11_den+=1
def success_12():
global p12_num
global p12_den
#db=pymysql.connect("localhost","root","","esp")
#cur=db.cursor()
#cur.execute("SELECT * FROM prob12")
#c=cur.fetchall()
x=[9,15]
#for row in c:
# x.append(row[0])
# x.append(row[1])
prob=(x[0]+p12_num)/(x[1]+p12_den)
return prob
def success_11():
global p11_num
global p11_den
#db=pymysql.connect("localhost","root","","esp")
#cur=db.cursor()
#cur.execute("SELECT * FROM prob11")
#c=cur.fetchall()
x=[9,15]
#for row in c:
# x.append(row[0])
# x.append(row[1])
prob=(x[0]+p11_num)/(x[1]+p11_den)
return prob
def opt_stage1(v,i,i_limit):
global p11_num
global p11_den
#v=[31,32,33,34]
#i=[195,300,900,1100]
#i_limit=[250,400,1200,1500]
if v[0]>30 and i[0]<=200:
print("increase limit by 25%")
i_limit[0]=1.25*i_limit[0]
#v=[28,32,33,34]
#i=[210,300,900,1100]
#get_input()
flag=0
if v[0]<30 or i[0]>0.95*i_limit[0]:
prob1=success_11()
prob2=success_12()
prob1=0.3
prob2=0.8
print(prob1,prob2)
if (prob1<0.25 or prob2<0.5) and flag==-1:
print("set limit of current for field 1 as 200")
i_limit[0]=200
return(0)
#get_input()
else:
flag=-1
print("lower value of current limit for field 1 by 25%")
i_limit[0]=0.75*i_limit[0]
#get_input()
if v[0]>30 and i[0]<=0.95*i_limit[0]:
print("field 1 optimised")
print("updating probability values of action 1...")
update11(1)
return(1)
else:
print("action unsuccessful")
print("again reduce value of current for field by 25%")
update11(0)
i_limit[0]=0.75*i_limit[0]
#get_input()
if v[0]>30 and i[0]<=0.95*i_limit[0]:
print("field 1 optimised")
print("updating probability of action 2...")
update12(1)
return(2)
else:
print("now reduce value of current limit of field 1 by 200")
update12(0)
i_limit[0]=i_limit[0]-200
return(3)
if v[0]<30 and i[0]>0.95*i_limit[0]:
print("field 1 is still not optimised")
actionX()
return(4)
else:
print("field 1 is optimised")
return(5)
#up11()
#up12()
def check_opacity():
print("enter value of opacity")
op=int(input())
return op
def start():
op=56
if op>50:
get_input()
print("optimising field 1")
value1=opt_stage1(v,i,i_limit)
print("optimising field 2")
value2=opt_stage2(v,i,i_limit)
print("optimising field 3")
value3=opt_stage3(v,i,i_limit)
print("optimising field 4")
value4=opt_stage4(v,i,i_limit)
print(value1,value2,value3,value4)
start()