容器化改造
This commit is contained in:
parent
98fd8ded5f
commit
f0b4fb76dc
12
common.py
12
common.py
|
|
@ -89,12 +89,16 @@ def register(factor_code, display_name, table, category, desc,
|
|||
}
|
||||
with db.factor_conn() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("SELECT column_name FROM information_schema.columns "
|
||||
"WHERE table_schema=DATABASE() AND table_name='factor_metadata'")
|
||||
cols = {r[0] for r in cur.fetchall()}
|
||||
# ShardingSphere 代理不支持 information_schema 内省 → 用真实查询取列名
|
||||
cur.execute("SELECT * FROM factor_metadata LIMIT 0")
|
||||
cols = [d[0] for d in (cur.description or [])]
|
||||
if not cols: # 极端兜底:代理连列元数据都不给时,用平台已知 schema
|
||||
cols = ["factor_code", "display_name", "target_ds_name", "target_table_name",
|
||||
"start_date", "end_date", "author", "description", "category",
|
||||
"frequency", "status", "factor_type"]
|
||||
use = [k for k in values if k in cols]
|
||||
if "factor_code" not in use:
|
||||
raise RuntimeError("factor_metadata 无 factor_code 列?请核实线上 schema")
|
||||
raise RuntimeError(f"factor_metadata 取不到 factor_code 列;实际列: {cols}")
|
||||
ph = ",".join(["%s"] * len(use))
|
||||
upd = ",".join(f"{k}=VALUES({k})" for k in use if k != "factor_code")
|
||||
cur.execute(
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ services:
|
|||
env_file: .env
|
||||
restart: unless-stopped
|
||||
command: sleep infinity
|
||||
volumes:
|
||||
- .:/app # 代码卷挂载:改码即生效,不用重构镜像(开发期)。冻结成 prod 镜像时删此行并 --build。
|
||||
# 跨机部署(默认):.env 三处用 LAN IP,默认 bridge 网络出网到 LAN 即可。
|
||||
# 与 astock-kg 同机同网时,改用服务名连基座 PG——取消下面两行注释并填网络名:
|
||||
# networks: [default, akg_net]
|
||||
|
|
|
|||
19
run.py
19
run.py
|
|
@ -11,6 +11,10 @@ daily 模式:不给 --date 则取今天;start=end=date。history 模式:
|
|||
"""
|
||||
import argparse
|
||||
import datetime as dt
|
||||
import warnings
|
||||
|
||||
# pandas 用 DBAPI 连接读 SQL 会 warn(无害,功能正常)——静音保持日志干净
|
||||
warnings.filterwarnings("ignore", message=".*only supports SQLAlchemy.*")
|
||||
|
||||
import common
|
||||
import db
|
||||
|
|
@ -35,6 +39,21 @@ def cmd_views():
|
|||
except Exception as e: # noqa: BLE001
|
||||
print(f" ❌ {name}: {e!r}")
|
||||
|
||||
fronts = [
|
||||
("热度 heat(trade_date)", "heat", "SELECT MAX(trade_date) FROM stock_fund_heat_scores"),
|
||||
("一致预期 consensus(asof)", "pg", "SELECT MAX(asof_date) FROM v_factor_consensus"),
|
||||
("事件 events(disclosure)", "pg", "SELECT MAX(disclosure_date) FROM v_factor_events"),
|
||||
("传导 transmission(scan)", "pg", "SELECT MAX(scan_date) FROM v_factor_transmission"),
|
||||
("行情 gp_day_data(ts)", "price", "SELECT MAX(`timestamp`) FROM gp_day_data"),
|
||||
]
|
||||
print("\n数据前沿(各源最新日期——build 的 --date 照此选,别选没数据的未来日):")
|
||||
for name, src, sql in fronts:
|
||||
try:
|
||||
df = db.read_pg(sql) if src == "pg" else db.read_mysql(src, sql)
|
||||
print(f" {name}: {df.iloc[0, 0]}")
|
||||
except Exception as e: # noqa: BLE001
|
||||
print(f" {name}: ❌ {e!r}")
|
||||
|
||||
|
||||
_META = {
|
||||
"akg_upside": ("astock-kg 预期空间", "分析师一致预期目标价隐含收益率(target_mid/price-1)"),
|
||||
|
|
|
|||
Loading…
Reference in New Issue