mriusero commited on
Commit
e55813a
·
1 Parent(s): 626c449

feat: scaling

Browse files
Files changed (2) hide show
  1. src/production/flow.py +1 -1
  2. src/ui/dashboard.py +52 -19
src/production/flow.py CHANGED
@@ -83,7 +83,7 @@ async def generate_data(state):
83
 
84
  print(f" - part {part_id} data generated")
85
  part_id += 1
86
- await asyncio.sleep(0.5)
87
 
88
  current_time += timedelta(seconds=1)
89
 
 
83
 
84
  print(f" - part {part_id} data generated")
85
  part_id += 1
86
+ await asyncio.sleep(0.2)
87
 
88
  current_time += timedelta(seconds=1)
89
 
src/ui/dashboard.py CHANGED
@@ -7,7 +7,11 @@ from src.production.metrics.tools import tools_metrics
7
  from src.production.metrics.machine import machine_metrics, fetch_issues
8
  from src.ui.graphs.tools_graphs import ToolMetricsDisplay
9
 
 
10
  async def dataflow(state):
 
 
 
11
  if 'tools' not in state['data']:
12
  state['data']['tools'] = {}
13
 
@@ -21,7 +25,7 @@ async def dataflow(state):
21
 
22
  raw_data = state['data'].get('raw_df', pd.DataFrame())
23
  if raw_data.empty:
24
- return pd.DataFrame()
25
 
26
  tools_data = await tools_metrics(raw_data)
27
  tools_data = {tool: df for tool, df in tools_data.items() if not df.empty}
@@ -30,34 +34,63 @@ async def dataflow(state):
30
 
31
  machine_data = await machine_metrics(raw_data)
32
  state['efficiency'] = machine_data
 
33
  issues = await fetch_issues(raw_data)
34
  state['data']['issues'] = issues
35
 
36
- df1 = pd.DataFrame(state['data']['tools'].get('tool_1', pd.DataFrame()))
37
- return df1
 
 
38
 
39
- def dashboard_ui(state):
 
 
 
 
40
  display = ToolMetricsDisplay()
41
- plots = display.tool_block(df=pd.DataFrame(), id=1)
 
 
 
 
 
 
 
 
 
42
 
43
- async def on_tick(state):
44
- df1 = await dataflow(state)
45
- updated = [
46
- display.normal_curve(df1, cote='pos'),
47
- display.gauge(df1, type='cp', cote='pos'),
48
- display.gauge(df1, type='cpk', cote='pos'),
49
 
50
- display.normal_curve(df1, cote='ori'),
51
- display.gauge(df1, type='cp', cote='ori'),
52
- display.gauge(df1, type='cpk', cote='ori'),
 
 
 
 
 
 
 
 
53
 
54
- display.control_graph(df1),
55
- ]
56
- return updated + [state]
57
 
58
- timer = gr.Timer(1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  timer.tick(
60
  fn=on_tick,
61
  inputs=[state],
62
- outputs=plots + [state]
63
  )
 
7
  from src.production.metrics.machine import machine_metrics, fetch_issues
8
  from src.ui.graphs.tools_graphs import ToolMetricsDisplay
9
 
10
+
11
  async def dataflow(state):
12
+ """
13
+ Main dataflow function that processes raw production data and updates the state with tool metrics, machine efficiency, and issues.
14
+ """
15
  if 'tools' not in state['data']:
16
  state['data']['tools'] = {}
17
 
 
25
 
26
  raw_data = state['data'].get('raw_df', pd.DataFrame())
27
  if raw_data.empty:
28
+ return [pd.DataFrame()] * 4
29
 
30
  tools_data = await tools_metrics(raw_data)
31
  tools_data = {tool: df for tool, df in tools_data.items() if not df.empty}
 
34
 
35
  machine_data = await machine_metrics(raw_data)
36
  state['efficiency'] = machine_data
37
+
38
  issues = await fetch_issues(raw_data)
39
  state['data']['issues'] = issues
40
 
41
+ return [
42
+ pd.DataFrame(state['data']['tools'].get(f'tool_{i}', pd.DataFrame()))
43
+ for i in range(1, 5)
44
+ ]
45
 
46
+
47
+ def create_display_and_plots(df):
48
+ """
49
+ Create a ToolMetricsDisplay instance and generate plots for the provided DataFrame.
50
+ """
51
  display = ToolMetricsDisplay()
52
+ plots = [
53
+ display.normal_curve(df, cote='pos'),
54
+ display.gauge(df, type='cp', cote='pos'),
55
+ display.gauge(df, type='cpk', cote='pos'),
56
+ display.normal_curve(df, cote='ori'),
57
+ display.gauge(df, type='cp', cote='ori'),
58
+ display.gauge(df, type='cpk', cote='ori'),
59
+ display.control_graph(df),
60
+ ]
61
+ return display, plots
62
 
 
 
 
 
 
 
63
 
64
+ def init_displays_and_blocks(n=4):
65
+ """
66
+ Initialize a list of ToolMetricsDisplay instances and their corresponding blocks.
67
+ """
68
+ displays = []
69
+ blocks = []
70
+ for i in range(1, n + 1):
71
+ display = ToolMetricsDisplay()
72
+ displays.append(display)
73
+ blocks.extend(display.tool_block(df=pd.DataFrame(), id=i))
74
+ return displays, blocks
75
 
 
 
 
76
 
77
+ def dashboard_ui(state):
78
+ """
79
+ Create the Gradio UI for the dashboard, initializing displays and setting up the dataflow.
80
+ """
81
+ displays, initial_plots = init_displays_and_blocks()
82
+
83
+ async def on_tick(state):
84
+ dfs = await dataflow(state)
85
+ all_plots = []
86
+ for df in dfs:
87
+ _, plots = create_display_and_plots(df)
88
+ all_plots.extend(plots)
89
+ return all_plots + [state]
90
+
91
+ timer = gr.Timer(0.1)
92
  timer.tick(
93
  fn=on_tick,
94
  inputs=[state],
95
+ outputs=initial_plots + [state]
96
  )