ming

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2024 License: MIT Imports: 8 Imported by: 7

README

ming

Build Status Go Report Card GoDoc

ming是一个Golang包,主要提供了将明日系统的数据导入至redis的功能。

限制
  • ming基于ming800
  • 适合单机版本且只有1个校区的版本
校区约定

因为受限1个校区,所以多个校区的可以通过在"课程类别"添加校区信息的做法来实现多个校区

  • 课程类别命名约定

        课程类别(校区)
    
  • 例子

        // 括号为中文全角括号
        四年级(校区A)
        校区:校区A
        类别:四年级
    
同步后的redis中的keys
  • 所有校区 key: "ming:campuses", type: ordered set, value: 校区, score: timestamp.

  • 所有课程 key: "ming:categories", type: ordered set, value: 课程, score: timestamp.

  • 校区对应的课程 key: ming:$CAMPUS:categories, type: ordered set, value: 课程, score: timestamp.

  • 校区-课程对应的班级 key: ming:$CAMPUS:$CATEGORY:classes, type: ordered set, value: 班级, score: timestamp.

  • 课程对应的校区 key: ming:$CATEGORY:campuses, type: ordered set, value: 校区, score: timestamp.

  • 所有教师 key: "ming:teachers", type: ordered set, value: 教师, score: timestamp.

  • 班级对应的教师 key: ming:$CAMPUS:$CATEGORY:$CLASS:teachers, type: ordered set, value: 校区, score: timestamp.

  • 教师对应的班级 key: ming:$TEACHER:classes, type: ordered set, value: 班级, score: timestamp.

  • 班级的上课时间段 key: ming:$CAMPUS:$CATEGORY:$CLASS:period, type: string, value: 上课时间段(如果多个,只取第一个).

  • 课程对应的所有时间段 key: ming:$CAMPUS:$CATEGORY:periods, type: ordered set, value: 上课时间段, score: 上课时间段的权重. 权重 = 周几*86400 + 开始小时 * 3600 + 开始分钟 * 60

  • 时间段对应的班级 key: ming:$CAMPUS:$CATEGORY:$PERIOD:classes, type: ordered set, value: 班级, score: timestamp.

  • 所有学生 key: ming:students, type: ordered set, value: $NAME:$PHONE_NUM.

  • 一个学生所在的班级 key: ming:$NAME:$PHONE_NUM:classes, type: ordered set, value: $CAMPUS:$CATEGORY:$CLASS.

  • 所有电话 key: ming:phone_nums", type: ordered set, value: 联系电话.

  • 联系电话对应的学生 key: ming:$PHONE_NUM:students, type: ordered set, value: 学生.

  • 一个班级中所有学生 key: ming:$CAMPUS:$CATEGORY:$CLASS:students, type: ordered set, value: 学生姓名.

例子

将明日系统数据导入到Redis中.

    // Create a ming.DB instance.
    db := ming.DB{RedisServer: RedisServer, RedisPassword: RedisPassword}

    // Sync Redis from ming server.
    // ServerURL is ming800 server URL.
    if err = db.SyncFromMing(ServerURL, Company, User, Password); err != nil {
            return
    } 

可以参考tools/ming800-to-redis/

Documentation
License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPeriodScore

func GetPeriodScore(period string) int

GetPeriodScore gets the score for the period string.

Params:

period: period string. e.g. "星期一09:00-11:30".

Return:

computed score.

func ParseCategory

func ParseCategory(category string) (string, string)

ParseCategory gets campus and real category from category string.

Param:
    category: raw category string like this: 初一(中山)
Return:
    campus, category. e.g. campus: 中山,category: 初一

func ParseClassValue

func ParseClassValue(classValue string) (string, string, string)

ParseClassValue parses the value of class.

Params:

classValue: class string contains campus, category and real class.
            format: $CAMPUS:$CATEGORY:$CLASS e.g. "新校区:一年级:一年级2班"

Returns:

campus, category, real class.

func Valid8DigitTelephoneNum

