lfqian commited on
Commit
1a4a38c
·
1 Parent(s): 731a8a5

fix: drive join arena time window from trading_decisions date bounds

Browse files
Files changed (1) hide show
  1. src/views/RequestView.vue +28 -10
src/views/RequestView.vue CHANGED
@@ -298,6 +298,7 @@ export default {
298
  assets: [],
299
 
300
  // time window control
 
301
  allDates: [],
302
  dateRange: [0, 0],
303
  maxDateIndex: 0,
@@ -365,9 +366,13 @@ export default {
365
  dataService.setSourceTable('trading_decisions')
366
  this.unsubscribe = dataService.subscribe((state) => {
367
  this.rowsRef = Array.isArray(state.tableRows) ? state.tableRows : []
 
 
368
  this.rebuildAssets().catch(() => {})
369
  })
370
  this.rowsRef = Array.isArray(dataService.tableRows) ? dataService.tableRows : []
 
 
371
  if (!dataService.loading) {
372
  dataService.load(false).catch(e => console.error('RequestView: load failed', e))
373
  }
@@ -406,6 +411,28 @@ export default {
406
  if (!this.allDates || index < 0 || index >= this.allDates.length) return '—'
407
  return this.allDates[index]
408
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
  calculateVolatility(values) {
410
  if (!Array.isArray(values) || values.length < 2) return 0
411
 
@@ -476,16 +503,7 @@ export default {
476
  console.log('[RequestView] Assets in rows:', assetsInRows)
477
  if (!assetsInRows.length) { this.assets = []; return }
478
 
479
- // Initialize all dates from first asset to set up slider
480
- if (this.allDates.length === 0 && assetsInRows.length > 0) {
481
- const firstSeq = await this.buildAssetSeq(assetsInRows[0])
482
- if (firstSeq.length > 0) {
483
- const cutoffTs = this.toTs('2025-08-01')
484
- this.allDates = firstSeq.map(r => r.date).filter(d => this.toTs(d) >= cutoffTs)
485
- this.maxDateIndex = this.allDates.length - 1
486
- this.dateRange = [0, this.maxDateIndex]
487
- }
488
- }
489
 
490
  const cards = []
491
  for (const code of assetsInRows) {
 
298
  assets: [],
299
 
300
  // time window control
301
+ dateBounds: { min: null, max: null },
302
  allDates: [],
303
  dateRange: [0, 0],
304
  maxDateIndex: 0,
 
366
  dataService.setSourceTable('trading_decisions')
367
  this.unsubscribe = dataService.subscribe((state) => {
368
  this.rowsRef = Array.isArray(state.tableRows) ? state.tableRows : []
369
+ this.dateBounds = state?.dateBounds || { min: null, max: null }
370
+ this.rebuildAllDatesFromBounds()
371
  this.rebuildAssets().catch(() => {})
372
  })
373
  this.rowsRef = Array.isArray(dataService.tableRows) ? dataService.tableRows : []
374
+ this.dateBounds = dataService.dateBounds || { min: null, max: null }
375
+ this.rebuildAllDatesFromBounds()
376
  if (!dataService.loading) {
377
  dataService.load(false).catch(e => console.error('RequestView: load failed', e))
378
  }
 
411
  if (!this.allDates || index < 0 || index >= this.allDates.length) return '—'
412
  return this.allDates[index]
413
  },
414
+ rebuildAllDatesFromBounds() {
415
+ const minRaw = this.dateBounds?.min
416
+ const maxRaw = this.dateBounds?.max
417
+ const minTs = this.toTs(minRaw)
418
+ const maxTs = this.toTs(maxRaw)
419
+ if (!Number.isFinite(minTs) || !Number.isFinite(maxTs) || maxTs < minTs) return
420
+ const dates = []
421
+ const cur = new Date(minTs)
422
+ const end = new Date(maxTs)
423
+ cur.setUTCHours(0, 0, 0, 0)
424
+ end.setUTCHours(0, 0, 0, 0)
425
+ while (cur <= end) {
426
+ dates.push(cur.toISOString().split('T')[0])
427
+ cur.setUTCDate(cur.getUTCDate() + 1)
428
+ }
429
+ this.allDates = dates
430
+ this.maxDateIndex = Math.max(0, dates.length - 1)
431
+ const prev = Array.isArray(this.dateRange) ? this.dateRange : [0, this.maxDateIndex]
432
+ const s = Math.max(0, Math.min(prev[0] ?? 0, this.maxDateIndex))
433
+ const e = Math.max(0, Math.min(prev[1] ?? this.maxDateIndex, this.maxDateIndex))
434
+ this.dateRange = [Math.min(s, e), Math.max(s, e)]
435
+ },
436
  calculateVolatility(values) {
437
  if (!Array.isArray(values) || values.length < 2) return 0
438
 
 
503
  console.log('[RequestView] Assets in rows:', assetsInRows)
504
  if (!assetsInRows.length) { this.assets = []; return }
505
 
506
+ if (!this.allDates.length) this.rebuildAllDatesFromBounds()
 
 
 
 
 
 
 
 
 
507
 
508
  const cards = []
509
  for (const code of assetsInRows) {