File size: 2,931 Bytes
3ac9172
 
edd5045
c4bed48
6c34ff7
bef178c
3ac9172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
edd5045
 
 
 
 
 
 
 
 
3ac9172
 
 
5fa7a59
3ac9172
6c34ff7
5fa7a59
edd5045
 
 
 
 
5fa7a59
6c34ff7
 
 
 
 
 
 
3ac9172
 
6c34ff7
 
3ac9172
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!-- src/views/LiveView.vue -->
<script setup>
import { ref, computed, onMounted } from 'vue'
import CompareChartE from '../components/CompareChartE.vue'
import AssetTabs from '../components/AssetTabs.vue'
import { dataService } from '../lib/dataService.js'

const ASSETS = ['BTC','ETH','SOL','BNB','DOGE','XRP']
const asset = ref(ASSETS[0])
const agents = ref([])

function score(row){ return typeof row.balance === 'number' ? row.balance : -Infinity }

const winners = computed(() => {
  const rows = (agents.value || []).filter(r => r.asset === asset.value)
  const byAgent = new Map()
  for (const r of rows) {
    const k = r.agent_name
    const cur = byAgent.get(k)
    if (!cur || score(r) > score(cur)) byAgent.set(k, r)
  }
  return [...byAgent.values()]
})

const winnersForChart = computed(() =>
  winners.value.map(w => ({
    agent_name: w.agent_name,
    asset:      w.asset,
    model:      w.model,
    strategy:   w.strategy,
    decision_ids: Array.isArray(w.decision_ids) ? w.decision_ids : undefined
  }))
)

const winnersSorted = computed(() => [...winners.value].sort((a,b) => score(b) - score(a)))

const fmtUSD = n => (n ?? 0).toLocaleString(undefined,{ style:'currency', currency:'USD', maximumFractionDigits:2 })

onMounted(async () => {
  try {
     // run the service load if needed (this populates tableRows + caches decisions)
     if (!dataService.loaded) await dataService.load(false)
   } catch (e) {
     console.error('LiveView: dataService.load failed', e)
   }
   // copy rows to local reactive state
   agents.value = Array.isArray(dataService.tableRows) ? dataService.tableRows : []
   console.log('LiveView: loaded rows =', agents.value.length)
})
</script>

<template>
  <div class="p-4 space-y-4">
    <AssetTabs v-model="asset" />

    <CompareChartE v-if="winnersForChart.length" :selected="winnersForChart" :visible="true" />
    <div v-else class="p-4 text-sm text-gray-500 border rounded-lg">
      No data for {{ asset }} yet. Make sure Supabase has decisions/runs for this asset and that
      <code>dataService.load()</code> completes. Check console for “LiveView: loaded rows” count.
    </div>


    <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
      <div v-for="row in winnersSorted" :key="row.agent_name+'|'+row.asset+'|'+row.model"
           class="p-4 rounded-2xl border shadow-sm flex justify-between items-center">
        <div class="min-w-0">
          <div class="font-semibold truncate">{{ row.agent_name }}</div>
          <div class="text-xs opacity-70 truncate">{{ row.model }}</div>
        </div>
        <div class="text-right">
          <div class="font-bold text-xl leading-6">{{ fmtUSD(row.balance) }}</div>
          <div class="text-xs opacity-70">EOD {{ (row.end_date || row.last_nav_ts) ? new Date(row.end_date || row.last_nav_ts).toLocaleDateString() : '-' }}</div>
        </div>
      </div>
    </div>
  </div>
</template>