DEV Community

no momo
no momo

Posted on

Frontend Data Engineering: Aggregating Match Logs into a Ranking Table

If you visit kanto-tactics.com, you'll see a ranking table of "comps" (four-unit cores). It looks simple, but the data pipeline to get there runs entirely in your browser.

The raw data from the public game feed is a flat list of hundreds of match logs. Extracting meaning from this is a classic data engineering problem.

The Combinatorial Explosion
The game has 69 units. A team is built around a core of 4 units. The number of possible combinations is C(69, 4) = 864,501. We have to group every match log by its 4-unit core.

Doing this naively with filter() for every possible combination will freeze the browser. Instead, we normalize the core into a sorted, joined string (e.g., "unit_1|unit_5|unit_22|unit_45"), and use a Map as a hash table to aggregate stats in a single O(N) pass:

const statsMap = new Map();

for (const match of matches) {
  const coreId = match.core.sort().join('|');
  if (!statsMap.has(coreId)) {
    statsMap.set(coreId, { games: 0, wins: 0, top4: 0, totalPlace: 0 });
  }
  const stats = statsMap.get(coreId);
  stats.games++;
  if (match.place === 1) stats.wins++;
  if (match.place <= 4) stats.top4++;
  stats.totalPlace += match.place;
}
Enter fullscreen mode Exit fullscreen mode

The 50-Game Threshold: A Statistical Necessity
The site enforces a minimum of 50 games before a comp appears in the top rankings. Why 50? Because with 10 games, an average placement of 2.0 could just be a lucky streak. By applying a hard filter if (stats.games >= 50), we drastically reduce the noise. It's a frontend implementation of a confidence threshold.

Offloading to Web Workers
Even with a single pass, processing 100k+ JSON objects and calculating averages will block the main thread, causing the UI to stutter. To keep the site responsive, this aggregation logic belongs in a Web Worker. The main thread passes the raw array to the worker via postMessage, the worker does the heavy lifting, and returns only the sorted top N results.

The full ranked table is live at kanto-tactics.com. If you're building data-heavy frontends, always check the size of your input before calling .map() on the main thread.

Top comments (0)