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

feat: access data

Browse files
src/production/flow.py CHANGED
@@ -12,8 +12,7 @@ def generate_data(state):
12
  """
13
  current_time = state["current_time"] if state["current_time"] else datetime.now()
14
  part_id = state["part_id"] if state["part_id"] else 0
15
- if 'raw' not in state['data']:
16
- state['data']['raw'] = []
17
  non_compliance_rates = {
18
  1: 0.05,
19
  2: 0.10,
@@ -21,6 +20,14 @@ def generate_data(state):
21
  4: 0.07
22
  }
23
 
 
 
 
 
 
 
 
 
24
  for _ in range(1000):
25
  if not state["running"]:
26
  break
@@ -30,14 +37,21 @@ def generate_data(state):
30
  error = machine_errors[error_key]
31
  downtime = error["downtime"]
32
 
33
- state['data']['raw'].append({
34
- "timestamp": current_time.strftime("%Y-%m-%d %H:%M:%S"),
35
- "event": "Machine Error",
36
- "error_code": error_key,
37
- "error_description": error["description"],
38
- "downtime_start": current_time.strftime("%Y-%m-%d %H:%M:%S"),
39
- "downtime_end": (current_time + downtime).strftime("%Y-%m-%d %H:%M:%S")
40
- })
 
 
 
 
 
 
 
41
 
42
  current_time += downtime
43
  else:
@@ -51,14 +65,21 @@ def generate_data(state):
51
 
52
  compliance = 'OK' if (0.3 <= position <= 0.5) and (0.2 <= orientation <= 0.6) else 'NOK'
53
 
54
- state['data']['raw'].append({
55
- "part_id": part_id,
56
- "timestamp": current_time.strftime("%Y-%m-%d %H:%M:%S"),
57
- "position": round(position, 4),
58
- "orientation": round(orientation, 4),
59
- "tool_id": tool_id,
60
- "compliance": compliance
61
- })
 
 
 
 
 
 
 
62
 
63
  print(f" - part {part_id} data generated")
64
  part_id += 1
@@ -67,22 +88,4 @@ def generate_data(state):
67
  current_time += timedelta(seconds=1)
68
 
69
  state["current_time"] = current_time
70
- state["part_id"] = part_id
71
-
72
- raw_data = []
73
- for row in state['data']['raw']:
74
- raw_data.append({
75
- "Part ID": row.get("part_id", "N/A"),
76
- "Timestamp": row.get("timestamp", "N/A"),
77
- "Position": row.get("position", "N/A"),
78
- "Orientation": row.get("orientation", "N/A"),
79
- "Tool ID": row.get("tool_id", "N/A"),
80
- "Compliance": row.get("compliance", "N/A"),
81
- "Event": row.get("event", "N/A"),
82
- "Error Code": row.get("error_code", "N/A"),
83
- "Error Description": row.get("error_description", "N/A"),
84
- "Downtime Start": row.get("downtime_start", "N/A"),
85
- "Downtime End": row.get("downtime_end", "N/A")
86
- })
87
-
88
- state['data']['raw_df'] = pd.DataFrame(raw_data)
 
12
  """
13
  current_time = state["current_time"] if state["current_time"] else datetime.now()
14
  part_id = state["part_id"] if state["part_id"] else 0
15
+
 
16
  non_compliance_rates = {
17
  1: 0.05,
18
  2: 0.10,
 
20
  4: 0.07
21
  }
22
 
23
+ # Initialize raw_df if it doesn't exist
24
+ if 'raw_df' not in state['data']:
25
+ state['data']['raw_df'] = pd.DataFrame(columns=[
26
+ "Part ID", "Timestamp", "Position", "Orientation", "Tool ID",
27
+ "Compliance", "Event", "Error Code", "Error Description",
28
+ "Downtime Start", "Downtime End"
29
+ ])
30
+
31
  for _ in range(1000):
32
  if not state["running"]:
33
  break
 
37
  error = machine_errors[error_key]
38
  downtime = error["downtime"]
39
 
40
+ new_row = pd.DataFrame([{
41
+ "Part ID": "N/A",
42
+ "Timestamp": current_time.strftime("%Y-%m-%d %H:%M:%S"),
43
+ "Position": "N/A",
44
+ "Orientation": "N/A",
45
+ "Tool ID": "N/A",
46
+ "Compliance": "N/A",
47
+ "Event": "Machine Error",
48
+ "Error Code": error_key,
49
+ "Error Description": error["description"],
50
+ "Downtime Start": current_time.strftime("%Y-%m-%d %H:%M:%S"),
51
+ "Downtime End": (current_time + downtime).strftime("%Y-%m-%d %H:%M:%S")
52
+ }])
53
+
54
+ state['data']['raw_df'] = pd.concat([state['data']['raw_df'], new_row], ignore_index=True)
55
 
56
  current_time += downtime
57
  else:
 
65
 
66
  compliance = 'OK' if (0.3 <= position <= 0.5) and (0.2 <= orientation <= 0.6) else 'NOK'
67
 
68
+ new_row = pd.DataFrame([{
69
+ "Part ID": part_id,
70
+ "Timestamp": current_time.strftime("%Y-%m-%d %H:%M:%S"),
71
+ "Position": round(position, 4),
72
+ "Orientation": round(orientation, 4),
73
+ "Tool ID": tool_id,
74
+ "Compliance": compliance,
75
+ "Event": "N/A",
76
+ "Error Code": "N/A",
77
+ "Error Description": "N/A",
78
+ "Downtime Start": "N/A",
79
+ "Downtime End": "N/A"
80
+ }])
81
+
82
+ state['data']['raw_df'] = pd.concat([state['data']['raw_df'], new_row], ignore_index=True)
83
 
84
  print(f" - part {part_id} data generated")
85
  part_id += 1
 
88
  current_time += timedelta(seconds=1)
89
 
90
  state["current_time"] = current_time
91
+ state["part_id"] = part_id
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/production/metrics/machine.py CHANGED
@@ -2,7 +2,7 @@ import pandas as pd
2
  import json
3
  import os
4
 
5
- def get_machine_metrics(raw_data):
6
  """
7
  Calculate machine efficiency metrics from raw production data.
8
  :param raw_data: collection of raw production data containing timestamps, downtime, and compliance information.
@@ -62,4 +62,9 @@ def get_machine_metrics(raw_data):
62
  "TRS": TRS,
63
  "MTBF": str(mtbf),
64
  "MTTR": str(mttr)
65
- }
 
 
 
 
 
 
2
  import json
3
  import os
4
 
5
+ def machine_metrics(raw_data):
6
  """
7
  Calculate machine efficiency metrics from raw production data.
8
  :param raw_data: collection of raw production data containing timestamps, downtime, and compliance information.
 
62
  "TRS": TRS,
63
  "MTBF": str(mtbf),
64
  "MTTR": str(mttr)
65
+ }
66
+
67
+ def fetch_issues(raw_data):
68
+ df = pd.DataFrame(raw_data)
69
+ issues = df[df["Event"] == "Machine Error"]
70
+ return issues[["Timestamp", "Event", "Error Code", "Error Description", "Downtime Start", "Downtime End"]]
src/production/metrics/tools.py CHANGED
@@ -35,7 +35,7 @@ def process_unique_tool(tool, raw_data):
35
  return tool, tool_data
36
 
37
 
38
- def get_tools_metrics(raw_data):
39
  """
40
  Process the raw production data to extract tool metrics in parallel.
41
  """
 
35
  return tool, tool_data
36
 
37
 
38
+ def tools_metrics(raw_data):
39
  """
40
  Process the raw production data to extract tool metrics in parallel.
41
  """