fix: filtres Journal de Bord — direction + asset_class tous onglets
Direction (Ouvert) : t.direction n'existe pas dans trade_entry_prices → utilisait undefined, excluait tout. Remplacé par _isBearishStr(t.strategy) comme Fermés. Asset class (Ouvert, Fermés, Non loggés) : l'IA retournait parfois "commodities", "currencies", "fx", "equity" au lieu des clés canoniques. Double correction : - Frontend : _normalizeAssetClass() mappe les variantes → energy|metals|agriculture| indices|equities|forex dans les 3 sections filtrées - Backend database.py : _normalize_asset_class() appliqué à l'INSERT dans trade_entry_prices et skipped_trades (nouveaux trades normalisés au stockage) - Prompt ai_analyzer.py : suggested_trades[].asset_class contraint à l'enum explicite Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -239,6 +239,19 @@ function _isBearishStr(strategy: string) {
|
||||
return /put|bear|short|sell|vente|baissier/i.test(strategy ?? '')
|
||||
}
|
||||
|
||||
// Normalize AI-returned asset_class variants to canonical CATEGORIES keys
|
||||
function _normalizeAssetClass(cls: string | null | undefined): string {
|
||||
if (!cls) return ''
|
||||
const c = cls.toLowerCase().trim()
|
||||
if (/energy|oil|gas|petrol|brent|wti/.test(c)) return 'energy'
|
||||
if (/metal|gold|silver|copper|mining|precious/.test(c)) return 'metals'
|
||||
if (/agri|grain|corn|wheat|soy|crop|coton|coffee|cocoa/.test(c)) return 'agriculture'
|
||||
if (/index|indic|indices|spx|nasdaq|dow|s&p|russell|cac|dax/.test(c)) return 'indices'
|
||||
if (/equit|stock|action|share|sector|xle|xlf|xlk/.test(c)) return 'equities'
|
||||
if (/forex|currency|fx|devise|change|eur|usd|jpy|dxy/.test(c)) return 'forex'
|
||||
return c
|
||||
}
|
||||
|
||||
interface FilterBarProps {
|
||||
search: string; onSearch: (v: string) => void
|
||||
assetClass: string; onAssetClass: (v: string) => void
|
||||
@@ -330,7 +343,7 @@ function ClosedTradesSection({ days }: { days: number }) {
|
||||
const trades = allTrades.filter((t: any) => {
|
||||
const q = search.toLowerCase()
|
||||
if (q && !`${t.underlying} ${t.strategy ?? ''} ${t.pattern_name ?? ''}`.toLowerCase().includes(q)) return false
|
||||
if (assetClass !== 'all' && t.asset_class !== assetClass) return false
|
||||
if (assetClass !== 'all' && _normalizeAssetClass(t.asset_class) !== assetClass) return false
|
||||
const bearish = _isBearishStr(t.strategy ?? '')
|
||||
if (direction === 'bullish' && bearish) return false
|
||||
if (direction === 'bearish' && !bearish) return false
|
||||
@@ -900,9 +913,10 @@ function TradeMtmSection({ days }: { days: number }) {
|
||||
if ((t.latest_score ?? t.score_at_entry ?? 0) < minScoreFilter) return false
|
||||
const q = search.toLowerCase()
|
||||
if (q && !`${t.underlying} ${t.strategy ?? ''} ${t.pattern_name ?? ''}`.toLowerCase().includes(q)) return false
|
||||
if (assetClass !== 'all' && t.asset_class !== assetClass) return false
|
||||
if (direction === 'bullish' && t.direction !== 'bullish') return false
|
||||
if (direction === 'bearish' && t.direction !== 'bearish') return false
|
||||
if (assetClass !== 'all' && _normalizeAssetClass(t.asset_class) !== assetClass) return false
|
||||
const bearish = _isBearishStr(t.strategy ?? '')
|
||||
if (direction === 'bullish' && bearish) return false
|
||||
if (direction === 'bearish' && !bearish) return false
|
||||
return true
|
||||
})
|
||||
|
||||
@@ -1631,7 +1645,7 @@ function SkippedTradesSection({ days }: { days: number }) {
|
||||
const trades = allTrades.filter((t: any) => {
|
||||
const q = search.toLowerCase()
|
||||
if (q && !`${t.underlying} ${t.strategy ?? ''} ${t.pattern_name ?? ''}`.toLowerCase().includes(q)) return false
|
||||
if (assetClass !== 'all' && t.asset_class !== assetClass) return false
|
||||
if (assetClass !== 'all' && _normalizeAssetClass(t.asset_class) !== assetClass) return false
|
||||
if (reasonFilter !== 'all' && t.skip_reason !== reasonFilter) return false
|
||||
return true
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user