ecf30a9044
randomize room number when not set but the night number is set
89 lines
1.7 KiB
Go
89 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func AssignExtraRooms(rooms []RoomFolder, roomsPerNight int) {
|
|
latestnight := 0
|
|
|
|
for _, r := range rooms {
|
|
if r.Cfg.night > latestnight {
|
|
latestnight = r.Cfg.night
|
|
}
|
|
}
|
|
|
|
night := latestnight + 1
|
|
room := 1
|
|
|
|
for i, r := range rooms {
|
|
if r.Cfg.night > 0 {
|
|
continue
|
|
}
|
|
|
|
rooms[i].Cfg.night = night
|
|
rooms[i].Cfg.room = room
|
|
|
|
room++
|
|
if room > roomsPerNight {
|
|
room = 1
|
|
night++
|
|
}
|
|
}
|
|
}
|
|
|
|
func AssignRandomNightRooms(rooms []RoomFolder, roomsPerNight int) {
|
|
latestrooms := make(map[int]int)
|
|
|
|
for _, r := range rooms {
|
|
if latestroom, ok := latestrooms[r.Cfg.night]; !ok {
|
|
latestrooms[r.Cfg.night] = r.Cfg.room
|
|
} else if r.Cfg.room > latestroom {
|
|
latestrooms[r.Cfg.night] = r.Cfg.room
|
|
}
|
|
}
|
|
|
|
for i, r := range rooms {
|
|
if r.Cfg.night <= 0 || r.Cfg.room > 0 {
|
|
continue
|
|
}
|
|
|
|
if latestrooms[r.Cfg.night] < 0 {
|
|
latestrooms[r.Cfg.night] = 0
|
|
}
|
|
|
|
latestrooms[r.Cfg.night]++
|
|
rooms[i].Cfg.room = latestrooms[r.Cfg.night]
|
|
}
|
|
}
|
|
|
|
func CheckDuplicateRooms(rooms []RoomFolder) error {
|
|
maxnight := 0
|
|
maxroom := 0
|
|
|
|
for _, r := range rooms {
|
|
if r.Cfg.night > maxnight {
|
|
maxnight = r.Cfg.night
|
|
}
|
|
if r.Cfg.room > maxroom {
|
|
maxroom = r.Cfg.room
|
|
}
|
|
}
|
|
|
|
assignments := make([][]string, maxnight)
|
|
for night := range maxnight {
|
|
assignments[night] = make([]string, maxroom)
|
|
}
|
|
|
|
for _, r := range rooms {
|
|
if r.Cfg.night > 0 && r.Cfg.room > 0 {
|
|
if assignments[r.Cfg.night-1][r.Cfg.room-1] != "" {
|
|
return fmt.Errorf("duplicate room assignment for Room %d Night %d: %s, %s", r.Cfg.night, r.Cfg.room, assignments[r.Cfg.night][r.Cfg.room], r.Path)
|
|
}
|
|
assignments[r.Cfg.night-1][r.Cfg.room-1] = r.Path
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|