Repository navigation
Expand file tree
/
Copy pathjarvis_analytics.py
More file actions
53 lines (42 loc) · 1.71 KB
/
Copy pathjarvis_analytics.py
File metadata and controls
53 lines (42 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
import os
from collections import Counter
SESSION_LOG_FILE = 'session_logs.jsonl'
USER_FILE = 'users.json'
def load_sessions():
if not os.path.exists(SESSION_LOG_FILE):
return []
with open(SESSION_LOG_FILE, 'r') as f:
return [json.loads(line) for line in f if line.strip()]
def analyze_user(username):
sessions = load_sessions()
user_sessions = [s for s in sessions if s['username'].lower() == username.lower()]
if not user_sessions:
return f"I have no data on {username}, sir."
total = len(user_sessions)
hobbies = Counter([s['hobby_name'] for s in user_sessions])
fav_hobby = hobbies.most_common(1)[0][0] if hobbies else "None"
user_missions = 0
if os.path.exists(USER_FILE):
with open(USER_FILE, 'r') as f:
users = json.load(f)
if username in users:
user_missions = users[username].get('missions_completed', 0)
return f"Profile for {username}: {total} tracked sessions. Favorite speciality: {fav_hobby}. Total missions: {user_missions}."
def main():
print("=" * 45)
print(" 🧠 JARVIS ANALYTICS ENGINE ")
print("=" * 45)
if not os.path.exists(SESSION_LOG_FILE):
print("No session logs found. Run a simulation first!")
return
sessions = load_sessions()
print(f"Jarvis Report: {len(sessions)} total recorded sessions across all agents.")
unique_agents = list(set(s['username'] for s in sessions))
print(f"Active agents observed: {', '.join(unique_agents)}")
print("\n--- Detailed Jarvis Analysis ---")
for agent in unique_agents:
print(analyze_user(agent))
print("=" * 45)
if __name__ == "__main__":
main()