lfqian commited on
Commit
b6da842
·
1 Parent(s): 26f0ce0

LiveView: query max date directly from Supabase instead of using cached end_date

Browse files
Files changed (1) hide show
  1. src/views/LiveView.vue +19 -11
src/views/LiveView.vue CHANGED
@@ -174,6 +174,8 @@ import {
174
  const orderedAssets = ['BTC','ETH','BMRN','TSLA']
175
  const EXCLUDED_AGENT_NAMES = new Set(['vanilla', 'vinilla'])
176
 
 
 
177
  const ASSET_ICONS = {
178
  BTC: new URL('../assets/images/assets_images/BTC.png', import.meta.url).href,
179
  ETH: new URL('../assets/images/assets_images/ETH.png', import.meta.url).href,
@@ -379,19 +381,25 @@ watch(
379
 
380
  if (!perfs.length) { cards.value = []; return }
381
 
382
- // Get max end_date for this asset from Supabase data (tableRows)
383
  const currentAsset = asset.value
384
- const assetRows = (rowsRef.value || []).filter(r => r.asset === currentAsset && r.end_date)
385
  let maxEndDate = null
386
- if (assetRows.length > 0) {
387
- // Get all end_date values and find the maximum
388
- const dates = assetRows.map(r => r.end_date).sort()
389
- maxEndDate = dates[dates.length - 1] // Latest date
390
- console.log('[LiveView] Asset:', currentAsset, 'Total rows:', assetRows.length, 'All end_dates:', dates, 'Max:', maxEndDate)
391
- // Log first few rows for debugging
392
- console.log('[LiveView] Sample rows:', assetRows.slice(0, 3).map(r => ({ agent: r.agent_name, model: r.model, end_date: r.end_date })))
393
- } else {
394
- console.log('[LiveView] Asset:', currentAsset, 'NO ROWS FOUND with end_date!')
 
 
 
 
 
 
 
395
  }
396
 
397
  // Buy & Hold first
 
174
  const orderedAssets = ['BTC','ETH','BMRN','TSLA']
175
  const EXCLUDED_AGENT_NAMES = new Set(['vanilla', 'vinilla'])
176
 
177
+ import { supabase } from '../lib/supabase'
178
+
179
  const ASSET_ICONS = {
180
  BTC: new URL('../assets/images/assets_images/BTC.png', import.meta.url).href,
181
  ETH: new URL('../assets/images/assets_images/ETH.png', import.meta.url).href,
 
381
 
382
  if (!perfs.length) { cards.value = []; return }
383
 
384
+ // Get max date directly from Supabase for this asset
385
  const currentAsset = asset.value
 
386
  let maxEndDate = null
387
+ try {
388
+ const { data, error } = await supabase
389
+ .from('trading_decisions')
390
+ .select('date')
391
+ .eq('asset', currentAsset)
392
+ .order('date', { ascending: false })
393
+ .limit(1)
394
+
395
+ if (!error && data && data.length > 0) {
396
+ maxEndDate = data[0].date
397
+ console.log('[LiveView] Direct Supabase query - Asset:', currentAsset, 'Max date:', maxEndDate)
398
+ } else {
399
+ console.log('[LiveView] Supabase query failed or no data:', error)
400
+ }
401
+ } catch (e) {
402
+ console.error('[LiveView] Error querying Supabase:', e)
403
  }
404
 
405
  // Buy & Hold first