|
@@ -2,9 +2,16 @@ import openpyxl
|
|
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
|
|
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
|
|
from openpyxl.utils import get_column_letter
|
|
from openpyxl.utils import get_column_letter
|
|
from pymongo import MongoClient
|
|
from pymongo import MongoClient
|
|
|
|
+from bson import ObjectId
|
|
|
|
|
|
-db = MongoClient('192.168.3.206', 27080, unicode_decode_error_handler="ignore").data_quality
|
|
|
|
-coll_user = db["bidding_20230707"]
|
|
|
|
|
|
+# db = MongoClient('192.168.3.206', 27080, unicode_decode_error_handler="ignore").data_quality
|
|
|
|
+# coll_user = db["bidding_20230707"]
|
|
|
|
+
|
|
|
|
+# db = MongoClient('192.168.3.71', 29099, unicode_decode_error_handler="ignore").quality
|
|
|
|
+# coll_user = db["bidding_source"]
|
|
|
|
+
|
|
|
|
+db = MongoClient('192.168.3.166', 27082, unicode_decode_error_handler="ignore").yantianlei
|
|
|
|
+coll_user = db["2023Zglt_qgyys222"]
|
|
# 设置列宽
|
|
# 设置列宽
|
|
def setExcelWith(ws):
|
|
def setExcelWith(ws):
|
|
# 第一步:计算每列最大宽度,并存储在列表lks中。
|
|
# 第一步:计算每列最大宽度,并存储在列表lks中。
|
|
@@ -14,7 +21,7 @@ def setExcelWith(ws):
|
|
for j in range(1, ws.max_row + 1): # 每行循环
|
|
for j in range(1, ws.max_row + 1): # 每行循环
|
|
sz = ws.cell(row=j, column=i).value # 每个单元格内容
|
|
sz = ws.cell(row=j, column=i).value # 每个单元格内容
|
|
if isinstance(sz, str): # 中文占用多个字节,需要分开处理
|
|
if isinstance(sz, str): # 中文占用多个字节,需要分开处理
|
|
- lk1 = len(sz.encode('gbk')) # gbk解码一个中文两字节,utf-8一个中文三字节,gbk合适
|
|
|
|
|
|
+ lk1 = len(sz.encode('utf-8')) # gbk解码一个中文两字节,utf-8一个中文三字节,gbk合适
|
|
else:
|
|
else:
|
|
lk1 = len(str(sz))
|
|
lk1 = len(str(sz))
|
|
if lk < lk1:
|
|
if lk < lk1:
|
|
@@ -42,32 +49,39 @@ def writeExcel( path, sheetname, tongji_title, tongji_list):
|
|
# 写入excel
|
|
# 写入excel
|
|
for i in range(0, len(tongji_list)):
|
|
for i in range(0, len(tongji_list)):
|
|
for j in range(0, len(tongji_list[i])):
|
|
for j in range(0, len(tongji_list[i])):
|
|
- value = ILLEGAL_CHARACTERS_RE.sub(r'', tongji_list[i][j])
|
|
|
|
|
|
+ value = ILLEGAL_CHARACTERS_RE.sub(r'', str(tongji_list[i][j]))
|
|
ws.cell(row=i + 2, column=j + 1, value=value)
|
|
ws.cell(row=i + 2, column=j + 1, value=value)
|
|
setExcelWith(ws)
|
|
setExcelWith(ws)
|
|
book.save(path)
|
|
book.save(path)
|
|
-
|
|
|
|
def pankong(key, item):
|
|
def pankong(key, item):
|
|
if key in item and item[key]:
|
|
if key in item and item[key]:
|
|
value = item[key]
|
|
value = item[key]
|
|
else:
|
|
else:
|
|
value = ""
|
|
value = ""
|
|
return value
|
|
return value
|
|
-
|
|
|
|
# 读取数据
|
|
# 读取数据
|
|
def run_data_daochu():
|
|
def run_data_daochu():
|
|
- title_name =['id','标题','采购单位','中标单位','区域','flag_title','flag_buyer']
|
|
|
|
- mongo_list = ["id", "title", "buyer", "s_winner", "area",'flag_title','flag_buyer']
|
|
|
|
|
|
+ # title_name =['id','标题','项目名称','项目编号','采购单位','中标单位','中标金额','省','市','县','开标日期','原文地址','title_qa','projectname_qa',"region_qa","projectcode_qa","bidopentime_qa","budget_qa","bidamount_qa"]
|
|
|
|
+ # mongo_list = ["_id", "title", "projectname","projectcode","buyer","s_winner", "bidamount","area","city","district","bidopentime",'href','title_qa','projectname_qa','region_qa','projectcode_qa','bidopentime_qa','budget_qa','bidamount_qa']
|
|
|
|
+ # title_name = ['id', '标题', '项目名称', '项目编号', '采购单位', '中标单位', '中标金额', '省', '市', '县', '开标日期', '原文地址']
|
|
|
|
+ # mongo_list = ["_id", "title", "projectname", "projectcode", "buyer", "s_winner", "bidamount", "area", "city","district", "bidopentime", 'href']
|
|
|
|
+ title_name = ['id','得分']
|
|
|
|
+ mongo_list = ["id", 'score']
|
|
data_list_correct = []
|
|
data_list_correct = []
|
|
data_list_error =[]
|
|
data_list_error =[]
|
|
- for item in coll_user.find().batch_size(1000):
|
|
|
|
|
|
+ for item in coll_user.find():
|
|
|
|
+ # for item in coll_user.find({"_id": {"$in": [ObjectId("64dc46bfb44bf08751f1dc1a"), ObjectId("64dae31fb44bf08751ed9e59"), ObjectId("64d9df9ab44bf08751eb028b"), ObjectId("64f00847e2d7d34fa00d50eb")]}}):
|
|
info_temp = []
|
|
info_temp = []
|
|
|
|
+ #这个是遍历这条数据中要存的字段
|
|
for i in range(0, len(mongo_list)):
|
|
for i in range(0, len(mongo_list)):
|
|
info_temp.append(pankong(mongo_list[i],item))
|
|
info_temp.append(pankong(mongo_list[i],item))
|
|
- if item["flag_title"]==1 and item["flag_buyer"]==1:
|
|
|
|
- data_list_correct.append(info_temp)
|
|
|
|
- else:
|
|
|
|
- data_list_error.append(info_temp)
|
|
|
|
- writeExcel("output_correct.xlsx", "统计详情", title_name, data_list_correct)
|
|
|
|
|
|
+ # if item["title_qa"] or item["projectname_qa"]or item["region_qa"]or item["projectcode_qa"]or item["bidopentime_qa"]or item["budget_qa"]or item["bidamount_qa"]:
|
|
|
|
+ #是你所有要写入的数据
|
|
|
|
+ # if "flag" in item and item["flag"] == 1 :
|
|
|
|
+ data_list_error.append(info_temp)
|
|
|
|
+ # else:
|
|
|
|
+ # data_list_correct.append(info_temp)
|
|
|
|
+ # print(data_list_error)
|
|
writeExcel("output_error.xlsx", "统计详情", title_name, data_list_error)
|
|
writeExcel("output_error.xlsx", "统计详情", title_name, data_list_error)
|
|
|
|
+ # writeExcel("output_error.xlsx", "统计详情", title_name, data_list_error)
|
|
run_data_daochu()
|
|
run_data_daochu()
|