Gastansicht, Verbesserungen bei Planung
This commit is contained in:
1 parent
b3afa3ef32
commit
c08d43e7dd
38 files changed
+3845
-219
No files matched your search
+93
-13
@@ -14,6 +14,7 @@ type ServicePlanner struct {
|
||||
Services []ServiceOccurrence
|
||||
ExistingAssignments []Assignment
|
||||
Churches []Church
|
||||
LiturgicalDays []LiturgicalDay
|
||||
Options PlannerOptions
|
||||
}
|
||||
|
||||
@@ -41,6 +42,12 @@ func (p ServicePlanner) Plan() PlanResult {
|
||||
for _, s := range p.Services {
|
||||
serviceByID[s.ID] = s
|
||||
}
|
||||
highFeastByDate := map[string]bool{}
|
||||
for _, day := range p.LiturgicalDays {
|
||||
if day.IsHighFeast() {
|
||||
highFeastByDate[day.DateKey()] = true
|
||||
}
|
||||
}
|
||||
|
||||
working := make([]Assignment, 0, len(p.ExistingAssignments))
|
||||
for _, a := range p.ExistingAssignments {
|
||||
@@ -129,9 +136,10 @@ func (p ServicePlanner) Plan() PlanResult {
|
||||
continue
|
||||
}
|
||||
for i := existingForRole; i < required; i++ {
|
||||
highFeast := highFeastByDate[service.DateKey()]
|
||||
result := p.bestCandidate(service, role, activePeople, absencesByPerson,
|
||||
totalByPerson, monthByPerson, dayServicesByPerson, churchByPerson,
|
||||
lastDateByPerson, assignedRoles)
|
||||
lastDateByPerson, assignedRoles, highFeast, true)
|
||||
if result.person == nil {
|
||||
unfilled = append(unfilled, UnfilledSlot{
|
||||
Service: service,
|
||||
@@ -165,6 +173,59 @@ func (p ServicePlanner) Plan() PlanResult {
|
||||
}
|
||||
}
|
||||
|
||||
// Second pass, only on explicit request: use volunteers who agreed to be
|
||||
// planned beyond their preferences for the slots that remained open.
|
||||
if p.Options.AllowBeyondPreferences && len(unfilled) > 0 {
|
||||
var flagged []Person
|
||||
for _, person := range activePeople {
|
||||
if person.AllowBeyondPreferences {
|
||||
flagged = append(flagged, person)
|
||||
}
|
||||
}
|
||||
if len(flagged) > 0 {
|
||||
remaining := make([]UnfilledSlot, 0, len(unfilled))
|
||||
for _, slot := range unfilled {
|
||||
service := slot.Service
|
||||
highFeast := highFeastByDate[service.DateKey()]
|
||||
assignedRoles := map[string]map[Role]bool{}
|
||||
for _, assignment := range working {
|
||||
if assignment.ServiceID != service.ID {
|
||||
continue
|
||||
}
|
||||
if assignedRoles[assignment.PersonID] == nil {
|
||||
assignedRoles[assignment.PersonID] = map[Role]bool{}
|
||||
}
|
||||
assignedRoles[assignment.PersonID][assignment.Role] = true
|
||||
}
|
||||
result := p.bestCandidate(service, slot.Role, flagged, absencesByPerson,
|
||||
totalByPerson, monthByPerson, dayServicesByPerson, churchByPerson,
|
||||
lastDateByPerson, assignedRoles, highFeast, false)
|
||||
if result.person == nil {
|
||||
slot.Reason = result.reason
|
||||
remaining = append(remaining, slot)
|
||||
continue
|
||||
}
|
||||
person := *result.person
|
||||
assignment := Assignment{
|
||||
ID: newID(),
|
||||
ServiceID: service.ID,
|
||||
PersonID: person.ID,
|
||||
Role: slot.Role,
|
||||
BeyondPreferences: true,
|
||||
CreatedAt: now(),
|
||||
}
|
||||
newAssignments = append(newAssignments, assignment)
|
||||
working = append(working, assignment)
|
||||
if roleCounts[service.ID] == nil {
|
||||
roleCounts[service.ID] = map[Role]int{}
|
||||
}
|
||||
roleCounts[service.ID][slot.Role]++
|
||||
applyToCounts(assignment, service)
|
||||
}
|
||||
unfilled = remaining
|
||||
}
|
||||
}
|
||||
|
||||
filled := len(newAssignments)
|
||||
var message string
|
||||
switch {
|
||||
@@ -211,6 +272,8 @@ func (p ServicePlanner) bestCandidate(
|
||||
churchByPerson map[string]map[string]int,
|
||||
lastDateByPerson map[string]time.Time,
|
||||
assignedRolesByPerson map[string]map[Role]bool,
|
||||
highFeast bool,
|
||||
enforcePreferences bool,
|
||||
) candidateResult {
|
||||
blockedReasons := map[string]int{}
|
||||
var eligible []Person
|
||||
@@ -237,14 +300,14 @@ func (p ServicePlanner) bestCandidate(
|
||||
continue
|
||||
}
|
||||
}
|
||||
if p.Options.RespectPreferredWeekdays && len(person.PreferredWeekdays) > 0 &&
|
||||
!IntContains(person.PreferredWeekdays, Weekday(service.Date)) {
|
||||
blockedReasons["Einsatztag passt nicht"]++
|
||||
if p.Options.RespectPreferredWeekdays && enforcePreferences &&
|
||||
!person.MatchesWeekdayPreference(Weekday(service.Date), service.TimeMinutes, highFeast) {
|
||||
blockedReasons["Einsatztag oder Uhrzeit passt nicht"]++
|
||||
continue
|
||||
}
|
||||
month := MonthKey(service.Date)
|
||||
usedThisMonth := monthByPerson[person.ID+"|"+month]
|
||||
if person.MaxPerMonth > 0 && usedThisMonth >= person.MaxPerMonth {
|
||||
if enforcePreferences && person.MaxPerMonth > 0 && usedThisMonth >= person.MaxPerMonth {
|
||||
blockedReasons["Monatslimit erreicht"]++
|
||||
continue
|
||||
}
|
||||
@@ -303,7 +366,8 @@ func (p ServicePlanner) bestCandidate(
|
||||
}
|
||||
}
|
||||
}
|
||||
if IntContains(person.PreferredWeekdays, Weekday(service.Date)) {
|
||||
if person.MatchesWeekdayPreference(Weekday(service.Date), service.TimeMinutes, highFeast) &&
|
||||
len(person.PreferredWeekdays) > 0 {
|
||||
score += 3
|
||||
}
|
||||
score -= float64(total) * p.Options.WeightFairness
|
||||
@@ -377,6 +441,7 @@ func CandidateSuggestions(
|
||||
services []ServiceOccurrence,
|
||||
serviceAssignments []Assignment,
|
||||
ignorePreferredWeekdays bool,
|
||||
liturgicalDay *LiturgicalDay,
|
||||
) []CandidateSuggestion {
|
||||
monthKey := MonthKey(service.Date)
|
||||
serviceDateByID := map[string]ServiceOccurrence{}
|
||||
@@ -424,11 +489,13 @@ func CandidateSuggestions(
|
||||
}
|
||||
const fairnessSlack = 1
|
||||
weekday := Weekday(service.Date)
|
||||
highFeast := liturgicalDay != nil && liturgicalDay.IsHighFeast()
|
||||
|
||||
var suggestions []CandidateSuggestion
|
||||
for _, person := range eligible {
|
||||
var warnings []string
|
||||
blocked := false
|
||||
beyond := false
|
||||
for _, a := range absences {
|
||||
if a.PersonID == person.ID && a.Overlaps(service.Date) {
|
||||
warnings = append(warnings, "abwesend")
|
||||
@@ -436,13 +503,26 @@ func CandidateSuggestions(
|
||||
break
|
||||
}
|
||||
}
|
||||
if !ignorePreferredWeekdays && len(person.PreferredWeekdays) > 0 && !IntContains(person.PreferredWeekdays, weekday) {
|
||||
warnings = append(warnings, "Einsatztag passt nicht")
|
||||
blocked = true
|
||||
weekdayMatch := person.MatchesWeekdayPreference(weekday, service.TimeMinutes, highFeast)
|
||||
if !weekdayMatch {
|
||||
switch {
|
||||
case ignorePreferredWeekdays:
|
||||
beyond = true
|
||||
case person.AllowBeyondPreferences:
|
||||
beyond = true
|
||||
default:
|
||||
warnings = append(warnings, "Einsatztag oder Uhrzeit passt nicht")
|
||||
blocked = true
|
||||
}
|
||||
}
|
||||
if person.MaxPerMonth > 0 && monthlyCounts[person.ID+"|"+monthKey] >= person.MaxPerMonth {
|
||||
warnings = append(warnings, "Monatslimit")
|
||||
blocked = true
|
||||
if person.AllowBeyondPreferences {
|
||||
warnings = append(warnings, "Monatslimit")
|
||||
beyond = true
|
||||
} else {
|
||||
warnings = append(warnings, "Monatslimit")
|
||||
blocked = true
|
||||
}
|
||||
}
|
||||
used := dayServices[person.ID+"|"+service.DateKey()]
|
||||
if len(used) > 0 && !subsetOfSingle(used, service.ID) {
|
||||
@@ -473,7 +553,7 @@ func CandidateSuggestions(
|
||||
if len(person.PreferredChurchIDs) > 0 && !StringContains(person.PreferredChurchIDs, service.ChurchID) {
|
||||
score -= 2
|
||||
}
|
||||
if IntContains(person.PreferredWeekdays, weekday) {
|
||||
if weekdayMatch && len(person.PreferredWeekdays) > 0 {
|
||||
score += 3
|
||||
preferred = true
|
||||
}
|
||||
@@ -492,7 +572,7 @@ func CandidateSuggestions(
|
||||
}
|
||||
suggestions = append(suggestions, CandidateSuggestion{
|
||||
Person: person, Score: score, Warnings: warnings, Blocked: blocked,
|
||||
Preferred: preferred, TotalAssignments: total,
|
||||
Preferred: preferred, BeyondPreferences: beyond, TotalAssignments: total,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user