File size: 5,251 Bytes
83024c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
from keras.models import load_model
from numpy import random
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import datetime as dt
import PySimpleGUI as sg
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import gradio as gr

model = load_model('model.h5')

def transformer(Водород,Кислород,Азот,Метан,CO,CO2,Этилен,Этан,Ацетилен,Дибензилсульфид,Напряжение,Поверхностное_Н,Диэлектрическая_жесткость,Содержание_Воды,Срок_службы):
    data = np.array([[Водород,Кислород,Азот,Метан,CO,CO2,Этилен,Этан,Ацетилен,Дибензилсульфид,Напряжение,Поверхностное_Н,Диэлектрическая_жесткость,Содержание_Воды,Срок_службы]])
    prediction = model.predict(data)
    x = int(prediction[0])
    if x >= 56:
        transformer_index = f'Индекс состония трансформатора 1 с процентом оставшегося ресурса {x}'
    elif 29<=x<=55:
        transformer_index = f'Индекс состония трансформатора 2 с процентом оставшегося ресурса {x}'
    elif 17<=x<=28:
        transformer_index = f'Индекс состония трансформатора 3 с процентом оставшегося ресурса {x}'
    elif 6<=x<=16:
        transformer_index = f'Индекс состония трансформатора 4 с процентом оставшегося ресурса {x}'
    elif x<=5:
        transformer_index = f'Индекс состония трансформатора 5 с процентом оставшегося ресурса {x}'

    return transformer_index

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
xs = []
ys = []

def cock():
    myArray = np.array([])
    for n in range(1):
        a = random.randint(12886)
        b = random.randint(21800)
        c = random.randint(60600)
        d = random.randint(7406)
        e = random.randint(520)
        f = random.randint(2480)
        g = random.randint(16684)
        h = random.randint(1450)
        j = random.randint(164)
        k = random.randint(500)/100
        l = random.randint(100)
        z = random.randint(60)
        x = random.randint(70)
        v = random.randint(30)
        transformer(a,b,c,d,d,e,f,g,h,j,k,l,z,x,v)
        myArray = np.append(myArray,x)
        
    return(myArray)

def get_plot(period=1):
    temp_c=cock()
    xs.append(dt.datetime.now().strftime('%H:%M:%S.%f'))
    ys.append(temp_c)
    update = gr.LinePlot.update(
        value=pd.DataFrame({"x": xs, "y": ys}),
        xs="x",
        ys="y",
        title="Plot (updates every second)",
        width=600,
        height=350,
    )
    return update

def get_time():
    return dt.datetime.now()

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            c_time2 = gr.Textbox(label="Current Time refreshed every second")
            gr.Textbox(
                "Change the value of the slider to automatically update the plot",
                label="",
            )
            period = gr.Slider(
                label="Period of plot", value=1, minimum=0, maximum=10, step=1
            )
            plot = gr.LinePlot(show_label=False)
        with gr.Column():
            name = gr.Textbox(label="Enter your name")
            greeting = gr.Textbox(label="Greeting")
            button = gr.Button(value="Greet")
            button.click(lambda s: f"Hello {s}", name, greeting)

    demo.load(lambda: dt.datetime.now(), None, c_time2, every=1)
    dep = demo.load(get_plot, None, plot, every=1)
    period.change(get_plot, period, plot, every=1, cancels=[dep])

if __name__ == "__main__":
    demo.queue().launch()


#def animate(i, xs, ys):

    # Состояние трансформатора с текущего ридинга
    #temp_c = cock()

    # Добавляем значения на лист
    #xs.append(dt.datetime.now().strftime('%H:%M:%S.%f'))
    #ys.append(temp_c)

    # Лимит массивов 
    #xs = xs[-20:]
    #ys = ys[-20:]

    # нарисовать хс yс
    #ax.clear()
    #ax.plot(xs, ys)

    # Format plot
    #plt.xticks(rotation=45, ha='right')
    #plt.subplots_adjust(bottom=0.30)
    #plt.title('Показатель Индекса трансформатора')
    #plt.ylabel('Индекс состояния трансформатора')


#ani = animation.FuncAnimation(fig, animate, fargs=(xs, ys), interval=100)


#def draw_figure(canvas, figure):
   #tkcanvas = FigureCanvasTkAgg(figure, canvas)
   #tkcanvas.draw()
   #tkcanvas.get_tk_widget().pack(side='top', fill='both', expand=1)
   #return tkcanvas
#layout = [[sg.Text('Plot test')],
   #[sg.Canvas(key='-CANVAS-')],
   #[sg.Button('Ok')]]
#window = sg.Window('Matplotlib In PySimpleGUI', layout, size=(715, 500), finalize=True, element_justification='center', font='Helvetica 18')

#tkcanvas = draw_figure(window['-CANVAS-'].TKCanvas, fig)
#event, values = window.read()
#window.close()