Skip to content

Commit

Permalink
pdf for exahm and some small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
obcode committed May 15, 2024
1 parent 18e633f commit 4999f21
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 16 deletions.
13 changes: 12 additions & 1 deletion cmd/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var (
draft-muc.dai --- draft plan for muc.dai exams
draft-fk08 --- draft plan for fk08 exams
draft-fk10 --- draft plan for fk10 exams
draft-fs --- draft plan for fs`,
draft-fs --- draft plan for fs
draft-exahm --- draft plan for exams in exahm rooms`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
plexams := initPlexamsConfig()
Expand Down Expand Up @@ -84,6 +85,16 @@ var (
os.Exit(1)
}

case "draft-exahm":
if len(Outfile) == 0 {
Outfile = "draft-exahm.pdf"
}
fmt.Printf("generating %s\n", Outfile)
err := plexams.DraftExahmPDF(context.Background(), Outfile)
if err != nil {
os.Exit(1)
}

case "draft-fs":
if len(Outfile) == 0 {
Outfile = "draft-fs.pdf"
Expand Down
128 changes: 128 additions & 0 deletions plexams/pdfDraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/johnfercher/maroto/pkg/consts"
"github.com/johnfercher/maroto/pkg/pdf"
"github.com/johnfercher/maroto/pkg/props"
"github.com/obcode/plexams.go/graph/model"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -272,3 +273,130 @@ func (p *Plexams) tableForProgram(ctx context.Context, program, programLong stri
})

}

func (p *Plexams) DraftExahmPDF(ctx context.Context, outfile string) error {
m := pdf.NewMaroto(consts.Portrait, consts.A4)
m.SetPageMargins(10, 15, 10)

m.RegisterFooter(func() {
m.Row(20, func() {
m.Col(12, func() {
m.Text(fmt.Sprintf("Stand: %s Uhr, generiert mit https://github.com/obcode/plexams.go",
time.Now().Format("02.01.06, 15:04")), props.Text{
Top: 13,
Style: consts.BoldItalic,
Size: 8,
Align: consts.Left,
})
})
})
})

m.Row(6, func() {
m.Col(12, func() {
m.Text(
fmt.Sprintf("Vorläufiger Planungsstand Prüfungen der FK07 im %s", p.semesterFull()), props.Text{
Top: 3,
Size: 12,
Style: consts.Bold,
Align: consts.Center,
})
})
})
m.Row(6, func() {
m.Col(12, func() {
m.Text(
fmt.Sprintf("%s <%s>", p.planer.Name, p.planer.Email), props.Text{
Top: 3,
Size: 12,
Style: consts.Normal,
Align: consts.Center,
})
})
})
m.Row(15, func() {
m.Col(12, func() {
m.Text(
"--- zur Abstimmung ---", props.Text{
Top: 3,
Size: 12,
Style: consts.Normal,
Align: consts.Center,
})
})
})

p.tableForExahm(ctx, m)

err := m.OutputFileAndClose(outfile)
if err != nil {
log.Error().Err(err).Msg("Could not save PDF")
return err
}
return nil
}

