liumiaomiao 5 сар өмнө
parent
commit
c92329ec28

+ 0 - 0
lib/learn


BIN
tools/从mongo库导出数据execl/output.xlsx


+ 0 - 0
tools/从excle导入mysql/File_import_mysql.py → tools/标准样本数据入库/File_import_mysql.py


+ 0 - 0
tools/读execl数据入mongo库/execl_into_mongo.py → tools/标准样本数据入库/execl_into_mongo.py


+ 50 - 0
tools/标准样本数据入库/样本分析数据入mongo库.py

@@ -0,0 +1,50 @@
+from bson import ObjectId  # 导入 ObjectId
+import pymysql
+from pymongo import MongoClient
+#连接正式环境mongo
+collection_bid = MongoClient(f'mongodb://{"viewdata"}:{"viewdata"}@{"127.0.0.1:27088"}/',
+                         unicode_decode_error_handler="ignore", directConnection=True)["qfw"]["bidding"]
+#连接测试环境mongo
+db = MongoClient('192.168.3.149', 27180, unicode_decode_error_handler="ignore").data_quality
+coll_user = db["standard_sample_data_all"]
+
+# 字段映射
+field_mapping = {
+    "toptype": "toptype_ai",
+    "subtype": "subtype_ai",
+    "area": "area_ai",
+    "city": "city_ai",
+    "buyer": "buyer_ai",
+    "projectname": "projectname_ai",
+    "projectcode": "projectcode_ai",
+    "budget": "budget_ai",
+    "s_winner": "s_winner_ai",
+    "bidamount": "bidamount_ai",
+    "multipackage": "multipackage_ai"
+}
+
+def main():
+    documents_local = coll_user.find()  # 如果需要按条件查询,可以修改此行
+
+    for doc_local in documents_local:
+        # 依据第二个数据源的文档ID来查找主数据源中的相关数据
+        object_id = doc_local["_id"]
+        mongo_data = collection_bid.find_one({"_id": object_id})
+        if not mongo_data:
+            continue
+        # 构造更新数据
+        update_fields = {field_mapping[key]: mongo_data.get(key, None) for key in field_mapping}
+
+        # 执行更新操作:更新 MongoDB 数据源中的文档
+        update_result = coll_user.update_one(
+            {"_id": doc_local["_id"]},  # 根据 _id 匹配文档
+            {"$set": update_fields}  # 更新字段
+        )
+        # 打印更新结果
+        if update_result.modified_count > 0:
+            print(f"Document {doc_local['_id']} updated.")
+        else:
+            print(f"Document {doc_local['_id']} not modified.")
+
+if __name__ == "__main__":
+    main()

+ 0 - 0
tools/标准样本数据入库/样本分析数据入mysql库.py