""" 功能:绑定试卷和填入音频次数 author:pengchen 时间:2020/09/14 """ import config import datetime import pandas as pd from cloudinf import cloudInf def main(): inf=cloudInf() #获取考试相关信息 result=inf.findexam(protocal=config.protocal, domain=config.domain,examId=config.examId) examname=result.json()["name"] examType=result.json()["examType"] bindpaperList = pd.DataFrame(columns=["考试ID","考试名称", "课程代码", "课程名称", "卷型", "试卷名称", "绑定几率","是否有音频"]) #获取课程相关信息 result=inf.findcourse(protocal=config.protocal, domain=config.domain,examId=config.examId) courseLst=result.json() for course in courseLst: #获取所有试卷 result=inf.getGenPaper(protocal=config.protocal, domain=config.domain, courseNo=course["courseCode"]) paperList=result.json() #获取所有卷型 result=inf.queryExamCoursePaperTypeLis(protocal=config.protocal, examId=config.examId,domain=config.domain,courseId=course["courseId"]) paperGroupList=result.json() #根据条件过滤paperList audioconfigreqdataLst=[] exampaperList=[] for paperGroup in paperGroupList: filterLst=filterPaper(paperGroup["paperType"],paperList) if config.numberrule: number = min(int(config.numberrule), len(filterLst)) else: number=len(filterLst) #计算weight numlst=split_integer(100,number) #开始生成绑定试卷 for i in range(0,number): #生成绑定试卷值 exampaper = { "groupCode": paperGroup["paperType"], "paper": { "id": filterLst[i]["id"] }, "weight":numlst[i] } exampaperList.append(exampaper) audioconfigreqdata = { "courseCode": course["courseCode"], "examId": config.examId, "examName": examname, "groupCode": paperGroup["paperType"], "paper": { "id": filterLst[i]["id"] }, "paperName": filterLst[i]["name"] } # 获取所有音频配置 result = inf.getAudioConfig(protocal=config.protocal, data=[audioconfigreqdata], domain=config.domain) if len(result.json())==0: audioflag=False else: #修改配置信息并存入List audioflag=True # bindpaper = [config.examId, examname, course["courseCode"], course["name"], paperGroup["paperType"], # filterLst[i]["name"], numlst[i],audioflag] bindpaperList=bindpaperList.append( {"考试ID": config.examId, "考试名称": examname, "课程代码": course["courseCode"], "课程名称": course["courseName"], "卷型": paperGroup["paperType"], "试卷名称": filterLst[i]["name"], "绑定几率": numlst[i], "是否有音频": audioflag},ignore_index=True) # 开始获取音频信息 audioconfigreqdataLst.append(audioconfigreqdata) #开始绑定试卷 exampaperdata = { "examId": config.examId, "examName": examname, "examType": examType, "courseCode": course["courseCode"], "courseName": "", "callType": "WHOLE_SET", "scrambling_the_question_order": 0, "scrambling_the_option_order": 0, "examPaperList": exampaperList } print(exampaperdata) result = inf.bindpaper(protocal=config.protocal, data=exampaperdata, domain=config.domain) if result.status_code == 200: print(course["courseCode"], "bind paper success") else: print(course["courseCode"], "bind paper failed") #开始获取音频信息 # 获取所有音频配置 result = inf.getAudioConfig(protocal=config.protocal, data=audioconfigreqdataLst, domain=config.domain) # 将音频配置存入json文件中 audioconfiglist = [] for audioconfig in result.json(): audioconfig["playTime"] = str(config.playtime) audioconfiglist.append(audioconfig) if audioconfiglist: result = inf.addAudioConfig(protocal=config.protocal, paperdata=audioconfiglist, domain=config.domain) if result.status_code == 200: print(course["courseCode"], "add audioconfig success") else: print(course["courseCode"], "add audioconfig failed") bindpaperList.to_excel("bindpaper.xlsx",index=False) def filterPaper(paperGroup,paperList): filterList=[] for paper in paperList: flag=True if config.timerule: #如果不为空,则按照此timerule匹配 createtime=paper["createTime"] configcreatetime=config.timerule createtime=datetime.datetime.strptime(createtime,"%Y-%m-%d %H:%M:%S") configcreatetime=datetime.datetime.strptime(configcreatetime,"%Y-%m-%d %H:%M:%S") if createtime 0 quotient = int(m / n) remainder = m % n if remainder > 0: return [quotient] * (n - remainder) + [quotient + 1] * remainder if remainder < 0: return [quotient - 1] * -remainder + [quotient] * (n + remainder) return [quotient] * n if __name__=="__main__": main()