コード例 #1
0
ファイル: checkininfo.py プロジェクト: block1b/Entry
class CheckInInfo(object):
    def __init__(self, tec_id, course_id, course_filename, stu_filename):
        self.course = CourseInfo()
        self.stu = StuInfo()
        self.tim = TimeWindows()
        self.section = self.tim.get_now_section()
        self.tecid = tec_id
        self.courseid = course_id
        self.classnames = self.get_checkin_classnames(tec_id, course_id,
                                                      course_filename)
        self.stuids = self.get_checkin_stuids(self.classnames, stu_filename)
        self.seqid = str(self.tim.get_now_section())
        self.starttime = self.tim.get_time2()
        self.sampletime = ""

    # 获取待考勤班级s,待考勤学生s
    # 获取待考勤班级s
    def get_checkin_classnames(self, teacher_id, course_id, course_filename):
        # 所有的课程信息
        all_course_info = self.course.get_all_course_info(course_filename)
        # 所需课程信息
        a_teacher_course_infos = self.course.get_course_info_from_teacher_id(
            teacher_id, all_course_info)
        # 所需班级集合
        classnames = self.course.get_classnames(course_id, teacher_id,
                                                a_teacher_course_infos)
        return classnames

    # 获取待考勤学生s
    def get_checkin_stuids(self, classnames, stu_filename):
        # 所有学生信息
        all_stu_info = self.stu.get_all_stu_info(stu_filename)
        # 待考勤学生信息
        wait_checkin_stu_info = self.stu.get_wait_checkin_stu_info(
            classnames, all_stu_info)
        # 待考勤学生id集合
        stuids = self.stu.get_stuids(wait_checkin_stu_info)
        return stuids
コード例 #2
0
class CheckInArray(object):
    # 队列元素【考勤对象1(节次, tecid, courseid)】
    List = []

    def __init__(self):
        self.ini = IniInfo()
        self.tim = TimeWindows()
        self.t = None  # 计时器

    # 完成考勤对象队列的维护

    # 更新队列
    # 时间窗口开启即队列更新规则:
    # 1.判定节次
    # 2.该节次内不存在时间窗口,更新队列,开启计时器。
    # 3.该节次内存在时间窗口,class不冲突,进入队列。
    # 4.该节次内存在时间窗口,class冲突,不能进入队列。
    # 5.不同节次,更新队列,关闭现有计时器,开启新计时器。

    # 清空队列
    def clear_arry(self):
        self.__class__.List = []
        print "计时结束"

    # 判断该当前对象与队首是否为相同节次
    def same_section(self, now_cii, list_first):
        if now_cii.section == list_first.section:
            return True
        else:
            return False

    # 判断当前对象与队列中的对象,班级是否冲突
    def same_classnames(self, now_cii, list_arry):
        all_checkin_classnames = []
        for acii in list_arry:
            all_checkin_classnames += acii.classnames
        for aclassname in now_cii.classnames:
            if aclassname in all_checkin_classnames:
                return False
        return True

    # 判断当前考勤对象与考勤队列中的对象,教师是否冲突
    def same_tecid(self, now_cii, list_arry):
        for acii in list_arry:
            if now_cii.tecid == acii.tecid:
                return False
        return True

    def update_arry(self, now_cii):
        # 空队列添加考勤对象
        # 考勤对象now_cii
        now_section = self.tim.get_now_section()
        # 判断节次是否为0
        if now_section:
            # 判断现有队列是否为空
            if self.__class__.List:
                # 如果当前考勤对象与队首的节次相同,进入队列
                if self.same_section(now_cii, self.__class__.List[0]):
                    # 判断人员是否冲突
                    if self.same_classnames(now_cii, self.__class__.List) \
                            and self.same_tecid(now_cii, self.__class__.List):
                        # 人员不冲突,进入队列
                        self.__class__.List.append(now_cii)
                        return True
                    else:
                        return False
                else:
                    # 节次变化,清空队列,进入队列,重启计时器
                    self.clear_arry()
                    self.__class__.List.append(now_cii)
                    self.t.cancel()
                    self.t = threading.Timer(float(self.ini.get_window_long()),
                                             self.clear_arry())
                    self.t.start()
                    return True
            else:
                self.__class__.List.append(now_cii)
                # ??为什么立即结束了??问题出在类方法self.clesr_arry“()”<--日天,不要“()”
                time_long = float(self.ini.get_window_long())
                self.t = threading.Timer(time_long, self.clear_arry)
                self.t.start()
                return True
        else:
            # 非考勤时间
            return False