Skip to content

Commit fc72c85

Browse files
committed
feat: tweak exahm draft
1 parent 7c81c37 commit fc72c85

File tree

3 files changed

+71
-16
lines changed

3 files changed

+71
-16
lines changed

db/rooms.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,26 @@ func (db *DB) PrePlannedRooms(ctx context.Context) ([]*model.PrePlannedRoom, err
149149
return rooms, nil
150150
}
151151

152+
func (db *DB) PrePlannedRoomsForExam(ctx context.Context, ancode int) ([]*model.PrePlannedRoom, error) {
153+
collection := db.getCollectionSemester(collectionRoomsPrePlanned)
154+
155+
cur, err := collection.Find(ctx, bson.M{"ancode": ancode})
156+
if err != nil {
157+
log.Error().Err(err).Str("collection", collectionRoomsPrePlanned).Msg("MongoDB Find")
158+
return nil, err
159+
}
160+
defer cur.Close(ctx) //nolint:errcheck
161+
162+
rooms := make([]*model.PrePlannedRoom, 0)
163+
err = cur.All(ctx, &rooms)
164+
if err != nil {
165+
log.Error().Err(err).Str("collection", collectionRoomsPrePlanned).Msg("Cannot decode to rooms")
166+
return nil, err
167+
}
168+
169+
return rooms, nil
170+
}
171+
152172
func (db *DB) AddPrePlannedRoomToExam(ctx context.Context, prePlannedRoom *model.PrePlannedRoom) (bool, error) {
153173
collection := db.getCollectionSemester(collectionRoomsPrePlanned)
154174
// Delete any existing document with the same ancode, room, and mtknr

plexams/pdfDraft.go

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ OUTER:
299299
}
300300

301301
func (p *Plexams) DraftExahmPDF(ctx context.Context, outfile string) error {
302-
m := pdf.NewMaroto(consts.Portrait, consts.A4)
302+
m := pdf.NewMaroto(consts.Landscape, consts.A4)
303303
m.SetPageMargins(10, 15, 10)
304304

305305
m.RegisterFooter(func() {
@@ -350,7 +350,7 @@ func (p *Plexams) DraftExahmPDF(ctx context.Context, outfile string) error {
350350
})
351351
})
352352

353-
p.tableForExahm(ctx, m, false)
353+
// p.tableForExahm(ctx, m, false)
354354
p.tableForExahm(ctx, m, true)
355355

356356
err := m.OutputFileAndClose(outfile)
@@ -362,7 +362,7 @@ func (p *Plexams) DraftExahmPDF(ctx context.Context, outfile string) error {
362362
}
363363

364364
func (p *Plexams) tableForExahm(ctx context.Context, m pdf.Maroto, sortByDate bool) {
365-
header := []string{"AnCode", "Modul", "Prüfender", "Termin", "Plätze"}
365+
header := []string{"AnCode", "Modul", "Prüfender", "Termin", "Plätze", "Räume"}
366366

367367
text := "Prüfungen mit EXaHM/SEB, sortiert nach AnCode"
368368
if sortByDate {
@@ -404,23 +404,54 @@ func (p *Plexams) tableForExahm(ctx context.Context, m pdf.Maroto, sortByDate bo
404404
if exams[j].PlanEntry == nil {
405405
return true
406406
}
407-
return exams[i].PlanEntry.DayNumber < exams[j].PlanEntry.DayNumber ||
408-
(exams[i].PlanEntry.DayNumber == exams[j].PlanEntry.DayNumber &&
409-
exams[i].PlanEntry.SlotNumber < exams[j].PlanEntry.SlotNumber)
407+
if exams[i].PlanEntry.DayNumber != exams[j].PlanEntry.DayNumber {
408+
return exams[i].PlanEntry.DayNumber < exams[j].PlanEntry.DayNumber
409+
}
410+
if exams[i].PlanEntry.SlotNumber != exams[j].PlanEntry.SlotNumber {
411+
return exams[i].PlanEntry.SlotNumber < exams[j].PlanEntry.SlotNumber
412+
}
413+
return exams[i].Ancode < exams[j].Ancode
410414
})
411415
}
412416

