refactor: integrate dashboard into server.py :8899, remove standalone dashboard

This commit is contained in:
hmo
2026-07-19 11:06:50 +08:00
parent 782a914a3c
commit b08bfa5d03
19 changed files with 300 additions and 330 deletions
+22
View File
@@ -0,0 +1,22 @@
import sqlite3
# Script connects to THIS db
proj_db = '/home/hmo/projects/MoFin/data/mofin.db'
# Real data lives in THIS db
real_db = '/home/hmo/web-dashboard/data/mofin.db'
for label, path in [("project", proj_db), ("real", real_db)]:
db = sqlite3.connect(path)
tables = [r[0] for r in db.execute("SELECT name FROM sqlite_master WHERE type='table'")]
print(f"{label} db ({path}): {len(tables)} tables")
for t in tables:
if t == 'todos':
sql = db.execute(f"SELECT sql FROM sqlite_master WHERE name='{t}'").fetchone()
print(f" {t}: {sql[0][:100] if sql else 'no sql'}")
elif t in ('holdings', 'holding_strategies', 'watchlist_stocks', 'portfolio_summary'):
cnt = db.execute(f"SELECT COUNT(*) FROM {t}").fetchone()[0]
print(f" {t}: {cnt} rows")
else:
cnt = db.execute(f"SELECT COUNT(*) FROM {t}").fetchone()[0]
print(f" {t}: {cnt} rows")
db.close()
+2
View File
@@ -0,0 +1,2 @@
from mofin_db import read_capital_flow_cache, write_live_prices, write_mtf_cache, write_capital_flow_cache
print("imports OK")
+6
View File
@@ -0,0 +1,6 @@
import urllib.request, json
r = urllib.request.urlopen("http://localhost:8899/api/portfolio")
d = json.loads(r.read())
for h in d.get('holdings', []):
if h['code'] in ('01888', '00700', '000657'):
print(f"{h['code']} {h['name']}: price={h['price']} curr={h.get('currency')}")
+8
View File
@@ -0,0 +1,8 @@
import sqlite3
for label, path in [("project", '/home/hmo/projects/MoFin/data/mofin.db'), ("real", '/home/hmo/web-dashboard/data/mofin.db')]:
db = sqlite3.connect(path)
sql = db.execute("SELECT sql FROM sqlite_master WHERE name='todos'").fetchone()
print(f"=== {label}: {path} ===")
print(sql[0] if sql else "NOT FOUND")
db.close()
+6
View File
@@ -0,0 +1,6 @@
"""Fix DB_PATH in self_todo_executor.py"""
path = '/home/hmo/.hermes/profiles/position-analyst/scripts/self_todo_executor.py'
content = open(path).read()
content = content.replace('projects/MoFin/data', 'web-dashboard/data')
open(path, 'w').write(content)
print("DB_PATH fixed to web-dashboard/data/mofin.db")
+47
View File
@@ -0,0 +1,47 @@
"""Fix: unify todos table schema across project and real DB"""
import sqlite3
project_db = '/home/hmo/projects/MoFin/data/mofin.db'
real_db = '/home/hmo/web-dashboard/data/mofin.db'
# Zhiwei's canonical schema (from project db)
target_schema = """
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
description TEXT,
status TEXT DEFAULT 'pending',
priority TEXT DEFAULT 'medium',
source TEXT DEFAULT 'manual',
fix_action TEXT,
retry_count INTEGER DEFAULT 0,
note TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
"""
def ensure_todos(db_path, label):
db = sqlite3.connect(db_path)
existing = db.execute("SELECT name FROM sqlite_master WHERE name='todos'").fetchone()
if not existing:
db.execute(f"CREATE TABLE todos ({target_schema})")
print(f"{label}: created todos table")
else:
# Ensure all columns exist
existing_cols = {r[1] for r in db.execute("PRAGMA table_info(todos)")}
needed = {'title', 'description', 'status', 'priority', 'source', 'fix_action',
'retry_count', 'note', 'created_at', 'updated_at'}
missing = needed - existing_cols
for col in missing:
if col in ('retry_count',):
db.execute(f"ALTER TABLE todos ADD COLUMN {col} INTEGER DEFAULT 0")
elif col in ('created_at', 'updated_at'):
db.execute(f"ALTER TABLE todos ADD COLUMN {col} TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
else:
db.execute(f"ALTER TABLE todos ADD COLUMN {col} TEXT")
print(f"{label}: checked, {len(missing)} missing columns added" if missing else f"{label}: schema OK")
db.commit()
db.close()
ensure_todos(project_db, "project db")
ensure_todos(real_db, "real db")
print("\nDone. Both DBs now have matching todos schema.")
+7
View File
@@ -0,0 +1,7 @@
import sqlite3
db = sqlite3.connect('/home/hmo/web-dashboard/data/mofin.db')
tables = [r[0] for r in db.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name")]
for t in tables:
cols = [r[1] for r in db.execute(f"PRAGMA table_info({t})")]
print(f"{t}: {', '.join(cols)}")
db.close()
+7
View File
@@ -0,0 +1,7 @@
import urllib.request,json,time
r = urllib.request.Request(
"https://push2.eastmoney.com/api/qt/stock/get?secid=116.00700&fields=f43,f170&fltt=2",
headers={"User-Agent": "Mozilla/5.0"})
start = time.time()
resp = json.loads(urllib.request.urlopen(r, timeout=5).read())
print(f"OK {time.time()-start:.1f}s price={resp.get('data',{}).get('f43','?')}")
+32
View File
@@ -0,0 +1,32 @@
"""Verify self_todo_executor works with real DB"""
import subprocess
script = '/home/hmo/.hermes/profiles/position-analyst/scripts/self_todo_executor.py'
# Test 1: DB_PATH
content = open(script).read()
if 'web-dashboard/data/mofin.db' in content:
print("DB_PATH: OK")
else:
print("DB_PATH: WRONG")
exit(1)
# Test 2: script can import and run
try:
import importlib.util
spec = importlib.util.spec_from_file_location("executor", script)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
print("Import: OK")
except Exception as e:
print(f"Import: FAIL -> {e}")
exit(1)
# Test 3: get_pending works
try:
rows = mod.get_pending()
print(f"get_pending: OK ({len(rows)} pending)")
except Exception as e:
print(f"get_pending: FAIL -> {e}")
exit(1)
print("\nAll checks passed.")