Example #1
0
def sum_history(wechat_id):
    subprocess.call("clear")
    while True:
        obj = ManCheckin(wechat_id)
        if obj.tea_id == 0:
            print PrtInfo.failedMessage(4)
            prompt = raw_input('maybe try again?(y/n)')
            if prompt == 'n':
                break
        else:
            BaseCheckin.update_sum(obj)
            sum_records = SumFile.read_file(
                BaseCheckin.init_sum_name(obj.tea_id, obj.crs_id))
            r = range(1, obj.init_seq_id(obj.tea_id, obj.crs_id))
            r.append('exit')
            q = Form(['seq id'], ['once', 'all', 'back'])
            ch = q.init_form()

            if ch == len(q.items) or ch == -1:
                break
            elif ch == 1:
                c = Form(['seq id'], r)
                seq_id = c.init_form()
                if seq_id == len(r) or seq_id == -1:
                    break
                sum_format(sum_records, seq_id=seq_id)
                break
            sum_format(sum_records)
            break
Example #2
0
def attendence(wechat_id):
    subprocess.call("clear")
    while True:
        obj = ManCheckin(wechat_id)
        if obj.tea_id == 0:
            print PrtInfo.failedMessage(4)
            prompt = raw_input('maybe try again?(y/n)')
            if prompt == 'n':
                break
        else:
            c = BaseCheckin.find_checkin_obj_for_tea(wechat_id)
            if c != None:
                detail_records = BaseFile.read_file(
                    c.init_detail_name(str(c.tea_id), str(c.crs_id),
                                       str(c.seq_id)))
                detail_records = BaseCheckin.filter_invalid_detail_records(
                    detail_records)
                temp = []
                for i in detail_records:
                    if i['IsSuc'] == 'True':
                        temp.append(i)
                print detail_format(temp)
                break
            else:
                break
Example #3
0
def absence(wechat_id):
    subprocess.call("clear")
    while True:
        obj = ManCheckin(wechat_id)
        if obj.tea_id == 0:
            print PrtInfo.failedMessage(4)
            prompt = raw_input('maybe try again?(y/n)')
            if prompt == 'n':
                break
        else:
            c = BaseCheckin.find_checkin_obj_for_tea(wechat_id)
            if c != None:
                temp = []
                for stu in c.init_student_records():
                    auto_rec = c.get_latest_record(stu['StuID'], 'Auto')
                    if auto_rec == {} or auto_rec['IsSuc'] == 'False':
                        auto_rec = {
                            'StuID': stu['StuID'],
                            'checkinTime': '?????????????????????',
                            'ProofPath': 'none',
                            'checkinType': 'Auto',
                            'IsSuc': 'False',
                            'checkinResult': '???'
                        }
                        temp.append(auto_rec)
                print detail_format(temp)
                break
            else:
                break
Example #4
0
 def get_stu_id_in_class_list(self, wechat_id):
     student_records = self.init_student_records()
     for stu_rec in student_records:
         if stu_rec['WeChatID'] == wechat_id:
             return stu_rec['StuID']
     else:
         print PrtInfo.notFoundMessage(3)
         return None
Example #5
0
 def init_student_records(self):
     stu_records = BaseFile.read_file(BaseCheckin.student_file.name)
     class_list = self.init_class_records()
     temp_list = []
     for stu_rec in stu_records:
         if stu_rec['ClassID'] in class_list:
             temp_list.append(stu_rec)
     print PrtInfo.successMessage(1)
     return temp_list
Example #6
0
 def find_checkin_obj_for_tea(wechat_id):
     if BaseCheckin.checkin_list == []:
         print PrtInfo.failedMessage(6)
         return None
     else:
         tea_id = BaseCheckin.init_teacher_id_by_wechatid(wechat_id)
         for i in BaseCheckin.checkin_list:
             if i.tea_id == tea_id:
                 return i
         else:
             print PrtInfo.failedMessage(6)
             return None
