mriusero commited on
Commit
cc39e44
·
1 Parent(s): e904c97

feat: tool graph (1st draw)

Browse files
Files changed (2) hide show
  1. src/ui/dashboard.py +36 -80
  2. src/ui/graphs/tools_graphs.py +33 -48
src/ui/dashboard.py CHANGED
@@ -1,98 +1,54 @@
1
  import time
2
  import json
3
  import gradio as gr
 
4
 
5
- from src.production.flow import generate_data#, compile
6
- from src.production.metrics.tools import get_tools_metrics
7
- from src.production.metrics.machine import get_machine_metrics
8
 
9
- def dashboard_ui(state):
10
-
11
- def update_dashboard(state):
12
- if state['running']:
13
- generate_data(state)
14
 
15
- raw_data = state['data']['raw_df']
16
- print(raw_data)
17
 
 
18
 
19
- tools_dfs = get_tools_metrics(raw_data)
20
- tools_dfs = {tool: df for tool, df in tools_dfs.items() if not df.empty}
21
 
22
- for tool, df in tools_dfs.items():
23
- print(tool)
24
- print(df.columns.tolist())
25
- print("\n")
26
 
27
- machine_results = get_machine_metrics(raw_data)
28
- machine_json = json.dumps(machine_results, indent=4)
29
- print(machine_json)
30
 
31
- return state
 
32
 
 
 
 
33
 
 
 
 
 
 
34
 
 
 
 
 
 
35
 
 
 
 
36
 
37
- timer = gr.Timer(0.1)
 
38
  timer.tick(
39
- fn=update_dashboard,
40
  inputs=state,
41
- outputs=state
42
- )
43
-
44
-
45
-
46
- # # ---------------- TOOLS METRICS DISPLAY ----------------
47
- # tools_count = 4
48
- # visualizers = [ToolMetricsDisplay() for _ in range(tools_count)]
49
- # for id, display in enumerate(visualizers, start=1):
50
- # with gr.Row():
51
- # df = datalist.value['data'][id - 1][0]
52
- # header = f"Tool {id}"
53
- # html_content = f"""
54
- # <div style="display: flex; align-items: center; justify-content: flex-start; width: 100%;">
55
- # <div style="flex: 0 0 2%; border-top: 1px solid white;"></div>
56
- # <h2 style="flex: 0 0 auto; margin: 0 10px;">{header}</h2>
57
- # <div style="flex: 1; border-top: 1px solid white;"></div>
58
- # </div>
59
- # """
60
- # gr.HTML(html_content)
61
- # with gr.Row():
62
- # with gr.Column(scale=1):
63
- # gr.Markdown("### `Position`")
64
- # with gr.Group():
65
- # with gr.Row(height=250):
66
- # pos_normal_plot = gr.Plot(display.normal_curve(df=df, cote='pos'))
67
- # with gr.Row(height=150):
68
- # pos_cp_gauge = gr.Plot(display.gauge(df=df, type='cp', cote='pos'))
69
- # pos_cpk_gauge = gr.Plot(display.gauge(df=df, type='cpk', cote='pos'))
70
- #
71
- # with gr.Column(scale=1):
72
- # gr.Markdown("### `Orientation`")
73
- # with gr.Group():
74
- # with gr.Row(height=250):
75
- # ori_normal_plot = gr.Plot(display.normal_curve(df=df, cote='ori'))
76
- # with gr.Row(height=150):
77
- # ori_cp_gauge = gr.Plot(display.gauge(df=df, type='cp', cote='ori'))
78
- # ori_cpk_gauge = gr.Plot(display.gauge(df=df, type='cpk', cote='ori'))
79
- #
80
- # with gr.Column(scale=2):
81
- # gr.Markdown("### `Control card`")
82
- # with gr.Row(height=400):
83
- # control_plot = gr.Plot(display.control_graph(df=df))
84
- #
85
- # timer = gr.Timer(1)
86
- # timer.tick(
87
- # lambda : [
88
- # display.normal_curve(df=df, cote='pos'),
89
- # display.gauge(df=df, type='cp', cote='pos'),
90
- # display.gauge(df=df, type='cpk', cote='pos'),
91
- # display.normal_curve(df=df, cote='ori'),
92
- # display.gauge(df=df, type='cp', cote='ori'),
93
- # display.gauge(df=df, type='cpk', cote='ori'),
94
- # display.control_graph(df=df)
95
- # ],
96
- # outputs=[pos_normal_plot, pos_cp_gauge, pos_cpk_gauge, ori_normal_plot, ori_cp_gauge, ori_cpk_gauge,
97
- # control_plot]
98
- # )
 
1
  import time
2
  import json
3
  import gradio as gr
4
+ import pandas as pd
5
 
6
+ from src.production.flow import generate_data
7
+ from src.production.metrics.tools import tools_metrics
8
+ from src.production.metrics.machine import machine_metrics, fetch_issues
9
 
10
+ from src.ui.graphs.tools_graphs import ToolMetricsDisplay
 
 
 
 
11
 
12
+ def dashboard_ui(state):
 
13
 
14
+ display1 = ToolMetricsDisplay()
15
 
16
+ def dataflow(state):
 
17
 
18
+ # --- INIT ---
19
+ if 'tools' not in state['data']:
20
+ state['data']['tools'] = {}
 
21
 
22
+ if 'issues' not in state['data']:
23
+ state['data']['issues'] = {}
 
24
 
25
+ # --- DATA FLOW ---
26
+ if state['running']:
27
 
28
+ # Generation
29
+ generate_data(state)
30
+ raw_data = state['data']['raw_df']
31
 
