From f78599c1fe3b8c107c4aaa6055c3928072c8102d Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Wed, 27 Mar 2024 22:09:06 +0800 Subject: [PATCH] =?UTF-8?q?database=5Ftools=E5=A2=9E=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=87=BD=E6=95=B0ChooseIDsByUsageInterval=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E4=B8=80=E6=AE=B5=E6=97=B6=E9=97=B4=E5=86=85=E6=9F=90?= =?UTF-8?q?=E5=B9=B4=E7=BA=A7=E5=B9=B3=E5=9D=87=E6=AD=A3=E7=A1=AE=E7=8E=87?= =?UTF-8?q?=E5=9C=A8=E5=8C=BA=E9=97=B4=E5=86=85=E7=9A=84=E9=A2=98=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index b6a9531c..e71ff668 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -1,5 +1,6 @@ import json,re,os,Levenshtein,fitz,time,sys,subprocess import pandas as pd +import numpy as np import pyperclip @@ -2251,5 +2252,35 @@ def RefineExclude(excludejson): #将excludejson的key变为6位题号 newjson[key.zfill(6)] = excludejson[key] return newjson + +def ChooseIDsByUsageInterval(startdate,enddate,interval,grade,prodict): #返回根据条件选出的题号字典及对应小题, 需要留意的记录长度不一的题号, 以及所有使用过的题号 + used_problems = [] + for id in prodict: + currentproblem = prodict[id] + currentusages = [parseUsage(u) for u in currentproblem["usages"] if startdate <= parseUsage(u)["date"] <= enddate and grade+"届" in parseUsage(u)["classid"]] + if not currentusages == []: + used_problems.append((id,currentusages)) + cautionids = [] #使用记录长度不一的题目id + chosenproblems = {} #使用记录的平均值在thresholds中的题目id(键值为题号id, 内容为小题号, 内容为空表示没有小题) + for item in used_problems: + id,usages = item + subproblems = [u["subproblems"] for u in usages] + if max(subproblems) != min(subproblems): + cautionids.append(id) + print(f"!!! 题号 {id} 的使用记录中小题数目不全相同, 请检查") + else: + for i in range(subproblems[0]): + difflist = [u["difficulties"][i] for u in usages] + diffmean = np.mean(difflist) + if interval[0] <= diffmean <= interval[1]: + if subproblems[0] == 1: + chosenproblems[id] = [] + elif not id in chosenproblems: + chosenproblems[id] = [i+1] + else: + chosenproblems[id].append(i+1) + return (chosenproblems,cautionids,used_problems) #返回根据条件选出的题号字典及对应小题, 需要留意的记录长度不一的题号, 以及所有使用过的题号 + + if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file