fix(stats): align model peers ranking

This commit is contained in:
Adam
2026-06-20 06:14:24 -05:00
parent e6cdc543f3
commit 95237a90a7
+6 -6
View File
@@ -248,15 +248,15 @@ function buildStatsModelData(
) )
.filter((item) => item.totalTokens > 0) .filter((item) => item.totalTokens > 0)
.toSorted((a, b) => b.totalTokens - a.totalTokens || a.model.localeCompare(b.model)) .toSorted((a, b) => b.totalTokens - a.totalTokens || a.model.localeCompare(b.model))
const peers = aggregateByModelName(rowsForProduct(normalized, SITE_PRODUCT, window.start, window.end)) const windowPeers = aggregateByModelName(rowsForProduct(normalized, SITE_PRODUCT, window.start, window.end))
.filter((item) => item.totalTokens > 0) .filter((item) => item.totalTokens > 0)
.toSorted((a, b) => b.totalTokens - a.totalTokens || a.model.localeCompare(b.model)) .toSorted((a, b) => b.totalTokens - a.totalTokens || a.model.localeCompare(b.model))
const rankIndex = rankPeers.findIndex((item) => item.model === model) const rankIndex = rankPeers.findIndex((item) => item.model === model)
const rank = rankIndex >= 0 ? rankIndex + 1 : null const rank = rankIndex >= 0 ? rankIndex + 1 : null
const previousRankIndex = previousRankPeers.findIndex((item) => item.model === model) const previousRankIndex = previousRankPeers.findIndex((item) => item.model === model)
const peerRankIndex = peers.findIndex((item) => item.model === model) const peerRank = rankIndex >= 0 ? rankIndex + 1 : 1
const peerRank = peerRankIndex >= 0 ? peerRankIndex + 1 : 1 const totalTokens = windowPeers.reduce((sum, item) => sum + item.totalTokens, 0)
const totalTokens = peers.reduce((sum, item) => sum + item.totalTokens, 0) const peerTokens = rankPeers.reduce((sum, item) => sum + item.totalTokens, 0)
return { return {
updatedAt: Number.isFinite(latestUpdate) ? new Date(latestUpdate).toISOString() : null, updatedAt: Number.isFinite(latestUpdate) ? new Date(latestUpdate).toISOString() : null,
@@ -266,7 +266,7 @@ function buildStatsModelData(
author: formatProvider(current.provider), author: formatProvider(current.provider),
rank, rank,
previousRank: previousRankIndex >= 0 ? previousRankIndex + 1 : null, previousRank: previousRankIndex >= 0 ? previousRankIndex + 1 : null,
totalModels: peers.length, totalModels: windowPeers.length,
tokenShare: totalTokens > 0 ? round((current.totalTokens / totalTokens) * 100, 2) : 0, tokenShare: totalTokens > 0 ? round((current.totalTokens / totalTokens) * 100, 2) : 0,
tokenChange: percentChange(current.totalTokens, previous.totalTokens), tokenChange: percentChange(current.totalTokens, previous.totalTokens),
totals: { totals: {
@@ -285,7 +285,7 @@ function buildStatsModelData(
usage: buildModelUsage(currentRows, window, "2M"), usage: buildModelUsage(currentRows, window, "2M"),
tokenMix: buildModelTokenMix(current), tokenMix: buildModelTokenMix(current),
country: createRangeRecord((range) => buildCountryStats(geo, getWindow(range, earliest, latest))), country: createRangeRecord((range) => buildCountryStats(geo, getWindow(range, earliest, latest))),
peers: buildModelPeers(peers, peerRank, totalTokens), peers: buildModelPeers(rankPeers, peerRank, peerTokens),
} }
} }