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