32
+ # Process tools metrics
33
+ tools_data = tools_metrics(raw_data)
34
+ tools_data = {tool: df for tool, df in tools_data.items() if not df.empty}
35
+ for tool, df in tools_data.items():
36
+ state['data']['tools'][tool] = df
37
 
38
+ # Process machine metrics
39
+ machine_data = machine_metrics(raw_data)
40
+ state['machine'] = machine_data
41
+ issues = fetch_issues(raw_data)
42
+ state['data']['issues'] = issues
43
 
44
+ # --- UPDATE UI ---
45
+ df1 = pd.DataFrame(state['data']['tools'].get('tool_1', pd.DataFrame()))
46
+ return display1.tool_block(df=df1, id=1)
47
 
48
+ plots = display1.tool_block(df=pd.DataFrame(), id=1)
49
+ timer = gr.Timer(1)
50
  timer.tick(
51
+ fn=dataflow,
52
  inputs=state,
53
+ outputs=plots
54
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/ui/graphs/tools_graphs.py CHANGED
@@ -143,52 +143,37 @@ class ToolMetricsDisplay:
143
  )
144
  return fig
145
 
146
- #def tool_block(self, df, id=1):
147
- # header = f"Tool {id}"
148
- # html_content = f"""
149
- # <div style="display: flex; align-items: center; justify-content: flex-start; width: 100%;">
150
- # <div style="flex: 0 0 2%; border-top: 1px solid white;"></div>
151
- # <h2 style="flex: 0 0 auto; margin: 0 10px;">{header}</h2>
152
- # <div style="flex: 1; border-top: 1px solid white;"></div>
153
- # </div>
154
- # """
155
- # gr.HTML(html_content)
156
- #
157
- # with gr.Row():
158
- # with gr.Column(scale=1):
159
- # gr.Markdown("### `Position`")
160
- # with gr.Group():
161
- # with gr.Row(height=250):
162
- # pos_normal_plot = gr.Plot(self.normal_curve(df=df, cote='pos'))
163
- # with gr.Row(height=150):
164
- # pos_cp_gauge = gr.Plot(self.gauge(df=df, type='cp', cote='pos'))
165
- # pos_cpk_gauge = gr.Plot(self.gauge(df=df, type='cpk', cote='pos'))
166
- #
167
- # with gr.Column(scale=1):
168
- # gr.Markdown("### `Orientation`")
169
- # with gr.Group():
170
- # with gr.Row(height=250):
171
- # ori_normal_plot = gr.Plot(self.normal_curve(df=df, cote='ori'))
172
- # with gr.Row(height=150):
173
- # ori_cp_gauge = gr.Plot(self.gauge(df=df, type='cp', cote='ori'))
174
- # ori_cpk_gauge = gr.Plot(self.gauge(df=df, type='cpk', cote='ori'))
175
- #
176
- # with gr.Column(scale=2):
177
- # gr.Markdown("### `Control card`")
178
- # with gr.Row(height=400):
179
- # control_plot = gr.Plot(self.control_graph(df=df))
180
 
181
- #timer = gr.Timer(1)
182
- #
183
- #timer.tick(
184
- # lambda: [
185
- # self.update_normal_curve(cote='pos'),
186
- # self.update_gauge(type='cp', cote='pos'),
187
- # self.update_gauge(type='cpk', cote='pos'),
188
- # self.update_normal_curve(cote='ori'),
189
- # self.update_gauge(type='cp', cote='ori'),
190
- # self.update_gauge(type='cpk', cote='ori'),
191
- # self.update_control_graph()
192
- # ],
193
- # outputs=[pos_normal_plot, pos_cp_gauge, pos_cpk_gauge, ori_normal_plot, ori_cp_gauge, ori_cpk_gauge, control_plot]
194
- #)
 
143
  )
144
  return fig
145
 
146
+ def tool_block(self, df, id=1):
147
+ header = f"Tool {id}"
148
+ html_content = f"""
149
+ <div style="display: flex; align-items: center; justify-content: flex-start; width: 100%;">
150
+ <div style="flex: 0 0 2%; border-top: 1px solid white;"></div>
151
+ <h2 style="flex: 0 0 auto; margin: 0 10px;">{header}</h2>
152
+ <div style="flex: 1; border-top: 1px solid white;"></div>
153
+ </div>
154
+ """
155
+ gr.HTML(html_content)
156
+ with gr.Row():
157
+ with gr.Column(scale=1):
158
+ gr.Markdown("### `Position`")
159
+ with gr.Group():
160
+ with gr.Row(height=250):
161
+ pos_normal_plot = gr.Plot(self.normal_curve(df=df, cote='pos'))
162
+ with gr.Row(height=150):
163
+ pos_cp_gauge = gr.Plot(self.gauge(df=df, type='cp', cote='pos'))
164
+ pos_cpk_gauge = gr.Plot(self.gauge(df=df, type='cpk', cote='pos'))
165
+ with gr.Column(scale=1):
166
+ gr.Markdown("### `Orientation`")
167
+ with gr.Group():
168
+ with gr.Row(height=250):
169
+ ori_normal_plot = gr.Plot(self.normal_curve(df=df, cote='ori'))
170
+ with gr.Row(height=150):
171
+ ori_cp_gauge = gr.Plot(self.gauge(df=df, type='cp', cote='ori'))
172
+ ori_cpk_gauge = gr.Plot(self.gauge(df=df, type='cpk', cote='ori'))
173
+ with gr.Column(scale=2):
174
+ gr.Markdown("### `Control card`")
175
+ with gr.Row(height=400):
176
+ control_plot = gr.Plot(self.control_graph(df=df))
 
 
 
177
 
178
+ return [pos_normal_plot, pos_cp_gauge, pos_cpk_gauge, ori_normal_plot, ori_cp_gauge, ori_cpk_gauge,
179
+ control_plot]