Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ docker compose up -d

```bash
cd packages/database
bun run db:push
bun run db:migrate
```

5. Popular o banco com os dados de demos
Expand Down
40 changes: 40 additions & 0 deletions apps/parser/src/damages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { DemoFile, NewDamage } from "./types.js";

export const createDamages = (data: DemoFile, matchId: string) => {
const damages: NewDamage[] = [];

for (const damage of data.damages) {
damages.push({
matchId,

tick: damage.tick,
roundNumber: damage.roundNumber,

healthDamage: damage.healthDamage,
armorDamage: damage.armorDamage,

attackerSteamId: damage.attackerSteamId,
attackerSide: damage.attackerSide,
attackerTeamName: damage.attackerTeamName,
isAttackerControllingBot: damage.isAttackerControllingBot,

victimSteamId: damage.victimSteamId,
victimSide: damage.victimSide,
victimTeamName: damage.victimTeamName,
isVictimControllingBot: damage.isVictimControllingBot,

victimHealth: damage.victimHealth,
victimNewHealth: damage.victimNewHealth,
victimArmor: damage.victimArmor,
victimNewArmor: damage.victimNewArmor,

hitgroup: damage.hitgroup,

weaponName: damage.weaponName,
weaponType: damage.weaponType,
weaponUniqueId: damage.weaponUniqueId,
});
}

return damages;
};
52 changes: 52 additions & 0 deletions apps/parser/src/kills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { DemoFile, NewKill } from "./types.js";

export const createKills = (data: DemoFile, matchId: string) => {
const kills: NewKill[] = [];
for (const kill of data.kills) {
kills.push({
matchId,
roundNumber: kill.roundNumber,
tick: kill.tick,
weaponType: kill.weaponType,
weaponName: kill.weaponName,
killerName: kill.killerName,
killerSteamId: kill.killerSteamId,
killerSide: kill.killerSide,
killerTeamName: kill.killerTeamName,
killerX: kill.killerX,
killerY: kill.killerY,
killerZ: kill.killerZ,
isKillerAirborne: kill.is_killer_airborne,
isKillerBlinded: kill.is_killer_blinded,
isKillerControllingBot: kill.isKillerControllingBot,
victimName: kill.victimName,
victimSteamId: kill.victimSteamId,
victimSide: kill.victimSide,
victimTeamName: kill.victimTeamName,
victimX: kill.victimX,
victimY: kill.victimY,
victimZ: kill.victimZ,
isVictimAirborne: kill.is_victim_airborne,
isVictimBlinded: kill.is_victim_blinded,
isVictimControllingBot: kill.isVictimControllingBot,
isVictimInspectingWeapon: kill.isVictimInspectingWeapon,
assisterName: kill.assisterName,
assisterSteamId: kill.assisterSteamId,
assisterSide: kill.assisterSide,
assisterTeamName: kill.assisterTeamName,
assisterX: kill.assisterX,
assisterY: kill.assisterY,
assisterZ: kill.assisterZ,
isAssisterControllingBot: kill.isAssisterControllingBot,
isAssistedFlash: kill.isAssistedFlash,
isHeadshot: kill.isHeadshot,
penetratedObjects: kill.penetratedObjects,
isThroughSmoke: kill.isThroughSmoke,
isNoScope: kill.isNoScope,
isTradeKill: kill.isTradeKill,
isTradeDeath: kill.isTradeDeath,
distance: kill.distance,
});
}
return kills;
};
37 changes: 37 additions & 0 deletions apps/parser/src/rounds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { DemoFile, NewRound } from "./types.js";

