gradebook

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2025 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package gradebook is a library to read and write gradebook files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssignmentCategories

type AssignmentCategories []string

AssignmentCategories stores basic assignment categories, the broad groupings such as "major" and "minor".

type AssignmentRecord added in v0.2.0

type AssignmentRecord struct {
	Email string   `json:"email"`
	Grade *float64 `json:"grade"`
}

AssignmentRecord represents a grade for a particular student on a particular assignment. If AssignmentRecord.Grade is nil, then the student was absent on the day of the assignment and should not be counted when calculating grades.

type AssignmentRecords added in v0.2.0

type AssignmentRecords []*AssignmentRecord

AssignmentRecords stores AssignmentRecord structs.

type AverageResult

type AverageResult struct {
	Value float64
	Valid bool
}

AverageResult represents the result of *Student.Average. The result is only valid for use if the given Student has scores of a given type to average.

func (AverageResult) String

func (ar AverageResult) String() string

String returns a string representation of an AverageResult.

type CategoriesByAssignmentType

type CategoriesByAssignmentType map[string]string

CategoriesByAssignmentType maps categories by their assignment type. (E.g., "test", "essay", and "project" all have the category "major". Every assignment type must belong to one and only one category, and every assignment type must be present in CategoriesByAssignmentType. Also, and this is less obvious, every assignment category must have an assignment type. If a category has only a single assignment type, the category and type will often have the same name. E.g., both the category and the type are "cp"."

type Class

type Class struct {
	TermsByID                   `json:"terms_by_id"`
	LabelsByAssignmentCategory  `json:"labels_by_assignment_category"`
	WeightsByAssignmentCategory `json:"weights_by_assignment_category"`
	CategoriesByAssignmentType  `json:"categories_by_assignment_type"`
	StudentsByEmail             `json:"students_by_email"`
	Name                        string `json:"name"`
	AssignmentCategories        `json:"assignment_categories"`
}

Class represents a class and its students.

func UnmarshalCalcClass

func UnmarshalCalcClass(classFile string) (*Class, error)

UnmarshalCalcClass unmarshals a class.json file into a pointer to Class. Unlike UnmarshalClass, this function creates the Grades map needed to store grades.

func UnmarshalClass

func UnmarshalClass(classFile string) (*Class, error)

UnmarshalClass unmarshals a class.json file into a pointer to Class.

func (*Class) AssignmentCategoriesSortedByLabel

func (c *Class) AssignmentCategoriesSortedByLabel() []string

AssignmentCategoriesSortedByLabel returns a slice of categories sorted by label.

func (*Class) EmailsSortedByStudentName

func (c *Class) EmailsSortedByStudentName() []string

EmailsSortedByStudentName returns a slice of student emails sorted by student name.

func (*Class) LoadGrades

func (c *Class) LoadGrades(dir string, term *Term) error

LoadGrades scans a given directory for *.gradebook files and adds grades from those files to students. The method returns an error if there is a problem reading, unmarshaling, or closing a file.

func (*Class) StudentsSortedByName

func (c *Class) StudentsSortedByName() []*Student

StudentsSortedByName returns a slice of students sorted by last and first name.

func (*Class) Validate

func (c *Class) Validate() error

Validate checks whether a *Class is valid. It returns nil if the *Class is valid. Otherwise it returns an error containing one more errors from the individual checks. Those errors are combined using errors.Join.

type Gradebook

type Gradebook struct {
	AssignmentDate     string            `json:"assignment_date"`
	AssignmentName     string            `json:"assignment_name"`
	AssignmentType     string            `json:"assignment_type"`
	AssignmentCategory string            `json:"assignment_category"`
	AssignmentRecords  AssignmentRecords `json:"assignment_records"`
}

Gradebook represents a single gradebook file.

func UnmarshalGradebook

func UnmarshalGradebook(gradebookFile string) (*Gradebook, error)

UnmarshalGradebook unmarshals a gradebook file into a pointer to Gradebook.

type LabelsByAssignmentCategory

type LabelsByAssignmentCategory map[string]string

LabelsByAssignmentCategory maps human-readable labels by a category of assignment. E.g., the category "cp" has the label "Class Participation", and the category "major" has the label "Major Assessments".

type Student

type Student struct {
	GradesByCategory map[string][]float64
	FirstName        string `json:"first_name"`
	LastName         string `json:"last_name"`
}

Student represents a student.

func NewStudent

func NewStudent(firstName, lastName string) (*Student, error)

NewStudent a new *Student. If firstName or lastName is empty, the method returns an error.

func (*Student) Average

func (s *Student) Average(category string) AverageResult

Average calculates the average for a slice of scores in a given category and returns an AverageResult and an error. If the category is unknown, the method returns an error. If the slice of scores is empty, the method returns an invalid AverageResult.

func (*Student) TotalAverage

func (s *Student) TotalAverage(weights WeightsByAssignmentCategory) AverageResult

TotalAverage returns an AverageResult and error for all of a student's scores. The method will return an invalid result if the student has no scores in any category. The method will return an error if any call to Average for a given category returns an error.

type StudentsByEmail

type StudentsByEmail map[string]*Student

StudentsByEmail maps students by their email. (NB: an email is an appropriate equivalent to a database's primary key because emails are unique.)

type Term

type Term struct {
	Start string
	End   string
}

Term represents a grading period (e.g., a quarter or semester).

func (Term) Includes

func (t Term) Includes(d string) bool

Includes determines whether a date falls within a term.

type TermsByID

type TermsByID map[string]*Term

TermsByID maps Terms by short ID (e.g., "q1" points to the first quarter).

type WeightsByAssignmentCategory

type WeightsByAssignmentCategory map[string]int

WeightsByAssignmentCategory maps percentage values in a grading rubric by assignment category. The sum of the weights must equal 100 in order for this type to be valid.

Directories

Path Synopsis
internal
set
Package set provides a minimal ADT and operations for sets.
Package set provides a minimal ADT and operations for sets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL