Spaces:
Sleeping
Sleeping
github-actions[bot] commited on
Commit ·
3f3a7a8
1
Parent(s): 553ea4b
Auto-deploy backend from GitHub Actions
Browse files- app/services/graph_service.py +16 -17
app/services/graph_service.py
CHANGED
|
@@ -42,7 +42,6 @@ async def get_user_skill_web(user_id: str) -> dict | None:
|
|
| 42 |
"""
|
| 43 |
|
| 44 |
# Query 2: Mastered Skills with Aggregated Domains
|
| 45 |
-
# A single skill can belong to multiple domains, so we collect them into an array.
|
| 46 |
skills_query = """
|
| 47 |
MATCH (u:User {id: $user_id})-[m:MASTERED]->(k:Skill)
|
| 48 |
OPTIONAL MATCH (k)-[:BELONGS_TO]->(d:Domain)-[:FALLS_UNDER]->(s:Strand)
|
|
@@ -66,28 +65,28 @@ async def get_user_skill_web(user_id: str) -> dict | None:
|
|
| 66 |
return None
|
| 67 |
|
| 68 |
# Format Strand distribution cleanly (e.g., {"stem": 1400, "abm": 50})
|
| 69 |
-
xp_distribution = {
|
|
|
|
|
|
|
| 70 |
|
| 71 |
# Build strict JSON objects, eliminating frontend Regex parsing
|
| 72 |
top_skills = []
|
| 73 |
for rec in skill_records:
|
| 74 |
strands = rec["strands"]
|
| 75 |
-
# Default to the first strand found, or fallback to 'stem' if detached
|
| 76 |
primary_strand = strands[0].lower() if strands else "stem"
|
| 77 |
-
|
| 78 |
-
top_skills.append(
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
except Exception as e:
|
| 92 |
logger.error(f"Failed to fetch Skill Web from Neo4j: {str(e)}")
|
| 93 |
return None
|
|
|
|
| 42 |
"""
|
| 43 |
|
| 44 |
# Query 2: Mastered Skills with Aggregated Domains
|
|
|
|
| 45 |
skills_query = """
|
| 46 |
MATCH (u:User {id: $user_id})-[m:MASTERED]->(k:Skill)
|
| 47 |
OPTIONAL MATCH (k)-[:BELONGS_TO]->(d:Domain)-[:FALLS_UNDER]->(s:Strand)
|
|
|
|
| 65 |
return None
|
| 66 |
|
| 67 |
# Format Strand distribution cleanly (e.g., {"stem": 1400, "abm": 50})
|
| 68 |
+
xp_distribution = {
|
| 69 |
+
record["strand"].lower(): record["xp"] for record in xp_records
|
| 70 |
+
}
|
| 71 |
|
| 72 |
# Build strict JSON objects, eliminating frontend Regex parsing
|
| 73 |
top_skills = []
|
| 74 |
for rec in skill_records:
|
| 75 |
strands = rec["strands"]
|
|
|
|
| 76 |
primary_strand = strands[0].lower() if strands else "stem"
|
| 77 |
+
|
| 78 |
+
top_skills.append(
|
| 79 |
+
{
|
| 80 |
+
"skill_name": rec["skill_name"],
|
| 81 |
+
"domains": rec["domains"], # Array of strings mapping many-to-many
|
| 82 |
+
"strand": primary_strand,
|
| 83 |
+
"level": rec["level"],
|
| 84 |
+
"xp": rec["xp"],
|
| 85 |
+
}
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
return {"xp_distribution": xp_distribution, "top_skills": top_skills}
|
| 89 |
+
|
|
|
|
| 90 |
except Exception as e:
|
| 91 |
logger.error(f"Failed to fetch Skill Web from Neo4j: {str(e)}")
|
| 92 |
return None
|