generate grades due

master
Joshua Herring 3 weeks ago
parent 9eeaa5c960
commit d1f855d55b

@ -8,6 +8,7 @@ import (
"math/rand" "math/rand"
"os" "os"
"strings" "strings"
"time"
"github.com/brianvoe/gofakeit/v6" "github.com/brianvoe/gofakeit/v6"
) )
@ -502,6 +503,7 @@ type Section struct {
Instructor string `json:"course_instructor"` Instructor string `json:"course_instructor"`
CourseTitle string `json:"course_title"` CourseTitle string `json:"course_title"`
CourseType string `json:"course_type"` CourseType string `json:"course_type"`
GradesDue string `json:"grades_due"`
} }
type Config struct { type Config struct {
@ -599,6 +601,12 @@ func GenerateSectionData(config Config, users []User) []Section {
sectionIDs := uniqueNumericStrings(5, config.NumberOfSections) sectionIDs := uniqueNumericStrings(5, config.NumberOfSections)
now := time.Now()
dueDates := []string{
now.AddDate(0, 0, 7).Format("Monday 2 January 2006"),
now.AddDate(0, 1, 0).Format("Monday 2 January 2006"),
}
sections := make([]Section, config.NumberOfSections) sections := make([]Section, config.NumberOfSections)
for i := range sections { for i := range sections {
@ -606,6 +614,7 @@ func GenerateSectionData(config Config, users []User) []Section {
my_section.SectionID = sectionIDs[i] my_section.SectionID = sectionIDs[i]
my_section.Instructor = instructorUIDs[rand.Intn(len(instructorUIDs))] my_section.Instructor = instructorUIDs[rand.Intn(len(instructorUIDs))]
my_section.CourseType = course_type[rand.Intn(len(course_type))] my_section.CourseType = course_type[rand.Intn(len(course_type))]
my_section.GradesDue = dueDates[rand.Intn(len(dueDates))]
sections[i] = my_section sections[i] = my_section
} }
@ -622,11 +631,11 @@ func SaveGeneratedSections(sections []Section) {
defer f.Close() defer f.Close()
w := csv.NewWriter(f) w := csv.NewWriter(f)
if err := w.Write([]string{"section_id", "course_number", "course_instructor", "course_title", "course_type"}); err != nil { if err := w.Write([]string{"section_id", "course_number", "course_instructor", "course_title", "course_type", "grades_due"}); err != nil {
log.Fatalf("failed to write csv header: %v", err) log.Fatalf("failed to write csv header: %v", err)
} }
for _, s := range sections { for _, s := range sections {
if err := w.Write([]string{s.SectionID, s.CourseNumber, s.Instructor, s.CourseTitle, s.CourseType}); err != nil { if err := w.Write([]string{s.SectionID, s.CourseNumber, s.Instructor, s.CourseTitle, s.CourseType, s.GradesDue}); err != nil {
log.Fatalf("failed to write csv row: %v", err) log.Fatalf("failed to write csv row: %v", err)
} }
} }

Loading…
Cancel
Save