Spaces:
Sleeping
Sleeping
refactor: removed unused user_data module and simplified logs handling
Browse files- logs.py +24 -0
- user_data.py +0 -13
logs.py
CHANGED
|
@@ -11,3 +11,27 @@ def save_log(user_id: int, history: dict, response: str):
|
|
| 11 |
)
|
| 12 |
with open("recommender.log", "a", encoding="utf-8") as f:
|
| 13 |
f.write(log_entry)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
)
|
| 12 |
with open("recommender.log", "a", encoding="utf-8") as f:
|
| 13 |
f.write(log_entry)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def get_user_history(user_id: int) -> dict:
|
| 17 |
+
"""
|
| 18 |
+
Lê o arquivo recommender.log e retorna o último histórico do usuário.
|
| 19 |
+
"""
|
| 20 |
+
history = {}
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
with open("recommender.log", "r", encoding="utf-8") as f:
|
| 24 |
+
lines = f.readlines()
|
| 25 |
+
|
| 26 |
+
current_user = None
|
| 27 |
+
|
| 28 |
+
for line in lines:
|
| 29 |
+
if line.startswith("Usuário:"):
|
| 30 |
+
current_user = int(line.split(":")[1].strip())
|
| 31 |
+
elif line.startswith("Histórico:") and current_user == user_id:
|
| 32 |
+
history = eval(line.split(":", 1)[1].strip())
|
| 33 |
+
|
| 34 |
+
except FileNotFoundError:
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
return history
|
user_data.py
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
user_histories = {
|
| 2 |
-
1: {'fiction': 5, 'non_fiction': 2, 'science': 0, 'fantasy': 0},
|
| 3 |
-
2: {'fiction': 1, 'non_fiction': 4, 'science': 1, 'fantasy': 2},
|
| 4 |
-
3: {'fiction': 0, 'non_fiction': 1, 'science': 5, 'fantasy': 0},
|
| 5 |
-
4: {'fiction': 1, 'non_fiction': 0, 'science': 0, 'fantasy': 6},
|
| 6 |
-
}
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def get_user_history(user_id: int) -> dict:
|
| 10 |
-
"""
|
| 11 |
-
Retorna o histórico de compras do usuário.
|
| 12 |
-
"""
|
| 13 |
-
return user_histories.get(user_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|