zb

package module
v0.0.0-...-cb76a74 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2019 License: MIT Imports: 11 Imported by: 0

README

zb

Build Status Go Report Card GoDoc

zb是一个基于明日系统导出至redis中的学校数据,提供转班相应操作的一个Golang包。

服务器实现
  • api是API服务器。
  • server是应用服务器,提供了用户转班申请界面以及简单的admin管理页面。
生产环境搭建
Requirements
  • Go1.8 and later
Documentation
License

Documentation

Overview

Package zb provides functions for student transfer operation on redis database which imported from ming. zb是一个基于明日系统导出至redis中的学校数据,提供转班相应操作的一个Golang包。

Index

Constants

This section is empty.

Variables

View Source
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

func ValidBlacklist(blacklist map[string][]string) bool

ValidBlacklist validates the backlist.

Types

type Blacklist

type Blacklist struct {
	List map[string][]string `json:"blacklist"`
}

Blacklist represents the blacklist of student transfer.

type DB

type DB struct {
	ming.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

func (db *DB) ClearAllRecords() error

ClearAllRecords clears all records in redis.

func (*DB) ClearBlacklist

func (db *DB) ClearBlacklist() error

ClearBlacklist clear the backlist in redis.

func (*DB) Enable

func (db *DB) Enable(flag bool) error

Enable sets the flag to enable / disable transfer operation.

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

func (db *DB) GetAllRecords() ([]Record, error)

GetAllRecords gets all records in redis.

func (*DB) GetAvailblePeriodsOfCategory

func (db *DB) GetAvailblePeriodsOfCategory(category string) (map[string][]string, error)

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) IsEnabled

func (db *DB) IsEnabled() (bool, error)

IsEnabled gets the status if transfer operation is enabled.

func (*DB) IsFromClassInBlacklist

func (db *DB) IsFromClassInBlacklist(campus, category, class string) (bool, error)

IsFromClassInBlacklist checks if the class transfer from is in blacklist.

func (*DB) IsToPeriodInBlacklist

func (db *DB) IsToPeriodInBlacklist(campus, category, period string) (bool, error)

IsToPeriodInBlacklist checks if the period transfer to is in blacklist.

func (*DB) LoadBlacklistFromJSON

func (db *DB) LoadBlacklistFromJSON(file string, blacklist *Blacklist) error

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

func (db *DB) SetBlacklist(blacklist map[string][]string) error

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".

func (*DB) SetRecord

func (db *DB) SetRecord(r Record) error

SetRecord sets the record in redis.

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.

Jump to

Keyboard shortcuts

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