iSJTU Models#

The followings are data models of iSJTU. Please refer to iSJTU Interface for more details.

Containers#

Container models are not concrete models, but abstract models that are used to group other models.

class pysjtu.models.base.Result#

Bases: object

Base class for Result. All item models inherit from this class.

class pysjtu.models.base.LazyResult#

Bases: Result, ABC

Base class for LazyResult. All lazy item models inherit from this class.

class pysjtu.models.base.QueryResult(method_ref, post_ref, query_params, page_size=15)#

Bases: Generic[T_Result]

A key accessible, sliceable, and iterable interface to query result collections. All lazy container models inherit from this class.

See Result Content for more information.

A QueryResult object is constructed with a raw data callable reference.

A QueryResult object is returned by a query operation, and isn’t meant to be constructed by a user.

A QueryResult object is lazy, which means network I/Os won’t be performed until items are actually accessed.

Parameters:
  • method_ref (Callable) – The request method to be called when fetching data.

  • post_ref (Callable) – The schema load method to be called on fetched data.

  • query_params (dict) – Parameters for this query.

  • page_size (int) – The page size for result iteration.

flush_cache()#

Flush caches. Local caches are dropped and data will be fetched from remote.

class pysjtu.models.base.Results(year=0, term=0)#

Bases: List[T_Result]

Base class for Results. All eager container models inherit from this class.

See Result Content for more information.

Parameters:
  • year (int) – year of the query.

  • term (int) – term of the query.

filter(**param)#

Get Result objects matching specific criteria. The criteria are specified by keyword arguments.

Available fields are defined by child classes.

Note

There are three special time-related fields: week, time and day.

When filtering by them, the filter logic is contains instead of equals.

Parameters:

param – query criteria

Returns:

Result objects matching given criteria.

Return type:

List[T_Result]

Common Models#

Some common data types used in other models.

class pysjtu.models.common.Gender(value)#

Bases: IntEnum

Gender defined by iSJTU.

male = 1#

Male

female = 2#

Female

Schedule Models#

class pysjtu.models.schedule.ScheduleCourse(name, course_id, class_name, class_id, day=None, week=None, time=None, location=None, credit=None, assessment=None, remark=None, teacher_name=None, teacher_title=None, hour_total=None, hour_remark=None, hour_week=None, field=None)#

Bases: Result

A model which describes a course in CourseLib. Some fields may be empty.

Parameters:
  • name (str) – literal name of the course.

  • day (Optional[int]) – in which day(s) of weeks classes are given.

  • week (Optional[list]) – in which week(s) classes are given.

  • time (Optional[range]) – at which time of days classes are given.

  • location (Optional[str]) – the place where classes are given.

  • credit (Optional[float]) – credits that the course provides.

  • assessment (Optional[str]) – assessment method of this course. (exams, assesses, etc)

  • remark (Optional[str]) – remarks of this course.

  • teacher_name (List[str]]) – the teacher who offers this course.

  • teacher_title (List[str]]) – title of the course’s teacher.

  • course_id (str) – course id.

  • class_name (str) – class name (constant between years).

  • class_id (str) – class id (variable between years).

  • hour_total (Optional[int]) – credit hours of the course.

  • hour_remark (Optional[dict]) – detailed explanation of the credit hours.

  • hour_week (Optional[float]) – credit hours of the course every week.

  • field (Optional[str]) – professional field of this course.

class pysjtu.models.schedule.Schedule(year=0, term=0)#

Bases: Results[ScheduleCourse]

A list-like interface to Schedule collections.

Exam Models#

class pysjtu.models.exam.Exam(name, location=None, seat=None, course_id=None, course_name=None, class_name=None, rebuild=None, credit=None, self_study=None, date=None, time=None)#

Bases: Result

A model which describes an exam. Some fields may be empty.

