diff --git a/index.mjs b/index.mjs index 10f8d92..57e9405 100644 --- a/index.mjs +++ b/index.mjs @@ -65,25 +65,64 @@ console.log(`Common Game Data Found: ${commonGameIds.length}`); commonGames.reverse(); -commonGames +let gameData = commonGames .map(({ info, metadata }) => ({ id: metadata.matchId, - queueId: info.queueId, data: info.participants .filter(({ puuid }) => puuid === ice.puuid || puuid === val.puuid) - .map(({ championId, championName, summonerName, lane }) => ({ - championId, - championName, - summonerName, - lane, - })), + .map( + ({ + championName, + summonerName, + individualPosition, + teamPosition, + win, + }) => ({ + championName, + summonerName, + individualPosition, + teamPosition, + win, + }), + ) + .map(({ individualPosition, teamPosition, ...rest }) => { + const estimates = [...new Set([individualPosition, teamPosition])]; + + /** @type {string} */ + let positionEstimate; + if (estimates.length === 1) { + positionEstimate = estimates[0]; + } else if (estimates.length > 1) { + positionEstimate = + estimates.find((e) => e === "BOTTOM" || e === "UTILITY") || + estimates[0]; + } else { + positionEstimate = "NONE"; + } + + return { + ...rest, + positionEstimate, + }; + }), })) - .filter((g) => g.queueId !== 400) - // .filter(({ data }) => { - // const lanes = data.map((s) => s.lane); - // return lanes.includes("BOTTOM") && lanes.includes("SUPPORT"); - // }) - .forEach((g) => console.log(g)); + .filter(({ data }) => + data + .map(({ positionEstimate }) => positionEstimate) + .every((estimates) => estimates === "BOTTOM" || estimates === "UTILITY"), + ) + .map(({ data, ...rest }) => { + return { + ...rest, + win: data[0].win, + data: data.reduce((acc, playerData) => { + acc[playerData.summonerName] = playerData.positionEstimate; + return acc; + }, {}), + }; + }); + +gameData.forEach((g) => console.log(JSON.stringify(g, null, " "))); /** * @param {string} puuid