export const createRounds = (data: DemoFile, matchId: string) => {
const rounds: NewRound[] = [];

for (const round of data.rounds) {
rounds.push({
matchId,
number: round.number,
startTick: round.startTick,
freezeTimeEndTick: round.freezeTimeEndTick,
endTick: round.endTick,
endOfficiallyTick: round.endOfficiallyTick,
overtimeNumber: round.overtimeNumber,
teamAName: round.teamAName,
teamBName: round.teamBName,
teamAScore: round.teamAScore,
teamBScore: round.teamBScore,
teamASide: round.teamASide,
teamBSide: round.teamBSide,
teamAEquipmentValue: round.teamAEquipmentValue,
teamBEquipmentValue: round.teamBEquipmentValue,
teamAMoneySpent: round.teamAMoneySpent,
teamBMoneySpent: round.teamBmoneySpent,
teamAEconomyType: round.teamAEconomyType,
teamBEconomyType: round.teamBEconomyType,
duration: round.duration,
endReason: round.endReason,
winnerName: round.winnerName,
winnerSide: round.winnerSide,
teamAStartMoney: round.teamAStartMoney,
teamBStartMoney: round.teamBStartMoney,
});
}

return rounds;
};
15 changes: 15 additions & 0 deletions apps/parser/src/save-demo-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { DrizzleQueryError, db } from "@repo/database";
import * as schema from "@repo/database/schema";
import JSONbig from "json-bigint";
import { createClutches } from "./clutches.js";
import { createDamages } from "./damages.js";
import { createDuels } from "./duels.js";
import { createKills } from "./kills.js";
import { createMatch } from "./match.js";
import { calculateAggregatedStats } from "./players.js";
import { createRounds } from "./rounds.js";
import { createTeams, mapTeamsIds } from "./teams.js";
import type { DemoFile, NewMatch, NewPlayer } from "./types.js";

