关键字筛选题号 施工中

This commit is contained in:
weiye.wang 2024-04-16 00:24:07 +08:00
parent 55d9d28093
commit b1a9718222
4 changed files with 374 additions and 51 deletions

View File

@ -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:

View File

@ -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()

View File

@ -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)

340
工具v3/题号筛选器.ui Normal file
View File

@ -0,0 +1,340 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>533</height>
</rect>
</property>
<property name="windowTitle">
<string>题号筛选器</string>
</property>
<property name="windowOpacity">
<double>1.000000000000000</double>
</property>
<widget class="QPushButton" name="pushButton_content">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>内容</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_obj">
<property name="geometry">
<rect>
<x>20</x>
<y>50</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>目标编号</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_tag">
<property name="geometry">
<rect>
<x>20</x>
<y>80</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>标签</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_usage">
<property name="geometry">
<rect>
<x>20</x>
<y>110</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>使用记录</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_origin">
<property name="geometry">
<rect>
<x>20</x>
<y>140</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>出处</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_genre">
<property name="geometry">
<rect>
<x>20</x>
<y>170</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>题目类型</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_ans">
<property name="geometry">
<rect>
<x>20</x>
<y>200</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>答案</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_solution">
<property name="geometry">
<rect>
<x>20</x>
<y>230</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>解答与提示</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_same">
<property name="geometry">
<rect>
<x>20</x>
<y>260</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>相同题号</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_related">
<property name="geometry">
<rect>
<x>20</x>
<y>290</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>相关题号</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_remark">
<property name="geometry">
<rect>
<x>20</x>
<y>320</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>备注</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>20</x>
<y>460</y>
<width>75</width>
<height>48</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>运行</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_undo">
<property name="geometry">
<rect>
<x>20</x>
<y>370</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>撤销上一个</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_clearAll">
<property name="geometry">
<rect>
<x>20</x>
<y>400</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>清除</string>
</property>
</widget>
<widget class="QLabel" name="label_conditions">
<property name="geometry">
<rect>
<x>120</x>
<y>100</y>
<width>261</width>
<height>331</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>120</x>
<y>80</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>当前条件:</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_not">
<property name="geometry">
<rect>
<x>280</x>
<y>20</y>
<width>111</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>选中表示不包含</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_SingleCondition">
<property name="geometry">
<rect>
<x>120</x>
<y>50</y>
<width>261</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>120</x>
<y>20</y>
<width>151</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>输入条件, 用&quot;,&quot;分隔表示&quot;或&quot;</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>120</x>
<y>440</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>筛选结果数目:</string>
</property>
</widget>
<widget class="QLCDNumber" name="lcdNumber_resCount">
<property name="geometry">
<rect>
<x>120</x>
<y>460</y>
<width>161</width>
<height>51</height>
</rect>
</property>
<property name="digitCount">
<number>6</number>
</property>
<property name="value" stdset="0">
<double>0.000000000000000</double>
</property>
</widget>
<widget class="QPushButton" name="pushButton_savebuild">
<property name="geometry">
<rect>
<x>300</x>
<y>460</y>
<width>81</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>保存和编译</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_Detailed">
<property name="geometry">
<rect>
<x>310</x>
<y>440</y>
<width>79</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>详细信息</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>