You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
200 lines
4.2 KiB
Go
200 lines
4.2 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
_ "fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"maurer/grading_report/dbi"
|
|
)
|
|
|
|
func read_enrollments() {
|
|
|
|
var entity_map map[string][]dbi.SectionEnrollment
|
|
var all_enrollments []dbi.SectionEnrollment
|
|
|
|
import_data, e := os.ReadFile("data/enrollments.json")
|
|
if e != nil {
|
|
log.Fatalf("Unable to open enrollments.json: %s\n", e)
|
|
}
|
|
|
|
e = json.Unmarshal(import_data, &entity_map)
|
|
if e != nil {
|
|
log.Fatalf("Unable to read data from enrollments.json: %s\n", e)
|
|
}
|
|
|
|
for _, entities := range entity_map {
|
|
for _, entity := range entities {
|
|
all_enrollments = append(all_enrollments, entity)
|
|
}
|
|
}
|
|
|
|
e = dbi.BulkAddEnrollments(all_enrollments)
|
|
if e != nil {
|
|
log.Fatalf("Error saving enrollment: %s\n", e)
|
|
}
|
|
|
|
}
|
|
|
|
func read_users() {
|
|
var entity_map map[string]dbi.User
|
|
var entities []dbi.User
|
|
|
|
entity_data, e := os.ReadFile("data/users.json")
|
|
if e != nil {
|
|
log.Fatalf("Unable to open sections.json: %s\n", e)
|
|
}
|
|
|
|
e = json.Unmarshal(entity_data, &entity_map)
|
|
if e != nil {
|
|
log.Fatalf("Unable to read data from sections.json: %s\n", e)
|
|
}
|
|
|
|
for _, entity := range entity_map {
|
|
entities = append(entities, entity)
|
|
}
|
|
|
|
e = dbi.BulkAddUser(entities)
|
|
if e != nil {
|
|
log.Fatalf("Error saving user: %s\n", e)
|
|
}
|
|
|
|
}
|
|
|
|
func read_starratings() {
|
|
|
|
var entity_map map[string][]dbi.StarRating
|
|
|
|
import_data, e := os.ReadFile("data/star_ratings.json")
|
|
if e != nil {
|
|
log.Fatalf("Unable to open star_ratings.json: %s\n", e)
|
|
}
|
|
|
|
e = json.Unmarshal(import_data, &entity_map)
|
|
if e != nil {
|
|
log.Fatalf("Unable to read data from starratings.json: %s\n", e)
|
|
}
|
|
|
|
for _, entities := range entity_map {
|
|
for _, entity := range entities {
|
|
e = dbi.AddStarRating(entity.SectionID, entity.UID)
|
|
if e != nil {
|
|
log.Fatalf("Error saving star rating: %s\n", e)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
func read_sectiontypes() {
|
|
|
|
var entity_map map[string]dbi.SectionType
|
|
var entities []dbi.SectionType
|
|
|
|
import_data, e := os.ReadFile("data/sectiontypes.json")
|
|
if e != nil {
|
|
log.Fatalf("Unable to open sectiontypes.json: %s\n", e)
|
|
}
|
|
|
|
e = json.Unmarshal(import_data, &entity_map)
|
|
if e != nil {
|
|
log.Fatalf("Unable to read data from sectiontypes.json: %s\n", e)
|
|
}
|
|
|
|
for _, entity := range entity_map {
|
|
entities = append(entities, entity)
|
|
}
|
|
|
|
e = dbi.BulkAddSectionTypes(entities)
|
|
if e != nil {
|
|
log.Fatalf("Error saving sectiontype: %s\n", e)
|
|
}
|
|
|
|
}
|
|
|
|
func read_sections() {
|
|
|
|
var sections_map map[string]dbi.Section
|
|
var sections []dbi.Section
|
|
|
|
sections_data, e := os.ReadFile("data/sections.json")
|
|
if e != nil {
|
|
log.Fatalf("Unable to open sections.json: %s\n", e)
|
|
}
|
|
|
|
e = json.Unmarshal(sections_data, §ions_map)
|
|
if e != nil {
|
|
log.Fatalf("Unable to read data from sections.json: %s\n", e)
|
|
}
|
|
|
|
for _, section := range sections_map {
|
|
sections = append(sections, section)
|
|
}
|
|
|
|
e = dbi.BulkAddSections(sections)
|
|
if e != nil {
|
|
log.Fatalf("Error saving section: %s\n", e)
|
|
}
|
|
|
|
}
|
|
|
|
func read_grades() {
|
|
var grades_map map[string][]dbi.SectionGrade
|
|
var section_grades []dbi.SectionGrade
|
|
|
|
grades_data, e := os.ReadFile("data/grades.json")
|
|
if e != nil {
|
|
log.Fatalf("Unable to open grades.json: %s\n", e)
|
|
}
|
|
|
|
e = json.Unmarshal(grades_data, &grades_map)
|
|
if e != nil {
|
|
log.Fatalf("Unable to read data from grades.json: %s\n", e)
|
|
}
|
|
|
|
for _, section_list := range grades_map {
|
|
section_grades = append(section_grades, section_list...)
|
|
}
|
|
|
|
e = dbi.BulkAddSectionGrades(section_grades)
|
|
if e != nil {
|
|
log.Fatalf("Error saving section grades: %s\n", e)
|
|
}
|
|
|
|
}
|
|
|
|
func read_instructors() {
|
|
var instructors_map map[string][]dbi.SectionInstructor
|
|
var section_instructors []dbi.SectionInstructor
|
|
|
|
instructors_data, e := os.ReadFile("data/instructors.json")
|
|
if e != nil {
|
|
log.Fatalf("Unable to open instructors.json: %s\n", e)
|
|
}
|
|
|
|
e = json.Unmarshal(instructors_data, &instructors_map)
|
|
if e != nil {
|
|
log.Fatalf("Unable to read data from instructors.json: %s\n", e)
|
|
}
|
|
|
|
for _, section_list := range instructors_map {
|
|
section_instructors = append(section_instructors, section_list...)
|
|
}
|
|
|
|
e = dbi.BulkAddSectionInstructors(section_instructors)
|
|
if e != nil {
|
|
log.Fatalf("Error saving section instructors: %s\n", e)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
read_sections()
|
|
read_sectiontypes()
|
|
read_users()
|
|
read_instructors()
|
|
read_enrollments()
|
|
read_starratings()
|
|
read_grades()
|
|
}
|