|
| 1 | +import {readCsvFile} from "../components/loadfiles.js"; |
| 2 | + |
| 3 | +const draftOrder = await readCsvFile("src/data/static/draft_order.csv"); |
| 4 | +const currentPicks = await readCsvFile("src/data/static/current_picks.csv"); |
| 5 | +const teamInfo = await readCsvFile("src/data/static/team_info.csv"); |
| 6 | + |
| 7 | +// Build a lookup map: pick key (e.g. "ANA1") -> owner |
| 8 | +const pickOwnerMap = {}; |
| 9 | +for (const pick of currentPicks) { |
| 10 | + pickOwnerMap[pick.PICK] = pick.OWNER; |
| 11 | +} |
| 12 | + |
| 13 | +// Build a lookup map: ABBR -> NAME |
| 14 | +const teamNameMap = {}; |
| 15 | +for (const team of teamInfo) { |
| 16 | + teamNameMap[team.ABBR] = team.NAME; |
| 17 | +} |
| 18 | + |
| 19 | +// Determine which rounds beyond 1 exist in current_picks |
| 20 | +const roundsInPicks = [...new Set(currentPicks.map(p => { |
| 21 | + const match = p.PICK.match(/\d+$/); |
| 22 | + return match ? parseInt(match[0]) : null; |
| 23 | +}).filter(Boolean))].sort((a, b) => a - b); |
| 24 | + |
| 25 | +const otherRounds = roundsInPicks.filter(r => r > 1); |
| 26 | + |
| 27 | +// Round 1 order |
| 28 | +const round1Rows = draftOrder |
| 29 | + .filter(row => row.ROUND === "1") |
| 30 | + .sort((a, b) => +a.ORDER - +b.ORDER) |
| 31 | + .map(row => ({ |
| 32 | + order: +row.ORDER, |
| 33 | + pick: row.TEAM, |
| 34 | + pickName: teamNameMap[row.TEAM] || row.TEAM, |
| 35 | + owner: pickOwnerMap[`${row.TEAM}1`] || "—", |
| 36 | + ownerName: teamNameMap[pickOwnerMap[`${row.TEAM}1`]] || "—" |
| 37 | + })); |
| 38 | + |
| 39 | +// Other rounds order (ROUND=2 rows define the order for all rounds 2+) |
| 40 | +const otherRoundsRows = draftOrder |
| 41 | + .filter(row => row.ROUND === "2") |
| 42 | + .sort((a, b) => +a.ORDER - +b.ORDER) |
| 43 | + .map(row => { |
| 44 | + const entry = { |
| 45 | + order: +row.ORDER, |
| 46 | + pick: row.TEAM, |
| 47 | + pickName: teamNameMap[row.TEAM] || row.TEAM |
| 48 | + }; |
| 49 | + for (const r of otherRounds) { |
| 50 | + const owner = pickOwnerMap[`${row.TEAM}${r}`] || "—"; |
| 51 | + entry[`r${r}`] = owner; |
| 52 | + entry[`r${r}Name`] = teamNameMap[owner] || "—"; |
| 53 | + } |
| 54 | + return entry; |
| 55 | + }); |
| 56 | + |
| 57 | +process.stdout.write(JSON.stringify({ |
| 58 | + round1: round1Rows, |
| 59 | + otherRounds: otherRoundsRows, |
| 60 | + otherRoundNumbers: otherRounds |
| 61 | +})); |
0 commit comments