示例#1
0
class TDelay(BaseCheckin):
    """to provide some methods for teacher"""
    def __init__(self):
        self.manager = ResultManager()

    def leave_checkin(self, teacher_wechat_id):
        """to confirm delay"""
        teacher_id = self.get_teacherid(teacher_wechat_id)
        courselist = self.get_courselist(teacher_id)
        course_id = self.teacher_choose_course(courselist)
        filename = self.get_detailname(teacher_id, course_id)
        stu_array = []  # 请假的学生列表
        reader = self.read_file(filename)
        print '这次考勤请假的未被确认的人员为:'
        for line in reader:
            if line['checkinResult'] == '请假':
                stu_array.append(line)

        if stu_array:
            bufferdata = []
            stu_id = self.choose_num(stu_array)
            count = 0
            while count == 0:
                for line in stu_array:
                    for line1 in reader:
                        if line['StuID'] == line1['StuID'] == stu_id:
                            message = {'checkinResult': '请假已确认'}
                            line1.update(message)
                            stu_array.remove(line)
                            if stu_array == []:
                                count = 1
                        else:
                            pass
                        bufferdata.append(line1)
                print '请假信息已经确认!'

            self.write_file(bufferdata, filename)
            self.manager.update_sum(teacher_id, course_id)
        else:
            print "此次考勤没有请假的学生!"
示例#2
0
 def __init__(self):
     self.manager = ResultManager()
示例#3
0
 def __init__(self):
     self.timer = Timer()  # 建立一个Timer计时器的实例
     self.manager = ResultManager()
示例#4
0
class TeacherAutoCheckIn(BaseCheckin):
    """teacher auto check in methods"""
    def __init__(self):
        self.timer = Timer()  # 建立一个Timer计时器的实例
        self.manager = ResultManager()

    def to_first_judge(self, teacher_id, course_id):
        """first to judging weather the teacher have classes to check or not """
        class_list = []
        data = self.read_file('InData/courseInfo.csv')
        count = 0  # 设置下边追加班级时的控制变量
        for cline in data:
            if (cline['CourseID'] == str(course_id)) & (cline['TeacherID']
                                                        == str(teacher_id)):
                count = 1
                class_list.append(cline['ClassNums'])
            else:
                pass
        if count == 0:
            print '没有上课的班级!'
            return
        return class_list

    def get_stime(self, now_time):
        """get now time in a format"""
        stime0 = now_time.split(" ")
        stime1 = stime0[1].split(':')
        stime = stime1[0] + stime1[1]
        return stime

    def get_bagintime(self, b_time):
        """get begin time in a format"""
        begin_time = b_time
        begin_time_array = re.split('[- :]', begin_time)
        begintime = begin_time_array[3] + begin_time_array[
            4] + begin_time_array[5]
        return begintime

    def enter_list(self, teacher_id, course_id):
        """to judging weather the teacher can enter the list or not"""
        class_list = self.to_first_judge(teacher_id, course_id)  # 设置上课的班级列表
        if class_list == []:
            return False
        nowtime = time.strftime('%Y-%m-%d %H:%M:%S')
        messagelist = [teacher_id, course_id, class_list, nowtime]
        if readini.List:  # 列表非空要进行判断!
            for line in readini.List:
                if line[0] != teacher_id:
                    if set(class_list) & set(line[2]):
                        print "班级已存在"
                        stime = self.get_stime(nowtime)
                        read = readini()
                        s = read.readIni()  # 从readIni中得到课程的开始时间和结束时间
                        begintime = self.get_bagintime(line[3])
                        # 首先,若是下课时间则可以提出上一位教师
                        if (s[0] < stime < s[1]) | (s[2] < stime < s[3]) | (s[4] < stime < s[5]) | \
                                (s[6] < stime < s[7]):
                            # self.s.manage_action(line[0], line[1])
                            self.append_judge(readini.List, messagelist)
                            print "此时为下课时间,踢出相同班级的教师成功,成功进入队列!"
                            return True
                        # 若为上课时间、则比较节次信息
                        elif self.judge_sec(begintime) < self.judge_sec(stime):
                            # self.s.manage_action(line[0], line[1])
                            self.append_judge(readini.List, messagelist)
                            print "此时为上课时间,提出上一节次的教师成功!"
                            return True
                        else:
                            print "当前班级正在考勤、您无法开启!"
                            return False
                    else:
                        readini.List.append(messagelist)
                        return True
                else:
                    print "教师已经在队列之内"
                    return False
        else:
            self.append_message(messagelist)
            return True

    def append_message(self, _messagelist):
        """append message when the teacher is allowed to enter the list"""
        readini.List.append(_messagelist)
        print "进入队列成功"
        self.timer.start_checktime()

    def append_judge(self, _list, _messagelist):
        """to judge a right way to append message when a teacher push another one"""
        line = readini.List[0]
        self.manager.manage_action(line[0], line[1])
        readini.List.remove(line)
        if readini.List:
            readini.List.append(_messagelist)
            self.timer.stop_checkin()
        else:
            readini.List.append(_messagelist)
            self.timer.start_checktime()

    # 教师开始考勤
    def start_checkin(self, teacher_wechatid):
        """when a teacher want to start auto check in"""
        teacher_id = self.get_teacherid(teacher_wechatid)
        course_list = self.get_courselist(teacher_id)
        course_id = self.teacher_choose_course(course_list)

        if self.get_seqnumlist(course_id, teacher_id) != []:
            seq_id = max(self.get_seqnumlist(course_id, teacher_id))
        else:
            seq_id = 1
        # if (self.Course_judge_time(TeacherID,CourseID) != False):
        if self.enter_list(teacher_id, course_id) != False:
            self.create_seq(teacher_id, course_id)
            self.creat_sum(teacher_id, course_id, int(seq_id))
            print "创建自助考勤考勤文件成功"
        else:
            print "开启考勤失败"