Example #7
0
def start_manual_menu(wechat_id):
    subprocess.call("clear")
    while True:
        obj = ManCheckin(wechat_id)
        if obj.tea_id == 0:
            print PrtInfo.failedMessage(4)
            prompt = raw_input('maybe try again?(y/n)')
            if prompt == 'n':
                break
        else:
            obj.add_seq_id(obj.seq_id)
            obj.write_detail_file(obj.init_detail_records())
            obj.update_sum_by_certain_seq_id(obj.seq_id)
            break
Example #8
0
 def init_detail_records(self):
     stu_records = BaseFile.read_file(BaseCheckin.student_file.name)
     temp_list = []
     for stu_rec in stu_records:
         temp_dict = {'StuID': stu_rec['StuID'],
                      'checkinTime': time.strftime('%Y-%m-%d %H:%M:%S'),
                      'ProofPath': 'Auto',
                      'checkinType': 'Man',
                      'IsSuc': 'True',
                      'checkinResult': '出勤'
                      }
         temp_list.append(temp_dict)
     print PrtInfo.successMessage(3)
     return temp_list
 def time_next(self):
     # 计时器保存t1,踢掉队首,并检查是否有t2
     # 如果有t2 , new一个新的计时器startTiming(t2 - t1)
     # 如果没有则startTiming():
     t1 = BaseCheckin.checkin_list[0].enter_time
     BaseCheckin.checkin_list[0].notify()
         # 通知观察者 考勤对象就要被踢掉了
     del BaseCheckin.checkin_list[0]
     if BaseCheckin.checkin_list != []:
         t2 = BaseCheckin.checkin_list[0].enter_time
         # dev = ((int(t2) - int(t1)) % 100) + ((int(t2) - int(t1)) / 100) * 60
         dev = self.dev(t1,t2)
         self.start_timing(dev*60)
     else:
         PrtInfo.tipsMessage(0)
Example #10
0
 def init_detail_records(self):
     stu_records = self.init_student_records()
     temp_list = []
     for stu_rec in stu_records:
         temp_dict = {
             'StuID': stu_rec['StuID'],
             'checkinTime': time.strftime('%Y-%m-%d %H:%M:%S'),
             'ProofPath': 'Auto',
             'checkinType': 'Auto',
             'IsSuc': 'False',
             'checkinResult': '缺勤'
         }
         temp_list.append(temp_dict)
     print PrtInfo.successMessage(3)
     return temp_list
Example #11
0
def start_checkin_menu(wechat_id):
    subprocess.call("clear")
    while True:
        obj = BaseCheckin.find_checkin_obj_for_tea(wechat_id)
        if obj != None:
            print PrtInfo.failedMessage(7)
            break
        obj = AutoCheckin(wechat_id)
        if obj == None:
            print PrtInfo.failedMessage(4)
            prompt = raw_input('maybe try again?(y/n)')
            if prompt == 'n':
                break
        else:
            obj.start_checkin()
            break
Example #12
0
def start_random_menu(wechat_id):
    subprocess.call("clear")
    while True:
        obj = BaseCheckin.find_checkin_obj_for_tea(wechat_id)
        if obj == None:
            print PrtInfo.failedMessage(4)
            prompt = raw_input('maybe try again?(y/n)')
            if prompt == 'n':
                subprocess.call("clear")
                break
        else:
            try:
                i = int(raw_input('Please input random number:'))
                obj.start_random_checkin(i)
                break
            except ValueError, e:
                print 'invalid input ,try again'
Example #13
0
 def init_course_id_by_wechatid(wechat_id):
     tea_id = BaseCheckin.init_teacher_id_by_wechatid(wechat_id)
     crs_id_list = []
     crs_records = BaseFile.read_file(BaseCheckin.course_file.name)
     for record in crs_records:
         if (record['TeacherID'] == tea_id) & (record['CourseID']
                                               not in crs_id_list):
             crs_id_list.append(record['CourseID'])
     if crs_id_list == []:
         print PrtInfo.notFoundMessage(1)
         return 0
     while True:
         crs_id_list.append('back')
         f = Form(['Course ID'], crs_id_list)
         c = f.init_form()
         if c == len(crs_id_list):
             return 0
         else:
             return f.items[c - 1]
