x-forecast · paper portfolio
Research · Live

复现工具包

克隆 repo, 跑一条命令, 拿到跟本站完全一致的 NAV 数字. 为面试 demo 设计.

一句话复现

git clone https://github.com/<account>/x-forecast.git && cd x-forecast && npm install && pip install -r scripts/requirements.txt && npm run data:all && npm run dev
然后打开 http://localhost:4321 — 数字跟生产环境一致.

分步

  1. 1. 前置条件
    • Node.js ≥ 18 (test: node -v)
    • Python ≥ 3.9 (test: python --version)
    • git ≥ 2.30
  2. 2. Clone
    git clone https://github.com/<account>/x-forecast.git
    cd x-forecast
  3. 3. 装依赖
    npm install
    pip install -r scripts/requirements.txt
  4. 4. 拉价 + 算 NAV
    npm run data:all
    # → python scripts/fetch_prices.py
    # → python scripts/compute_nav.py
    产出 data/prices/*.csv 和 data/nav/nav-history.json. 网络通畅约 1 分钟.
  5. 5. 本地预览
    npm run dev   # http://localhost:4321
    npm run build # → dist/  (static)

验证

第 4 步后, 用本地 nav-history.json 跟生产 JSON API 对比:

diff <(jq '.history' data/nav/nav-history.json) \
     <(curl -s https://x-forecast.com/api/v1/nav.json | jq '.history')
应该没输出 (完全一致). 有差异通常是上游数据源在本站上次 build 后做了修正, 不是 bug.

容器构建 (可选)

# Dockerfile (sketch — full version in repo /Dockerfile)
FROM node:20-bookworm-slim
RUN apt-get update && apt-get install -y python3 python3-pip
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY scripts/requirements.txt ./scripts/
RUN pip install -r scripts/requirements.txt
COPY . .
RUN npm run data:all && npm run build
EXPOSE 4321
CMD ["npm", "run", "preview"]

这套 kit 是面试现场 demo 的基础 — 当场让面试官跑一遍数据流, 比 PPT 强 10 倍.