Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ primuss-data [all|<ancode>] --- send emails to teachers about primuss data and n
constraints --- ask for constraints
prepared --- announce exams to plan and constraints
draft --- announce draft plan
published --- announce published exams
published-exams --- announce published exams
invigilations --- send email requesting invigilations constraints
nta-with-room-alone --- send emails to students with room alone before planning
nta-planned --- send emails about rooms to all students with nta after planning
Expand Down Expand Up @@ -58,8 +58,8 @@ nta-planned --- send emails about rooms to all students with nta after plann
if err != nil {
log.Fatalf("got error: %v\n", err)
}
case "published":
err := plexams.SendEmailPublished(context.Background(), run)
case "published-exams":
err := plexams.SendEmailPublishedExams(context.Background(), run)
if err != nil {
log.Fatalf("got error: %v\n", err)
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/invigilation.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ reserve [daynumber] [slotnumber] [invigilator ID] --- add reserve for slot (d

invigilatorID, err := strconv.Atoi(args[3])
if err != nil {
fmt.Printf("cannot use %s as invigilators id", args[3])
os.Exit(1)
// find invigilator by name
invigilatorName := args[3]
invigilatorID, err = plexams.GetTeacherIdByRegex(ctx, invigilatorName)
if err != nil || invigilatorID == 0 {
fmt.Printf("cannot find invigilator with regex %s", args[3])
os.Exit(1)
}
}

oldInvigilator, err := plexams.GetInvigilatorInSlot(ctx, room, day, slot)
Expand Down
13 changes: 13 additions & 0 deletions db/zpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ func (db *DB) GetTeacher(ctx context.Context, id int) (*model.Teacher, error) {
return &teacher, nil
}

func (db *DB) GetTeacherIdByRegex(ctx context.Context, name string) (int, error) {
collection := db.Client.Database(db.databaseName).Collection("teachers")

var teacher model.Teacher
err := collection.FindOne(ctx, bson.D{{Key: "fullname", Value: bson.D{{Key: "$regex", Value: name}}}}).Decode(&teacher)
if err != nil {
log.Error().Err(err).Str("name", name).Msg("cannot find teacher in db")
return 0, err
}

return teacher.ID, nil
}

func (db *DB) GetTeachers(ctx context.Context) ([]*model.Teacher, error) {
return db.getTeachers(ctx, func(model.Teacher) bool { return true })
}
Expand Down
4 changes: 2 additions & 2 deletions plexams/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
//go:embed tmpl/handicapEmailRoomAloneHTML.tmpl
//go:embed tmpl/preparedEmail.tmpl
//go:embed tmpl/preparedEmailHTML.tmpl
//go:embed tmpl/publishedEmail.tmpl
//go:embed tmpl/publishedEmailHTML.tmpl
//go:embed tmpl/publishedEmailExams.tmpl
//go:embed tmpl/publishedEmailExamsHTML.tmpl
//go:embed tmpl/invigilationEmail.tmpl
//go:embed tmpl/invigilationEmailHTML.tmpl
var emailTemplates embed.FS
Expand Down
2 changes: 1 addition & 1 deletion plexams/email_published.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/theckman/yacspin"
)

func (p *Plexams) SendEmailPublished(ctx context.Context, run bool) error {
func (p *Plexams) SendEmailPublishedExams(ctx context.Context, run bool) error {
cfg := yacspin.Config{
Frequency: 100 * time.Millisecond,
CharSet: yacspin.CharSets[69],
Expand Down
File renamed without changes.
18 changes: 13 additions & 5 deletions plexams/validate_invigilation.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,11 @@ func (p *Plexams) ValidateInvigilatorSlots() error {
roomWithoutInvigilatorDay := make(map[int]int)
slotWithoutReserveDay := make(map[int]int)

maxInvigsMissingInOneSlot := make(map[int]int)

// all rooms and reserve max one invigilator
for _, slot := range p.semesterConfig.Slots {
invigsMissing := 0
spinner.Message(aurora.Sprintf(aurora.Magenta("checking slot (%d,%d)"),
aurora.Cyan(slot.DayNumber), aurora.Cyan(slot.SlotNumber)))

Expand All @@ -291,6 +294,7 @@ func (p *Plexams) ValidateInvigilatorSlots() error {

if len(invigilations) == 0 {
slotWithoutReserveDay[slot.DayNumber]++
invigsMissing++
} else if len(invigilations) > 1 {
validationMessages = append(validationMessages, aurora.Sprintf(aurora.Red("more than one reserve invigilator in slot (%d,%d)"),
aurora.Magenta(slot.DayNumber), aurora.Magenta(slot.SlotNumber)))
Expand All @@ -307,11 +311,15 @@ func (p *Plexams) ValidateInvigilatorSlots() error {
}
if len(invigilations) == 0 {
roomWithoutInvigilatorDay[slot.DayNumber]++
invigsMissing++
} else if len(invigilations) > 1 {
validationMessages = append(validationMessages, aurora.Sprintf(aurora.Red("more than one invigilator for room %s in slot (%d,%d)"),
validationMessages = append(validationMessages, aurora.Sprintf(aurora.Yellow("more than one invigilator for room %s in slot (%d,%d)"),
aurora.Magenta(room), aurora.Magenta(slot.DayNumber), aurora.Magenta(slot.SlotNumber)))
}
}
if invigsMissing > maxInvigsMissingInOneSlot[slot.DayNumber] {
maxInvigsMissingInOneSlot[slot.DayNumber] = invigsMissing
}
}

if len(roomWithoutInvigilatorDay) > 0 || len(slotWithoutReserveDay) > 0 {
Expand All @@ -332,16 +340,16 @@ func (p *Plexams) ValidateInvigilatorSlots() error {

if roomsWithoutInvig+slotsWithoutReserve > 0 {
var msg strings.Builder
msg.WriteString(aurora.Sprintf(aurora.Red("Day %2d: %2d open invigilations, "),
aurora.Magenta(day), aurora.Cyan(roomsWithoutInvig+slotsWithoutReserve)))
msg.WriteString(aurora.Sprintf(aurora.Yellow("Day %2d: %2d open invigilations, %2d max. in one Slot "),
aurora.Magenta(day), aurora.Cyan(roomsWithoutInvig+slotsWithoutReserve), aurora.Cyan(maxInvigsMissingInOneSlot[day])))

if roomsWithoutInvig > 0 {
msg.WriteString(aurora.Sprintf(aurora.Red("%2d rooms without invigilator,"), aurora.Cyan(roomsWithoutInvig)))
msg.WriteString(aurora.Sprintf(aurora.Yellow("%2d rooms without invigilator,"), aurora.Cyan(roomsWithoutInvig)))
} else {
msg.WriteString(" ")
}
if slotsWithoutReserve > 0 {
msg.WriteString(aurora.Sprintf(aurora.Red("%2d slots without reserve"), aurora.Cyan(slotsWithoutReserve)))
msg.WriteString(aurora.Sprintf(aurora.Yellow("%2d slots without reserve"), aurora.Cyan(slotsWithoutReserve)))
}

validationMessages = append(validationMessages, msg.String())
Expand Down
4 changes: 4 additions & 0 deletions plexams/zpa_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func (p *Plexams) GetTeacher(ctx context.Context, id int) (*model.Teacher, error
return p.dbClient.GetTeacher(ctx, id)
}

func (p *Plexams) GetTeacherIdByRegex(ctx context.Context, name string) (int, error) {
return p.dbClient.GetTeacherIdByRegex(ctx, name)
}

func (p *Plexams) GetTeachers(ctx context.Context, fromZpa *bool) ([]*model.Teacher, error) {
if fromZpa != nil && *fromZpa {
if err := p.SetZPA(); err != nil {
Expand Down