From 7c30e4a723e225259e3c961be36bbd63e9aeea6b Mon Sep 17 00:00:00 2001 From: Joshua Herring Date: Sun, 12 Apr 2026 14:49:30 -0400 Subject: [PATCH] Generate Instructor Assignments --- grading_data_generator.go | 84 +++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/grading_data_generator.go b/grading_data_generator.go index 3ba3d98..09fb9cc 100644 --- a/grading_data_generator.go +++ b/grading_data_generator.go @@ -505,11 +505,15 @@ type Section struct { } type Config struct { - NumberOfUsers int `json:"number_of_users"` - NumberOfSections int `json:"number_of_sections"` - NumberOfInstructors int `json:"number_of_instructors"` - EnrollmentsPerStudent int `json:"enrollments_per_student"` - PercentStatus map[string]int `json:"percent_status"` + NumberOfUsers int `json:"number_of_users"` + NumberOfSections int `json:"number_of_sections"` + EnrollmentsPerStudent int `json:"enrollments_per_student"` + PercentStatus map[string]int `json:"percent_status"` +} + +type InstructorsSections struct { + InstructorID string `json:"instructor_id"` + SectionID string `json:"section_id"` } var statuses = []string{"JD", "LLM", "MCL", "PHD", "SJD", "MLS", "SPEC", "MNR", "CERT", "Admin", "Instructor"} @@ -570,17 +574,17 @@ func SaveGeneratedUsers(users []User) { fmt.Printf("Generated %d users to users.csv\n", len(users)) } -func GenerateSectionData(config Config) []Section { - // Generate unique instructor names: "LastName, X" - instructorNames := make([]string, 0, config.NumberOfInstructors) - seenInstructors := make(map[string]struct{}, config.NumberOfInstructors) - for len(instructorNames) < config.NumberOfInstructors { - name := fmt.Sprintf("%s, %c", gofakeit.LastName(), 'A'+rune(rand.Intn(26))) - if _, exists := seenInstructors[name]; !exists { - seenInstructors[name] = struct{}{} - instructorNames = append(instructorNames, name) +func GenerateSectionData(config Config, users []User) []Section { + // Build list of instructor UIDs from users with Status "Instructor" + instructorUIDs := make([]string, 0) + for _, u := range users { + if u.Status == "Instructor" { + instructorUIDs = append(instructorUIDs, u.UID) } } + if len(instructorUIDs) == 0 { + log.Fatal("no users with Status \"Instructor\" found") + } // Generate unique course numbers: one uppercase letter + 3 digits seenCourseNumbers := make(map[string]struct{}, config.NumberOfSections) @@ -600,7 +604,7 @@ func GenerateSectionData(config Config) []Section { my_section := course_information[rand.Intn(len(course_information))] my_section.SectionID = sectionIDs[i] - my_section.Instructor = instructorNames[rand.Intn(len(instructorNames))] + my_section.Instructor = instructorUIDs[rand.Intn(len(instructorUIDs))] my_section.CourseType = course_type[rand.Intn(len(course_type))] sections[i] = my_section @@ -634,6 +638,51 @@ func SaveGeneratedSections(sections []Section) { fmt.Printf("Generated %d sections to sections.csv\n", len(sections)) } +func GenerateInstructorAssignmentData(users []User, sections []Section) []InstructorsSections { + instructorUIDs := make([]string, 0) + for _, u := range users { + if u.Status == "Instructor" { + instructorUIDs = append(instructorUIDs, u.UID) + } + } + if len(instructorUIDs) == 0 { + log.Fatal("no users with Status \"Instructor\" found") + } + + assignments := make([]InstructorsSections, len(sections)) + for i, s := range sections { + assignments[i] = InstructorsSections{ + InstructorID: instructorUIDs[i%len(instructorUIDs)], + SectionID: s.SectionID, + } + } + return assignments +} + +func SaveInstructorsSections(assignments []InstructorsSections) { + f, err := os.Create("instructors_sections.csv") + if err != nil { + log.Fatalf("failed to create instructors_sections.csv: %v", err) + } + defer f.Close() + + w := csv.NewWriter(f) + if err := w.Write([]string{"instructor_id", "section_id"}); err != nil { + log.Fatalf("failed to write csv header: %v", err) + } + for _, a := range assignments { + if err := w.Write([]string{a.InstructorID, a.SectionID}); err != nil { + log.Fatalf("failed to write csv row: %v", err) + } + } + w.Flush() + if err := w.Error(); err != nil { + log.Fatalf("csv flush error: %v", err) + } + + fmt.Printf("Generated %d instructor assignments to instructors_sections.csv\n", len(assignments)) +} + type SectionEnrollment struct { SectionID string `json:"section_id"` UID string `json:"uid"` @@ -704,9 +753,12 @@ func main() { generated_users := GenerateUserData(config) SaveGeneratedUsers(generated_users) - generated_sections := GenerateSectionData(config) + generated_sections := GenerateSectionData(config, generated_users) SaveGeneratedSections(generated_sections) + generated_assignments := GenerateInstructorAssignmentData(generated_users, generated_sections) + SaveInstructorsSections(generated_assignments) + generated_enrollments := GenerateSectionEnrollmentData(generated_users, generated_sections, config) SaveGeneratedSectionEnrollments(generated_enrollments)