Gastansicht, Verbesserungen bei Planung
This commit is contained in:
1 parent
b3afa3ef32
commit
c08d43e7dd
38 files changed
+3845
-219
No files matched your search
+184
-25
@@ -2,6 +2,8 @@ package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -89,19 +91,86 @@ type Church struct {
|
||||
Notes string `json:"notes"`
|
||||
}
|
||||
|
||||
// WeekdayPeriod narrows a preferred weekday to a part of the day.
|
||||
type WeekdayPeriod string
|
||||
|
||||
const (
|
||||
PeriodAllDay WeekdayPeriod = "all"
|
||||
PeriodMorning WeekdayPeriod = "morning"
|
||||
PeriodAfternoon WeekdayPeriod = "afternoon"
|
||||
PeriodEvening WeekdayPeriod = "evening"
|
||||
)
|
||||
|
||||
var AllWeekdayPeriods = []WeekdayPeriod{PeriodAllDay, PeriodMorning, PeriodAfternoon, PeriodEvening}
|
||||
|
||||
func (p WeekdayPeriod) Label() string {
|
||||
switch p {
|
||||
case PeriodMorning:
|
||||
return "vormittags (0–12 Uhr)"
|
||||
case PeriodAfternoon:
|
||||
return "nachmittags (12–17 Uhr)"
|
||||
case PeriodEvening:
|
||||
return "abends (ab 17 Uhr)"
|
||||
default:
|
||||
return "ganztägig"
|
||||
}
|
||||
}
|
||||
|
||||
func (p WeekdayPeriod) ShortLabel() string {
|
||||
switch p {
|
||||
case PeriodMorning:
|
||||
return "vormittags"
|
||||
case PeriodAfternoon:
|
||||
return "nachmittags"
|
||||
case PeriodEvening:
|
||||
return "abends"
|
||||
default:
|
||||
return "ganztägig"
|
||||
}
|
||||
}
|
||||
|
||||
func (p WeekdayPeriod) IsValid() bool {
|
||||
return p == PeriodAllDay || p == PeriodMorning || p == PeriodAfternoon || p == PeriodEvening
|
||||
}
|
||||
|
||||
// Matches reports whether a service starting at timeMinutes falls into the
|
||||
// selected part of the day. Morning is 0–12, afternoon 12–17, evening after 17.
|
||||
func (p WeekdayPeriod) Matches(timeMinutes int) bool {
|
||||
switch p {
|
||||
case PeriodMorning:
|
||||
return timeMinutes < 12*60
|
||||
case PeriodAfternoon:
|
||||
return timeMinutes >= 12*60 && timeMinutes < 17*60
|
||||
case PeriodEvening:
|
||||
return timeMinutes >= 17*60
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// WeekdayPeriodPreference stores the selected part of the day for one
|
||||
// preferred weekday. Weekdays without an entry count as all day.
|
||||
type WeekdayPeriodPreference struct {
|
||||
Weekday int `json:"weekday"`
|
||||
Period WeekdayPeriod `json:"period"`
|
||||
}
|
||||
|
||||
type Person struct {
|
||||
ID string `json:"id"`
|
||||
FirstName string `json:"firstName"`
|
||||
LastName string `json:"lastName"`
|
||||
Roles []Role `json:"roles"`
|
||||
Email string `json:"email"`
|
||||
EmailLocked bool `json:"-"`
|
||||
PreferredChurchIDs []string `json:"preferredChurchIDs"`
|
||||
PreferredWeekdays []int `json:"preferredWeekdays"`
|
||||
PreferredServiceTitles []string `json:"preferredServiceTitles"`
|
||||
MaxPerMonth int `json:"maxPerMonth"`
|
||||
Active bool `json:"active"`
|
||||
Notes string `json:"notes"`
|
||||
ID string `json:"id"`
|
||||
ShortCode string `json:"shortCode"`
|
||||
FirstName string `json:"firstName"`
|
||||
LastName string `json:"lastName"`
|
||||
Roles []Role `json:"roles"`
|
||||
Email string `json:"email"`
|
||||
EmailLocked bool `json:"-"`
|
||||
PreferredChurchIDs []string `json:"preferredChurchIDs"`
|
||||
PreferredWeekdays []int `json:"preferredWeekdays"`
|
||||
PreferredWeekdayPeriods []WeekdayPeriodPreference `json:"preferredWeekdayPeriods"`
|
||||
PreferredServiceTitles []string `json:"preferredServiceTitles"`
|
||||
MaxPerMonth int `json:"maxPerMonth"`
|
||||
AllowBeyondPreferences bool `json:"allowBeyondPreferences"`
|
||||
Active bool `json:"active"`
|
||||
Notes string `json:"notes"`
|
||||
}
|
||||
|
||||
func (p Person) FullName() string {
|
||||
@@ -127,6 +196,80 @@ func (p Person) AbbreviatedName() string {
|
||||
return p.LastName
|
||||
}
|
||||
|
||||
// DisplayShort is the guest-facing label: an explicitly maintained Kürzel wins,
|
||||
// otherwise the initials from first and last name.
|
||||
func (p Person) DisplayShort() string {
|
||||
if code := strings.TrimSpace(p.ShortCode); code != "" {
|
||||
return code
|
||||
}
|
||||
return p.Initials()
|
||||
}
|
||||
|
||||
// WeekdayPeriodFor returns the selected part of the day for a weekday.
|
||||
func (p Person) WeekdayPeriodFor(weekday int) WeekdayPeriod {
|
||||
for _, preference := range p.PreferredWeekdayPeriods {
|
||||
if preference.Weekday == weekday && preference.Period.IsValid() {
|
||||
return preference.Period
|
||||
}
|
||||
}
|
||||
return PeriodAllDay
|
||||
}
|
||||
|
||||
// MatchesWeekdayPreference reports whether the service day and time satisfy
|
||||
// the weekday preferences. High feasts count like Sundays, so a Sunday
|
||||
// preference also covers them. An empty weekday list means no restriction.
|
||||
func (p Person) MatchesWeekdayPreference(weekday, timeMinutes int, highFeast bool) bool {
|
||||
if len(p.PreferredWeekdays) == 0 {
|
||||
return true
|
||||
}
|
||||
candidates := []int{weekday}
|
||||
if highFeast && weekday != 1 {
|
||||
candidates = append(candidates, 1)
|
||||
}
|
||||
for _, day := range candidates {
|
||||
if IntContains(p.PreferredWeekdays, day) && p.WeekdayPeriodFor(day).Matches(timeMinutes) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// PreferenceNote is the free-text planning note shown next to assignments.
|
||||
func (p Person) PreferenceNote() string { return strings.TrimSpace(p.Notes) }
|
||||
|
||||
// PersonLabels computes stable short labels for a set of people. If two people
|
||||
// share a label, every member of that group gets a running number appended.
|
||||
func PersonLabels(people []Person) map[string]string {
|
||||
sorted := append([]Person(nil), people...)
|
||||
sort.SliceStable(sorted, func(i, j int) bool {
|
||||
if sorted[i].LastName != sorted[j].LastName {
|
||||
return sorted[i].LastName < sorted[j].LastName
|
||||
}
|
||||
if sorted[i].FirstName != sorted[j].FirstName {
|
||||
return sorted[i].FirstName < sorted[j].FirstName
|
||||
}
|
||||
return sorted[i].ID < sorted[j].ID
|
||||
})
|
||||
base := make(map[string]string, len(sorted))
|
||||
counts := map[string]int{}
|
||||
for _, person := range sorted {
|
||||
label := person.DisplayShort()
|
||||
base[person.ID] = label
|
||||
counts[label]++
|
||||
}
|
||||
seen := map[string]int{}
|
||||
labels := make(map[string]string, len(sorted))
|
||||
for _, person := range sorted {
|
||||
label := base[person.ID]
|
||||
if counts[label] > 1 {
|
||||
seen[label]++
|
||||
label += strconv.Itoa(seen[label])
|
||||
}
|
||||
labels[person.ID] = label
|
||||
}
|
||||
return labels
|
||||
}
|
||||
|
||||
func (p Person) RoleLabel() string {
|
||||
var parts []string
|
||||
for _, role := range AllRoles {
|
||||
@@ -336,13 +479,14 @@ func (s ServiceOccurrence) RolesNeeded() []Role {
|
||||
}
|
||||
|
||||
type Assignment struct {
|
||||
ID string `json:"id"`
|
||||
ServiceID string `json:"serviceID"`
|
||||
PersonID string `json:"personID"`
|
||||
Role Role `json:"role"`
|
||||
Locked bool `json:"locked"`
|
||||
Note string `json:"note"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
ID string `json:"id"`
|
||||
ServiceID string `json:"serviceID"`
|
||||
PersonID string `json:"personID"`
|
||||
Role Role `json:"role"`
|
||||
Locked bool `json:"locked"`
|
||||
BeyondPreferences bool `json:"beyondPreferences"`
|
||||
Note string `json:"note"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
// Liturgical model ---------------------------------------------------------
|
||||
@@ -702,6 +846,19 @@ func (r DayPlanRow) AssignmentCount() int {
|
||||
}
|
||||
func (r DayPlanRow) HasServices() bool { return len(r.Services) > 0 }
|
||||
|
||||
// HasBeyondPreferences marks days with at least one assignment that goes
|
||||
// beyond the person's preferences.
|
||||
func (r DayPlanRow) HasBeyondPreferences() bool {
|
||||
for _, service := range r.Services {
|
||||
for _, assignment := range service.Assignments {
|
||||
if assignment.BeyondPreferences {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r DayPlanRow) IsSunday() bool {
|
||||
return (r.LiturgicalDay != nil && r.LiturgicalDay.IsSunday()) || IsSunday(r.Date)
|
||||
}
|
||||
@@ -823,6 +980,7 @@ func (s RangeStatistics) AverageAssignments() float64 {
|
||||
type PlannerOptions struct {
|
||||
ReplaceExisting bool
|
||||
RespectPreferredWeekdays bool
|
||||
AllowBeyondPreferences bool
|
||||
AllowDoubleRolesOnSameDay bool
|
||||
WeightChurchPreference float64
|
||||
WeightServicePreference float64
|
||||
@@ -850,10 +1008,11 @@ type PlanResult struct {
|
||||
}
|
||||
|
||||
type CandidateSuggestion struct {
|
||||
Person Person
|
||||
Score float64
|
||||
Warnings []string
|
||||
Blocked bool
|
||||
Preferred bool
|
||||
TotalAssignments int
|
||||
Person Person
|
||||
Score float64
|
||||
Warnings []string
|
||||
Blocked bool
|
||||
Preferred bool
|
||||
BeyondPreferences bool
|
||||
TotalAssignments int
|
||||
}
|
||||
Reference in new issue
Block a user