feat(series): correct a round's result by hand (1.48.0)
This commit is contained in:
1 parent
6142bceca9
commit
e199f3aa1a
11 files changed
+178
-14
No files matched your search
@@ -49,9 +49,34 @@ export function normalizeSeries(series = {}, { uid } = {}) {
|
||||
countMode: series.countMode === "drop" ? "drop" : "best",
|
||||
countValue: clampInt(series.countValue, series.countMode === "drop" ? 0 : 9),
|
||||
createdAt: Number(series.createdAt) > 0 ? Number(series.createdAt) : Date.now(),
|
||||
manualResults: normalizeManualResults(series.manualResults),
|
||||
};
|
||||
}
|
||||
|
||||
// A round's result set by hand (eventId -> driver ids, winner first), e.g. when the
|
||||
// qualifying went wrong and the club decided the order itself.
|
||||
function normalizeManualResults(value) {
|
||||
const out = {};
|
||||
if (!value || typeof value !== "object") return out;
|
||||
Object.entries(value).forEach(([eventId, ids]) => {
|
||||
const list = Array.isArray(ids) ? [...new Set(ids.map(String).filter(Boolean))] : [];
|
||||
if (eventId && list.length) out[eventId] = list;
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
// The day result a round scores: the hand-set order when there is one, else the calculated.
|
||||
export function getSeriesDayResult(series, eventId, calculated = [], getDriverName = () => "") {
|
||||
const manual = series?.manualResults?.[eventId];
|
||||
if (!manual?.length) return calculated;
|
||||
return manual.map((driverId) => ({
|
||||
driverId,
|
||||
driverName: getDriverName(driverId) || calculated.find((row) => row.driverId === driverId)?.driverName || driverId,
|
||||
hasLap: true,
|
||||
manual: true,
|
||||
}));
|
||||
}
|
||||
|
||||
export function getSeriesPointsForPlace(series, place) {
|
||||
const table = series.pointsTable || [];
|
||||
if (!(place >= 1)) return 0;
|
||||
|
||||
Reference in new issue
Block a user