initial commit
commit
e6ae628ac5
@ -0,0 +1,199 @@
|
||||
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()
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
module Maurer/convert_data
|
||||
|
||||
go 1.26.1
|
||||
|
||||
replace maurer/grading_report => ../grading_report
|
||||
|
||||
require maurer/grading_report v0.0.0-00010101000000-000000000000
|
||||
|
||||
require (
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/ncruces/go-strftime v1.0.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
golang.org/x/crypto v0.49.0 // indirect
|
||||
golang.org/x/sys v0.42.0 // indirect
|
||||
modernc.org/libc v1.72.0 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.11.0 // indirect
|
||||
modernc.org/sqlite v1.50.0 // indirect
|
||||
)
|
||||
Loading…
Reference in New Issue