mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-25 15:56:19 -05:00
league script update
This commit is contained in:
parent
e3c9955bf5
commit
6daaf2cc51
|
|
@ -6,9 +6,12 @@ import prisma from "../client";
|
|||
|
||||
const files = ["P_EU", "P_US", "T_EU", "T_US", "P_JP", "T_JP"];
|
||||
|
||||
let oldestDate = new Date("2050");
|
||||
|
||||
async function main() {
|
||||
for (const file of files) {
|
||||
const squads: Prisma.LeagueSquadCreateInput[] = [];
|
||||
const squadsData: Prisma.LeagueSquadCreateManyInput[] = [];
|
||||
const playersData: Prisma.PlayerCreateManyInput[] = [];
|
||||
const data = fs.readFileSync(
|
||||
path.resolve(__dirname, `./data/league/${file}.json`)
|
||||
);
|
||||
|
|
@ -19,39 +22,87 @@ async function main() {
|
|||
if (ranking.cheater) continue;
|
||||
if (ranking.point < 2200) continue;
|
||||
|
||||
squads.push({
|
||||
const startTime = new Date(rotation.start_time * 1000);
|
||||
|
||||
if (startTime.getTime() < oldestDate.getTime()) {
|
||||
oldestDate = startTime;
|
||||
}
|
||||
|
||||
squadsData.push({
|
||||
leaguePower: ranking.point,
|
||||
region:
|
||||
rotation.league_ranking_region.code === "US"
|
||||
? "NA"
|
||||
: rotation.league_ranking_region.code,
|
||||
startTime: new Date(rotation.start_time * 1000),
|
||||
startTime,
|
||||
type: rotation.league_type.key === "pair" ? "TWIN" : "QUAD",
|
||||
members: {
|
||||
create: ranking.tag_members.map((member: any) => ({
|
||||
weapon: getWeaponNormalized(member.weapon[1].trim()),
|
||||
player: {
|
||||
connectOrCreate: {
|
||||
create: {
|
||||
switchAccountId: member.unique_id,
|
||||
principalId: member.principal_id,
|
||||
},
|
||||
where: {
|
||||
switchAccountId: member.unique_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
})),
|
||||
},
|
||||
});
|
||||
|
||||
ranking.tag_members.forEach((member: any) => {
|
||||
playersData.push({
|
||||
switchAccountId: member.unique_id,
|
||||
principalId: member.principal_id,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const newSquads = squads.map((input) =>
|
||||
prisma.leagueSquad.create({ data: input })
|
||||
);
|
||||
console.log("oldest = ", oldestDate.getTime());
|
||||
|
||||
await prisma.leagueSquad.createMany({ data: squadsData });
|
||||
|
||||
console.log("leagueSquads created");
|
||||
|
||||
await prisma.player.createMany({ data: playersData, skipDuplicates: true });
|
||||
|
||||
console.log("players created");
|
||||
|
||||
const createdSquads = await prisma.leagueSquad.findMany({
|
||||
where: { startTime: { gte: oldestDate } },
|
||||
});
|
||||
const ids = new Set<number>();
|
||||
const leagueMembersData: Prisma.LeagueSquadMemberCreateManyInput[] = [];
|
||||
|
||||
for (const rotation of league) {
|
||||
for (const ranking of rotation.rankings) {
|
||||
if (ranking.cheater) continue;
|
||||
if (ranking.point < 2200) continue;
|
||||
|
||||
const startTime = new Date(rotation.start_time * 1000);
|
||||
|
||||
const type = rotation.league_type.key === "pair" ? "TWIN" : "QUAD";
|
||||
const region =
|
||||
rotation.league_ranking_region.code === "US"
|
||||
? "NA"
|
||||
: rotation.league_ranking_region.code;
|
||||
|
||||
const squad = createdSquads.find(
|
||||
(squad) =>
|
||||
squad.leaguePower === ranking.point &&
|
||||
squad.region === region &&
|
||||
squad.type === type &&
|
||||
squad.startTime.getTime() === startTime.getTime() &&
|
||||
!ids.has(squad.id)
|
||||
);
|
||||
|
||||
if (!squad) throw Error("squad not found");
|
||||
|
||||
ids.add(squad.id);
|
||||
|
||||
ranking.tag_members.forEach((member: any) => {
|
||||
leagueMembersData.push({
|
||||
switchAccountId: member.unique_id,
|
||||
squadId: squad.id,
|
||||
weapon: getWeaponNormalized(member.weapon[1].trim()),
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.leagueSquadMember.createMany({ data: leagueMembersData });
|
||||
|
||||
console.log("members created");
|
||||
|
||||
await prisma.$transaction([...newSquads]);
|
||||
console.log("done with", file);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user