func (p *Plexams) tableForExahm(ctx context.Context, m pdf.Maroto) {
header := []string{"AnCode", "Modul", "Prüfer:in", "Termin"}

m.Row(18, func() {
m.Col(12, func() {
m.Text(
"Prüfungen mit EXaHM/SEB", props.Text{
Top: 10,
Size: 12,
Style: consts.Bold,
})
})
})

contents := make([][]string, 0)

allExams, err := p.PlannedExams(ctx)
exams := make([]*model.PlannedExam, 0)

for _, exam := range allExams {
if exam.Constraints != nil && exam.Constraints.RoomConstraints != nil &&
(exam.Constraints.RoomConstraints.ExahmRooms || exam.Constraints.RoomConstraints.Seb) {
exams = append(exams, exam)
}
}

if err != nil {
log.Error().Err(err).Msg("error while getting exams")
}
for _, exam := range exams {
if exam.PlanEntry == nil {
contents = append(contents,
[]string{strconv.Itoa(exam.Ancode), exam.ZpaExam.Module, exam.ZpaExam.MainExamer,
"fehlt noch"})
} else {
starttime := p.getSlotTime(exam.PlanEntry.DayNumber, exam.PlanEntry.SlotNumber)
contents = append(contents,
[]string{strconv.Itoa(exam.Ancode), exam.ZpaExam.Module, exam.ZpaExam.MainExamer,
r.Replace(starttime.Local().Format("Mon. 02.01.06, 15:04 Uhr"))})
}
}

grayColor := color.Color{
Red: 211,
Green: 211,
Blue: 211,
}

m.TableList(header, contents, props.TableList{
HeaderProp: props.TableListContent{
Size: 11,
GridSizes: []uint{1, 5, 2, 4},
},
ContentProp: props.TableListContent{
Size: 11,
GridSizes: []uint{1, 5, 2, 4},
},
Align: consts.Left,
AlternatedBackground: &grayColor,
HeaderContentSpace: 1,
Line: false,
})

}
4 changes: 2 additions & 2 deletions plexams/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func getSlotsForDay(allSlots []*model.Slot, day *time.Time) []*model.Slot {
slots := make([]*model.Slot, 0)

for _, slot := range allSlots {
if day.Local().Day() == slot.Starttime.Day() && day.Local().Month() == slot.Starttime.Month() {
if day.Local().Day() == slot.Starttime.Local().Day() && day.Local().Month() == slot.Starttime.Local().Month() {
slots = append(slots, slot)
}
}
Expand All @@ -188,7 +188,7 @@ func removeSlotsForDay(allSlots []*model.Slot, day *time.Time) []*model.Slot {
slots := make([]*model.Slot, 0)

for _, slot := range allSlots {
if !(day.Day() == slot.Starttime.Day() && day.Month() == slot.Starttime.Month()) {
if !(day.Local().Day() == slot.Starttime.Local().Day() && day.Local().Month() == slot.Starttime.Local().Month()) {
slots = append(slots, slot)
}
}
Expand Down
2 changes: 1 addition & 1 deletion plexams/plannedExams.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (p *Plexams) PlannedExamsForProgram(ctx context.Context, program string, on
continue
}
for _, primussExam := range plannedExam.PrimussExams {
if primussExam.Exam.Program == program {
if primussExam.Exam.Program == program && len(primussExam.StudentRegs) > 0 {
plannedExamsForProgram = append(plannedExamsForProgram, plannedExam)
break
}
Expand Down
19 changes: 12 additions & 7 deletions plexams/plexams.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func (p *Plexams) setGoSlots() {
if p.semesterConfig.GoDay0.Year() == day.Date.Year() &&
p.semesterConfig.GoDay0.Month() == day.Date.Month() &&
p.semesterConfig.GoDay0.Day() == day.Date.Day() {
offset = i
offset = i + 1
// fmt.Printf("offset == %d\n", offset)
break
}
}
Expand All @@ -159,22 +160,26 @@ func (p *Plexams) setGoSlots() {
}] = slot
}

for k, v := range slotsMap {
fmt.Printf("slot[%v] = %v\n", k, v)
}
// for k, v := range slotsMap {
// fmt.Printf("slot[%v] = %v\n", k, v)
// }

goSlots := make([]*model.Slot, 0, len(goSlotsII))

for _, goSlot := range goSlotsII {
goSlots = append(goSlots, slotsMap[slotNumber{
slot, ok := slotsMap[slotNumber{
day: goSlot[0] + offset,
slot: goSlot[1],
}])
}]
if ok {
goSlots = append(goSlots, slot)
}
}

// offSet := (p.semesterConfig.GoDay0.Sub(p.semesterConfig.Days[0].Date).Hours() / 24)
fmt.Printf("day0 = %v, goday0 = %v, offset = %v\n", p.semesterConfig.Days[0].Date, p.semesterConfig.GoDay0, offset)
// fmt.Printf("day0 = %v, goday0 = %v, offset = %v\n", p.semesterConfig.Days[0].Date, p.semesterConfig.GoDay0, offset)
p.semesterConfig.GoSlots = goSlots
// fmt.Printf("Go-Slots = %+v\n", p.semesterConfig.GoSlots)
}

func (p *Plexams) GetGoSlots() [][]int {
Expand Down
13 changes: 10 additions & 3 deletions plexams/slots.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,17 @@ func CalculatedAllowedSlots(semesterConfigSlots []*model.Slot, goSlots [][]int,
slotsWithoutExcludedDays := make([]*model.Slot, 0)
for _, excludeDay := range constraints.ExcludeDays {
for _, slot := range slots {
if !time.Date(slot.Starttime.Year(), slot.Starttime.Month(), slot.Starttime.Day(), 0, 0, 0, 0, time.Local).
Equal(*excludeDay) {
slotsWithoutExcludedDays = append(slotsWithoutExcludedDays, slot)
s := slot.Starttime.Local()
e := excludeDay.Local()
if constraints.Ancode == 204 {
fmt.Printf("slot %s -- excluded day %s\n", s.String(), e.String())
}
if e.Year() == s.Year() && e.Month() == s.Month() && e.Day() == s.Day() {
fmt.Println(">>>> FOUND <<<<")
break
}

slotsWithoutExcludedDays = append(slotsWithoutExcludedDays, slot)
}
}
slots = slotsWithoutExcludedDays
Expand Down
4 changes: 2 additions & 2 deletions plexams/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (p *Plexams) ValidateConstraints() error {
if day.Equal(time.Date(slot.Starttime.Year(), slot.Starttime.Month(), slot.Starttime.Day(), 0, 0, 0, 0, time.Local)) {
validationMessages = append(validationMessages,
aurora.Sprintf(aurora.Red("Exam %d planned on excluded day %s"),
aurora.Magenta(constraint.Ancode), aurora.Cyan(day.Format("02.01.06"))))
aurora.Magenta(constraint.Ancode), aurora.Cyan(day.Local().Format("02.01.06"))))
}
}

Expand All @@ -339,7 +339,7 @@ func (p *Plexams) ValidateConstraints() error {
}
}

if constraint.RoomConstraints != nil && constraint.RoomConstraints.ExahmRooms || constraint.RoomConstraints.Seb {
if constraint.RoomConstraints != nil && (constraint.RoomConstraints.ExahmRooms || constraint.RoomConstraints.Seb) {
if !p.roomBookedDuringExamTime(bookedEntries, slot) {
validationMessages = append(validationMessages,
aurora.Sprintf(aurora.Red("Exam %d planned at %s, but no room booked"),
Expand Down

0 comments on commit 4999f21

Please sign in to comment.