Documentation ¶
Overview ¶
Package zb provides functions for student transfer operation on redis database which imported from ming. zb是一个基于明日系统导出至redis中的学校数据,提供转班相应操作的一个Golang包。
Index ¶
- Variables
- func ValidBlacklist(blacklist map[string][]string) bool
- type Blacklist
- type DB
- func (db *DB) ClearAllRecords() error
- func (db *DB) ClearBlacklist() error
- func (db *DB) Enable(flag bool) error
- func (db *DB) FilterToPeriodsOfCategoryWithBlacklist(category string, campusPeriods map[string][]string) (map[string][]string, error)
- func (db *DB) GetAllRecords() ([]Record, error)
- func (db *DB) GetAvailblePeriodsOfCategory(category string) (map[string][]string, error)
- func (db *DB) GetStatistics() (Statistics, error)
- func (db *DB) IsEnabled() (bool, error)
- func (db *DB) IsFromClassInBlacklist(campus, category, class string) (bool, error)
- func (db *DB) IsToPeriodInBlacklist(campus, category, period string) (bool, error)
- func (db *DB) LoadBlacklistFromJSON(file string, blacklist *Blacklist) error
- func (db *DB) SetBlacklist(blacklist map[string][]string) error
- func (db *DB) SetRecord(r Record) error
- type Record
- type Statistics
Constants ¶
This section is empty.
Variables ¶
var (
BlacklistTypes = map[string]string{
"from_campuses": "can't transfer students from the campuses",
"from_periods": "can't transfer students from the periods",
"from_classes": "can't transfer students from classes",
"to_campuses": "can't transfer students to the campuses",
"to_periods": "can't transfer students to the periods",
"to_classes": "can't transfer students to the classes",
}
)
Functions ¶
func ValidBlacklist ¶
ValidBlacklist validates the backlist.
Types ¶
type DB ¶
DB represents database to store transfer data. It's wrapper of ming.DB. Usage: import "github.com/shchnmz/ming" db := zb.DB{ming.DB{redisServer, redisPassword}}
func (*DB) ClearAllRecords ¶
ClearAllRecords clears all records in redis.
func (*DB) ClearBlacklist ¶
ClearBlacklist clear the backlist in redis.
func (*DB) FilterToPeriodsOfCategoryWithBlacklist ¶
func (db *DB) FilterToPeriodsOfCategoryWithBlacklist(category string, campusPeriods map[string][]string) (map[string][]string, error)
FilterToPeriodsOfCategoryWithBlacklist filters periods of the category in blacklist.
Params:
category: category of the periods. campusPeriods: map contains periods to filter. key: campus, value: periods.
Returns:
filtered campus - periods map. key: campus, value: periods.
func (*DB) GetAllRecords ¶
GetAllRecords gets all records in redis.
func (*DB) GetAvailblePeriodsOfCategory ¶
GetAvailblePeriodsOfCategory gets category's periods for all campuses, filtered with blacklist.
Params:
category: category which you want to get all periods.
Returns:
a map contains all periods. key: campus, value: periods.
func (*DB) GetStatistics ¶
func (db *DB) GetStatistics() (Statistics, error)
GetStatistics returns the statistics of student transfer.
func (*DB) IsFromClassInBlacklist ¶
IsFromClassInBlacklist checks if the class transfer from is in blacklist.
func (*DB) IsToPeriodInBlacklist ¶
IsToPeriodInBlacklist checks if the period transfer to is in blacklist.
func (*DB) LoadBlacklistFromJSON ¶
LoadBlacklistFromJSON loads the blacklist from JSON file then set it to redis.
Params:
file: JSON file name. There're following types of blacklist: "from_campuses", "from_periods", "from_classes", "to_campuses", "to_periods", "to_classes". Example blacklist.json: { "blacklist": { "from_campuses":["校区C"], "from_periods":[], "from_classes":[ "校区A:二年级:17秋新基二三1", "校区B:四年级:17秋新素零1" ], "to_campuses":["校区C"], "to_periods":[ "校区A:幼中:星期二16:25-17:55", "校区B:一年级:星期日13:00-14:45" ], "to_classes":[] } }
func (*DB) SetBlacklist ¶
SetBlacklist updates the backlist in redis.
Params:
blacklist: There're following types of blacklist: "from_campuses", "from_periods", "from_classes", "to_campuses", "to_periods", "to_classes".
type Record ¶
type Record struct { Name string `redis:"name"` PhoneNum string `redis:"phone_num"` Category string `redis:"category"` FromCampus string `redis:"from_campus"` FromClass string `redis:"from_class"` FromPeriod string `redis:"from_period"` ToCampus string `redis:"to_campus"` ToPeriod string `redis:"to_period"` Time string `redis:"time"` }
Record represents the transfer record.
type Statistics ¶
type Statistics struct { StudentNumOfEachCampus map[string]int StudentNumOfEachCategory map[string]int StudentNumOfEachTeacher map[string]int StudentPercentOfEachTeacher map[string]float32 // ClassesOfEachTeacher stores the classes belongs to the same teacher. // key: teacher, value: a map(set) stores classes in the format: // campus:category:class:period. ClassesOfEachTeacher map[string]map[string]bool // StudentNumOfEachToPeriod stores student number of each to_period. // key: campus:category:class:period, value: a map stores student number for each to_period. StudentNumOfEachToPeriod map[string]map[string]int }
Statistics represents the statistics of student transfer.