@@ -8,6 +8,7 @@ import { benchmarks } from "./benchmarksUtil.ts";
88import * as allFetchers from "../fetcher/allFetchers.ts" ;
99import { getMatchBlob } from "./getMatchBlob.ts" ;
1010import { getStartOfBlockMinutes } from "./time.ts" ;
11+ import { getMatchRankTier } from "./queries.ts" ;
1112import { isContributor } from "../../CONTRIBUTORS.ts" ;
1213
1314const { metaFetcher } = allFetchers ;
@@ -99,9 +100,16 @@ async function getProMatchInfo(match: Match): Promise<ProMatchInfo> {
99100 * */
100101export async function getPlayerBenchmarks ( m : Match ) {
101102 const turbo = isTurbo ( m ) ;
103+ // Bracket 1-8 from the average rank of the players, matching what the
104+ // write side does in counts.ts (turbo only has global benchmarks)
105+ const { avg } = turbo ? { avg : null } : await getMatchRankTier ( db , m . players ) ;
106+ const bracket = avg ? Math . floor ( avg / 10 ) : null ;
102107 return Promise . all (
103108 m . players . map ( async ( p ) => {
104- const result : Record < string , { raw ?: number ; pct ?: number } > = { } ;
109+ const result : Record <
110+ string ,
111+ { raw ?: number ; pct ?: number ; pct_bracket ?: number }
112+ > = { } ;
105113 for ( let metric of Object . keys ( benchmarks ) ) {
106114 result [ metric ] = { } ;
107115 // Use data from previous epoch
@@ -139,6 +147,18 @@ export async function getPlayerBenchmarks(m: Match) {
139147 const pct =
140148 metric === "deaths_per_min" ? 1 - count / card : count / card ;
141149 result [ metric ] . pct = pct ;
150+ if ( bracket ) {
151+ // Same distribution restricted to this match's rank bracket
152+ const bracketKey = `${ key } :${ bracket } ` ;
153+ const bracketCard = await redis . zcard ( bracketKey ) ;
154+ if ( bracketCard > 0 ) {
155+ const bracketCount = await redis . zcount ( bracketKey , "0" , raw ) ;
156+ result [ metric ] . pct_bracket =
157+ metric === "deaths_per_min"
158+ ? 1 - bracketCount / bracketCard
159+ : bracketCount / bracketCard ;
160+ }
161+ }
142162 }
143163 }
144164 return result ;
0 commit comments