Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit 3a18f95

Browse files
committed
add dashboards related endpoints
1 parent d050600 commit 3a18f95

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/data_neuron/report_cmd/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ def list_dashboards():
1717
return [f.split('.')[0] for f in os.listdir(dashboards_dir) if f.endswith('.yml')]
1818

1919

20+
def load_dashboard(dashboard_name):
21+
dashboard_file = os.path.join("dashboards", f"{dashboard_name}.yml")
22+
if not os.path.exists(dashboard_file):
23+
return None
24+
with open(dashboard_file, 'r') as f:
25+
return yaml.safe_load(f)
26+
27+
2028
def load_dashboard(dashboard_name):
2129
dashboard_file = os.path.join("dashboards", f"{dashboard_name}.yml")
2230
with open(dashboard_file, 'r') as f:

src/data_neuron/server.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .context_init_cmd.main import init_context
44
from .ask_cmd.main import query as ask_query
55
from .chat_cmd.main import process_chat_message
6-
from .report_cmd.main import generate_report_html
6+
from .report_cmd.main import generate_report_html, list_dashboards, load_dashboard
77
import os
88

99
app = Flask(__name__)
@@ -52,6 +52,27 @@ def generate_report():
5252
return jsonify({"error": str(e)}), 500
5353

5454

55+
@app.route('/dashboards', methods=['GET'])
56+
def get_dashboards():
57+
try:
58+
dashboards = list_dashboards()
59+
return jsonify({"dashboards": dashboards})
60+
except Exception as e:
61+
return jsonify({"error": str(e)}), 500
62+
63+
64+
@app.route('/dashboards/<dashboard_id>', methods=['GET'])
65+
def get_dashboard(dashboard_id):
66+
try:
67+
dashboard = load_dashboard(dashboard_id)
68+
if dashboard:
69+
return jsonify(dashboard)
70+
else:
71+
return jsonify({"error": "Dashboard not found"}), 404
72+
except Exception as e:
73+
return jsonify({"error": str(e)}), 500
74+
75+
5576
def run_server(host='0.0.0.0', port=8084, debug=False):
5677
app.run(host=host, port=port, debug=debug)
5778

0 commit comments

Comments
 (0)