Parameters:
  • name (str) – name of the course on which you are being examined.

  • location (Optional[str]) – the place where this exam is held.

  • seat (Optional[int]) – seat number

  • course_id (Optional[str]) – course id of the course on which you are being examined.

  • course_name (Optional[str]) – course name of the course on which you are being examined.

  • class_name (Optional[str]) – class name of the class you are attending on the course which are being examined.

  • rebuild (Optional[bool]) – whether this exam is a rebuild test.

  • credit (Optional[float]) – credits that the course provides.

  • self_study (Optional[bool]) – whether this course is a self study course.

  • date (datetime' objects>]) – date of the exam

  • time (datetime' objects>]]) – time range of the exam

class pysjtu.models.exam.Exams(year=0, term=0)#

Bases: Results[Exam]

A list-like interface to Exam collections.

Score Models#

class pysjtu.models.score.ScoreFactor(name, percentage, score)#

Bases: Result

A model which describes detailed composition of a course’s score.

Parameters:
  • name (str) – item name

  • percentage (float) – item factor

  • score (str) – item score

class pysjtu.models.score.Score(name, teacher, score, credit, gp, invalid=None, course_type=None, category=None, score_type=None, method=None, course_id=None, class_name=None, class_id=None, year=0, term=0, _detail=None, _func_detail=None)#

Bases: Result

A model which describes the score of a specific course. Some fields may be empty.

Parameters:
  • name (str) – literal name of the course.

  • teacher (str) – the teacher who offers this course.

  • score (str) – score of this course

  • credit (float) – credits that the course provides.

  • gp (float) – gp earned in this course.

  • invalid (bool) – whether this score is voided.

  • detail (List[ScoreFactor]) – a ScoreFactor object representing detailed composition of the score.

  • course_type (str) – type of this course. (compulsory, elective, etc)

  • category (str) – category of this course. (specialized, general, PE, etc)

  • score_type (str) – type of your score. (acquired by normal examination, etc)

  • method (str) – assessment method of this course. (exams, assesses, etc)

  • course_id (str) – course id.

  • class_name (str) – class name (constant between years).

  • class_id (str) – class id (variable between years).

class pysjtu.models.score.Scores(year=0, term=0, func_detail=None)#

Bases: Results[Score]

A list-like interface to Score collections.

This class is a subclass of pysjtu.models.base.Results.

GPA Models#

class pysjtu.models.gpa.LogicEnum(value)#

Bases: IntEnum

Used by GPAQueryParams to specify condition logic.

AND = 0#

All conditions must be satisfied.

OR = 1#

At least one condition must be satisfied.

class pysjtu.models.gpa.CourseRange(value)#

Bases: Enum

Used by GPAQueryParams to specify courses taken into account when ranking.

ALL = 'qbkc'#

All courses taken.

CORE = 'hxkc'#

Only core courses taken.

class pysjtu.models.gpa.Ranking(value)#

Bases: Enum

Used by GPAQueryParams to specify student range upon which to rank.

GRADE_AND_FIELD = 'njzy'#

Rank students in the same grade and field.

class pysjtu.models.gpa.DedupMethod(value)#

Bases: Enum

Used by GPAQueryParams to specify which score to take if a student has taken a course multiple times.

LAST_SCORE = 'zhyccj'#

Take the last score.

class pysjtu.models.gpa.GPAQueryParams(start_term, end_term, condition_logic, makeup_as_60, rebuild_as_60, gp_round, gpa_round, exclude_gp, exclude_gpa, course_whole, course_range, excluded_courses, excluded_course_groups, included_course_groups, dedup_method, ranking, has_roll, registered, attending)#

Bases: Result

A model which describes GPA query parameters. Used when performing gpa queries (pysjtu.Client().query_gpa(…)). You may leave fields empty if you don’t want to filter by them.

Parameters:
  • start_term (Optional[int]) – begin term of the query.

  • end_term (Optional[int]) – end term of the query.

  • condition_logic (LogicEnum) – logic applied between has_roll, registered and attending.

  • makeup_as_60 (bool) – treat makeup scores (P) as 60.

  • rebuild_as_60 (bool) – treat rebuild scores (P) as 60.

  • gp_round (int) – round gp to a given precision in decimal digits.

  • gpa_round (int) – round gpa to a given precision in decimal digits.

  • exclude_gp (List[str]) – exclude courses matching given criteria when calculating gp.

  • exclude_gpa (List[str]) – exclude courses matching given criteria when calculating gpa.

  • course_whole (List[str]) – unknown parameter. (统计全程的课程)

  • course_range (CourseRange) – courses taken into account when ranking

  • excluded_courses (str) – ids of courses excluded from statistics.

  • excluded_course_groups (str) – ids of course groups excluded from statistics.

  • included_course_groups (str) – ids of course groups included in statistics.

  • dedup_method (DedupMethod) – which score to take if a student has taken a course multiple times.

  • ranking (Ranking) – student range upon which to rank

  • has_roll (bool) – only include students who are enrolled in school.

  • registered (bool) – only include students who are registered.

  • attending (bool) – only include students who are attending school now.

class pysjtu.models.gpa.GPA(total_score, course_count, fail_count, total_credit, acquired_credit, failed_credit, pass_rate, gp, gp_ranking, gpa, gpa_ranking, total_students)#

Bases: Result

A model which describes GP & GPA and rankings.

Parameters:
  • total_score (float) – summed score of all matched courses.

  • course_count (int) – number of all matched courses.

  • fail_count (int) – number of failed courses.

  • total_credit (float) – summed credit of all matched courses.

  • acquired_credit (float) – summed credit of passed courses.

  • failed_credit (float) – summed credit of failed courses.

  • pass_rate (float) – the pass rate of all matched courses.

  • gp (float) – summed gp of all matched courses.

  • gp_ranking (int) – ranking of the gp.

  • gpa (float) – gpa of all matched courses.

  • gpa_ranking (int) – ranking of the gpa.

  • total_students (int) – number of students participates in the ranking.

College-Wide Course Models#

class pysjtu.models.course.LibCourse(name, day=None, week=None, time=None, location=None, locations=None, faculty=None, credit=None, teacher=None, course_id=None, class_name=None, class_id=None, class_composition=None, hour_total=None, hour_remark=None, seats=None, students_elected=None, students_planned=None)#

Bases: Result

A model which describes a course in CourseLib. Some fields may be empty.

Parameters:
  • name (str) – literal name of the course.

  • day (Optional[int]) – in which day(s) of weeks classes are given.

  • week (Optional[list]) – in which week(s) classes are given.

  • time (Optional[range]) – at which time of days classes are given.

  • location (Optional[str]) – the place where classes are given.

  • locations (List[str]]) – the places where classes are given.

  • faculty (Optional[str]) – the faculty which offers this course.

  • credit (Optional[float]) – credits that the course provides.

  • teacher (List[str]]) – the teacher who offers this course.

  • course_id (Optional[str]) – course id.

  • class_name (Optional[str]) – class name (constant between years).

  • class_id (Optional[str]) – class id (variable between years).

  • class_composition (List[str]]) – students from which faculties do the course consists of.

  • hour_total (Optional[int]) – credit hours of the course.

  • hour_remark (Optional[dict]) – detailed explanation of the credit hours.

  • seats (Optional[int]) – number of seats available in this course.

  • students_elected (Optional[int]) – number of students elected this course.

  • students_planned (Optional[int]) – number of students planned when setting this course.