Example #14
0
def detail_now(wechat_id):
    subprocess.call("clear")
    while True:
        obj = ManCheckin(wechat_id)
        if obj.tea_id == 0:
            print PrtInfo.failedMessage(4)
            prompt = raw_input('maybe try again?(y/n)')
            if prompt == 'n':
                break
        else:
            c = BaseCheckin.find_checkin_obj_for_tea(wechat_id)
            if c != None:
                detail_records = BaseFile.read_file(
                    c.init_detail_name(str(c.tea_id), str(c.crs_id),
                                       str(c.seq_id)))
                detail_format(detail_records)
                break
            else:
                break
Example #15
0
def detail_history(wechat_id):
    subprocess.call("clear")
    while True:
        obj = ManCheckin(wechat_id)
        if obj.tea_id == 0:
            print PrtInfo.failedMessage(4)
            prompt = raw_input('maybe try again?(y/n)')
            if prompt == 'n':
                break
        else:
            r = range(1, obj.init_seq_id(obj.tea_id, obj.crs_id))
            r.append('exit')
            c = Form(['seq id'], r)
            seq_id = c.init_form()
            if seq_id == len(r) or seq_id == -1:
                break
            detail_records = DetailFile.read_file(
                BaseCheckin.init_detail_name(obj.tea_id, obj.crs_id, seq_id))
            detail_format(detail_records)
            break
Example #16
0
def stu_menu():
    subprocess.call("clear")
    wechat_id = raw_input(PrtInfo.promptMessage(0))
    while True:
        m = StudentForm()
        c = m.init_form()
        if c == 1:
            join_checkin_menu(wechat_id)
        if c == 2:
            subprocess.call("clear")
            break
Example #17
0
def tea_menu():
    subprocess.call("clear")
    wechat_id = raw_input(PrtInfo.promptMessage(0))
    while True:
        m = TeacherForm()
        c = m.init_form()
        if c == 1:
            start_menu(wechat_id)
        if c == 2:
            update_menu(wechat_id)
        if c == 3:
            history_menu(wechat_id)
        if c == 4:
            progress_menu(wechat_id)
        if c == 5:
            subprocess.call("clear")
            break
Example #18
0
 def confirm_leave(obj,detail_file):
     records = BaseFile.read_file(detail_file.name)
     leave_list = []
     for rec in records:
         if rec['checkinResult'] == '假条提交':
             leave_list.append(rec)
     if leave_list is not []:
         print 'You have ' + str(leave_list.__len__()) + ' leave events to handle!'
         for line in leave_list:
             print 'Name:' + BaseCheckin.get_student_name(obj,line['StuID'])
             print 'Image:' + line['ProofPath']
             choice = raw_input(PrtInfo.promptMessage(8))
             if choice == 'y':
                 print line['ProofPath']
                 line['checkinResult'] = '请假'
             else:
                 print line['ProofPath']
                 line['checkinResult'] = '缺勤'
             detail_file.write_file([line], 'ab')
