Skip to content

Commit f028a80

Browse files
Jinyu XuJinyu Xu
authored andcommitted
feat: add professional analysis mobile experience
1 parent 77deaae commit f028a80

9 files changed

Lines changed: 971 additions & 1476 deletions

File tree

‎src/components/ProfessionalAnalysisReport.vue‎

Lines changed: 502 additions & 0 deletions
Large diffs are not rendered by default.

‎src/locales/index.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import zhTW from './zh-TW'
44
import enUS from './en-US'
55
import jaJP from './ja-JP'
66
import koKR from './ko-KR'
7+
import professionalReport from './professional-report'
78
import {
89
Locale as VantLocale
910
} from 'vant'
@@ -39,11 +40,11 @@ const i18n = createI18n({
3940
locale: initialLocale,
4041
fallbackLocale: 'en-US',
4142
messages: {
42-
'zh-CN': zhCN,
43-
'zh-TW': zhTW,
44-
'en-US': enUS,
45-
'ja-JP': jaJP,
46-
'ko-KR': koKR
43+
'zh-CN': { ...zhCN, professional_report: professionalReport['zh-CN'] },
44+
'zh-TW': { ...zhTW, professional_report: professionalReport['zh-TW'] },
45+
'en-US': { ...enUS, professional_report: professionalReport['en-US'] },
46+
'ja-JP': { ...jaJP, professional_report: professionalReport['ja-JP'] },
47+
'ko-KR': { ...koKR, professional_report: professionalReport['ko-KR'] }
4748
}
4849
})
4950

‎src/locales/professional-report.js‎

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/utils/aiAnalysisHistory.js‎

Lines changed: 15 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,33 @@
1-
/**
2-
* Build analysis result payload for the AI analysis result page from a history list item.
3-
* Mirrors PC viewHistoryResult: prefer raw_result (full_result), merge list metadata, fallback SL/TP.
4-
*/
5-
6-
function normalizeConfidence(value) {
7-
const num = Number(value)
8-
if (!Number.isFinite(num)) return 0
9-
if (num > 0 && num <= 1) return Math.round(num * 100)
10-
return num
11-
}
1+
import { professionalReportEnvelope } from './professionalReport.js'
122