Course Selection Models#

class pysjtu.models.selection.LessonTime(weekday: 'int', week: 'List[Union[range, int]]', time: 'List[range]')#

Bases: object

class pysjtu.models.selection.SelectionSharedInfo(term, selection_year, selection_term, major_id, student_grade, natural_class_id, self_selecting_status, ccdm, student_type_code, gender, field_id, student_background)#

Bases: object

A model which contains shared information in this round of selection.

Parameters:
  • term (str) – current term when querying.

  • selection_year (int) – year of selected courses.

  • selection_term (int) – term of selected courses.

  • major_id (str) – internal major id.

  • student_grade (int) – year of enrollment.

  • natural_class_id (str) – class id of the administrative class of the student.

  • self_selecting_status (int) – unknown parameter.

  • ccdm (str) – unknown parameter.

  • student_type_code (int) – unknown parameter.

  • gender (Gender) – student’s gender.

  • field_id (str) – student’s professional field.

  • student_background (int) – unknown parameter.

class pysjtu.models.selection.SelectionSector(task_type, xkly, pe_op_param, sector_type_id, include_other_grades, include_other_majors, sfznkx, zdkxms, txbsfrl, kkbk, xkkz_id=None, course_type_code=None, name=None, shared_info=None, _func_classes=None, _hash=None)#

