From fe708aa0c8b1c319d9b5a139bcf2b68733caaa62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9A=93=E6=9C=88=E5=BD=92=E5=B0=98?= Date: Wed, 19 Feb 2025 02:28:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=97=B6=E5=B0=86=E7=BC=96=E7=A0=81=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E4=B8=BAint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/code.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/code.py b/api/code.py index 18a27ad..b892030 100644 --- a/api/code.py +++ b/api/code.py @@ -104,9 +104,11 @@ async def add_code_by_file(request: Request, id: str = Path(description="文件I uploader_id = await file.first().values(id="uploader__id") if str(uploader_id["id"]) == user_id: try: - df = pd.read_excel(file.absolute_path) + df = pd.read_excel(file.absolute_path, dtype={"code": str}) + df["code"] = df["code"].astype(str).str.zfill(8) for index, row in df.iterrows(): - row["code"] = str(row["code"]).replace(".", "").replace("/", "").replace("_", "").replace("-", + print(row['code'],type(row['code'])) + row["code"] = row["code"].replace(".", "").replace("/", "").replace("_", "").replace("-", "").replace( "?", "").replace( @@ -276,7 +278,7 @@ async def get_code_list(request: Request, max_score = data["hits"].get("max_score", 1) # 处理每一条匹配结果 for hit in data["hits"]["hits"]: - code = await Code.get_or_none(code=str(hit["_source"]["code"])) + code = await Code.get_or_none(code=hit["_source"]["code"]) # 归一化匹配度,转换为百分比 match_rate = round((hit["_score"] / max_score) * 100, 2) # 归一化后计算百分比 # 将匹配结果添加到列表中 @@ -377,7 +379,7 @@ async def get_code_list(request: Request, max_score = data["hits"].get("max_score", 1) # 处理每一条匹配结果 for hit in data["hits"]["hits"]: - code = await Code.get_or_none(code=str(hit["_source"]["code"])) + code = await Code.get_or_none(code=hit["_source"]["code"]) # 归一化匹配度,转换为百分比 match_rate = round((hit["_score"] / max_score) * 100, 2) # 归一化后计算百分比 # 将匹配结果添加到列表中