Skip to content

Commit 53ebba6

Browse files
committed
add hash for gexf
1 parent d38fef4 commit 53ebba6

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

backend/app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def ai_process():
9393
def explain_topic():
9494
try:
9595
data = request.get_json()
96-
print("Received explain-topic request with data:", {k: v for k, v in data.items() if k != 'apiKey'}) # Log data without API key
96+
# print("Received explain-topic request with data:", {k: v for k, v in data.items() if k != 'apiKey'}) # Log data without API key
9797

9898
topic = data.get("topic", "")
9999
search_term = data.get("searchTerm", "")

backend/app/services/gexy_node_service.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import psutil
44
import networkx as nx
55
from datetime import datetime
6+
import hashlib
7+
from pathlib import Path
68

79

810
class GexfNodeGenerator:
911
def __init__(self):
1012
self.save_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "gexf")
1113
os.makedirs(self.save_dir, exist_ok=True)
12-
self.gexf_path = os.path.join(self.save_dir, "generated_nodes.gexf")
1314

1415
# DuckDB connection (copied from TopicService)
1516
db_path = os.path.join(
@@ -33,13 +34,30 @@ def __init__(self):
3334
f"Database not found at {db_path}. Please ensure the database file exists before running the application."
3435
)
3536

37+
def get_unique_filename(self, topics):
38+
"""Generate a unique filename based on the topics"""
39+
# Sort topics to ensure consistent hash for same topics in different order
40+
sorted_topics = sorted(topics)
41+
# Create a hash of the topics
42+
topics_str = "|".join(sorted_topics)
43+
hash_object = hashlib.md5(topics_str.encode())
44+
hash_hex = hash_object.hexdigest()[:12] # Use first 12 characters of hash
45+
# Include timestamp to ensure uniqueness even for same topics
46+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
47+
return f"topics_{hash_hex}_{timestamp}.gexf"
48+
3649
def generate_gexf_nodes_for_topics(self, topics):
3750
"""
3851
Generate and store a GEXF file for all repos containing any of the given topics.
3952
Returns the path to the generated GEXF file.
4053
"""
4154
if not topics:
4255
return None
56+
57+
# Generate unique filename for this search
58+
filename = self.get_unique_filename(topics)
59+
gexf_path = os.path.join(self.save_dir, filename)
60+
4361
topics_lower = [t.lower() for t in topics]
4462
placeholders = ",".join(["?"] * len(topics_lower))
4563

@@ -150,5 +168,5 @@ def generate_gexf_nodes_for_topics(self, topics):
150168
# print(f"Years range: {min(years)} to {max(years)}")
151169
# print(f"Number of nodes with year=0: {years.count(0)}")
152170

153-
nx.write_gexf(G, self.gexf_path)
154-
return self.gexf_path # Return the file path
171+
nx.write_gexf(G, gexf_path)
172+
return gexf_path # Return the unique file path

0 commit comments

Comments
 (0)