regionals

This commit is contained in:
yohlo
2025-10-16 09:12:11 -05:00
parent 612f1f28bf
commit 470b4ef99c
28 changed files with 962 additions and 97 deletions

View File

@@ -91,7 +91,7 @@ export function createBadgesService(pb: PocketBase) {
async calculateMatchBadgeProgress(playerId: string, badge: Badge): Promise<number> {
const criteria = badge.criteria;
const stats = await pb.collection("player_stats").getFirstListItem<PlayerStats>(
const stats = await pb.collection("player_mainline_stats").getFirstListItem<PlayerStats>(
`player_id = "${playerId}"`
).catch(() => null);
@@ -103,8 +103,8 @@ export function createBadgesService(pb: PocketBase) {
if (criteria.overtime_matches !== undefined || criteria.overtime_wins !== undefined) {
const matches = await pb.collection("matches").getFullList({
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended" && ot_count > 0`,
expand: 'home,away,home.players,away.players',
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended" && ot_count > 0 && (tournament.regional = false || tournament.regional = null)`,
expand: 'tournament,home,away,home.players,away.players',
});
if (criteria.overtime_matches !== undefined) {
@@ -131,8 +131,8 @@ export function createBadgesService(pb: PocketBase) {
if (criteria.margin_of_victory !== undefined) {
const matches = await pb.collection("matches").getFullList({
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended"`,
expand: 'home,away,home.players,away.players',
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended" && (tournament.regional = false || tournament.regional = null)`,
expand: 'tournament,home,away,home.players,away.players',
});
const bigWins = matches.filter(m => {
@@ -159,7 +159,7 @@ export function createBadgesService(pb: PocketBase) {
const criteria = badge.criteria;
const matches = await pb.collection("matches").getFullList({
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended"`,
filter: `(home.players.id ?~ "${playerId}" || away.players.id ?~ "${playerId}") && status = "ended" && (tournament.regional = false || tournament.regional = null)`,
expand: 'tournament,home,away,home.players,away.players',
});
@@ -209,8 +209,8 @@ export function createBadgesService(pb: PocketBase) {
for (const tournamentId of tournamentIds) {
const tournamentMatches = await pb.collection("matches").getFullList({
filter: `tournament = "${tournamentId}" && status = "ended"`,
expand: 'home,away,home.players,away.players',
filter: `tournament = "${tournamentId}" && status = "ended" && (tournament.regional = false || tournament.regional = null)`,
expand: 'tournament,home,away,home.players,away.players',
});
const winnersMatches = tournamentMatches.filter(m => !m.is_losers_bracket);
@@ -241,8 +241,8 @@ export function createBadgesService(pb: PocketBase) {
for (const tournamentId of tournamentIds) {
const tournamentMatches = await pb.collection("matches").getFullList({
filter: `tournament = "${tournamentId}" && status = "ended"`,
expand: 'home,away,home.players,away.players',
filter: `tournament = "${tournamentId}" && status = "ended" && (tournament.regional = false || tournament.regional = null)`,
expand: 'tournament,home,away,home.players,away.players',
});
if (criteria.placement === 2) {
@@ -293,6 +293,7 @@ export function createBadgesService(pb: PocketBase) {
if (criteria.tournament_record !== undefined) {
const tournaments = await pb.collection("tournaments").getFullList({
filter: 'regional = false || regional = null',
sort: 'start_time',
});
@@ -344,6 +345,7 @@ export function createBadgesService(pb: PocketBase) {
if (criteria.consecutive_wins !== undefined) {
const tournaments = await pb.collection("tournaments").getFullList({
filter: 'regional = false || regional = null',
sort: 'start_time',
});

View File

@@ -32,7 +32,7 @@ export function createMatchesService(pb: PocketBase) {
},
async createMatch(data: MatchInput): Promise<Match> {
logger.info("PocketBase | Creating match", data);
// logger.info("PocketBase | Creating match", data);
const result = await pb.collection("matches").create<Match>(data);
return result;
},
@@ -92,23 +92,40 @@ export function createMatchesService(pb: PocketBase) {
return [];
}
const filterConditions: string[] = [];
player1TeamIds.forEach(team1Id => {
player2TeamIds.forEach(team2Id => {
filterConditions.push(`(home="${team1Id}" && away="${team2Id}")`);
filterConditions.push(`(home="${team2Id}" && away="${team1Id}")`);
const allTeamIds = [...new Set([...player1TeamIds, ...player2TeamIds])];
const batchSize = 10;
const allMatches: any[] = [];
for (let i = 0; i < allTeamIds.length; i += batchSize) {
const batch = allTeamIds.slice(i, i + batchSize);
const teamFilters = batch.map(id => `home="${id}" || away="${id}"`).join(' || ');
const results = await pb.collection("matches").getFullList({
filter: teamFilters,
expand: "tournament, home, away, home.players, away.players",
sort: "-created",
});
});
const filter = filterConditions.join(" || ");
allMatches.push(...results);
}
const results = await pb.collection("matches").getFullList({
filter,
expand: "tournament, home, away, home.players, away.players",
sort: "-created",
});
const uniqueMatches = Array.from(
new Map(allMatches.map(m => [m.id, m])).values()
);
return results.map(match => transformMatch(match));
return uniqueMatches
.filter(match => {
const homeTeamId = typeof match.home === 'string' ? match.home : match.home?.id;
const awayTeamId = typeof match.away === 'string' ? match.away : match.away?.id;
const player1InHome = player1TeamIds.includes(homeTeamId);
const player1InAway = player1TeamIds.includes(awayTeamId);
const player2InHome = player2TeamIds.includes(homeTeamId);
const player2InAway = player2TeamIds.includes(awayTeamId);
return (player1InHome && player2InAway) || (player1InAway && player2InHome);
})
.map(match => transformMatch(match));
},
async getMatchesBetweenTeams(team1Id: string, team2Id: string): Promise<Match[]> {

View File

@@ -8,7 +8,6 @@ import type {
import type { Match } from "@/features/matches/types";
import { transformPlayer, transformPlayerInfo, transformMatch } from "@/lib/pocketbase/util/transform-types";
import PocketBase from "pocketbase";
import { DataFetchOptions } from "./base";
export function createPlayersService(pb: PocketBase) {
return {
@@ -65,9 +64,15 @@ export function createPlayersService(pb: PocketBase) {
return result.map(transformPlayer);
},
async getPlayerStats(playerId: string): Promise<PlayerStats> {
async getPlayerStats(playerId: string, viewType: 'all' | 'mainline' | 'regional' = 'all'): Promise<PlayerStats> {
try {
const result = await pb.collection("player_stats").getFirstListItem<PlayerStats>(
const collectionMap = {
all: 'player_stats',
mainline: 'player_mainline_stats',
regional: 'player_regional_stats',
};
const result = await pb.collection(collectionMap[viewType]).getFirstListItem<PlayerStats>(
`player_id = "${playerId}"`
);
return result;
@@ -90,8 +95,14 @@ export function createPlayersService(pb: PocketBase) {
}
},
async getAllPlayerStats(): Promise<PlayerStats[]> {
const result = await pb.collection("player_stats").getFullList<PlayerStats>({
async getAllPlayerStats(viewType: 'all' | 'mainline' | 'regional' = 'all'): Promise<PlayerStats[]> {
const collectionMap = {
all: 'player_stats',
mainline: 'player_mainline_stats',
regional: 'player_regional_stats',
};
const result = await pb.collection(collectionMap[viewType]).getFullList<PlayerStats>({
sort: "-win_percentage,-total_cups_made",
});
return result;

View File

@@ -34,7 +34,7 @@ export function createTournamentsService(pb: PocketBase) {
.getFirstListItem('',
{
expand: "teams, teams.players, matches, matches.tournament, matches.home, matches.away, matches.home.players, matches.away.players",
sort: "-created",
sort: "-start_time",
}
);
@@ -52,7 +52,7 @@ export function createTournamentsService(pb: PocketBase) {
.collection("tournaments")
.getFullList({
expand: "teams,teams.players,matches",
sort: "-created",
sort: "-start_time",
});
const tournamentsWithStats = await Promise.all(result.map(async (tournament) => {