This commit is contained in:
2025-08-20 17:10:28 +08:00
parent c451fdf0e5
commit 854a2b5c91
3 changed files with 26 additions and 13 deletions

View File

@@ -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 += ")"