|
2 | 2 | import type { iJersey } from "@/v2/models/jersey/jersey"; |
3 | 3 | import { Jersey } from "@/v2/models/jersey/jersey"; |
4 | 4 | import { JerseyBan } from "@/v2/models/jersey/jerseyBan"; |
5 | | -import { JerseyBid } from "@/v2/models/jersey/jerseyBid"; |
6 | 5 | import type { iJerseyBidInfo } from "@/v2/models/jersey/jerseyBidInfo"; |
7 | 6 | import { JerseyBidInfo } from "@/v2/models/jersey/jerseyBidInfo"; |
8 | 7 | import { Member } from "@/v2/models/jersey/member"; |
9 | 8 | import type { iTeam } from "@/v2/models/jersey/team"; |
10 | 9 | import { type iUser } from "@/v2/models/user"; |
11 | | -import { getEligible, isEligibleWithoutUserLegible } from "@/v2/utils/jersey"; |
| 10 | +import { getEligible } from "@/v2/utils/jersey"; |
12 | 11 | import { logAndThrow } from "@/v2/utils/logger"; |
13 | 12 | import { MongoSession } from "@/v2/utils/mongoSession"; |
14 | 13 | import mongoose from "mongoose"; |
@@ -71,62 +70,62 @@ async function allocateUser( |
71 | 70 | ); |
72 | 71 | } |
73 | 72 |
|
74 | | -async function allocate(jersey: iJersey, priority: number, round: number, session: MongoSession) { |
75 | | - // console.log(`Allocating jersey ${jersey.number} with priority ${priority}`); |
76 | | - const bids = await JerseyBid.find({ jersey: jersey._id, priority, round }).lean().session(session.session); |
77 | | - |
78 | | - let bidders = logAndThrow( |
79 | | - await Promise.allSettled( |
80 | | - bids.map( |
81 | | - async (b) => |
82 | | - await JerseyBidInfo.findOne({ user: b.user }) |
83 | | - .populate<{ user: iUser }>("user") |
84 | | - .session(session.session) |
85 | | - .orFail(), |
86 | | - ), |
87 | | - ), |
88 | | - "Fail", |
89 | | - ); |
90 | | - |
91 | | - bidders.sort((a, b) => { |
92 | | - if (a.points != b.points) return a.points - b.points; |
93 | | - else if (a.user.year != b.user.year) return a.user.year - b.user.year; |
94 | | - else { |
95 | | - return getRand() - 0.5; |
96 | | - } |
97 | | - }); |
98 | | - |
99 | | - while (bidders.length > 0) { |
100 | | - const tmp = logAndThrow( |
101 | | - await Promise.allSettled( |
102 | | - bidders.map(async (b) => { |
103 | | - return { |
104 | | - bidder: b, |
105 | | - eligible: await isEligibleWithoutUserLegible(b.user, [jersey], session), |
106 | | - isAllocated: (await JerseyBidInfo.findOne({ _id: b._id }).orFail().session(session.session)).isAllocated, |
107 | | - }; |
108 | | - }), |
109 | | - ), |
110 | | - "Bidder eligibility parse error", |
111 | | - ); |
112 | | - |
113 | | - tmp |
114 | | - .filter((bidder) => !bidder.eligible) |
115 | | - .forEach((b) => console.log(`${b.bidder.user.username} failed to get ${jersey.number}`)); |
116 | | - tmp |
117 | | - .filter((bidder) => bidder.isAllocated) |
118 | | - .forEach((b) => console.log(`${b.bidder.user.username} already allocated, skipping..`)); |
119 | | - |
120 | | - bidders = tmp.filter((bidder) => bidder.eligible && !bidder.isAllocated).map((b) => b.bidder); |
121 | | - |
122 | | - if (bidders.length == 0) break; |
123 | | - |
124 | | - const bidder = bidders.pop(); |
125 | | - if (!bidder) break; |
126 | | - |
127 | | - await allocateUser(bidder, jersey, round, session); |
128 | | - } |
129 | | -} |
| 73 | +// async function allocate(jersey: iJersey, priority: number, round: number, session: MongoSession) { |
| 74 | +// // console.log(`Allocating jersey ${jersey.number} with priority ${priority}`); |
| 75 | +// const bids = await JerseyBid.find({ jersey: jersey._id, priority, round }).lean().session(session.session); |
| 76 | + |
| 77 | +// let bidders = logAndThrow( |
| 78 | +// await Promise.allSettled( |
| 79 | +// bids.map( |
| 80 | +// async (b) => |
| 81 | +// await JerseyBidInfo.findOne({ user: b.user }) |
| 82 | +// .populate<{ user: iUser }>("user") |
| 83 | +// .session(session.session) |
| 84 | +// .orFail(), |
| 85 | +// ), |
| 86 | +// ), |
| 87 | +// "Fail", |
| 88 | +// ); |
| 89 | + |
| 90 | +// bidders.sort((a, b) => { |
| 91 | +// if (a.points != b.points) return a.points - b.points; |
| 92 | +// else if (a.user.year != b.user.year) return a.user.year - b.user.year; |
| 93 | +// else { |
| 94 | +// return getRand() - 0.5; |
| 95 | +// } |
| 96 | +// }); |
| 97 | + |
| 98 | +// while (bidders.length > 0) { |
| 99 | +// const tmp = logAndThrow( |
| 100 | +// await Promise.allSettled( |
| 101 | +// bidders.map(async (b) => { |
| 102 | +// return { |
| 103 | +// bidder: b, |
| 104 | +// eligible: await isEligibleWithoutUserLegible(b.user, [jersey], session), |
| 105 | +// isAllocated: (await JerseyBidInfo.findOne({ _id: b._id }).orFail().session(session.session)).isAllocated, |
| 106 | +// }; |
| 107 | +// }), |
| 108 | +// ), |
| 109 | +// "Bidder eligibility parse error", |
| 110 | +// ); |
| 111 | + |
| 112 | +// tmp |
| 113 | +// .filter((bidder) => !bidder.eligible) |
| 114 | +// .forEach((b) => console.log(`${b.bidder.user.username} failed to get ${jersey.number}`)); |
| 115 | +// tmp |
| 116 | +// .filter((bidder) => bidder.isAllocated) |
| 117 | +// .forEach((b) => console.log(`${b.bidder.user.username} already allocated, skipping..`)); |
| 118 | + |
| 119 | +// bidders = tmp.filter((bidder) => bidder.eligible && !bidder.isAllocated).map((b) => b.bidder); |
| 120 | + |
| 121 | +// if (bidders.length == 0) break; |
| 122 | + |
| 123 | +// const bidder = bidders.pop(); |
| 124 | +// if (!bidder) break; |
| 125 | + |
| 126 | +// await allocateUser(bidder, jersey, round, session); |
| 127 | +// } |
| 128 | +// } |
130 | 129 |
|
131 | 130 | function shuffle<T>(array: T[]): T[] { |
132 | 131 | let currentIndex = array.length; |
|
0 commit comments