lfqian commited on
Commit
adb60aa
Β·
1 Parent(s): 51f1339

fix: normalize date comparisons for live charts and join arena assets

Browse files
src/components/CompareChartE.vue CHANGED
@@ -81,6 +81,11 @@ function toPct(points){
81
  if (typeof y0 !== 'number' || !isFinite(y0) || y0 === 0) return points
82
  return points.map(([t, y]) => [t, ((y / y0) - 1) * 100])
83
  }
 
 
 
 
 
84
 
85
  // --- Agent & Model logo registries (fill with your actual assets)
86
  const AGENT_LOGOS = {
@@ -216,7 +221,7 @@ export default defineComponent({
216
  let seq = ids.length
217
  ? (rowSeries.length ? rowSeries.slice() : all.filter(r => ids.includes(r.id)))
218
  : all.filter(r => r.agent_name === agent && r.asset === asset && r.model === model)
219
- seq.sort((a,b) => (a.date > b.date ? 1 : -1))
220
  const isCrypto = asset === 'BTC' || asset === 'ETH'
221
  let filtered = isCrypto ? seq : await filterRowsToNyseTradingDays(seq)
222
 
 
81
  if (typeof y0 !== 'number' || !isFinite(y0) || y0 === 0) return points
82
  return points.map(([t, y]) => [t, ((y / y0) - 1) * 100])
83
  }
84
+ const toTs = (d) => {
85
+ if (!d) return NaN
86
+ const t = Date.parse(String(d))
87
+ return Number.isFinite(t) ? t : NaN
88
+ }
89
 
90
  // --- Agent & Model logo registries (fill with your actual assets)
91
  const AGENT_LOGOS = {
 
221
  let seq = ids.length
222
  ? (rowSeries.length ? rowSeries.slice() : all.filter(r => ids.includes(r.id)))
223
  : all.filter(r => r.agent_name === agent && r.asset === asset && r.model === model)
224
+ seq.sort((a, b) => toTs(a?.date) - toTs(b?.date))
225
  const isCrypto = asset === 'BTC' || asset === 'ETH'
226
  let filtered = isCrypto ? seq : await filterRowsToNyseTradingDays(seq)
227
 
src/views/LiveView.vue CHANGED
@@ -318,6 +318,11 @@ const signedMoney = (n) => `${n >= 0 ? '+' : 'βˆ’'}${fmtUSD(Math.abs(n))}`
318
  const fmtSharpe = (s) => (s == null ? 'β€”' : Number(s).toFixed(2))
319
  const score = (row) => (typeof row.balance === 'number' ? row.balance : -Infinity)
320
  const profitOf = (c) => (typeof c?.profitUsd === 'number' ? c.profitUsd : ((c?.balance ?? 0) - 100000))
 
 
 
 
 
321
  const isClaude4Model = (model) => {
322
  const m = String(model || '').toLowerCase()
323
  return m.includes('claude') && m.includes('sonnet') && m.includes('4')
@@ -378,7 +383,7 @@ async function buildSeq(sel) {
378
  ? (rowSeries.length ? rowSeries.slice() : allDecisions.filter(r => ids.includes(r.id)))
379
  : allDecisions.filter(r => r.agent_name === agentName && r.asset === assetCode && r.model === model)
380
 
381
- seq.sort((a,b) => (a.date > b.date ? 1 : -1))
382
  const cutoff = ASSET_CUTOFF[assetCode]
383
  if (cutoff) {
384
  const t0 = new Date(cutoff + 'T00:00:00Z')
 
318
  const fmtSharpe = (s) => (s == null ? 'β€”' : Number(s).toFixed(2))
319
  const score = (row) => (typeof row.balance === 'number' ? row.balance : -Infinity)
320
  const profitOf = (c) => (typeof c?.profitUsd === 'number' ? c.profitUsd : ((c?.balance ?? 0) - 100000))
321
+ const toTs = (d) => {
322
+ if (!d) return NaN
323
+ const t = Date.parse(String(d))
324
+ return Number.isFinite(t) ? t : NaN
325
+ }
326
  const isClaude4Model = (model) => {
327
  const m = String(model || '').toLowerCase()
328
  return m.includes('claude') && m.includes('sonnet') && m.includes('4')
 
383
  ? (rowSeries.length ? rowSeries.slice() : allDecisions.filter(r => ids.includes(r.id)))
384
  : allDecisions.filter(r => r.agent_name === agentName && r.asset === assetCode && r.model === model)
385
 
386
+ seq.sort((a, b) => toTs(a?.date) - toTs(b?.date))
387
  const cutoff = ASSET_CUTOFF[assetCode]
388
  if (cutoff) {
389
  const t0 = new Date(cutoff + 'T00:00:00Z')
src/views/RequestView.vue CHANGED
@@ -383,6 +383,11 @@ export default {
383
  },
384
 
385
  methods: {
 
 
 
 
 
386
  signedPct(p) {
387
  const v = Number(p || 0) * 100
388
  const s = v >= 0 ? '+' : 'βˆ’'
@@ -431,14 +436,19 @@ export default {
431
  .filter(r => r && r.asset === assetCode && Array.isArray(r.series) && r.series.length)
432
  .map(r => r.series)
433
  if (candidates.length) {
434
- candidates.sort((a, b) => b.length - a.length)
 
 
 
 
 
435
  seq = [...candidates[0]]
436
  }
437
  } catch (_) {}
438
  if (!seq.length) {
439
  seq = (this.allDecisions || []).filter(r => r.asset === assetCode)
440
  }
441
- seq.sort((a,b) => (a.date > b.date ? 1 : -1))
442
  const isCrypto = assetCode === 'BTC' || assetCode === 'ETH'
443
  if (!isCrypto) {
444
  try { seq = await filterRowsToNyseTradingDays(seq) } catch {}
@@ -468,7 +478,8 @@ export default {
468
  if (this.allDates.length === 0 && assetsInRows.length > 0) {
469
  const firstSeq = await this.buildAssetSeq(assetsInRows[0])
470
  if (firstSeq.length > 0) {
471
- this.allDates = firstSeq.map(r => r.date).filter(d => d >= '2025-08-01')
 
472
  this.maxDateIndex = this.allDates.length - 1
473
  this.dateRange = [0, this.maxDateIndex]
474
  }
@@ -483,7 +494,12 @@ export default {
483
  // Filter sequence based on date range
484
  const startDate = this.allDates[this.dateRange[0]] || '2025-08-01'
485
  const endDate = this.allDates[this.dateRange[1]] || this.allDates[this.allDates.length - 1]
486
- const seq = fullSeq.filter(r => r.date >= startDate && r.date <= endDate)
 
 
 
 
 
487
  console.log('[RequestView] Asset', code, 'filtered seq length:', seq?.length || 0, 'from', startDate, 'to', endDate)
488
  if (!seq.length) continue
489
 
 
383
  },
384
 
385
  methods: {
386
+ toTs(raw) {
387
+ if (!raw) return NaN
388
+ const t = Date.parse(String(raw))
389
+ return Number.isFinite(t) ? t : NaN
390
+ },
391
  signedPct(p) {
392
  const v = Number(p || 0) * 100
393
  const s = v >= 0 ? '+' : 'βˆ’'
 
436
  .filter(r => r && r.asset === assetCode && Array.isArray(r.series) && r.series.length)
437
  .map(r => r.series)
438
  if (candidates.length) {
439
+ candidates.sort((a, b) => {
440
+ const aLast = this.toTs(a[a.length - 1]?.date)
441
+ const bLast = this.toTs(b[b.length - 1]?.date)
442
+ if (Number.isFinite(aLast) && Number.isFinite(bLast) && aLast !== bLast) return bLast - aLast
443
+ return b.length - a.length
444
+ })
445
  seq = [...candidates[0]]
446
  }
447
  } catch (_) {}
448
  if (!seq.length) {
449
  seq = (this.allDecisions || []).filter(r => r.asset === assetCode)
450
  }
451
+ seq.sort((a, b) => this.toTs(a?.date) - this.toTs(b?.date))
452
  const isCrypto = assetCode === 'BTC' || assetCode === 'ETH'
453
  if (!isCrypto) {
454
  try { seq = await filterRowsToNyseTradingDays(seq) } catch {}
 
478
  if (this.allDates.length === 0 && assetsInRows.length > 0) {
479
  const firstSeq = await this.buildAssetSeq(assetsInRows[0])
480
  if (firstSeq.length > 0) {
481
+ const cutoffTs = this.toTs('2025-08-01')
482
+ this.allDates = firstSeq.map(r => r.date).filter(d => this.toTs(d) >= cutoffTs)
483
  this.maxDateIndex = this.allDates.length - 1
484
  this.dateRange = [0, this.maxDateIndex]
485
  }
 
494
  // Filter sequence based on date range
495
  const startDate = this.allDates[this.dateRange[0]] || '2025-08-01'
496
  const endDate = this.allDates[this.dateRange[1]] || this.allDates[this.allDates.length - 1]
497
+ const startTs = this.toTs(startDate)
498
+ const endTs = this.toTs(endDate)
499
+ const seq = fullSeq.filter(r => {
500
+ const ts = this.toTs(r?.date)
501
+ return Number.isFinite(ts) && ts >= startTs && ts <= endTs
502
+ })
503
  console.log('[RequestView] Asset', code, 'filtered seq length:', seq?.length || 0, 'from', startDate, 'to', endDate)
504
  if (!seq.length) continue
505