Bases: Result

A model which describes a course sector in this round of selection.

Parameters:
  • name (Optional[str]) – sector name.

  • shared_info (Optional[SelectionSharedInfo]) – shared information in this round of selection.

  • task_type (int) – unknown parameter.

  • xkly (int) – unknown parameter.

  • pe_op_param (int) – unknown parameter. (translation: the parameters updated in operations related to PE lessons.)

  • sector_type_id (str) – unknown parameter.

  • include_other_grades (bool) – include courses from other grades.

  • include_other_majors (bool) – include courses from other majors.

  • sfznkx (bool) – unknown parameter.

  • zdkxms (int) – unknown parameter.

  • txbsfrl (int) – unknown parameter. (used when dropping courses.)

  • kkbk (int) – unknown parameter.

  • course_type_code (Optional[str]) – unknown parameter.

  • xkkz_id (Optional[str]) – unknown parameter.

property classes: List[SelectionClass]#

Selectable classes in this course sector.

class pysjtu.models.selection.SelectionClass(name, credit, course_id, internal_course_id, class_name, class_id, students_registered, register_id=<class 'pysjtu.models.base._PARTIAL'>, teachers=<class 'pysjtu.models.base._PARTIAL'>, locations=<class 'pysjtu.models.base._PARTIAL'>, time=<class 'pysjtu.models.base._PARTIAL'>, course_type=<class 'pysjtu.models.base._PARTIAL'>, remark=<class 'pysjtu.models.base._PARTIAL'>, students_planned=<class 'pysjtu.models.base._PARTIAL'>, sector=None, _load_func=None)#

Bases: LazyResult

A model which describes a selectable class in this round of selection.

The data is not fetched until it is accessed for the first time.

Parameters:
  • name (str) – literal name of the course.

  • credit (float) – credits that the course provides.

  • course_id (str) – course id.

  • course_id – internal course id.

  • class_name (str) – class name (constant between years).

  • class_id (str) – class id (variable between years).

  • students_registered (int) – number of students registered for this course.

  • students_planned (int) – number of students planned when setting this course.

  • register_id (str) – dynamic id used when (de)registering for this class.

  • teachers (List[Tuple[str]]) – the teachers who offer this course.

  • locations (List[str]) – the places where classes are given.

  • time (LessonTime) – the time when the class is given.

  • course_type (List[str]) – course type. (eg. general, required, optional, …)

  • remark (Optional[str]) – remarks of this class.

  • sector (SelectionSector) – the sector which this course lies in.

is_registered(timeout=10)#

Check whether the student has registered for this class.

Parameters:

timeout – (optional) How long to wait for the server to send data before giving up.

Returns:

A boolean value indicates the registration status.

Return type:

bool

register(timeout=10)#

Register for this class.

Parameters:

timeout – (optional) How long to wait for the server to send data before giving up.

Raises:

pysjtu.exceptions.RegistrationException

Raises:

pysjtu.exceptions.FullCapacityException

Raises:

pysjtu.exceptions.TimeConflictException

Raises:

pysjtu.exceptions.SelectionNotAvailableException

drop(timeout=10)#

Drop this class.

Parameters:

timeout – (optional) How long to wait for the server to send data before giving up.

Raises:

pysjtu.exceptions.DropException

Raises:

pysjtu.exceptions.SelectionNotAvailableException