添加楼盘评级算法
This commit is contained in:
@@ -7,6 +7,7 @@ import pandas as pd
|
|||||||
from goojia_utils import MAIN_MONGO_CLIENT
|
from goojia_utils import MAIN_MONGO_CLIENT
|
||||||
from goojia_utils import dateutils
|
from goojia_utils import dateutils
|
||||||
from sklearn.mixture import GaussianMixture
|
from sklearn.mixture import GaussianMixture
|
||||||
|
from pymongo import InsertOne, DeleteMany, ReplaceOne, UpdateOne
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -33,18 +34,9 @@ for server_area in server_area_conn.find({'display': {'$ne': '全国'}}, {"displ
|
|||||||
data["community_rating"] = data['target'].apply(lambda x: level_map[str(x)])
|
data["community_rating"] = data['target'].apply(lambda x: level_map[str(x)])
|
||||||
opts = []
|
opts = []
|
||||||
for item in data.to_dict('records'):
|
for item in data.to_dict('records'):
|
||||||
opts.append({
|
opts.append(UpdateOne({"city": city, "region": item["region"], "district_name": item["district_name"]},
|
||||||
"updateOne": {
|
{"$set": {"community_rating": item["community_rating"]}}, upsert=True
|
||||||
"filter": {"city": city, "region": item["region"], "district_name": item["district_name"]},
|
))
|
||||||
"update": {"$set": {"community_rating": item["community_rating"]}}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
print({
|
|
||||||
"updateOne": {
|
|
||||||
"filter": {"city": city, "region": item["region"], "district_name": item["district_name"]},
|
|
||||||
"update": {"$set": {"community_rating": item["community_rating"]}}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
# 按照每 1000 条分割 updates 列表
|
# 按照每 1000 条分割 updates 列表
|
||||||
batch_size = 1000
|
batch_size = 1000
|
||||||
batches = [opts[i:i + batch_size] for i in range(0, len(opts), batch_size)]
|
batches = [opts[i:i + batch_size] for i in range(0, len(opts), batch_size)]
|
||||||
|
|||||||
Reference in New Issue
Block a user