@opndev/tennis-match-center 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changes +26 -0
- package/lib/auto-planner.mjs +5 -32
- package/lib/components/day-grid.mjs +288 -0
- package/lib/components/gameday-board.mjs +1691 -0
- package/lib/components/gameday-card.mjs +325 -0
- package/lib/components/gameday-list.mjs +199 -0
- package/lib/components/match.mjs +368 -0
- package/lib/components/participant.mjs +101 -0
- package/lib/components/planning-board.mjs +914 -131
- package/lib/components/schedule-board.mjs +219 -50
- package/lib/day-rows.mjs +19 -3
- package/lib/gameday-dialog.mjs +93 -0
- package/lib/gameday-facts.mjs +305 -0
- package/lib/gameday-next.mjs +164 -0
- package/lib/gameday-parts.mjs +112 -0
- package/lib/index.mjs +1 -3
- package/lib/knockout-draw.mjs +4 -0
- package/lib/knockout-planner.mjs +99 -5
- package/lib/lighting.mjs +50 -4
- package/lib/plan-placement.mjs +54 -3
- package/lib/planning-day.mjs +15 -9
- package/lib/webcomponents.mjs +12 -0
- package/package.json +6 -1
- package/opndev-tennis-match-center-0.0.1.tgz +0 -0
package/lib/knockout-planner.mjs
CHANGED
|
@@ -67,16 +67,71 @@ function holdCourts(item, pool, day, where, row) {
|
|
|
67
67
|
|
|
68
68
|
const at = court => row.indexOf(court)
|
|
69
69
|
const busy = new Set(row.filter(court => !pool.includes(court)).map(at))
|
|
70
|
+
// Where the draw played its last round: one that has to move moves
|
|
71
|
+
// as little as it can.
|
|
72
|
+
const were = (item.draw.lastCourts ?? []).map(id => row.findIndex(c => c.id === id))
|
|
73
|
+
const wereLo = were.length ? Math.min(...were) : null
|
|
74
|
+
const wereHi = were.length ? Math.max(...were) : null
|
|
75
|
+
|
|
76
|
+
const drift = window => wereLo == null
|
|
77
|
+
? 0
|
|
78
|
+
: Math.max(...window.map(court => {
|
|
79
|
+
const p = at(court)
|
|
80
|
+
|
|
81
|
+
return p < wereLo ? wereLo - p : (p > wereHi ? p - wereHi : 0)
|
|
82
|
+
}))
|
|
83
|
+
|
|
84
|
+
// How close the light is: this round and the next, two slots
|
|
85
|
+
// apiece. Asking about the whole rest of the draw refused every
|
|
86
|
+
// unlit court from the first round on. roundsRemaining counts the
|
|
87
|
+
// rounds after this one, so add the current one back.
|
|
88
|
+
const slotAfter = rounds => where.slots[
|
|
89
|
+
where.slotIndex + ((rounds + 1) * 2) - 1
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
const dark = day.darkFromMinutes != null
|
|
93
|
+
const soon = slotAfter(Math.min(item.draw.roundsRemaining, 1))
|
|
94
|
+
const last = slotAfter(item.draw.roundsRemaining)
|
|
95
|
+
|
|
96
|
+
// This round or the next runs into the light: take a lit court now
|
|
97
|
+
// rather than climb onto one later.
|
|
98
|
+
const wantsLight = dark && (soon == null || day.needsLight(soon))
|
|
99
|
+
|
|
100
|
+
// Done before the light goes, so it has no business on a lit
|
|
101
|
+
// court: one afternoon Final sat on one pushes a four-round draw
|
|
102
|
+
// off the pair it was keeping.
|
|
103
|
+
const sparesLight = dark && !wantsLight
|
|
104
|
+
&& last != null && !day.needsLight(last)
|
|
70
105
|
|
|
71
106
|
let best = null
|
|
72
107
|
|
|
73
108
|
for (let start = 0; start + item.count <= fitting.length; start++) {
|
|
74
109
|
const window = fitting.slice(start, start + item.count)
|
|
75
110
|
const cost = [
|
|
111
|
+
// Continuous court use is a group rule, not a knockout one: a
|
|
112
|
+
// round happens once, and between two of them a court is simply
|
|
113
|
+
// free. The ask is that a round lands near its own draw, not
|
|
114
|
+
// that a court never stops.
|
|
76
115
|
holesWith(busy, window.map(at), row.length),
|
|
116
|
+
drift(window),
|
|
77
117
|
at(window[window.length - 1]) - at(window[0]),
|
|
78
|
-
|
|
79
|
-
|
|
118
|
+
// Lit courts are the scarce ones after dark and all low in the
|
|
119
|
+
// row, so everyone still playing wants the same handful. A draw
|
|
120
|
+
// that keeps going holds them; one that is finished takes an
|
|
121
|
+
// unlit court. Where nothing says when it gets dark there is
|
|
122
|
+
// nothing to weigh, and the draw stays low as before.
|
|
123
|
+
...(day.darkFromMinutes == null
|
|
124
|
+
? [at(window[0]), window.filter(court => !court.lit).length]
|
|
125
|
+
: [
|
|
126
|
+
// The middle case is the common one: light hours still
|
|
127
|
+
// hours away, no opinion either way, and the lowest court
|
|
128
|
+
// below decides. That packs the row from the bottom;
|
|
129
|
+
// preferring unlit outright drove draws to the far end.
|
|
130
|
+
wantsLight ? window.filter(court => !court.lit).length
|
|
131
|
+
: sparesLight ? window.filter(court => court.lit).length
|
|
132
|
+
: 0,
|
|
133
|
+
at(window[0]),
|
|
134
|
+
]),
|
|
80
135
|
]
|
|
81
136
|
|
|
82
137
|
if (best === null || cheaperWindow(cost, best.cost)) {
|
|
@@ -376,11 +431,24 @@ export function assignKnockout(day, { competitions, draws, sessions, split }) {
|
|
|
376
431
|
return [{ parts: 1, count: held.length, held }]
|
|
377
432
|
}
|
|
378
433
|
|
|
379
|
-
|
|
434
|
+
// A round that owes rest may always be halved: it costs the
|
|
435
|
+
// same two slots, and the half that played first sits out the
|
|
436
|
+
// second. A slot long enough to cover the rest owes nothing,
|
|
437
|
+
// so there is nothing to cut for.
|
|
438
|
+
// Two divisions take turns instead (see whoseTurn), and the
|
|
439
|
+
// turn is the rest.
|
|
440
|
+
const restCuts = restSlots > 0 && units.length !== 2
|
|
441
|
+
const forRest = !split && !forceSplit && restCuts
|
|
442
|
+
const cutting = split || forceSplit || restCuts
|
|
380
443
|
const slotsLeft = own.length - slotIndex
|
|
381
444
|
const usable = day.usable(lane.courts, slot).length
|
|
382
445
|
|
|
446
|
+
// Halving is where cutting stops. A quarter holds its courts
|
|
447
|
+
// four slots to buy the same one slot of rest, which leaves
|
|
448
|
+
// nothing schedulable around it. Quarters stay on the split
|
|
449
|
+
// path, where the caller asks for them.
|
|
383
450
|
const options = draw.cuts(cutting)
|
|
451
|
+
.filter(cut => !forRest || cut.parts <= 2)
|
|
384
452
|
.filter(cut => fittingCourts(cut.parts).length >= cut.count)
|
|
385
453
|
|
|
386
454
|
if (options.length > 0 || !cutting) {
|
|
@@ -436,16 +504,42 @@ export function assignKnockout(day, { competitions, draws, sessions, split }) {
|
|
|
436
504
|
return draw.breaksStride(choice.parts)
|
|
437
505
|
}
|
|
438
506
|
|
|
507
|
+
/**
|
|
508
|
+
* The court-slots a band strands. A whole round hands its
|
|
509
|
+
* courts back for the rest it owes and they stand idle; a round
|
|
510
|
+
* in parts plays its other part on them instead.
|
|
511
|
+
*
|
|
512
|
+
* The Final owes no rest, so it strands nothing and three of
|
|
513
|
+
* them belong in one band.
|
|
514
|
+
*
|
|
515
|
+
* @returns {number}
|
|
516
|
+
*/
|
|
517
|
+
function stranded(taken) {
|
|
518
|
+
return taken.reduce((total, { draw, choice }) =>
|
|
519
|
+
total + (choice.parts === 1 && draw.roundsRemaining > 1
|
|
520
|
+
? choice.count * restSlots
|
|
521
|
+
: 0), 0)
|
|
522
|
+
}
|
|
523
|
+
|
|
439
524
|
/**
|
|
440
525
|
* What a band costs, compared term by term, lowest winning:
|
|
441
|
-
* divisions breaking stride, then
|
|
442
|
-
*
|
|
526
|
+
* divisions breaking stride, then court time the band strands,
|
|
527
|
+
* then divisions left standing when they could have gone on,
|
|
528
|
+
* then courts left idle, then the deepest cut anyone takes,
|
|
529
|
+
* then the number of cuts.
|
|
530
|
+
*
|
|
531
|
+
* Stranded time ranks above all but stride: it is the
|
|
532
|
+
* difference between a draw coming down in nine slots and one
|
|
533
|
+
* dribbling out over eleven. Divisions before courts keeps
|
|
534
|
+
* three draws level, where one taking a round whole fills more
|
|
535
|
+
* of the slot and leaves the other two waiting for theirs.
|
|
443
536
|
*
|
|
444
537
|
* @returns {number[]}
|
|
445
538
|
*/
|
|
446
539
|
function cost(taken) {
|
|
447
540
|
return [
|
|
448
541
|
taken.filter(breaksStride).length,
|
|
542
|
+
stranded(taken),
|
|
449
543
|
-taken.reduce((total, { choice }) => total + choice.count, 0),
|
|
450
544
|
Math.max(...taken.map(({ choice }) => choice.parts), 0),
|
|
451
545
|
taken.reduce((total, { choice }) => total + choice.parts, 0),
|
package/lib/lighting.mjs
CHANGED
|
@@ -32,14 +32,60 @@ export function withLitRequired(state, darkFromTime) {
|
|
|
32
32
|
...state,
|
|
33
33
|
slots: state.slots.map(slot => ({
|
|
34
34
|
...slot,
|
|
35
|
-
lit_required:
|
|
36
|
-
? slot.lit_required ?? false
|
|
37
|
-
: slot.end_minutes > darkFrom,
|
|
35
|
+
lit_required: litRequired(slot, darkFrom),
|
|
38
36
|
})),
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Whether this slot has to be played under lights: it runs past dark,
|
|
42
|
+
* or it starts inside the buffer before dark, where an unlit court is
|
|
43
|
+
* no longer worth starting on. The same question PlanningDay asks
|
|
44
|
+
* when it places, so a board draws what the planner would allow.
|
|
45
|
+
*
|
|
46
|
+
* @param {Object} slot
|
|
47
|
+
* @param {?number} darkFromMinutes
|
|
48
|
+
* @param {number} [lightBufferMinutes]
|
|
49
|
+
* @returns {boolean}
|
|
50
|
+
*/
|
|
51
|
+
export function litRequired(slot, darkFromMinutes, lightBufferMinutes = 0) {
|
|
52
|
+
if (slot.lit_required) {
|
|
53
|
+
return true
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (darkFromMinutes == null) {
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (slot.end_minutes != null && slot.end_minutes > darkFromMinutes) {
|
|
61
|
+
return true
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return slot.start_minutes != null
|
|
65
|
+
&& slot.start_minutes >= darkFromMinutes - lightBufferMinutes
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Whether this court can host this slot at all. A slot needing light
|
|
70
|
+
* on a court that has none is a physical impossibility, not a soft
|
|
71
|
+
* preference - spec.md: "a non-lit court cannot be assigned to the
|
|
72
|
+
* evening slot". Both boards ask it, so both answer it the same way.
|
|
73
|
+
*
|
|
74
|
+
* @param {Object} court
|
|
75
|
+
* @param {Object} slot
|
|
76
|
+
* @returns {boolean}
|
|
77
|
+
*/
|
|
78
|
+
export function courtCanTake(court, slot) {
|
|
79
|
+
return !(slot.lit_required && !court.lit)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* "HH:MM" as minutes past midnight.
|
|
84
|
+
*
|
|
85
|
+
* @param {?string} time
|
|
86
|
+
* @returns {?number}
|
|
87
|
+
*/
|
|
88
|
+
export function toMinutes(time) {
|
|
43
89
|
if (typeof time !== 'string') {
|
|
44
90
|
return null
|
|
45
91
|
}
|
package/lib/plan-placement.mjs
CHANGED
|
@@ -205,15 +205,66 @@ export function placeGroupsIntoCells({ cells, groups }) {
|
|
|
205
205
|
})
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
const
|
|
208
|
+
const wanted = []
|
|
209
209
|
|
|
210
210
|
for (const group of groups) {
|
|
211
211
|
templates.get(group.id).forEach((entry, index) => {
|
|
212
212
|
if (entry.playable && !taken.has(`${group.id}:${index}`)) {
|
|
213
|
-
|
|
213
|
+
wanted.push({ group, entry, index })
|
|
214
214
|
}
|
|
215
215
|
})
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
// Planning gives court time it has not always said the use of: a
|
|
219
|
+
// region painted for the competition and never named, or named only
|
|
220
|
+
// as far as its division. That is still capacity, so what the
|
|
221
|
+
// fixtures above could not be matched to goes in it, in order,
|
|
222
|
+
// rather than being reported short while the cells stand empty.
|
|
223
|
+
//
|
|
224
|
+
// A cell named for another division is left alone: the plan says
|
|
225
|
+
// who that hour belongs to, and filling it with someone else's
|
|
226
|
+
// match would quietly undo the planning rather than use it.
|
|
227
|
+
const spare = unusedCells
|
|
228
|
+
.filter(cell => cell.group_id == null || cell.match_slot == null)
|
|
229
|
+
.sort((a, b) =>
|
|
230
|
+
a.date.localeCompare(b.date)
|
|
231
|
+
|| a.slot.localeCompare(b.slot)
|
|
232
|
+
|| a.court_id - b.court_id
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
const unplaced = []
|
|
236
|
+
const filled = new Set()
|
|
237
|
+
|
|
238
|
+
for (const { group, entry, index } of wanted) {
|
|
239
|
+
const cell = spare.find((candidate, at) =>
|
|
240
|
+
!filled.has(at)
|
|
241
|
+
&& (candidate.division_id == null || candidate.division_id === group.divisionId)
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
if (!cell) {
|
|
245
|
+
unplaced.push({ group_id: group.id, match_slot: index, slot: entry.slot })
|
|
246
|
+
continue
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
filled.add(spare.indexOf(cell))
|
|
250
|
+
|
|
251
|
+
matches.push({
|
|
252
|
+
id: null,
|
|
253
|
+
round: 'group',
|
|
254
|
+
division_id: group.divisionId,
|
|
255
|
+
group_id: group.id,
|
|
256
|
+
slot: index,
|
|
257
|
+
court_id: cell.court_id,
|
|
258
|
+
date: cell.date,
|
|
259
|
+
hour: cell.slot,
|
|
260
|
+
home_team_id: entry.homeId,
|
|
261
|
+
visitor_team_id: entry.visitorId,
|
|
262
|
+
})
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
matches,
|
|
267
|
+
unplaced,
|
|
268
|
+
unusedCells: unusedCells.filter(cell => !spare.filter((_, at) => filled.has(at)).includes(cell)),
|
|
269
|
+
}
|
|
219
270
|
}
|
package/lib/planning-day.mjs
CHANGED
|
@@ -5,14 +5,15 @@
|
|
|
5
5
|
import { courtUsableAt, runFits } from './court-runs.mjs'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* How long before dark an unlit court stops taking new play
|
|
8
|
+
* How long before dark an unlit court stops taking new play, where the
|
|
9
|
+
* event has not said otherwise.
|
|
9
10
|
*
|
|
10
|
-
* A match
|
|
11
|
-
* overrun
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* A match ending exactly as the light goes is pushing it: the
|
|
12
|
+
* overrun has nowhere to finish. Caution rather than a fact about the
|
|
13
|
+
* venue, so it is a knob. Zero holds an unlit court open until the
|
|
14
|
+
* light goes, which is how the 2025 desk used courts 27 to 30.
|
|
14
15
|
*/
|
|
15
|
-
const LIGHT_BUFFER_MINUTES = 60
|
|
16
|
+
export const LIGHT_BUFFER_MINUTES = 60
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* One date of the event as the planner works through it: the courts it
|
|
@@ -38,10 +39,13 @@ export class PlanningDay {
|
|
|
38
39
|
* @param {Plan} params.plan Where cells are placed.
|
|
39
40
|
* @param {?number} [params.darkFromMinutes] When the light goes, if
|
|
40
41
|
* the event says. Without it a slot's own flag is all there is.
|
|
42
|
+
* @param {number} [params.lightBufferMinutes] How long before dark an
|
|
43
|
+
* unlit court stops taking new play. Zero holds an unlit court open
|
|
44
|
+
* until the light itself goes.
|
|
41
45
|
*/
|
|
42
46
|
constructor({
|
|
43
47
|
date, proCourts, openCourts, slotsByCompetition, occupancy, plan,
|
|
44
|
-
darkFromMinutes = null,
|
|
48
|
+
darkFromMinutes = null, lightBufferMinutes = LIGHT_BUFFER_MINUTES,
|
|
45
49
|
}) {
|
|
46
50
|
this.date = date
|
|
47
51
|
this.proCourts = proCourts
|
|
@@ -50,13 +54,14 @@ export class PlanningDay {
|
|
|
50
54
|
this.occupancy = occupancy
|
|
51
55
|
this.plan = plan
|
|
52
56
|
this.darkFromMinutes = darkFromMinutes
|
|
57
|
+
this.lightBufferMinutes = lightBufferMinutes
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
/**
|
|
56
61
|
* Whether this slot has to be played under lights.
|
|
57
62
|
*
|
|
58
63
|
* Its own flag says whether it runs past dark. The buffer says the
|
|
59
|
-
*
|
|
64
|
+
* stretch before that is no place to start on an unlit court either.
|
|
60
65
|
*
|
|
61
66
|
* @param {Object} slot
|
|
62
67
|
* @returns {boolean}
|
|
@@ -70,7 +75,8 @@ export class PlanningDay {
|
|
|
70
75
|
return false
|
|
71
76
|
}
|
|
72
77
|
|
|
73
|
-
return slot.start_minutes
|
|
78
|
+
return slot.start_minutes
|
|
79
|
+
>= this.darkFromMinutes - this.lightBufferMinutes
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
/**
|
package/lib/webcomponents.mjs
CHANGED
|
@@ -12,14 +12,26 @@
|
|
|
12
12
|
* own tag for it, imports the component's module and registers it.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import { TennisDayGridElement } from './components/day-grid.mjs'
|
|
15
16
|
import { TennisPlanningBoardElement } from './components/planning-board.mjs'
|
|
16
17
|
import { TennisRosterTeamElement } from './components/roster-team.mjs'
|
|
17
18
|
import { TennisRosterBoardElement } from './components/roster-board.mjs'
|
|
18
19
|
import { TennisBracketBoardElement } from './components/bracket-board.mjs'
|
|
19
20
|
import { TennisScheduleBoardElement } from './components/schedule-board.mjs'
|
|
21
|
+
import { TennisGamedayCardElement } from './components/gameday-card.mjs'
|
|
22
|
+
import { TennisGamedayListElement } from './components/gameday-list.mjs'
|
|
23
|
+
import { TennisGamedayBoardElement } from './components/gameday-board.mjs'
|
|
24
|
+
import { TennisMatchElement } from './components/match.mjs'
|
|
25
|
+
import { TennisParticipantElement } from './components/participant.mjs'
|
|
20
26
|
|
|
27
|
+
TennisDayGridElement.register()
|
|
21
28
|
TennisPlanningBoardElement.register()
|
|
22
29
|
TennisRosterTeamElement.register()
|
|
23
30
|
TennisRosterBoardElement.register()
|
|
24
31
|
TennisBracketBoardElement.register()
|
|
25
32
|
TennisScheduleBoardElement.register()
|
|
33
|
+
TennisGamedayCardElement.register()
|
|
34
|
+
TennisGamedayListElement.register()
|
|
35
|
+
TennisGamedayBoardElement.register()
|
|
36
|
+
TennisMatchElement.register()
|
|
37
|
+
TennisParticipantElement.register()
|
package/package.json
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
"name": "Wesley Schwengle"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
|
+
"@skirbi/semtic": ">=0.0.40",
|
|
8
|
+
"@skirbi/sugar": ">=0.1.20",
|
|
7
9
|
"@twemoji/api": ">=17.0.0"
|
|
8
10
|
},
|
|
9
11
|
"description": "Match Center",
|
|
@@ -22,6 +24,9 @@
|
|
|
22
24
|
],
|
|
23
25
|
"license": "AGPL-3.0-or-later",
|
|
24
26
|
"name": "@opndev/tennis-match-center",
|
|
27
|
+
"overrides": {
|
|
28
|
+
"@skirbi/sugar": ">=0.1.20"
|
|
29
|
+
},
|
|
25
30
|
"peerDependencies": {
|
|
26
31
|
"@skirbi/sugar": ">=0.1.20"
|
|
27
32
|
},
|
|
@@ -35,5 +40,5 @@
|
|
|
35
40
|
},
|
|
36
41
|
"sideEffects": true,
|
|
37
42
|
"type": "module",
|
|
38
|
-
"version": "0.0.
|
|
43
|
+
"version": "0.0.2"
|
|
39
44
|
}
|
|
Binary file
|