示例#5
0
class TeacherManualCheckIn(BaseCheckin):
    """some methods to do manual check"""

    # 对教师手工考勤类的初始化
    def __init__(self):
        self.manager = ResultManager()

    def choose_stu_num(self, course_list):
        """
        to choose check in student
        :param course_list:
        :return:
        """
        list = enumerate(course_list)
        for index, item in list:
            if index > 0:
                print index, ":", item['StuID']
        try:
            choose_num = int(raw_input("请选择希望修改学生的学号:"))
            list = enumerate(course_list)
            for index, item in list:
                if index == choose_num:
                    return item
        except ValueError:
            print "所选择的值错误"
            self.choose_num(course_list)

    def check_result_choose(self):
        """
        to choose the check in result
        :return:
        """
        print "1.出勤  2.缺勤  3.迟到  4.早退  5.请假已确认"
        choose_num = int(raw_input("请选择希望修改学生的学号:"))
        if choose_num == 1:
            return '出勤'
        elif choose_num == 2:
            return '缺勤'
        elif choose_num == 3:
            return '迟到'
        elif choose_num == 4:
            return '早退'
        elif choose_num == 5:
            return '请假已确认'

    # 教师进行手工考勤修改
    def manual_checkin_alter(self, teacher_id, course_list):
        """
        teacher can alter the result for student
        teacher can choose num to do this action
        """
        course_id = self.teacher_choose_course(course_list)
        file_name = self.get_detailname(teacher_id, course_id)
        data = self.read_file(file_name)
        stu_line = self.choose_stu_num(data)
        bufferdata = []
        for line in data:
            if line['StuID'] == stu_line['StuID']:
                line['checkinResult'] = self.check_result_choose()
                print Reminder.AlterSuccessfully
            else:
                pass
            bufferdata.append(line)
        self.write_file(bufferdata, file_name)
        self.manager.update_sum(teacher_id, course_id)

    # 教师进行手工考勤增加
    def manual_checkin_add(self, teacher_id, course_list):
        """
        add detail file data
        :param teacher_id:
        :param course_list:
        :return:
        """
        course_id = self.teacher_choose_course(course_list)
        filename = 'OutData/seq.csv'
        data = self.read_file(filename)
        nowtime = time.strftime('%Y-%m-%d %H:%M:%S')
        seq_num = ''
        for line in data:
            if line['TeacherID'] == teacher_id:
                seq_num = line['SeqID']
            else:
                pass
        if seq_num == '':
            seq_num = 1
        else:
            seq_num = str(int(seq_num) + 1)
        message_list = [{'TeacherID': teacher_id, 'CourseID': course_id, 'SeqID': seq_num, \
                         'StartTime': nowtime}]
        if seq_num == 1:
            self.write_file(message_list, filename)
        else:
            self.write_file(message_list, filename, way='a+')
        if message_list:
            seq_num = int(seq_num)
            self.manual_checkin_add_detile(teacher_id, seq_num, course_id,
                                           nowtime)

    def manual_checkin_add_detile(self, teacher_id, seq_num, course_id,
                                  nowtime):
        """
        :param teacher_id:
        :param seq_num:
        :param course_id:
        :param nowtime:
        :return:
        """
        teacher_class = self.get_classlist(course_id)
        file_name = 'OutData/' + str(teacher_id) + '_' + str(course_id) + '_' + \
                    str(seq_num) + '_' + 'checkinDetail.csv'
        stufile = 'InData/studentInfo.csv'
        stu = []
        data = self.read_file(stufile)
        for line in data:  # 由教师ID和课程ID得到班级列表,将班级中的所有学生全部写入列表,默认出勤。
            if line['ClassID'] in teacher_class:
                message = {'StuID': line['StuID'], 'checkTime': nowtime, 'ProofPath': '无', \
                           'checkinType': 'man', 'IsSuss': 'True', 'checkinResult': '出勤'}
                stu.append(message)
        self.write_file(stu, file_name)

        print Reminder.AddSuccessfully
        self.creat_sum(teacher_id, course_id, seq_num)
        self.manager.update_sum(teacher_id, course_id)

    def cform(self, teacher_id, course_list):
        """
        :param teacher_id:
        :param course_list:
        :return:
        """
        print "****************欢迎进入手工考勤菜单***************"
        print "*******1.教师进行手工修改****2.教师进行手工增加******"
        print "*******0.退出****************"
        op_num = raw_input("请输入您想要的操作:")
        count = 0
        while count == 0:
            count = 1
            if op_num == '1':  # 教师手工考勤修改
                self.manual_checkin_alter(teacher_id, course_list)

            elif op_num == '2':  # 教师手工考勤增加
                self.manual_checkin_add(teacher_id, course_list)

            elif op_num == '0':
                break

            else:
                flagchar = raw_input(Reminder.SystemInError)
                if flagchar:
                    return 0

    def manual_form_control(self, teacherwechat_id):
        """
        :param teacherwechat_id:
        :return:
        """
        count = 0
        teacher_id = self.get_teacherid(teacherwechat_id)
        courselist = self.get_courselist(teacher_id)
        self.cform(teacher_id, courselist)
        while count == 0:
            print "----------------------------"
            operator = raw_input("您是否在手工考勤界面继续操作?y/n:")
            if operator == 'y':
                self.cform(teacher_id, courselist)
            elif operator == 'n':
                return
            else:
                operator = raw_input("您的输入有误,请重新输入: (y/n)")
