database

package
v0.0.0-...-547a5e9 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package database implements a database access layer for the school-dashboard application.

It wraps an SQL database connection, prepares statements to query the database and then provides methods to return the results of any queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {

	// Name of the school
	School string

	// URN/LEA numbers (as found on performance tables)
	URN string
	LEA string

	// Default filter options
	Options map[string]string
}

A Config holds the details of the schools

func (Config) DefaultFilter

func (cfg Config) DefaultFilter() Filter

DefaultFilter produces a Filter object with the default values specified in the database.

type Database

type Database struct {

	// Config Options
	Config Config

	// Cached items
	Levels   map[int]subject.Level
	Subjects map[int]*subject.Subject

	// National data
	Attainment8 map[string](map[string]student.Attainment8)

	// Cached items for menu lookups
	Dates       []Lookup
	Resultsets  []Lookup
	NatYears    []Lookup
	Ethnicities []string

	// OtherEths tells us whether an ethnic group should be
	// collapsed into the 'Other' category
	OtherEths map[string]bool
	// contains filtered or unexported fields
}

A Database provides a wrapper to the school database.

func Connect

func Connect(filename string) (Database, error)

Connect to the database

func (Database) Classes

func (db Database) Classes(subjID, dateID string) ([]string, error)

Classes returns a list of classes that exists for a subject, at a particular date.

func (Database) Close

func (db Database) Close() error

Close the connection to the database.

func (Database) CurrentWeek

func (db Database) CurrentWeek() (string, error)

CurrentWeek looks up the name of the latest week, as used for attendance.

func (Database) GroupByClass

func (db Database) GroupByClass(subjID, class string, f Filter) (group.Group, error)

GroupByClass returns a group of students who are present in the subject/class specified at the particular date.

func (Database) GroupByFilter

func (db Database) GroupByFilter(f Filter) (group.Group, error)

GroupByFilter returns a group of students who satisfy the criteria specified in the filter.

func (Database) GroupByFilteredClass

func (db Database) GroupByFilteredClass(subjID, class string, f Filter) (group.Group, error)

GroupByFilteredClass returns a group of students who meet the filter criteria and are in the subject/class combination specified. If class="", then all students in that subject are returned.

func (Database) HistoricalResults

func (db Database) HistoricalResults(upn string, subjID int) (map[string]string, error)

HistoricalResults returns a map of student results for a particular subject, keyed by resultset name

func (Database) LookupDate

func (db Database) LookupDate(id string) (string, error)

LookupDate lookups the id number of the date, and returns its name

func (Database) LookupNatYear

func (db Database) LookupNatYear(id string) (string, error)

LookupNatYear looks up the id number of the National Dataset and returns its name

func (Database) LookupResultset

func (db Database) LookupResultset(id string) (string, error)

LookupResultset looks up the id number of the resultset and returns its name

func (Database) News

func (db Database) News() ([]NewsItem, error)

News returns a list of news items

func (*Database) Refresh

func (db *Database) Refresh() error

Refresh the cached config from the database

func (Database) Search

func (db Database) Search(name string, f Filter) (group.Group, error)

Search returns a list of students who's names match the search string

func (Database) Student

func (db Database) Student(upn string, f Filter) (student.Student, error)

Student loads the details of an individual student

type Filter

type Filter struct {
	// Effective date to use for membership of the group.
	// Holds the id number, but held as string for easier
	// parsing from query strings.
	Date string
	// Which set of assessment results to use.
	// Holds id number as above.
	Resultset string
	// Which year to use for national data comparisons.
	NatYear string
	// Which yeargroup to include in the group
	Year string
	// Pupil premium: "", "1", or "0" for Any/True/False
	PP string
	// EAL students: "", "1", or "0" for Any/True/False
	EAL string
	// Gender: "", "1", "0" for Any/Male/Female
	Gender string
	// SEN types to include - Empty for any
	SEN []string
	// Which Ethnic groups to include, empty for any
	Ethnicities []string
	// Which KS2 bands to include, empty for any
	KS2Bands []string
}

A Filter holds all the fields available to select a group of students on.

type Lookup

type Lookup struct {
	ID   string
	Name string
}

A Lookup collects object names and their ID numbers from the database. IDs are stored as strings to avoid the need for conversion when parsing query strings.

type NewsItem

type NewsItem struct {
	Date    string
	Comment string
}

A NewsItem contains the details of a news item

Jump to

Keyboard shortcuts

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