Expand Down Expand Up @@ -51,6 +54,18 @@ export const saveDemoData = async (fileName: string) => {
const clutches = createClutches(data, matchData.id);

await tx.insert(schema.clutches).values(clutches);

const kills = createKills(data, matchData.id);

await tx.insert(schema.kills).values(kills);

const rounds = createRounds(data, matchData.id);

await tx.insert(schema.rounds).values(rounds);

const damages = createDamages(data, matchData.id);

await tx.insert(schema.damages).values(damages);
});
console.log(
`Dados da demo ${data.demoFileName} salvos com sucesso no banco.`,
Expand Down
30 changes: 30 additions & 0 deletions apps/parser/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export type NewTeam = typeof schema.teams.$inferInsert;
export type NewPlayer = typeof schema.players.$inferInsert;
export type NewDuel = typeof schema.playerDuels.$inferInsert;
export type NewClutch = typeof schema.clutches.$inferInsert;
export type NewKill = typeof schema.kills.$inferInsert;
export type NewRound = typeof schema.rounds.$inferInsert;
export type NewDamage = typeof schema.damages.$inferInsert;

export type DemoFile = {
checksum: string;
Expand All @@ -21,6 +24,7 @@ export type DemoFile = {
shots: DemoShot[];
damages: DemoDamage[];
clutches: DemoClutch[];
rounds: DemoRound[];
};

export type DemoTeam = {
Expand Down Expand Up @@ -77,6 +81,32 @@ export interface DemoKill {
distance: number;
}

export interface DemoRound {
number: number;
startTick: number;
freezeTimeEndTick: number;
endTick: number;
endOfficiallyTick: number;
overtimeNumber: number;
teamAName: string;
teamBName: string;
teamAScore: number;
teamBScore: number;
teamASide: number;
teamBSide: number;
teamAEquipmentValue: number;
teamBEquipmentValue: number;
teamAMoneySpent: number;
teamBmoneySpent: number;
teamAEconomyType: string;
teamBEconomyType: string;
duration: number;
endReason: number;
winnerName: string;
winnerSide: number;
teamAStartMoney: number;
teamBStartMoney: number;
}
export type DemoClutch = {
frame: number;
tick: number;
Expand Down
31 changes: 23 additions & 8 deletions apps/web/app/(public)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { MatchDTO } from "@repo/contracts";
import { MatchPreview } from "@/components/match-list/MatchPreview";
import { listMatches } from "@/lib/api/match";
import { SeriesPreview } from "@/components/match-list/SeriesPreview";
import { listMatchesWithPlayers } from "@/lib/api/match";
import { findTeams } from "@/lib/api/series";

export const dynamic = "force-dynamic";

export default async function Home() {
const matches: MatchDTO[] = await listMatches();
const matches: MatchDTO[] = await listMatchesWithPlayers();

const matchMapByMonth = new Map<string, MatchDTO[]>();

Expand All @@ -22,7 +24,18 @@ export default async function Home() {
matchMapByMonth.set(month, [...currentMatchList, match]);
}
});
const matchMapEntries = Array.from(matchMapByMonth.entries());
const matchMapEntries = await Promise.all(
Array.from(matchMapByMonth.entries()).map(async ([month, matchList]) => {
const seriesTeam = await findTeams(matchList);

return {
month,
matchList,
seriesTeam,
};
}),
);

return (
<div className="max-w-7xl mx-auto py-12">
<h1 className="text-4xl font-bold text-center md:text-left">Partidas</h1>
Expand All @@ -32,14 +45,16 @@ export default async function Home() {
</p>
)}
<div className="flex flex-col gap-12">
{matchMapEntries.map(([month, matchList]) => (
{matchMapEntries.map(({ month, matchList, seriesTeam }) => (
<div className="flex flex-col mt-8 md:gap-4 gap-8" key={month}>
<p className="capitalize text-2xl border-b pb-2 mb-2 mx-4 md:px-0 px-5">
{month}
</p>
<SeriesPreview month={month} seriesTeam={seriesTeam} />
{matchList.map((match) => (
<div key={match.id}>
<MatchPreview match={match} />
<MatchPreview
match={match}
teamA0={seriesTeam.teamA.players}
teamB0={seriesTeam.teamB.players}
/>
</div>
))}
</div>
Expand Down
14 changes: 12 additions & 2 deletions apps/web/app/(public)/profile/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import { notFound } from "next/navigation";
import { PlayerProfile } from "@/components/player-profile/PlayerProfile";
import { getPlayerProfileData, getPlayersRankingData } from "@/lib/api/player";
import {
getPlayerAmount,
getPlayerProfileData,
getPlayersRankingData,
} from "@/lib/api/player";

export default async function ProfilePage({
params,
Expand All @@ -11,6 +15,8 @@ export default async function ProfilePage({
}) {
const { id } = await params;
const profileData = await getPlayerProfileData(id);
const playerAmount = await getPlayerAmount("all");
console.log("test:", playerAmount);
const playersRanking = await getPlayersRankingData();

if (!profileData) {
Expand All @@ -19,7 +25,11 @@ export default async function ProfilePage({

return (
<div className="py-12 mx-4">
<PlayerProfile profile={profileData} playersRanking={playersRanking} />
<PlayerProfile
profile={profileData}
playersRanking={playersRanking}
playerAmount={playerAmount}
/>
</div>
);
}
8 changes: 6 additions & 2 deletions apps/web/app/(public)/ranking/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { notFound } from "next/navigation";
import { PlayersRankingTable } from "@/components/ranking/PlayersRankingTable";
import { getPlayersRankingData } from "@/lib/api/player";
import { getPlayerAmount, getPlayersRankingData } from "@/lib/api/player";
import { sortRankingByStat } from "@/lib/ranking";

export const dynamic = "force-dynamic";
Expand All @@ -13,13 +13,17 @@ export default async function MainRankingPage() {
}

rankingData = sortRankingByStat(rankingData, "rating2");
const playerAmount = await getPlayerAmount();

return (
<div className="max-w-7xl mx-auto my-12">
<h1 className="text-4xl font-bold text-center md:text-left">Ranking</h1>

<div className="flex flex-col w-full mt-8">
<PlayersRankingTable players={rankingData} />
<PlayersRankingTable
players={rankingData}
playerAmount={playerAmount}
/>
</div>
</div>
);
Expand Down
Loading