133
export function parseFullResult(raw) {
144
if (raw == null) return null
15-
let obj = raw
16-
if (typeof obj === 'string') {
5+
let value = raw
6+
if (typeof value === 'string') {
177
try {
18-
obj = JSON.parse(obj)
8+
value = JSON.parse(value)
199
} catch {
2010
return null
2111
}
2212
}
23-
if (!obj || typeof obj !== 'object') return null
24-
if (
25-
obj.data &&
26-
typeof obj.data === 'object' &&
27-
!obj.decision &&
28-
(obj.data.decision || obj.data.summary || obj.data.consensus)
29-
) {
30-
obj = obj.data
31-
}
32-
return obj
33-
}
34-
35-
function isMeaningfulFullResult(full) {
36-
if (!full || typeof full !== 'object') return false
37-
if (String(full.task_status || '').toLowerCase() === 'processing') {
38-
return !!(full.consensus || full.detailed_analysis || (full.summary && full.summary.length > 40))
39-
}
40-
return !!(
41-
full.decision ||
42-
full.summary ||
43-
full.consensus ||
44-
full.detailed_analysis ||
45-
full.trading_plan ||
46-
full.trend_outlook
47-
)
48-
}
49-
50-
function buildTradingPlanFallback(item, price, decision) {
51-
const dec = String(decision || 'HOLD').toUpperCase()
52-
let stopLoss = null
53-
let takeProfit = null
54-
if (price > 0) {
55-
if (dec === 'SELL') {
56-
stopLoss = price * 1.05
57-
takeProfit = price * 0.95
58-
} else if (dec === 'BUY') {
59-
stopLoss = price * 0.95
60-
takeProfit = price * 1.05
61-
}
62-
}
63-
const entry = price || item?.price || item?.current_price
64-
return {
65-
entry_price: entry,
66-
stop_loss: stopLoss ?? item?.stop_loss,
67-
take_profit: takeProfit ?? item?.take_profit
68-
}
13+
if (!value || typeof value !== 'object') return null
14+
return value.data && typeof value.data === 'object' ? value.data : value
6915
}
7016

7117
/**
72-
* @param {object} item History row from GET /api/fast-analysis/history/all
73-
* @returns {object|null} Payload for useAiAnalysisStore().setLastResult()
18+
* History is a read boundary, not a reconstruction engine. Only a persisted
19+
* professional_report_v1 artifact is renderable; legacy rows must be regenerated.
7420
*/
7521
export function buildHistoryResultPayload(item) {
7622
if (!item || typeof item !== 'object') return null
77-
7823
const full = parseFullResult(item.full_result)
79-
const useFull = isMeaningfulFullResult(full)
80-
const price =
81-
Number(item.price) ||
82-
Number(item.current_price) ||
83-
Number(full?.market_data?.current_price) ||
84-
0
85-
const decision = (useFull ? full.decision : item.decision) || 'HOLD'
86-
const tradingPlanFallback = buildTradingPlanFallback(item, price, decision)
87-
88-
const fallback = {
89-
decision: item.decision,
90-
confidence: normalizeConfidence(item.confidence),
91-
summary: item.summary,
92-
market: item.market,
93-
symbol: item.symbol,
94-
timeframe: item.timeframe,
95-
market_data: {
96-
current_price: item.price || item.current_price,
97-
change_24h: 0
98-
},
99-
trading_plan: tradingPlanFallback,
100-
scores: item.scores || {},
101-
reasons: item.reasons || [],
102-
risks: item.risks || [],
103-
indicators: item.indicators || {},
104-
memory_id: item.id
105-
}
106-
107-
if (!useFull) {
108-
return fallback
109-
}
110-
111-
const risks =
112-
(Array.isArray(full.risks) && full.risks.length ? full.risks : null) ||
113-
(Array.isArray(full.risk_factors) && full.risk_factors.length ? full.risk_factors : null) ||
114-
fallback.risks
115-
116-
const reasons =
117-
(Array.isArray(full.reasons) && full.reasons.length ? full.reasons : null) || fallback.reasons
118-
119-
const scores =
120-
full.scores && Object.keys(full.scores).length ? full.scores : fallback.scores
121-
122-
const indicators =
123-
full.indicators && Object.keys(full.indicators).length
124-
? full.indicators
125-
: fallback.indicators
126-
24+
const envelope = professionalReportEnvelope(full)
25+
if (!envelope) return null
12726
return {
128-
...full,
129-
memory_id: item.id ?? full.memory_id,
130-
market: full.market || item.market,
131-
symbol: full.symbol || item.symbol,
132-
timeframe: full.timeframe || item.timeframe,
133-
decision: full.decision ?? item.decision,
134-
confidence: normalizeConfidence(
135-
full.confidence != null ? full.confidence : item.confidence
136-
),
137-
summary: full.summary ?? item.summary,
138-
reasons,
139-
scores,
140-
risks,
141-
indicators,
142-
market_data: full.market_data || fallback.market_data,
143-
trading_plan:
144-
full.trading_plan && Object.keys(full.trading_plan).length
145-
? full.trading_plan
146-
: fallback.trading_plan
27+
...envelope,
28+
runtime: {
29+
...(envelope.runtime || {}),
30+
memory_id: item.id ?? envelope.runtime?.memory_id
31+
}
14732
}
14833
}

‎src/utils/professionalReport.js‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
export const PROFESSIONAL_REPORT_SCHEMA = 'professional_report_v1'
2+
export const PROFESSIONAL_ENVELOPE_SCHEMA = 'professional_analysis_envelope_v1'
3+
4+
export function professionalReportArtifact(value) {
5+
if (!value || typeof value !== 'object') return null
6+
const candidate = value.report || value.professional_report || value
7+
if (!candidate || typeof candidate !== 'object') return null
8+
const schema = candidate.schema_version
9+
if (schema === PROFESSIONAL_REPORT_SCHEMA) return candidate
10+
if (schema === '1.0' && candidate.instrument && candidate.decision_profile) return candidate
11+
return null
12+
}
13+
14+
export function professionalReportEnvelope(value) {
15+
if (!value || typeof value !== 'object') return null
16+
const payload = value.code !== undefined && value.data && typeof value.data === 'object'
17+
? value.data
18+
: value
19+
const report = professionalReportArtifact(payload)
20+
if (!report) return null
21+
return {
22+
schema_version: PROFESSIONAL_ENVELOPE_SCHEMA,
23+
report,
24+
runtime: payload.runtime || {
25+
memory_id: payload.memory_id,
26+
analysis_time_ms: payload.analysis_time_ms,
27+
llm_time_ms: payload.llm_time_ms,
28+
data_collection_time_ms: payload.data_collection_time_ms
29+
},
30+
billing: payload.billing || null
31+
}
32+
}
33+
34+
export function reportInstrument(value) {
35+
return professionalReportArtifact(value)?.instrument || {}
36+
}
37+
38+
export function reportDecisionProfile(value) {
39+
return professionalReportArtifact(value)?.decision_profile || {}
40+
}
41+
42+
export function reportObservation(value, metrics) {
43+
const report = professionalReportArtifact(value)
44+
const rows = report?.evidence_snapshot?.observations
45+
if (!Array.isArray(rows)) return null
46+
const wanted = (Array.isArray(metrics) ? metrics : [metrics]).map((item) => String(item || '').toLowerCase())
47+
return rows.find((item) => wanted.includes(String(item?.metric || '').toLowerCase())) || null
48+
}
49+
50+
export function reportCurrentPrice(value) {
51+
return reportObservation(value, ['quote.price', 'current_price'])?.value ?? null
52+
}
53+
54+
export function reportChangePercent(value) {
55+
return reportObservation(value, ['quote.changePercent', 'change_24h'])?.value ?? null
56+
}
57+
58+
export function reportRiskReward(value) {
59+
const report = professionalReportArtifact(value)
60+
const plan = report?.risk_plan || {}
61+
return plan.net_risk_reward ?? plan.gross_risk_reward ?? null
62+
}
63+
64+
export function reportHasRiskRewardWarning(value) {
65+
const report = professionalReportArtifact(value)
66+
if (String(report?.decision_profile?.decision || '').toUpperCase() === 'HOLD') return false
67+
const plan = report?.risk_plan || {}
68+
const ratio = reportRiskReward(report)
69+
const warnings = Array.isArray(plan.warnings) ? plan.warnings : []
70+
return warnings.includes('net_risk_reward_below_one') || (
71+
ratio !== null && ratio !== '' && Number.isFinite(Number(ratio)) && Number(ratio) < 1
72+
)
73+
}

‎src/views/ai-analysis/History.vue‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,7 @@ export default {
134134
// cancelled
135135
}
136136
},
137-
/**
138-
* Reconstruct a payload the AI analysis page can render, mirroring
139-
* the PC `viewHistoryResult` logic so the user gets the same
140-
* "open from history" experience on mobile (entry / SL / TP
141-
* derived from price and decision when full_result is missing).
142-
*/
137+
/** Open only persisted professional_report_v1 artifacts. */
143138
openItem(item) {
144139
if ((item.status || '').toLowerCase() === 'processing') {
145140
showToast({ message: this.$t('ai_analysis.history_processing'), type: 'fail' })
@@ -148,7 +143,7 @@ export default {
148143
149144
const payload = buildHistoryResultPayload(item)
150145
if (!payload) {
151-
showToast({ message: this.$t('ai_analysis.error_tip'), type: 'fail' })
146+
showToast({ message: this.$t('professional_report.contract_required_desc'), type: 'fail' })
152147
return
153148
}
154149
this.aiStore.setLastResult(payload)

0 commit comments

Comments
 (0)