Example #19
0
 def entry_list(self):
     # self.enter_time = '8:30'
     class_list = self.init_class_records()
     intersection_flag = False
     # 全局队列为空:
     if BaseCheckin.checkin_list == []:
         print PrtInfo.successMessage(7)
         BaseCheckin.checkin_list.append(self)
         self.time_window.start_timing()
         return True
     # 非空
     kick_head = False
     for checkin_obj in BaseCheckin.checkin_list[:]:
         try:
             if set(class_list) & set(checkin_obj.class_list):
                 # 存在交集
                 # 节次不一样 踢掉
                 if self.section_id != checkin_obj.section_id:
                     intersection_flag = True
                     if BaseCheckin.checkin_list.index(checkin_obj) == 0:
                         # 踢掉的是队首
                         kick_head = True
                     checkin_obj.notify()
                     BaseCheckin.checkin_list.remove(checkin_obj)
                 # 节次一样,无法进入,退出函数
                 else:
                     return False
         except TypeError:
             print 'invalid operation'
             return False
     # 队列中的所有班都与来者没有交集,或者有交集被踢出去
     if (intersection_flag == False) | (kick_head == False):
         # 没有交集 或者 踢掉的不是队首
         self.time_window.just_waiting()
         BaseCheckin.checkin_list.append(self)
     elif (intersection_flag == True) & (kick_head == True) & \
             (BaseCheckin.checkin_list.__len__() != 0):
         # 有交集 且 踢掉的是队首 且 当前者不是队首
         print PrtInfo.successMessage(7)
         BaseCheckin.checkin_list.append(self)
         t2 = BaseCheckin.checkin_list[0].enter_time
         t3 = BaseCheckin.checkin_list[1].enter_time
         self.time_window.time_second(t2, t3)
     else:
         # 有交集 且 踢掉队首 且 自己是队首
         print PrtInfo.successMessage(6)
         BaseCheckin.checkin_list.append(self)
         self.time_window.start_timing()
Example #20
0
 def find_checkin_obj_with_wechat_id(wechat_id):
     if BaseCheckin.checkin_list == []:
         print PrtInfo.failedMessage(0)
         return None
     else:
         print PrtInfo.promptMessage(10)
         tea_ids = []
         for i in BaseCheckin.checkin_list:
             tea_ids.append(i.tea_id)
         choice = Form(['teacher id'], tea_ids).init_form()
         if choice == -1:
             return None
         tea_id = tea_ids[choice - 1]
         for i in BaseCheckin.checkin_list:
             if i.tea_id == tea_id:
                 if i.get_stu_id_in_class_list(wechat_id) != None:
                     return i
                 else:
                     print PrtInfo.notFoundMessage(4)
                     return None
         else:
             print PrtInfo.failedMessage(0)
             return None
Example #21
0
 def update_stu_detail_checkin_result(stu_id, seq_id,tea_id,crs_id):
     detail_records = BaseFile.read_file(BaseCheckin.init_detail_name(tea_id,crs_id, seq_id))
     for detail_rec in detail_records:
         if detail_rec['StuID'] == str(stu_id):
             if detail_rec['checkinResult'] == '请假提交':
                 if raw_input(PrtInfo.promptMessage(4)) == 'y' | 'Y':
                     detail_rec['checkinResult'] = '请假'
                 else:
                     detail_rec['checkinResult'] = '缺勤'
             detail_rec['IsSuc'] = 'True'
             detail_rec['checkinResult'] = raw_input(PrtInfo.promptMessage(4))
             print PrtInfo.successMessage(0)+detail_rec['checkinResult']
             detail_file = DetailFile(BaseCheckin.init_detail_name(tea_id, crs_id, seq_id))
             detail_file.write_file([detail_rec],'ab')
             return True
     print PrtInfo.notFoundMessage(3)
     return False
Example #22
0
 def upload_path(self):
     return raw_input(PrtInfo.promptMessage(5))
Example #23
0
 def write_detail_file(self, detail_records):
     DetailFile(self.init_detail_name(
         self.tea_id, self.crs_id, self.seq_id)).write_file(detail_records)
     print PrtInfo.successMessage(4)
Example #24
0
 def join_checkin(self, wechat_id):
     if self in BaseCheckin.checkin_list:
         checkin_type = raw_input(PrtInfo.promptMessage(6))
         if checkin_type == 'Auto':
             self.init_new_detail_record(wechat_id, 'Auto')
             PrtInfo.successMessage(8)
             return True
         elif checkin_type == 'Random':
             random_list = self.get_random_list()
             if random_list == []:
                 print 'No random check in now'
                 return False
             if self.get_stu_id_in_class_list(wechat_id) not in random_list:
                 print PrtInfo.notFoundMessage(4)
                 return False
             else:
                 self.init_new_detail_record(wechat_id, 'Random')
                 PrtInfo.successMessage(8)
         else:
             print PrtInfo.failedMessage(1)
     else:
         print PrtInfo.failedMessage(0)
         return False