func Valid8DigitTelephoneNum(phoneNum string) bool

Valid8DigitTelephoneNum checks if phone number matches the format: 1. Starts with 8 digital number. 2. Can have one or more '.' as sufix.

func ValidMobilePhoneNum

func ValidMobilePhoneNum(phoneNum string) bool

ValidMobilePhoneNum checks if phone number matches the format: 1. Starts with 11 digital number. 2. Can have one or more '.' as sufix.

func ValidPhoneNum

func ValidPhoneNum(phoneNum string) bool

ValidPhoneNum checks if phone number is 11-digit mobile phone number or 8-digit telephone number.

Types

type DB

type DB struct {
	RedisServer   string
	RedisPassword string
}

DB sync data from ming system.

func (*DB) ClassHandler

func (db *DB) ClassHandler(class *ming800.Class) error

ClassHandler implements ming800.WalkDB interface. It'll be called when a class is found.

func (*DB) Clear

func (db *DB) Clear() error

Clear cleans all existing ming800 data in redis. Do it before each new sync.

func (*DB) GetAllClasses

func (db *DB) GetAllClasses() ([]string, error)

GetAllClasses gets the names of all classes. Return: a slice contains the names of all classes. Class name format: $campus:$category:$class.

func (*DB) GetAllPeriods

func (db *DB) GetAllPeriods() ([]string, error)

GetAllPeriods gets the names of all classes. Return: a slice contains the all periods. Period name format: $campus:$category:$period.

func (*DB) GetAllPeriodsOfCategory

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

GetAllPeriodsOfCategory gets all category's periods for all campuses.

Params:

category: category which you want to get all periods.

Returns:

a map contains all periods. key: campus, value: periods.

func (*DB) GetAllStudents

func (db *DB) GetAllStudents() ([]string, error)

GetAllStudents gets all students. Return: Slice contains student in the format: $name:$phone_num.

func (*DB) GetClassPeriod

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

GetClassPeriod gets the period of the combination of campus, category, class.

func (*DB) GetClassesByNameAndPhoneNum

func (db *DB) GetClassesByNameAndPhoneNum(name, phoneNum string) ([]string, error)

GetClassesByNameAndPhoneNum searches classes by student name and phone number.

func (*DB) GetClassesPeriods

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

GetClassesPeriods gets the period of each class. Return: a map. Key: class name($campus:$category:$class), value: period.

func (*DB) GetNamesByPhoneNum

func (db *DB) GetNamesByPhoneNum(phoneNum string) ([]string, error)

GetNamesByPhoneNum searches student names by phone number.

func (*DB) GetStudentsOfTeacher

func (db *DB) GetStudentsOfTeacher(teacher string) ([]string, error)

GetStudentsOfTeacher gets all students of given teacher.

Params:

teacher: name of teacher.

Return:

students in the format: $STUDENT_NAME:$CONTACT_PHONE_NUM. e.g. 小明:13800138000

func (*DB) GetTeachers

func (db *DB) GetTeachers() ([]string, error)

GetTeachers lists all teacher names.

func (*DB) GetTeachersOfClass

func (db *DB) GetTeachersOfClass(campus, category, class string) ([]string, error)

GetTeachersOfClass gets teachers of the class.

func (*DB) StudentHandler

func (db *DB) StudentHandler(class *ming800.Class, student *ming800.Student) error

StudentHandler implements ming800.WalkDB interface. It'll be called when a student is found.

func (*DB) SyncFromMing

func (db *DB) SyncFromMing(serverURL, company, user, password string) error

SyncFromMing sync data included all current campuses, categories, students from ming800 to redis.

Params:

serverURL: server URL of ming800. e.g. "http://192.168.1.87:8080".
company: company or orgnization name of ming800.
user: user account of ming800.
password: user password of ming800.

func (*DB) ValidClass

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

ValidClass validates if the campus, category, class info match.

func (*DB) ValidPeriod

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

ValidPeriod validates if the campus, category, period info match.

Jump to

Keyboard shortcuts

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