def select_courseid(self, tec_id): c = CourseInfo() all_info = c.get_all_course_info("../internal/courseProgress.csv") the_tec_info = c.get_course_info_from_teacher_id(tec_id, all_info) course_names = c.get_course_names(the_tec_info) course_ids = c.get_course_ids(the_tec_info) i = 1 print "课头序号|课程名|课头号" for a_course_name in course_names: print str(i) + " " + a_course_name.decode('utf-8') + " " + course_ids[i - 1] i += 1 select = raw_input("请选择要考勤的课头号的序号:") select = int(select) if select > 0 and select <= len(course_names): select_id = course_ids[select - 1] return select_id else: print "别闹!没有这个选项" return
class CheckInInfo(object): def __init__(self, tec_id, course_id, course_filename, stu_filename, seq_filename): self.course = CourseInfo() self.stu = StuInfo() self.tim = TimeWindows() self.seq = SeqInfo() self.section = self.tim.get_now_section(self.tim.get_time()) 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.seq.get_seqid(tec_id, course_id, self.seq.get_all_seq_info(seq_filename)) + 1) self.starttime = self.tim.get_time2() # 获取待考勤班级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(teacher_id, course_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
class TecManCheckInInsertControl(object): def __init__(self): self.seq = SeqInfo() self.detail = DetailInfo() self.course = CourseInfo() self.stu = StuInfo() self.sum = SumInfo() # 获取当前系统时间 def get_time(self): """ 获取系统当前的时间 :return: """ return time.strftime("%Y-%m-%d %X", time.localtime()) # 获取所有学生的名单 def get_all_stuids(self, tec_id, course_id, course_filename, stu_filename): all_course_info = self.course.get_all_course_info(course_filename) classnums = self.course.get_classnames(tec_id, course_id, all_course_info) all_stu_info = self.stu.get_all_stu_info(stu_filename) stu_ids = self.stu.get_stuids( self.stu.get_wait_checkin_stu_info(classnums, all_stu_info)) if stu_ids: return stu_ids else: return None # 教师手工修改 def man_change(self, tec_id, course_id, seq_id, stu_id, result, course_filename, stu_filename, seq_filename, default_path): # 检查seqid的有效性 all_seq_info = self.seq.get_all_seq_info(seq_filename) new_seqid = self.seq.get_seqid(tec_id, course_id, all_seq_info) if int(seq_id) > 0 and int(seq_id) <= new_seqid: # 检查stuid的有效性 all_stuids = self.get_all_stuids(tec_id, course_id, course_filename, stu_filename) if all_stuids and stu_id in all_stuids: # 构造detail行数据 new_detail_info = [ self.detail.set_detail_line(stu_id, self.get_time(), "null", "man", "null", result) ] new_filename = self.detail.set_detail_filename( tec_id, course_id, str(seq_id)) new_filename = default_path + new_filename self.detail.write_file(new_detail_info, new_filename, 'ab') else: print "该学生非本班学生,请检查后重新操作" else: print "没有您选择的考勤序号,请检查后重新输入" # 教师手工考勤控制 def man_checkin(self, tec_id, course_id, course_filename, stu_filename, arrive, absence, late, early, note, seq_filename, default_path): error_ids = self.check_stuids( arrive, absence, late, early, note, self.get_all_stuids(tec_id, course_id, course_filename, stu_filename)) if error_ids: print "部分名单非本班学生,请检查后重新操作,错误(stuid)名单:", error_ids else: # 构造手工考勤的detail信息 new_detail_info = self.build_detail(arrive, absence, late, early, note) print "手工考勤记录完成" # 1.在seq表中增加记录 seq_id = self.update_seq_info(tec_id, course_id, seq_filename) # 2.在detail表中保存记录 self.update_detail_info(tec_id, course_id, seq_id, new_detail_info, default_path) # 1.在seq表中增加记录 def update_seq_info(self, tec_id, course_id, seq_filename): all_seq_info = self.seq.get_all_seq_info(seq_filename) new_seqid = self.seq.get_seqid(tec_id, course_id, all_seq_info) + 1 new_seq_line = self.seq.set_seq_line(tec_id, course_id, str(new_seqid), self.get_time()) new_seq_info = [new_seq_line] self.seq.write_file(new_seq_info, seq_filename, 'ab') return new_seqid # 2.在detail表中保存记录 def update_detail_info(self, tec_id, course_id, seq_id, detail_info, default_path): new_filename = self.detail.set_detail_filename(tec_id, course_id, str(seq_id)) new_filename = default_path + new_filename self.detail.write_file(detail_info, new_filename, 'wb') # 检查教师输入的学生名单是否在该考勤对象中 def check_stuids(self, arrive, absence, late, early, note, all_studis): # 验证输入的学生名单是否存在与考勤对象,不存在的打印提示错误。 warning = [] for a_person in arrive: if a_person in all_studis: pass else: warning.append(a_person) for a_person in absence: if a_person in all_studis: pass else: warning.append(a_person) for a_person in late: if a_person in all_studis: pass else: warning.append(a_person) for a_person in early: if a_person in all_studis: pass else: warning.append(a_person) for a_person in note: if a_person in all_studis: pass else: warning.append(a_person) # 若存在非考勤对象名单 if warning: return warning else: return None # 为4中考勤结果的学生构造detail数据 def build_detail(self, arrive, absence, late, early, note): new_detail_info = [] for a_person in arrive: new_detail_info.append( self.detail.set_detail_line(a_person, self.get_time(), "null", "man", "null", "到勤")) for a_person in absence: new_detail_info.append( self.detail.set_detail_line(a_person, self.get_time(), "null", "man", "null", "缺勤")) for a_person in late: new_detail_info.append( self.detail.set_detail_line(a_person, self.get_time(), "null", "man", "null", "迟到")) for a_person in early: new_detail_info.append( self.detail.set_detail_line(a_person, self.get_time(), "null", "man", "null", "早退")) for a_person in note: new_detail_info.append( self.detail.set_detail_line(a_person, self.get_time(), "null", "man", "null", "请假")) return new_detail_info
class UpdateSum(object): def __init__(self): self.seq = SeqInfo() self.course = CourseInfo() self.stu = StuInfo() self.sum = SumInfo() self.detail = DetailInfo() # 传入参数 tec_id, course_id, seq_id # 从seq表中获取本次的starttime, 需要附加文件名,seq_filename # 获取所有学生的名单,需要附加文件名,course_filename,stu_filename # 通过detail类的两个方法获得所有学生的考勤结果 # 获取sum表的文件名 # 若seq_id==1,需要初始化sum表 # 按学生考勤结果更新入sum表 def update_sum(self, tec_id, course_id, seq_id, course_filename, stu_filename, seq_filename): starttime = self.get_tec_start_time(tec_id, course_id, seq_id, seq_filename) stuids = self.get_all_stuids(tec_id, course_id, course_filename, stu_filename) sumfilename = self.sum.set_sum_filename(tec_id, course_id) if starttime and stuids and sumfilename: # 获得所有学生的考勤结果 detail_filename = self.detail.set_detail_filename( tec_id, course_id, seq_id) all_detail_info = self.detail.get_all_detail_info(detail_filename) for detail_line in all_detail_info: self.detail.set_detail_result(detail_line, starttime) new_sum_line = self.detail.detail_sum(all_detail_info, stuids, seq_id) # 更新sum if os.path.exists(sumfilename): pass else: # 初始化sum表 new_sum_info = self.sum.sum_creat(stuids) self.sum.write_file(new_sum_info, sumfilename) all_sum_info = self.sum.get_all_sum_info(sumfilename) new_sum_info = self.sum.sum_update(new_sum_line, all_sum_info, seq_id) self.sum.write_file(new_sum_info, sumfilename) else: print "您输入的内容有误,请检查后重新操作" # 获取教师发起考勤时间 def get_tec_start_time(self, tec_id, course_id, seq_id, seq_filename): all_seq_info = self.seq.get_all_seq_info(seq_filename) if self.seq.check_seq_id(tec_id, course_id, seq_id, all_seq_info): start_time = self.seq.get_start_time(tec_id, course_id, seq_id, all_seq_info) if start_time: return start_time else: return None else: print "您输入的考勤次序号错误" return None # 获取所有学生的名单 def get_all_stuids(self, tec_id, course_id, course_filename, stu_filename): all_course_info = self.course.get_all_course_info(course_filename) classnums = self.course.get_classnames(tec_id, course_id, all_course_info) all_stu_info = self.stu.get_all_stu_info(stu_filename) stu_ids = self.stu.get_stuids( self.stu.get_wait_checkin_stu_info(classnums, all_stu_info)) if stu_ids: return stu_ids else: return None # 遍历seq表,获取所有detail表,更新sum表 def update_all_sum(self, COURSEFILENAME, STUFILENAME, SEQFILENAME): all_seq_info = self.seq.get_all_seq_info(SEQFILENAME) for seq_line in all_seq_info: tec_id = seq_line["TeacherID"] course_id = seq_line["CourseID"] seq_id = seq_line["SeqID"] self.update_sum(tec_id, course_id, seq_id, COURSEFILENAME, STUFILENAME, SEQFILENAME)