rooms

package
v1.237.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: BSD-3-Clause Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rooms holds the stateful per-slot room-allocation machine that assigns concrete rooms to the exams planned in a slot. It was extracted verbatim from the plexams package (roomsPrepare.go); the logic is unchanged.

The machine is driven by a *Cfg that carries both the static configuration (room master data, pre-planned rooms, blocked rooms, the allowed rooms per slot, …) and the per-slot mutable state. The plexams package builds the Cfg (populating the exported fields) and drives the outer slot loop, calling PrepareForSlot once per slot; the roomsNotUsableInSlot carryover between slots therefore lives in the outer loop / the Cfg, not here.

It depends only on a small DB interface (ExamsInSlot + RoomByName, satisfied by *db.DB), a minimal Reporter (Step/Println/Warnf, satisfied structurally by the plexams reporter), and the pure roomcalc math.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrepareForSlot

func PrepareForSlot(ctx context.Context, db DB, cfg *Cfg, reporter Reporter) ([]*model.PlannedRoom, []*model.UnplacedExam, error)

PrepareForSlot assigns rooms to all exams planned in cfg.Slot and returns the planned rooms plus any students that could not be placed. It mutates cfg's runtime state (exams/availableRooms/plannedRoomsWithFreeSeats/RoomsNotUsableInSlot).

Types

type Cfg

type Cfg struct {
	RoomInfo        map[string]*model.Room
	PrePlannedRooms map[int][]*model.PrePlannedRoom
	AdditionalSeats map[int]int
	Slot            *model.Slot
	// IsNewDay marks the first slot (earliest start time) of its calendar day, so the
	// carryover of rooms blocked by an over-running exam is reset at the start of a day.
	IsNewDay             bool
	RoomsNotUsableInSlot set.Set[string]
	BlockedRooms         map[SlotKey]set.Set[string] // start time -> blocked room names
	ExactSeatRooms       map[int]map[string]bool     // ancode -> room names with an exact seat count (do not refill with this exam)
	RoomsForSlots        map[SlotKey][]string        // start time -> allowed room names (computed once)
	// SlotBlockMinutes is the spacing between consecutive slot start times (e.g. 120);
	// RoomTurnaroundMinutes is the ordinary Vorlauf/Nachlauf (15). Together they decide
	// whether an exam with an extended Nachlauf keeps its room past the following slot's
	// start (see roomOccupancyOverrunsSlot). 0 disables the check (default room turnaround
	// stays governed by the NTA-overrun rule only).
	SlotBlockMinutes      int
	RoomTurnaroundMinutes int
	// contains filtered or unexported fields
}

Cfg carries the static configuration and the per-slot mutable state of the room-allocation machine. The exported fields are populated by the plexams builder (and the characterization test); the unexported fields are the runtime state set during PrepareForSlot.

type DB

type DB interface {
	ExamsAt(ctx context.Context, starttime time.Time) ([]*model.PlannedExam, error)
	RoomByName(ctx context.Context, roomName string) (*model.Room, error)
}

DB is the persistence the room machine needs; *db.DB satisfies it.

type Reporter

type Reporter interface {
	Step(msg string)
	Println(a ...any)
	Warnf(format string, a ...any)
}

Reporter is the subset of the plexams progress reporter this machine uses.

type SlotKey

type SlotKey int64

SlotKey identifies a slot by its absolute start time, canonicalized to Unix seconds so it is a stable, location-independent map key. The plexams Cfg builder keys its blocked-rooms / rooms-for-slots maps with StartKey at the boundary.

func StartKey added in v1.234.0

func StartKey(t time.Time) SlotKey

StartKey canonicalizes a start time into a SlotKey (instant-based, so it matches regardless of the time's monotonic reading or location).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL