GeezerVison is showing github.com — fix(stats): scope data charts to go · ildella/opencode@a9a4b2f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/stats/app/src/routes/index.tsx +2-4Lines changed: 2 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -810,10 +810,8 @@ function stackedTopModelsSegments(point: UsagePoint, order: Map<string, number>) | 810 | 810 | } | 811 | 811 |
| 812 | 812 | function getTopModelsSegmentOrder(data: UsagePoint[]) { | 813 | | - return getRankOrder( | 814 | | - data.flatMap((point) => | 815 | | - point.segments.map((segment, index) => ({ key: segment.model, value: segment.value, index })), | 816 | | - ), | | 813 | + return new Map( | | 814 | + data.find((point) => point.segments.length > 0)?.segments.map((segment, index) => [segment.model, index]) ?? [], | 817 | 815 | ) | 818 | 816 | } | 819 | 817 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/stats/core/src/domain/geo.ts +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -86,7 +86,15 @@ export class GeoStatRepo extends Context.Service<GeoStatRepo, GeoStatRepo.Servic | 86 | 86 | totalTokens: geoStat.total_tokens, | 87 | 87 | }) | 88 | 88 | .from(geoStat) | 89 | | - .where(and(eq(geoStat.grain, "day"), eq(geoStat.client, "all"), eq(geoStat.source, "all"), scope)) | | 89 | + .where( | | 90 | + and( | | 91 | + eq(geoStat.grain, "day"), | | 92 | + eq(geoStat.client, "all"), | | 93 | + eq(geoStat.source, "all"), | | 94 | + inArray(geoStat.tier, ["Go", "go"]), | | 95 | + scope, | | 96 | + ), | | 97 | + ) | 90 | 98 | .orderBy(asc(geoStat.period_key)), | 91 | 99 | catch: (cause) => DatabaseError.make({ cause }), | 92 | 100 | }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/stats/core/src/domain/home.ts +13-10Lines changed: 13 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -96,6 +96,8 @@ const DAY_MS = 86_400_000 | 96 | 96 | const TOKEN_SCALE = 1_000_000 | 97 | 97 | const DOLLARS_PER_MICROCENT = 1 / 100_000_000 | 98 | 98 | const METRIC_MODEL_LIMIT = 10 | | 99 | +const TOP_MODEL_SEGMENT_LIMIT = 9 | | 100 | +const SITE_PRODUCT = "Go" | 99 | 101 | const LEADERBOARD_CHANGE_MIN_MULTIPLE = 10 | 100 | 102 | const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"] as const | 101 | 103 |
| @@ -227,15 +229,15 @@ function buildStatsModelData( | 227 | 229 | const latest = Math.max(...normalized.map((row) => row.periodStart)) | 228 | 230 | const latestUpdate = Math.max(...modelScopedRows.map((row) => row.updatedAt)) | 229 | 231 | const window = getWindow("2M", earliest, latest) | 230 | | - const currentRows = rowsForProduct(modelScopedRows, "All Users", window.start, window.end) | 231 | | - const previousRows = rowsForProduct(modelScopedRows, "All Users", window.previousStart, window.previousEnd) | | 232 | + const currentRows = rowsForProduct(modelScopedRows, SITE_PRODUCT, window.start, window.end) | | 233 | + const previousRows = rowsForProduct(modelScopedRows, SITE_PRODUCT, window.previousStart, window.previousEnd) | 232 | 234 | const current = combineRowsForModel(model, currentRows) | 233 | 235 | const previous = combineRowsForModel(model, previousRows) | 234 | | - const peers = aggregateByModelName(rowsForProduct(normalized, "All Users", window.start, window.end)) | | 236 | + const peers = aggregateByModelName(rowsForProduct(normalized, SITE_PRODUCT, window.start, window.end)) | 235 | 237 | .filter((item) => item.totalTokens > 0) | 236 | 238 | .toSorted((a, b) => b.totalTokens - a.totalTokens || a.model.localeCompare(b.model)) | 237 | 239 | const previousPeers = aggregateByModelName( | 238 | | - rowsForProduct(normalized, "All Users", window.previousStart, window.previousEnd), | | 240 | + rowsForProduct(normalized, SITE_PRODUCT, window.previousStart, window.previousEnd), | 239 | 241 | ) | 240 | 242 | .filter((item) => item.totalTokens > 0) | 241 | 243 | .toSorted((a, b) => b.totalTokens - a.totalTokens || a.model.localeCompare(b.model)) | @@ -289,11 +291,11 @@ function buildStatsLabData(providerParam: string, modelRows: ModelStatMetric[]): | 289 | 291 | const latest = Math.max(...normalized.map((row) => row.periodStart)) | 290 | 292 | const latestUpdate = Math.max(...providerRows.map((row) => row.updatedAt)) | 291 | 293 | const window = getWindow("2M", earliest, latest) | 292 | | - const currentRows = rowsForProduct(providerRows, "All Users", window.start, window.end) | 293 | | - const previousRows = rowsForProduct(providerRows, "All Users", window.previousStart, window.previousEnd) | | 294 | + const currentRows = rowsForProduct(providerRows, SITE_PRODUCT, window.start, window.end) | | 295 | + const previousRows = rowsForProduct(providerRows, SITE_PRODUCT, window.previousStart, window.previousEnd) | 294 | 296 | const current = combineRowsForModel("", currentRows) | 295 | 297 | const previous = combineRowsForModel("", previousRows) | 296 | | - const allCurrent = aggregateByModel(rowsForProduct(normalized, "All Users", window.start, window.end)) | | 298 | + const allCurrent = aggregateByModel(rowsForProduct(normalized, SITE_PRODUCT, window.start, window.end)) | 297 | 299 | const totalTokens = allCurrent.reduce((sum, item) => sum + item.totalTokens, 0) | 298 | 300 | const models = aggregateByModel(currentRows) | 299 | 301 | .filter((item) => item.totalTokens > 0) | @@ -337,9 +339,10 @@ function emptyStatsHomeData(): StatsHomeData { | 337 | 339 |
| 338 | 340 | function buildUsagePoints(rows: StatMetricRow[], product: UsageProduct, range: UsageRange, window: DateWindow) { | 339 | 341 | const windowRows = rowsForProduct(rows, product, window.start, window.end) | 340 | | - const modelOrder = aggregateByModel(windowRows) | | 342 | + const rankStart = Math.max(window.start, window.end - 7 * DAY_MS) | | 343 | + const modelOrder = aggregateByModel(rowsForProduct(rows, product, rankStart, window.end)) | 341 | 344 | .toSorted((a, b) => b.totalTokens - a.totalTokens) | 342 | | - .slice(0, 6) | | 345 | + .slice(0, TOP_MODEL_SEGMENT_LIMIT) | 343 | 346 | .map((item) => ({ key: modelKey(item.provider, item.model), model: item.model })) | 344 | 347 |
| 345 | 348 | return createBuckets(window, range).map((bucket) => { | @@ -408,7 +411,7 @@ function buildMarketShare(rows: ProviderMetricRow[], product: UsageProduct, rang | 408 | 411 | } | 409 | 412 |
| 410 | 413 | function buildCountryStats(rows: GeoMetricRow[], window: DateWindow) { | 411 | | - const countries = aggregateByCountry(rowsForProduct(rows, "All Users", window.start, window.end)) | | 414 | + const countries = aggregateByCountry(rowsForProduct(rows, SITE_PRODUCT, window.start, window.end)) | 412 | 415 | .filter((item) => item.tokens > 0 && item.country !== "AQ") | 413 | 416 | .toSorted((a, b) => b.tokens - a.tokens) | 414 | 417 | const totalTokens = countries.reduce((sum, item) => sum + item.tokens, 0) | |
Collapse file Copy file name to clipboardExpand all lines: packages/stats/core/src/domain/model.ts +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -74,7 +74,14 @@ export class ModelStatRepo extends Context.Service<ModelStatRepo, ModelStatRepo. | 74 | 74 | totalCostMicrocents: modelStat.total_cost_microcents, | 75 | 75 | }) | 76 | 76 | .from(modelStat) | 77 | | - .where(and(eq(modelStat.grain, "day"), eq(modelStat.client, "all"), eq(modelStat.source, "all"))) | | 77 | + .where( | | 78 | + and( | | 79 | + eq(modelStat.grain, "day"), | | 80 | + eq(modelStat.client, "all"), | | 81 | + eq(modelStat.source, "all"), | | 82 | + inArray(modelStat.tier, ["Go", "go"]), | | 83 | + ), | | 84 | + ) | 78 | 85 | .orderBy(asc(modelStat.period_key)), | 79 | 86 | catch: (cause) => DatabaseError.make({ cause }), | 80 | 87 | }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/stats/core/src/domain/provider.ts +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,7 +62,14 @@ export class ProviderStatRepo extends Context.Service<ProviderStatRepo, Provider | 62 | 62 | totalTokens: providerStat.total_tokens, | 63 | 63 | }) | 64 | 64 | .from(providerStat) | 65 | | - .where(and(eq(providerStat.grain, "day"), eq(providerStat.client, "all"), eq(providerStat.source, "all"))) | | 65 | + .where( | | 66 | + and( | | 67 | + eq(providerStat.grain, "day"), | | 68 | + eq(providerStat.client, "all"), | | 69 | + eq(providerStat.source, "all"), | | 70 | + inArray(providerStat.tier, ["Go", "go"]), | | 71 | + ), | | 72 | + ) | 66 | 73 | .orderBy(asc(providerStat.period_key)), | 67 | 74 | catch: (cause) => DatabaseError.make({ cause }), | 68 | 75 | }) | |
|