Spaces:
Build error
Build error
Upload history_agent.py
Browse files- agents/history_agent.py +17 -4
agents/history_agent.py
CHANGED
|
@@ -5,7 +5,16 @@ from datetime import datetime
|
|
| 5 |
|
| 6 |
class HistoryAgent:
|
| 7 |
def __init__(self):
|
| 8 |
-
self.entries = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def log_entry(self, date: str, entry_type: str, site: str):
|
| 11 |
self.entries.append({
|
|
@@ -15,12 +24,16 @@ class HistoryAgent:
|
|
| 15 |
})
|
| 16 |
|
| 17 |
def get_history(self):
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
def get_latest(self, entry_type=None):
|
| 21 |
-
filtered = [
|
|
|
|
|
|
|
|
|
|
| 22 |
if not filtered:
|
| 23 |
return None
|
| 24 |
-
return sorted(filtered, key=lambda x: x["date"])[-1]
|
| 25 |
|
| 26 |
|
|
|
|
| 5 |
|
| 6 |
class HistoryAgent:
|
| 7 |
def __init__(self):
|
| 8 |
+
self.entries = [
|
| 9 |
+
{"date": "06/15/2025", "type": "Pod", "site": "left_stomach"},
|
| 10 |
+
{"date": "06/16/2025", "type": "Sensor", "site": "left_leg"},
|
| 11 |
+
{"date": "06/18/2025", "type": "Pod", "site": "left_arm"},
|
| 12 |
+
{"date": "06/21/2025", "type": "Pod", "site": "left_stomach"},
|
| 13 |
+
{"date": "06/24/2025", "type": "Pod", "site": "left_leg"},
|
| 14 |
+
{"date": "06/26/2025", "type": "Sensor", "site": "right_leg"},
|
| 15 |
+
{"date": "06/27/2025", "type": "Pod", "site": "right_leg"},
|
| 16 |
+
{"date": "06/30/2025", "type": "Pod", "site": "right_arm"}
|
| 17 |
+
]
|
| 18 |
|
| 19 |
def log_entry(self, date: str, entry_type: str, site: str):
|
| 20 |
self.entries.append({
|
|
|
|
| 24 |
})
|
| 25 |
|
| 26 |
def get_history(self):
|
| 27 |
+
# Sort by date ascending
|
| 28 |
+
return sorted(self.entries, key=lambda x: datetime.strptime(x["date"], "%m/%d/%Y"))
|
| 29 |
|
| 30 |
def get_latest(self, entry_type=None):
|
| 31 |
+
filtered = [
|
| 32 |
+
e for e in self.entries
|
| 33 |
+
if entry_type is None or e["type"].lower() == entry_type.lower()
|
| 34 |
+
]
|
| 35 |
if not filtered:
|
| 36 |
return None
|
| 37 |
+
return sorted(filtered, key=lambda x: datetime.strptime(x["date"], "%m/%d/%Y"))[-1]
|
| 38 |
|
| 39 |
|