示例#6
0
 def __init__(self):
     """
     do the initialize
     """
     self.timer = None
     self.manager = ResultManager()
示例#7
0
class Timer(object):
    """
    do the exactly timer
    """
    def __init__(self):
        """
        do the initialize
        """
        self.timer = None
        self.manager = ResultManager()

    def time_check(self):
        """
         do the main work for timer
         to do the time calculation if two teacher enter the list on the same time
        :return:
        """
        if readini.List == []:
            print "the queue is empty!"
            return
        else:
            line = readini.List[0]
            self.manager.manage_action(line[0], line[1])
            print "即将提出上一位教师"
            readini.List.pop(0)
            self.stop_checkin()

    # 教师进入队列后开始进行倒计时
    def start_checktime(self):
        """
         start the timer
        :return:
        """
        self.timer = threading.Timer(100, self.time_check)
        self.timer.start()

    def stop_checkin(self):
        """
        do the calculation
        :return:
        """
        if self.timer != None:
            if readini.List != []:
                line = readini.List[0]
                self.manager.manage_action(line[0], line[1])
                read = readini()
                clist = read.List
                # leaveTime = clist[0]
                # leaveTimeArray = leaveTime.split('-| | :')
                # print leaveTime
                # print leaveTimeArray
                begin_time = clist[0][3]
                begin_time_array = re.split('[- :]', begin_time)

                # print beginTimeArray# 3 4 5 为时分秒

                nowtime = time.strftime('%Y-%m-%d %H:%M:%S')
                stime0 = nowtime.split(" ")
                stime1 = stime0[1].split(':')
                hourdev = int(stime1[0]) - int(begin_time_array[3])
                minutedev = int(stime1[1]) - int(begin_time_array[4])
                seconddev = int(stime1[2]) - int(begin_time_array[5])
                # print hourdev
                # print minutedev
                # print seconddev

                # 用第二位教师的开启时间和现有时间作对比dev=(100-(nowtime-t2starttime))
                # 目的是计算第二位教师的考勤剩余时间,并赋给计时器
                timedevbuffer = abs(
                    hourdev) * 3600 + minutedev * 60 + seconddev
                timedev = 100 - timedevbuffer
                print '队首教师剩余时间为', ":", timedev
                if timedev < 0:
                    return
                readini.List.pop(0)  # 计算后将教师踢出队列
                # 先取消上次计时后,再传入新的计时值
                self.timer.cancel()
                self.timer = threading.Timer(timedev, self.time_check)
                self.timer.start()
            else:
                print '当前队列已经没有教师'
                return
        else:
            self.timer = threading.Timer(100, self.time_check)
            self.timer.start()