diff --git a/backend.py b/backend.py index aa9412f..461ee4a 100644 --- a/backend.py +++ b/backend.py @@ -17,7 +17,7 @@ class Backend: self.time = time.time() self.title_filter = self.get_source_type() - self.global_filter = [] + self.global_filter = "" @@ -30,12 +30,12 @@ class Backend: # 总权重查询 total_query = f""" - SELECT SUM(count) - FROM questions - WHERE count > 0 AND title IN ({placeholders}) + SELECT SUM(q.count) + FROM questions q + WHERE q.count > 0 AND title IN ({placeholders}) {self.global_filter} """ - #print(total_query) + print(total_query) #print(self.title_filter) cursor.execute(total_query, self.title_filter) @@ -52,9 +52,9 @@ class Backend: SELECT * FROM ( SELECT *, - SUM(count) OVER (ORDER BY id ROWS UNBOUNDED PRECEDING) AS cum_weight - FROM questions - WHERE count > 0 AND title IN ({placeholders}) + SUM(q.count) OVER (ORDER BY id ROWS UNBOUNDED PRECEDING) AS cum_weight + FROM questions q + WHERE q.count > 0 AND title IN ({placeholders}) {self.global_filter} ) WHERE ? < cum_weight ORDER BY cum_weight @@ -192,4 +192,16 @@ class Backend: def set_config(self,a,b): self.title_filter = a - self.global_filter = b + + self.global_filter = "" + if len(b)>0: + self.global_filter = " and ( FALSE " + for item in b: + if item == "未做过的题": + self.global_filter +=" OR q.count = 3 " + elif item == "错过的题": + self.global_filter +=" OR q.count > 3 " + self.global_filter += ")" + + + diff --git a/components/constants.py b/components/constants.py index 304ec7f..f002870 100644 --- a/components/constants.py +++ b/components/constants.py @@ -14,8 +14,9 @@ FONT_FAMILY = "微软雅黑" indexMap = {6: "A. ", 7: "B. ", 8: "C. ", 9: "D. "} # 全局 -bottom_options = ["全部的题", "未做过的题", "错过的题", ] -instructions = f"""后面的选项仅在'{bottom_options[0]}'未被勾选时起效""" +bottom_options = ["未做过的题", "错过的题", ] +instructions = f"""第二行啥也不选就是不过滤,全部的题 +题目是加权平均抽取,默认权重为3,对一次减1,错一次加2.""" # 样式 # 创建字体 diff --git a/components/page1.py b/components/page1.py index a0781c9..5f21007 100644 --- a/components/page1.py +++ b/components/page1.py @@ -30,7 +30,7 @@ class Page1: self.bottom_vars = [] for option in bottom_options: - var = tk.BooleanVar(value=True) + var = tk.BooleanVar(value=False) chk = ttk.Checkbutton(self.bottom_frame, text=option, variable=var, style="Custom.TCheckbutton") chk.pack(side=tk.LEFT, padx=20) self.bottom_vars.append(var) @@ -71,7 +71,7 @@ class Page1: if __name__ == "__main__": top_options = ["1", "2", "3", "4"] - bottom_options = ["全部的题", "未做过的题", "错过的题", ] + bottom_options = ["未做过的题", "错过的题", ] root = tk.Tk() app = Page1(root, top_options, bottom_options)