Skip to content

Commit

Permalink
exam for student
Browse files Browse the repository at this point in the history
  • Loading branch information
obcode committed Jul 7, 2023
1 parent e1d5d87 commit b432b57
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ var (
Use: "info [subcommand]",
Short: "get info",
Long: `Get info.
goslots --- info about slots for GO/GN
request-rooms --- which rooms to request
stats --- get statistics
student-regs ancode --- get student-reqs for ancode
rooms-for-nta name --- get planned rooms for student.`,
goslots --- info about slots for GO/GN
request-rooms --- which rooms to request
stats --- get statistics
student-regs ancode --- get student-reqs for ancode
rooms-for-nta name --- get planned rooms for student
exams-for-student name --- get exams for student.`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
p := initPlexamsConfig()
Expand Down Expand Up @@ -84,6 +85,15 @@ rooms-for-nta name --- get planned rooms for student.`,
fmt.Println(err)
return
}
case "exams-for-student":
if len(args) < 2 {
log.Fatal("need name")
}
err := p.GetExamsForStudent(args[1])
if err != nil {
fmt.Println(err)
return
}
default:
fmt.Println("info called with unknown sub command")
}
Expand Down
50 changes: 50 additions & 0 deletions plexams/studentRegs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plexams
import (
"context"
"fmt"
"strings"

set "github.com/deckarep/golang-set/v2"
"github.com/obcode/plexams.go/graph/model"
Expand Down Expand Up @@ -62,3 +63,52 @@ func (p *Plexams) GetStudentRegsForAncode(ancode int) (*model.StudentRegsForAnco
StudentRegs: studentRegs,
}, nil
}

func (p *Plexams) GetExamsForStudent(name string) error {
ctx := context.Background()
students, err := p.dbClient.StudentRegsPerStudentPlanned(ctx)
if err != nil {
return err
}
var student *model.StudentRegsPerStudent
for _, studentInDB := range students {
if strings.HasPrefix(studentInDB.Student.Name, name) {
student = studentInDB
break
}
}
if student == nil {
return fmt.Errorf("NTA with name=%s not found", name)
}
log.Debug().Str("name", student.Student.Name).Msg("found student")

for _, ancode := range student.Ancodes {
exam, err := p.dbClient.GetZpaExamByAncode(ctx, ancode)
if err != nil {
log.Error().Err(err).Int("ancode", ancode).Msg("cannot get zpa exam")
}

constraints, err := p.ConstraintForAncode(ctx, ancode)
if err != nil {
log.Error().Err(err).Int("ancode", ancode).Msg("cannot get constraints")
}
if constraints != nil && constraints.NotPlannedByMe {
log.Debug().Int("ancode", ancode).Str("examer", exam.MainExamer).Str("module", exam.Module).Msg("exam not planned by me")
continue
}
log.Debug().Int("ancode", ancode).Str("examer", exam.MainExamer).Str("module", exam.Module).Msg("found exam")

fmt.Printf("%d. %s: %s\n", ancode, exam.MainExamer, exam.Module)

roomsForExam, err := p.dbClient.RoomsForAncode(ctx, ancode)
if err != nil {
log.Error().Err(err).Int("ancode", ancode).Msg("cannot get rooms")
}
for _, room := range roomsForExam {
fmt.Printf(" - Raum %s\n", room.RoomName)
}

}

return nil
}

0 comments on commit b432b57

Please sign in to comment.