diff --git a/工具v3/database_tools_2.py b/工具v3/database_tools_2.py index 64b7d74c..80a25f92 100644 --- a/工具v3/database_tools_2.py +++ b/工具v3/database_tools_2.py @@ -963,6 +963,32 @@ def generate_origin(origin_dict): data = f"{data}-改编自{origin_dict['前序']}" return data + +def MatchConditioninMariaDB(condition_list): + corr_dict = { + "content": ('problems','content'), + "objs": ('objcorresp','obj_ID'), + "tags": ('tagcorresp','tagname'), + "origin": ('problems','origin'), + "genre": ('problems','genre'), + "ans": ('problems','ans'), + "solution": ('problems','solution'), + "remark": ('remarks','remark_content') + } + mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest") + mycursor = mydb.cursor() + mycursor.execute("SELECT ID FROM problems WHERE NOT content REGEXP 'OBS';") + match = set([u[0] for u in mycursor.fetchall()]) + for field,reverse,regexp in condition_list: + if not field in ["same","related","usages"]: + table,column = corr_dict[field] + sql = f"SELECT ID FROM {table} WHERE {'NOT' if reverse else ''} {column} REGEXP '{regexp};" + mycursor.execute(sql) + newmatch = set([u[0] for u in mycursor.fetchall()]) + match = match & newmatch + mydb.close() + return match + def MatchCondition2024(problem,condition_list): #判断problem这一字典是否符合condition_list中的所有筛选条件 match = True #初始设定符合条件 for field, flag_not, matchexp in condition_list: diff --git a/工具v3/关键字筛选题号.py b/工具v3/关键字筛选题号.py index 7d79f11e..37992c48 100644 --- a/工具v3/关键字筛选题号.py +++ b/工具v3/关键字筛选题号.py @@ -8,8 +8,10 @@ class MyWindow(QWidget,Ui_Form): super().__init__() self.setupUi(self) self.conditions = [] - self.pro_dict = load_dict("../题库0.3/Problems.json") - self.lcdNumber_resCount.display(len(self.pro_dict)) + mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest") + mycursor = mydb.cursor() + mycursor.execute("SELECT count(*) FROM problems WHERE NOT content REGEXP 'OBS';") + self.lcdNumber_resCount.display(mycursor.fetchall()[0][0]) self.bind() def bind(self): @@ -47,23 +49,16 @@ class MyWindow(QWidget,Ui_Form): text += f"字段 {field} 中{'没有' if flag_not else '有 '}{' 或 '.join([t.strip() for t in matchexp.split(',')])}\n" self.label_conditions.setText(text) def exec(self): - self.matchlist = [] - self.conditions.append(("content",True,"OBSOLETE")) - for id in self.pro_dict: - if MatchCondition2024(self.pro_dict[id],self.conditions): - self.matchlist.append(id) - self.conditions = self.conditions[:-1].copy() + self.matchlist = MatchConditioninMariaDB(self.conditions) self.lcdNumber_resCount.display(len(self.matchlist)) def build(self): - exp = generate_exp(self.matchlist) + idlist = sorted(list(self.matchlist)) + exp = generate_exp(idlist) try: AppendTextFile(f"\n{time.ctime()}\n{exp}\n","临时文件/题号筛选.txt") except: SaveTextFile(f"{time.ctime()}\n{exp}\n","临时文件/题号筛选.txt") - prodictpath = "../题库0.3/Problems.json" - objdictpath = "../题库0.3/LessonObj.json" - raw_pro_dict = load_dict(prodictpath) configjson_detailed = { "pdf标题": "筛选题目编译", "教师版": True, @@ -102,9 +97,6 @@ class MyWindow(QWidget,Ui_Form): else: configjson = configjson_simple - # grades = configjson["字段显示设置"]["届别"] - # pro_dict = select_grade_from_pro_dict(raw_pro_dict,grades) - # obj_dict = load_dict(objdictpath) notetitle = configjson["pdf标题"] outputdir = "临时文件" #输出文件的目录 @@ -123,7 +115,7 @@ class MyWindow(QWidget,Ui_Form): mycursor = mydb.cursor() bodystring = "\\begin{enumerate}\n\n" for id in generate_number_set(exp): - bodystring += generateLaTeXBodyContentfromMariaDB(mycursor,id,configjson): + bodystring += generateLaTeXBodyContentfromMariaDB(mycursor,id,configjson) bodystring += "\\end{enumerate}\n\n" midtime = time.time() diff --git a/工具v3/关键字筛选题号old.py b/工具v3/关键字筛选题号old.py deleted file mode 100644 index 380656e5..00000000 --- a/工具v3/关键字筛选题号old.py +++ /dev/null @@ -1,35 +0,0 @@ -keywords_dict = { - "id":[""], #题号 - "content":[""], #题面内容 - "objs":[""], #目标代码 - "tags":[""], #标签, 如["第二单元"]等 - "genre":[""], #题目类型, 填空题, 选择题, 解答题 - "ans":[r""], #答案 - "solution":[""], #解答与提示 - "duration":[""], #解题时间(目前未设置) - "usages":[""], #使用记录, 数据库中格式为 <日期>\t<届别><班别>\t正确率[\t正确率]... 例如"20230301\t2023届01班\t0.985\t0.211 - "origin":[""], #题目来源 - "edit":[""], #导入者及编辑者 - "same":[""], #相同题目题号 - "related":[""], #关联题目题号 - "remark":[""], #备注, 注记 - "space":[""], #解答题下的空间(em)表示一个m的宽度 - "unrelated":[""], #无关题目题号 - # "content2":["双曲线"], #在字段名中加入数字表示这个字段的另一个必要条件 -} -#同一字段名中的条件为"或"的关系, 不同字段名(可加数字表示同一字段)中的条件为"且"的关系 -outputfilepath = "临时文件/题号筛选.txt" - -from database_tools import * - -prodictpath = "../题库0.3/Problems.json" -pro_dict = load_dict(prodictpath) - - -keywords_dict["content9_not"] = ["OBSOLETE"] -print(keywords_dict) -matchlist = [id for id in pro_dict if MatchCondition(pro_dict[id],keywords_dict)] -matchstring = generate_exp(matchlist) - -SaveTextFile(matchstring,outputfilepath) -os.system("code -g %s:1"%outputfilepath) \ No newline at end of file diff --git a/工具v3/题号筛选器.ui b/工具v3/题号筛选器.ui new file mode 100644 index 00000000..a50c10c3 --- /dev/null +++ b/工具v3/题号筛选器.ui @@ -0,0 +1,340 @@ + + + Form + + + + 0 + 0 + 400 + 533 + + + + 题号筛选器 + + + 1.000000000000000 + + + + + 20 + 20 + 75 + 24 + + + + 内容 + + + + + + 20 + 50 + 75 + 24 + + + + 目标编号 + + + + + + 20 + 80 + 75 + 24 + + + + 标签 + + + + + + 20 + 110 + 75 + 24 + + + + 使用记录 + + + + + + 20 + 140 + 75 + 24 + + + + 出处 + + + + + + 20 + 170 + 75 + 24 + + + + 题目类型 + + + + + + 20 + 200 + 75 + 24 + + + + 答案 + + + + + + 20 + 230 + 75 + 24 + + + + 解答与提示 + + + + + + 20 + 260 + 75 + 24 + + + + 相同题号 + + + + + + 20 + 290 + 75 + 24 + + + + 相关题号 + + + + + + 20 + 320 + 75 + 24 + + + + 备注 + + + + + + 20 + 460 + 75 + 48 + + + + + true + + + + 运行 + + + + + + 20 + 370 + 75 + 24 + + + + 撤销上一个 + + + + + + 20 + 400 + 75 + 24 + + + + 清除 + + + + + + 120 + 100 + 261 + 331 + + + + QFrame::StyledPanel + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + false + + + + + + 120 + 80 + 71 + 16 + + + + 当前条件: + + + + + + 280 + 20 + 111 + 20 + + + + 选中表示不包含 + + + + + + 120 + 50 + 261 + 20 + + + + + + + 120 + 20 + 151 + 16 + + + + 输入条件, 用","分隔表示"或" + + + + + + 120 + 440 + 91 + 16 + + + + 筛选结果数目: + + + + + + 120 + 460 + 161 + 51 + + + + 6 + + + 0.000000000000000 + + + + + + 300 + 460 + 81 + 51 + + + + + true + + + + 保存和编译 + + + + + + 310 + 440 + 79 + 20 + + + + 详细信息 + + + + + +