|
@@ -96,6 +96,8 @@ const DAY_MS = 86_400_000
|
|
|
const TOKEN_SCALE = 1_000_000
|
|
const TOKEN_SCALE = 1_000_000
|
|
|
const DOLLARS_PER_MICROCENT = 1 / 100_000_000
|
|
const DOLLARS_PER_MICROCENT = 1 / 100_000_000
|
|
|
const METRIC_MODEL_LIMIT = 10
|
|
const METRIC_MODEL_LIMIT = 10
|
|
|
|
|
+const TOP_MODEL_SEGMENT_LIMIT = 9
|
|
|
|
|
+const SITE_PRODUCT = "Go"
|
|
|
const LEADERBOARD_CHANGE_MIN_MULTIPLE = 10
|
|
const LEADERBOARD_CHANGE_MIN_MULTIPLE = 10
|
|
|
const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"] as const
|
|
const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"] as const
|
|
|
|
|
|
|
@@ -227,15 +229,15 @@ function buildStatsModelData(
|
|
|
const latest = Math.max(...normalized.map((row) => row.periodStart))
|
|
const latest = Math.max(...normalized.map((row) => row.periodStart))
|
|
|
const latestUpdate = Math.max(...modelScopedRows.map((row) => row.updatedAt))
|
|
const latestUpdate = Math.max(...modelScopedRows.map((row) => row.updatedAt))
|
|
|
const window = getWindow("2M", earliest, latest)
|
|
const window = getWindow("2M", earliest, latest)
|
|
|
- const currentRows = rowsForProduct(modelScopedRows, "All Users", window.start, window.end)
|
|
|
|
|
- const previousRows = rowsForProduct(modelScopedRows, "All Users", window.previousStart, window.previousEnd)
|
|
|
|
|
|
|
+ const currentRows = rowsForProduct(modelScopedRows, SITE_PRODUCT, window.start, window.end)
|
|
|
|
|
+ const previousRows = rowsForProduct(modelScopedRows, SITE_PRODUCT, window.previousStart, window.previousEnd)
|
|
|
const current = combineRowsForModel(model, currentRows)
|
|
const current = combineRowsForModel(model, currentRows)
|
|
|
const previous = combineRowsForModel(model, previousRows)
|
|
const previous = combineRowsForModel(model, previousRows)
|
|
|
- const peers = aggregateByModelName(rowsForProduct(normalized, "All Users", window.start, window.end))
|
|
|
|
|
|
|
+ const peers = 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 previousPeers = aggregateByModelName(
|
|
const previousPeers = aggregateByModelName(
|
|
|
- rowsForProduct(normalized, "All Users", window.previousStart, window.previousEnd),
|
|
|
|
|
|
|
+ rowsForProduct(normalized, SITE_PRODUCT, window.previousStart, window.previousEnd),
|
|
|
)
|
|
)
|
|
|
.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))
|
|
@@ -289,11 +291,11 @@ function buildStatsLabData(providerParam: string, modelRows: ModelStatMetric[]):
|
|
|
const latest = Math.max(...normalized.map((row) => row.periodStart))
|
|
const latest = Math.max(...normalized.map((row) => row.periodStart))
|
|
|
const latestUpdate = Math.max(...providerRows.map((row) => row.updatedAt))
|
|
const latestUpdate = Math.max(...providerRows.map((row) => row.updatedAt))
|
|
|
const window = getWindow("2M", earliest, latest)
|
|
const window = getWindow("2M", earliest, latest)
|
|
|
- const currentRows = rowsForProduct(providerRows, "All Users", window.start, window.end)
|
|
|
|
|
- const previousRows = rowsForProduct(providerRows, "All Users", window.previousStart, window.previousEnd)
|
|
|
|
|
|
|
+ const currentRows = rowsForProduct(providerRows, SITE_PRODUCT, window.start, window.end)
|
|
|
|
|
+ const previousRows = rowsForProduct(providerRows, SITE_PRODUCT, window.previousStart, window.previousEnd)
|
|
|
const current = combineRowsForModel("", currentRows)
|
|
const current = combineRowsForModel("", currentRows)
|
|
|
const previous = combineRowsForModel("", previousRows)
|
|
const previous = combineRowsForModel("", previousRows)
|
|
|
- const allCurrent = aggregateByModel(rowsForProduct(normalized, "All Users", window.start, window.end))
|
|
|
|
|
|
|
+ const allCurrent = aggregateByModel(rowsForProduct(normalized, SITE_PRODUCT, window.start, window.end))
|
|
|
const totalTokens = allCurrent.reduce((sum, item) => sum + item.totalTokens, 0)
|
|
const totalTokens = allCurrent.reduce((sum, item) => sum + item.totalTokens, 0)
|
|
|
const models = aggregateByModel(currentRows)
|
|
const models = aggregateByModel(currentRows)
|
|
|
.filter((item) => item.totalTokens > 0)
|
|
.filter((item) => item.totalTokens > 0)
|
|
@@ -337,9 +339,10 @@ function emptyStatsHomeData(): StatsHomeData {
|
|
|
|
|
|
|
|
function buildUsagePoints(rows: StatMetricRow[], product: UsageProduct, range: UsageRange, window: DateWindow) {
|
|
function buildUsagePoints(rows: StatMetricRow[], product: UsageProduct, range: UsageRange, window: DateWindow) {
|
|
|
const windowRows = rowsForProduct(rows, product, window.start, window.end)
|
|
const windowRows = rowsForProduct(rows, product, window.start, window.end)
|
|
|
- const modelOrder = aggregateByModel(windowRows)
|
|
|
|
|
|
|
+ const rankStart = Math.max(window.start, window.end - 7 * DAY_MS)
|
|
|
|
|
+ const modelOrder = aggregateByModel(rowsForProduct(rows, product, rankStart, window.end))
|
|
|
.toSorted((a, b) => b.totalTokens - a.totalTokens)
|
|
.toSorted((a, b) => b.totalTokens - a.totalTokens)
|
|
|
- .slice(0, 6)
|
|
|
|
|
|
|
+ .slice(0, TOP_MODEL_SEGMENT_LIMIT)
|
|
|
.map((item) => ({ key: modelKey(item.provider, item.model), model: item.model }))
|
|
.map((item) => ({ key: modelKey(item.provider, item.model), model: item.model }))
|
|
|
|
|
|
|
|
return createBuckets(window, range).map((bucket) => {
|
|
return createBuckets(window, range).map((bucket) => {
|
|
@@ -408,7 +411,7 @@ function buildMarketShare(rows: ProviderMetricRow[], product: UsageProduct, rang
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function buildCountryStats(rows: GeoMetricRow[], window: DateWindow) {
|
|
function buildCountryStats(rows: GeoMetricRow[], window: DateWindow) {
|
|
|
- const countries = aggregateByCountry(rowsForProduct(rows, "All Users", window.start, window.end))
|
|
|
|
|
|
|
+ const countries = aggregateByCountry(rowsForProduct(rows, SITE_PRODUCT, window.start, window.end))
|
|
|
.filter((item) => item.tokens > 0 && item.country !== "AQ")
|
|
.filter((item) => item.tokens > 0 && item.country !== "AQ")
|
|
|
.toSorted((a, b) => b.tokens - a.tokens)
|
|
.toSorted((a, b) => b.tokens - a.tokens)
|
|
|
const totalTokens = countries.reduce((sum, item) => sum + item.tokens, 0)
|
|
const totalTokens = countries.reduce((sum, item) => sum + item.tokens, 0)
|