Leonydis137 commited on
Commit
8e88cdf
·
verified ·
1 Parent(s): fe11cee

Create analysis_tools.py

Browse files
Files changed (1) hide show
  1. analysis_tools.py +48 -0
analysis_tools.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import matplotlib.pyplot as plt
3
+ import networkx as nx
4
+ from .memory_manager import retrieve_relevant
5
+
6
+
7
+ def analyze_sentiment_topics(conversation: list) -> dict:
8
+ """Return placeholder sentiment and key topics."""
9
+ sentiments = ["Positive", "Neutral", "Negative"]
10
+ sentiment = np.random.choice(sentiments, p=[0.4, 0.4, 0.2])
11
+ topics = ["AI Ethics", "Policy", "Culture", "Technology", "Future"]
12
+ return {
13
+ "sentiment": sentiment,
14
+ "topics": np.random.choice(topics, 3, replace=False).tolist()
15
+ }
16
+
17
+
18
+ def plot_participation(conversation: list, save_path: str) -> str:
19
+ """Save agent participation bar chart."""
20
+ agents = [msg['agent'] for msg in conversation]
21
+ counts = {agent: agents.count(agent) for agent in set(agents)}
22
+ plt.figure()
23
+ plt.bar(counts.keys(), counts.values())
24
+ plt.title("Agent Participation")
25
+ plt.tight_layout()
26
+ plt.savefig(save_path)
27
+ return save_path
28
+
29
+
30
+ def generate_knowledge_graph(conversation: list, save_path: str) -> str:
31
+ """Save a simple directed graph of agent interactions."""
32
+ G = nx.DiGraph()
33
+ # Add nodes for each unique agent
34
+ agents = [msg['agent'] for msg in conversation]
35
+ for agent in set(agents):
36
+ G.add_node(agent)
37
+ # Randomly connect nodes
38
+ import random
39
+ nodes = list(G.nodes)
40
+ for _ in range(len(nodes) * 2):
41
+ a, b = random.sample(nodes, 2)
42
+ G.add_edge(a, b)
43
+ plt.figure()
44
+ pos = nx.spring_layout(G)
45
+ nx.draw(G, pos, with_labels=True, node_size=1500)
46
+ plt.title("Knowledge Graph")
47
+ plt.savefig(save_path)
48
+ return save_path