anny

package
v1.238.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: 12 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 anny integrates the Anny room-booking system (anny.eu): it fetches the bookings from the Anny API, stores them, and answers queries about them and about the personalization configuration that decides which bookings are "ours". It is deliberately narrow: it depends only on a small DB interface (satisfied by *db.DB), a Reporter for progress output, and a static Config injected by the caller (so viper stays in plexams). The room-capacity views that consume Anny bookings (e.g. booked seats per slot) live in the plexams package; they call this service for the raw bookings and the configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Covers added in v1.229.0

func Covers(from, until, windowStart, windowEnd time.Time) bool

Covers reports whether a booking spanning [from, until] fully covers the window [windowStart, windowEnd] — used to check that a booked room is available for the whole time an exam needs it (its start/end plus the setup/teardown buffers).

func IsApprovedStatus

func IsApprovedStatus(status string) bool

IsApprovedStatus reports whether an Anny booking status counts as approved.

func MatchesAnyPersonalization

func MatchesAnyPersonalization(name string, names []string) bool

MatchesAnyPersonalization reports whether name equals (case-insensitively) any of the configured names. An empty list means "keep everything".

func RoomBookedDuringExamTime added in v1.213.3

func RoomBookedDuringExamTime(bookings []RoomBooking, slot *model.Slot) bool

RoomBookedDuringExamTime reports whether any booking fully covers the exam window of the slot — from the slot start to 90 minutes later, with the boundaries inclusive (a booking starting/ending exactly at an exam boundary counts).

Types

type Config

type Config struct {
	// Token is the Anny API bearer token (anny.token).
	Token string
	// URL is the bookings endpoint (anny.url); a default is used when empty.
	URL string
	// SeedPersonalizationNames is the config-file fallback used as the personalization
	// configuration when the DB holds none yet.
	SeedPersonalizationNames []string
}

Config holds the static configuration (from the config file) the service needs.

type DB

type DB interface {
	SaveAnnyBookings(ctx context.Context, bookings []*model.AnnyBooking) error
	GetAnnyConfig(ctx context.Context) (*model.AnnyConfig, error)
	SetAnnyConfig(ctx context.Context, cfg *model.AnnyConfig) error
	AnnyBookings(ctx context.Context, room *string) ([]*model.AnnyBooking, error)
	AllAnnyBookings(ctx context.Context) ([]*model.AnnyBooking, error)
	Rooms(ctx context.Context) ([]*model.Room, error)
	AddSyncLogEntry(ctx context.Context, entry *model.SyncLogEntry) error
}

DB is the persistence the anny service needs; *db.DB satisfies it.

type Reporter

type Reporter interface {
	Step(msg string)
	Println(a ...any)
	StopProgress(finalMsg string)
}

Reporter is the subset of the plexams progress reporter the fetch uses.

type RoomBooking added in v1.213.3

type RoomBooking struct {
	From     time.Time
	Until    time.Time
	Rooms    []string
	Approved bool
}

RoomBooking is one or more rooms booked in Anny for a time window, with the approval status. It is the merged, planning-facing view (see MergeRoomBookings) of the raw Anny bookings; it feeds the EXaHM room availability per slot.

func MergeRoomBookings added in v1.213.3

func MergeRoomBookings(entries []RoomBooking) []RoomBooking

MergeRoomBookings sorts the bookings by room, approval and time, and merges adjacent or overlapping bookings of the same single room and approval status into one window. Bookings that do not name exactly one room are left untouched.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the Anny integration.

func New

func New(db DB, cfg Config) *Service

New builds an Anny service. db may be nil when no database is configured; the methods that need it guard against that.

func (*Service) AllBookings

func (s *Service) AllBookings(ctx context.Context) ([]*model.AnnyBooking, error)

AllBookings returns all stored Anny bookings, each flagged with Mine.

func (*Service) Bookings

func (s *Service) Bookings(ctx context.Context, room *string) ([]*model.AnnyBooking, error)

Bookings returns the stored Anny bookings for a room (nil = all rooms), each flagged with Mine when its personalization name is one of ours.

func (*Service) Config

func (s *Service) Config(ctx context.Context) (*model.AnnyConfig, error)

Config returns the Anny settings from the DB, seeded from the config file (anny.personalization_name) when nothing is stored yet.

func (*Service) Fetch

func (s *Service) Fetch(ctx context.Context, reporter Reporter) error

Fetch fetches the bookings from the Anny API and stores them in the database. All bookings (all rooms, all people) are kept; "ours" is flagged via the personalization names at query time, not filtered away here.

func (*Service) PersonalizationNames

func (s *Service) PersonalizationNames(ctx context.Context) []string

PersonalizationNames returns the configured personalization names (DB, else config-file seed).

func (*Service) RoomNames

func (s *Service) RoomNames(ctx context.Context) (map[string]struct{}, error)

RoomNames returns the normalized names of the rooms marked as Anny rooms in the global rooms master data (RequestWith == ANNY).

func (*Service) SetPersonalizationNames

func (s *Service) SetPersonalizationNames(ctx context.Context, names []string) (*model.AnnyConfig, error)

SetPersonalizationNames stores the personalization names used to flag our bookings.

Jump to

Keyboard shortcuts

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