Spaces:
Sleeping
Sleeping
mriusero
commited on
Commit
·
3d63627
1
Parent(s):
9ef3aa7
feat: get downtimes
Browse files- data/downtimes.json +18 -0
- data/status.json +28 -1
- src/agent/mistral_agent.py +3 -0
- src/agent/tools/__init__.py +2 -1
- src/agent/tools/check_downtines.py +27 -0
- src/agent/tools/check_production.py +12 -7
- src/production/metrics/machine.py +5 -1
- src/ui/sidebar.py +1 -1
- tools.json +12 -0
data/downtimes.json
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"Timestamp":"2025-06-11 00:07:38",
|
4 |
+
"Event":"Machine Error",
|
5 |
+
"Error Code":"E003",
|
6 |
+
"Error Description":"Material Jam",
|
7 |
+
"Downtime Start":"2025-06-11 00:07:38",
|
8 |
+
"Downtime End":"2025-06-11 00:15:38"
|
9 |
+
},
|
10 |
+
{
|
11 |
+
"Timestamp":"2025-06-11 00:17:40",
|
12 |
+
"Event":"Machine Error",
|
13 |
+
"Error Code":"E007",
|
14 |
+
"Error Description":"Wear and Tear of Parts",
|
15 |
+
"Downtime Start":"2025-06-11 00:17:40",
|
16 |
+
"Downtime End":"2025-06-11 00:32:40"
|
17 |
+
}
|
18 |
+
]
|
data/status.json
CHANGED
@@ -1 +1,28 @@
|
|
1 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"opening_time": "0 days 00:28:14",
|
3 |
+
"required_time": "0 days 00:28:14",
|
4 |
+
"unplanned_stop_time": "0 days 00:23:00",
|
5 |
+
"operating_time": "0 days 00:05:14",
|
6 |
+
"net_time": "0 days 00:05:14",
|
7 |
+
"useful_time": "0 days 00:04:53",
|
8 |
+
"quality_rate": 93.31,
|
9 |
+
"quality_rate_tool_1": 96.18,
|
10 |
+
"quality_rate_tool_2": 91.67,
|
11 |
+
"operating_rate": 100.0,
|
12 |
+
"availability_rate": 18.54,
|
13 |
+
"OEE": 17.3,
|
14 |
+
"MTBF": "0 days 00:02:37",
|
15 |
+
"MTTR": "0 days 00:11:30",
|
16 |
+
"tool_1_cp_pos": 0.673,
|
17 |
+
"tool_1_cpk_pos": 0.6552,
|
18 |
+
"tool_1_cp_ori": 0.7081,
|
19 |
+
"tool_1_cpk_ori": 0.6937,
|
20 |
+
"tool_2_cp_pos": 0.4325,
|
21 |
+
"tool_2_cpk_pos": 0.4278,
|
22 |
+
"tool_2_cp_ori": 0.6556,
|
23 |
+
"tool_2_cpk_ori": 0.6436,
|
24 |
+
"all_cp_pos": 0.5155,
|
25 |
+
"all_cpk_pos": 0.5115,
|
26 |
+
"all_cp_ori": 0.681,
|
27 |
+
"all_cpk_ori": 0.6803
|
28 |
+
}
|
src/agent/mistral_agent.py
CHANGED
@@ -8,6 +8,7 @@ from src.agent.tools import (
|
|
8 |
retrieve_knowledge,
|
9 |
visit_webpage,
|
10 |
get_production_status,
|
|
|
11 |
)
|
12 |
|
13 |
load_dotenv()
|
@@ -24,6 +25,7 @@ class MistralAgent:
|
|
24 |
"retrieve_knowledge": retrieve_knowledge,
|
25 |
"visit_webpage": visit_webpage,
|
26 |
"get_production_status": get_production_status,
|
|
|
27 |
}
|
28 |
self.tools = self.get_tools()
|
29 |
|
@@ -36,5 +38,6 @@ class MistralAgent:
|
|
36 |
retrieve_knowledge,
|
37 |
visit_webpage,
|
38 |
get_production_status,
|
|
|
39 |
]
|
40 |
).get('tools')
|
|
|
8 |
retrieve_knowledge,
|
9 |
visit_webpage,
|
10 |
get_production_status,
|
11 |
+
get_downtimes,
|
12 |
)
|
13 |
|
14 |
load_dotenv()
|
|
|
25 |
"retrieve_knowledge": retrieve_knowledge,
|
26 |
"visit_webpage": visit_webpage,
|
27 |
"get_production_status": get_production_status,
|
28 |
+
"get_downtimes": get_downtimes,
|
29 |
}
|
30 |
self.tools = self.get_tools()
|
31 |
|
|
|
38 |
retrieve_knowledge,
|
39 |
visit_webpage,
|
40 |
get_production_status,
|
41 |
+
get_downtimes,
|
42 |
]
|
43 |
).get('tools')
|
src/agent/tools/__init__.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from .calculator import calculate_sum
|
2 |
from .retrieve_knowledge import retrieve_knowledge
|
3 |
from .visit_webpage import visit_webpage
|
4 |
-
from .check_production import get_production_status
|
|
|
|
1 |
from .calculator import calculate_sum
|
2 |
from .retrieve_knowledge import retrieve_knowledge
|
3 |
from .visit_webpage import visit_webpage
|
4 |
+
from .check_production import get_production_status
|
5 |
+
from .check_downtines import get_downtimes
|
src/agent/tools/check_downtines.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from src.agent.utils.tooling import tool
|
3 |
+
|
4 |
+
@tool
|
5 |
+
def get_downtimes() -> str:
|
6 |
+
"""
|
7 |
+
This tool retrieves the production downtimes including :
|
8 |
+
- Timestamps of downtimes starts and endings,
|
9 |
+
- Event, Error Code and Error Description
|
10 |
+
"""
|
11 |
+
try:
|
12 |
+
with open("data/downtimes.json", "r") as f:
|
13 |
+
json_string = f.read()
|
14 |
+
|
15 |
+
data = json.loads(json_string)
|
16 |
+
|
17 |
+
if data is None or len(data) == 0:
|
18 |
+
result = "No downtimes recorded yet. Please check the production status or wait for downtimes to occur."
|
19 |
+
else:
|
20 |
+
result = "## Downtimes:\n\n"
|
21 |
+
result += json_string
|
22 |
+
|
23 |
+
return result
|
24 |
+
|
25 |
+
except Exception as e:
|
26 |
+
print(f"Error getting production status: {e}")
|
27 |
+
return None
|
src/agent/tools/check_production.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from src.agent.utils.tooling import tool
|
2 |
|
3 |
@tool
|
@@ -9,13 +10,17 @@ def get_production_status() -> str:
|
|
9 |
with open("data/status.json", "r") as f:
|
10 |
json_string = f.read()
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
return result
|
20 |
|
21 |
except Exception as e:
|
|
|
1 |
+
import json
|
2 |
from src.agent.utils.tooling import tool
|
3 |
|
4 |
@tool
|
|
|
10 |
with open("data/status.json", "r") as f:
|
11 |
json_string = f.read()
|
12 |
|
13 |
+
data = json.loads(json_string)
|
14 |
+
|
15 |
+
if data == {}:
|
16 |
+
result = "Production has not started yet."
|
17 |
+
|
18 |
+
elif data["opening_time"] == "0 days 00:00:00":
|
19 |
+
result = "Production has not started yet."
|
20 |
+
else:
|
21 |
+
result = "## Production status:\n\n"
|
22 |
+
result += json_string
|
23 |
+
|
24 |
return result
|
25 |
|
26 |
except Exception as e:
|
src/production/metrics/machine.py
CHANGED
@@ -62,4 +62,8 @@ async def machine_metrics(raw_data):
|
|
62 |
async def fetch_issues(raw_data):
|
63 |
df = pd.DataFrame(raw_data)
|
64 |
issues = df[df["Event"] == "Machine Error"]
|
65 |
-
|
|
|
|
|
|
|
|
|
|
62 |
async def fetch_issues(raw_data):
|
63 |
df = pd.DataFrame(raw_data)
|
64 |
issues = df[df["Event"] == "Machine Error"]
|
65 |
+
selected_issues = issues[
|
66 |
+
["Timestamp", "Event", "Error Code", "Error Description", "Downtime Start", "Downtime End"]
|
67 |
+
]
|
68 |
+
selected_issues.to_json('data/downtimes.json', orient="records", indent=4)
|
69 |
+
return selected_issues
|
src/ui/sidebar.py
CHANGED
@@ -41,7 +41,7 @@ def sidebar_ui(state, width=700, visible=True):
|
|
41 |
examples=[
|
42 |
# ["What is the sum of 1+1 ?"],
|
43 |
["How is the production process going?"],
|
44 |
-
["What are the common
|
45 |
["Can you explain me Cp & Cpk KPIs ?"],
|
46 |
# ["Can you provide insights on equipment performance?"],
|
47 |
# ["How can I optimize the workflow in the production area?"],
|
|
|
41 |
examples=[
|
42 |
# ["What is the sum of 1+1 ?"],
|
43 |
["How is the production process going?"],
|
44 |
+
["What are the common downtimes faced in production?"],
|
45 |
["Can you explain me Cp & Cpk KPIs ?"],
|
46 |
# ["Can you provide insights on equipment performance?"],
|
47 |
# ["How can I optimize the workflow in the production area?"],
|
tools.json
CHANGED
@@ -71,5 +71,17 @@
|
|
71 |
"required": []
|
72 |
}
|
73 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
]
|
|
|
71 |
"required": []
|
72 |
}
|
73 |
}
|
74 |
+
},
|
75 |
+
{
|
76 |
+
"type": "function",
|
77 |
+
"function": {
|
78 |
+
"name": "get_downtimes",
|
79 |
+
"description": "This tool retrieves the production downtimes including :",
|
80 |
+
"parameters": {
|
81 |
+
"type": "object",
|
82 |
+
"properties": {},
|
83 |
+
"required": []
|
84 |
+
}
|
85 |
+
}
|
86 |
}
|
87 |
]
|