413417
for _, exam := range exams {
414-
if exam.PlanEntry == nil {
415-
contents = append(contents,
416-
[]string{strconv.Itoa(exam.Ancode), exam.ZpaExam.Module, exam.ZpaExam.MainExamer,
417-
"fehlt noch", strconv.Itoa(exam.StudentRegsCount)})
418-
} else {
418+
planEntry := "fehlt noch"
419+
if exam.PlanEntry != nil {
419420
starttime := p.getSlotTime(exam.PlanEntry.DayNumber, exam.PlanEntry.SlotNumber)
420-
contents = append(contents,
421-
[]string{strconv.Itoa(exam.Ancode), exam.ZpaExam.Module, exam.ZpaExam.MainExamer,
422-
r.Replace(starttime.Local().Format("Mon. 02.01.06, 15:04 Uhr")), strconv.Itoa(exam.StudentRegsCount)})
421+
planEntry = r.Replace(starttime.Local().Format("Mon. 02.01.06, 15:04 Uhr"))
422+
}
423+
424+
rooms := "fehlen noch"
425+
if len(exam.PlannedRooms) > 0 {
426+
var builder strings.Builder
427+
for i, room := range exam.PlannedRooms {
428+
if i != 0 {
429+
builder.WriteString(", ")
430+
}
431+
builder.WriteString(room.RoomName)
432+
}
433+
rooms = builder.String()
434+
} else {
435+
prePlannedRooms, err := p.PrePlannedRoomsForExam(ctx, exam.Ancode)
436+
if err != nil {
437+
log.Error().Err(err).Int("ancode", exam.Ancode).
438+
Msg("error while trying to get preplanned rooms")
439+
}
440+
if len(prePlannedRooms) > 0 {
441+
var builder strings.Builder
442+
for i, room := range prePlannedRooms {
443+
if i != 0 {
444+
builder.WriteString(", ")
445+
}
446+
builder.WriteString(room.RoomName)
447+
}
448+
rooms = builder.String()
449+
}
423450
}
451+
452+
contents = append(contents,
453+
[]string{strconv.Itoa(exam.Ancode), exam.ZpaExam.Module, exam.ZpaExam.MainExamer,
454+
planEntry, strconv.Itoa(exam.StudentRegsCount), rooms})
424455
}
425456

426457
grayColor := color.Color{
@@ -432,11 +463,11 @@ func (p *Plexams) tableForExahm(ctx context.Context, m pdf.Maroto, sortByDate bo
432463
m.TableList(header, contents, props.TableList{
433464
HeaderProp: props.TableListContent{
434465
Size: 11,
435-
GridSizes: []uint{1, 5, 2, 3, 1},
466+
GridSizes: []uint{1, 4, 2, 3, 1, 1},
436467
},
437468
ContentProp: props.TableListContent{
438469
Size: 11,
439-
GridSizes: []uint{1, 5, 2, 3, 1},
470+
GridSizes: []uint{1, 4, 2, 3, 1, 1},
440471
},
441472
Align: consts.Left,
442473
AlternatedBackground: &grayColor,

plexams/rooms.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ func (p *Plexams) PreAddRoomToExam(ctx context.Context, ancode int, roomName str
336336
})
337337
}
338338

339+
func (p *Plexams) PrePlannedRoomsForExam(ctx context.Context, ancode int) ([]*model.PrePlannedRoom, error) {
340+
return p.dbClient.PrePlannedRoomsForExam(ctx, ancode)
341+
}
342+
339343
func (p *Plexams) ChangeRoom(ctx context.Context, ancode int, oldRoomName, newRoomName string) (bool, error) {
340344
return false, fmt.Errorf("ChangeRoom is not implemented yet")
341345
// roomsForAncode, err := p.dbClient.RoomsForAncode(ctx, ancode)

0 commit comments

Comments
 (0)