-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupload_dashboard.py
More file actions
69 lines (59 loc) · 2.24 KB
/
Copy pathupload_dashboard.py
File metadata and controls
69 lines (59 loc) · 2.24 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Upload whoop_dashboard.json into Aura as a _Neodash_Dashboard node.
Matches the schema used by NeoDash & Aura built-in Dashboards:
(:_Neodash_Dashboard {uuid, title, version, user, content, date})
After running, the dashboard appears in:
Aura Console -> Dashboards -> Load -> "Saved in this database"
"""
import json
import os
import uuid
import sys
from pathlib import Path
from datetime import datetime, timezone
from neo4j import GraphDatabase
DASHBOARD_PATH = Path("/Users/mbuchhorn/projects/healthgraph-agent/neodash/whoop_dashboard.json")
# Read .env directly (no python-dotenv needed)
env = {}
for line in Path("/Users/mbuchhorn/projects/healthgraph-agent/.env").read_text().splitlines():
if "=" in line and not line.startswith("#"):
k, _, v = line.partition("=")
env[k.strip()] = v.strip()
URI = env["NEO4J_URI"]
USER = env["NEO4J_USER"]
PW = env["NEO4J_PASSWORD"]
content = DASHBOARD_PATH.read_text()
dash = json.loads(content)
title = dash["title"]
version = dash["version"]
# Deterministic UUID per title so repeated runs MERGE not duplicate
DASHBOARD_UUID = str(uuid.uuid5(uuid.NAMESPACE_DNS, f"healthgraph.{title}"))
NOW = datetime.now(timezone.utc).isoformat()
driver = GraphDatabase.driver(URI, auth=(USER, PW))
with driver.session() as sess:
res = sess.run(
"""
MERGE (n:_Neodash_Dashboard {uuid: $uuid})
SET n.title = $title,
n.version = $version,
n.user = $user,
n.content = $content,
n.date = datetime($date)
RETURN n.uuid AS uuid, n.title AS title
""",
uuid=DASHBOARD_UUID,
title=title,
version=version,
user=env.get("AURA_INSTANCENAME", "cli-upload"),
content=content,
date=NOW,
).single()
print(f"Upserted dashboard: uuid={res['uuid']} title={res['title']!r}")
# List all dashboards as Aura's picker would
print("\nDashboards in database:")
for row in sess.run(
"MATCH (n:_Neodash_Dashboard) RETURN n.uuid AS uuid, n.title AS title, "
"toString(n.date) AS date, n.user AS author, n.version AS version "
"ORDER BY toLower(n.title)"
):
print(f" - [{row['version']}] {row['title']} (uuid={row['uuid']}, date={row['date']})")
driver.close()