Skip to content

Support strategies 4/5, normalize cloud metrics (swing_pct) and preserve last-run strategy for AI scoring#22

Open
esclipse wants to merge 1 commit intomainfrom
codex/fix-missing-close-price-data-in-strategies-b6zch4
Open

Support strategies 4/5, normalize cloud metrics (swing_pct) and preserve last-run strategy for AI scoring#22
esclipse wants to merge 1 commit intomainfrom
codex/fix-missing-close-price-data-in-strategies-b6zch4

Conversation

@esclipse
Copy link
Owner

@esclipse esclipse commented Jan 9, 2026

Motivation

  • Accept and map additional strategy identifiers so the API and UI can request strategy4/strategy5 alongside existing strategies.
  • Normalize inconsistent cloud response fields into numeric metrics so the frontend can display values reliably (including a new swing_pct / 前3日振幅 field).
  • Merge results across strategies during an all run and preserve merged per-stock metrics so AI scoring and the leaderboard remain meaningful.
  • Improve frontend resilience so the stock leaderboard keeps showing and numeric fields render with clear fallbacks when data is missing.

Description

  • Extended strategy normalization and mapping by updating normalizeStrategyInput and toResultKey to recognize s4/s5 and strategy4/strategy5.
  • Implemented value normalization helpers (pickValue, toNumber, buildMatch, mergeMatch) in app/api/stock-analysis/route.ts and wired them into convertCloudFunctionResult so cloud responses produce consistent match objects (including swing_pct).
  • Sent the normalized strategy to the cloud function and support converting results for a specific strategy or merged across all five strategies.
  • Updated UI in app/stock/page.tsx to track lastRunStrategy, add a one-click 一键执行全部策略 action, expose s4/s5 in the selector, use lastRunStrategy for AI scoring, and render swing_pct and other metrics with null-safe fallbacks.

Testing

  • Started the Next.js dev server (npm run dev ...) and compiled the /stock page successfully (GET /stock returned 200). — succeeded.
  • Automated browser check using Playwright navigated to http://127.0.0.1:3000/stock and captured a screenshot of the updated page. — succeeded.
  • No unit tests were added or executed as part of this change.
  • Manual/interactive checks were performed during development to verify the UI renders leaderboard entries and that AI prompt formatting uses safe formatValue fallbacks. — performed successfully.

Codex Task

@vercel
Copy link

vercel bot commented Jan 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
mcp-test Ready Ready Preview, Comment Jan 9, 2026 9:49am

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7167367276

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +125 to +128
] as const).forEach((key) => {
if (merged[key] === null || merged[key] === undefined || merged[key] === 0) {
const incomingValue = incoming[key];
if (incomingValue !== null && incomingValue !== undefined) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don’t treat 0 as missing when merging metrics

The new merge logic treats 0 as a missing value (merged[key] === 0), so a legitimate metric like change_pct: 0 or volume_ratio: 0 from one strategy will be overwritten by another strategy’s non‑zero value. This corrupts merged results for stocks whose true value is zero (e.g., unchanged price). Consider only treating null/undefined as missing and avoid special‑casing 0.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant