GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(stats): scope data charts to go · ildella/opencode@a9a4b2f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/stats
    • app/src/routes
      • index.tsx
    • core/src/domain
      • geo.ts
      • home.ts
      • model.ts
      • provider.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/stats/app/src/routes/index.tsx‎

Copy file name to clipboardExpand all lines: packages/stats/app/src/routes/index.tsx
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,8 @@ function stackedTopModelsSegments(point: UsagePoint, order: Map<string, number>)
810810
}
811811

812812
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]) ?? [],
817815
)
818816
}
819817

Collapse file

‎packages/stats/core/src/domain/geo.ts‎

Copy file name to clipboardExpand all lines: packages/stats/core/src/domain/geo.ts
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ export class GeoStatRepo extends Context.Service<GeoStatRepo, GeoStatRepo.Servic
8686
totalTokens: geoStat.total_tokens,
8787
})
8888
.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+
)
9098
.orderBy(asc(geoStat.period_key)),
9199
catch: (cause) => DatabaseError.make({ cause }),
92100
})
Collapse file

‎packages/stats/core/src/domain/home.ts‎

Copy file name to clipboardExpand all lines: packages/stats/core/src/domain/home.ts
+13-10Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const DAY_MS = 86_400_000
9696
const TOKEN_SCALE = 1_000_000
9797
const DOLLARS_PER_MICROCENT = 1 / 100_000_000
9898
const METRIC_MODEL_LIMIT = 10
99+
const TOP_MODEL_SEGMENT_LIMIT = 9
100+
const SITE_PRODUCT = "Go"
99101
const LEADERBOARD_CHANGE_MIN_MULTIPLE = 10
100102
const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"] as const
101103

@@ -227,15 +229,15 @@ function buildStatsModelData(
227229
const latest = Math.max(...normalized.map((row) => row.periodStart))
228230
const latestUpdate = Math.max(...modelScopedRows.map((row) => row.updatedAt))
229231
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)
232234
const current = combineRowsForModel(model, currentRows)
233235
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))
235237
.filter((item) => item.totalTokens > 0)
236238
.toSorted((a, b) => b.totalTokens - a.totalTokens || a.model.localeCompare(b.model))
237239
const previousPeers = aggregateByModelName(
238-
rowsForProduct(normalized, "All Users", window.previousStart, window.previousEnd),
240+
rowsForProduct(normalized, SITE_PRODUCT, window.previousStart, window.previousEnd),
239241
)
240242
.filter((item) => item.totalTokens > 0)
241243
.toSorted((a, b) => b.totalTokens - a.totalTokens || a.model.localeCompare(b.model))
@@ -289,11 +291,11 @@ function buildStatsLabData(providerParam: string, modelRows: ModelStatMetric[]):
289291
const latest = Math.max(...normalized.map((row) => row.periodStart))
290292
const latestUpdate = Math.max(...providerRows.map((row) => row.updatedAt))
291293
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)
294296
const current = combineRowsForModel("", currentRows)
295297
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))
297299
const totalTokens = allCurrent.reduce((sum, item) => sum + item.totalTokens, 0)
298300
const models = aggregateByModel(currentRows)
299301
.filter((item) => item.totalTokens > 0)
@@ -337,9 +339,10 @@ function emptyStatsHomeData(): StatsHomeData {
337339

338340
function buildUsagePoints(rows: StatMetricRow[], product: UsageProduct, range: UsageRange, window: DateWindow) {
339341
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))
341344
.toSorted((a, b) => b.totalTokens - a.totalTokens)
342-
.slice(0, 6)
345+
.slice(0, TOP_MODEL_SEGMENT_LIMIT)
343346
.map((item) => ({ key: modelKey(item.provider, item.model), model: item.model }))
344347

345348
return createBuckets(window, range).map((bucket) => {
@@ -408,7 +411,7 @@ function buildMarketShare(rows: ProviderMetricRow[], product: UsageProduct, rang
408411
}
409412

410413
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))
412415
.filter((item) => item.tokens > 0 && item.country !== "AQ")
413416
.toSorted((a, b) => b.tokens - a.tokens)
414417
const totalTokens = countries.reduce((sum, item) => sum + item.tokens, 0)
Collapse file

‎packages/stats/core/src/domain/model.ts‎

Copy file name to clipboardExpand all lines: packages/stats/core/src/domain/model.ts
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ export class ModelStatRepo extends Context.Service<ModelStatRepo, ModelStatRepo.
7474
totalCostMicrocents: modelStat.total_cost_microcents,
7575
})
7676
.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+
)
7885
.orderBy(asc(modelStat.period_key)),
7986
catch: (cause) => DatabaseError.make({ cause }),
8087
})
Collapse file

‎packages/stats/core/src/domain/provider.ts‎

Copy file name to clipboardExpand all lines: packages/stats/core/src/domain/provider.ts
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ export class ProviderStatRepo extends Context.Service<ProviderStatRepo, Provider
6262
totalTokens: providerStat.total_tokens,
6363
})
6464
.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+
)
6673
.orderBy(asc(providerStat.period_key)),
6774
catch: (cause) => DatabaseError.make({ cause }),
6875
})

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.