fix bug
This commit is contained in:
@@ -18,7 +18,8 @@ import pymongo
|
|||||||
import sklearn.cluster
|
import sklearn.cluster
|
||||||
import pandas
|
import pandas
|
||||||
import numpy
|
import numpy
|
||||||
import sys, time
|
import sys
|
||||||
|
import time
|
||||||
#import pp
|
#import pp
|
||||||
import fangjia
|
import fangjia
|
||||||
import datetime
|
import datetime
|
||||||
@@ -35,6 +36,53 @@ import pandas as pd
|
|||||||
import calendar
|
import calendar
|
||||||
|
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
from elasticsearch import Elasticsearch, helpers
|
||||||
|
client_DB_es = Elasticsearch('192.168.0.206', port=9200, timeout=1000, http_auth=(
|
||||||
|
'developer', '5e8edd851d2fdfbd7415232c67367cc3'))
|
||||||
|
ES_db_index = "seawater-2018,seawater-2017,seawater-2016"
|
||||||
|
|
||||||
|
|
||||||
|
def findHouse_region(ct, rl, timd, timm, fields):
|
||||||
|
# local_switch and select_content are not applied in this function
|
||||||
|
|
||||||
|
# query = {"city": ct, "cat": "rent", "region": rl, # 'rent_type':'整租',
|
||||||
|
# "district_name": {"$in": lk},
|
||||||
|
# "p_date": {"$gt": timd, "$lt": timm}}
|
||||||
|
city = ct
|
||||||
|
region = rl
|
||||||
|
# district_name = lk[0]
|
||||||
|
# name_pack = findquery_statement['name_pack']
|
||||||
|
query_list =client_DB_es.search(
|
||||||
|
index=ES_db_index,
|
||||||
|
scroll='20m',
|
||||||
|
size=100,
|
||||||
|
doc_type="_doc",
|
||||||
|
_source = fields,
|
||||||
|
body={
|
||||||
|
"query":
|
||||||
|
{"bool":
|
||||||
|
{"must":
|
||||||
|
[{"term": {"cat": "rent"}},
|
||||||
|
{"term": {"city": city}},
|
||||||
|
{"term": {"region": region}},
|
||||||
|
# {"term": {"district_name": district_name}},
|
||||||
|
#{"terms": {"district_name": lk}},
|
||||||
|
# {"terms": {"district_name": ["新泾三村", "新泾四村"]}},
|
||||||
|
{"range": {"p_date": {
|
||||||
|
"gte": timd, "lte": timm}}}
|
||||||
|
], "must_not": [], "should": []
|
||||||
|
}
|
||||||
|
}, "from": 0, "size": 100, "sort": [], "aggs": {}}
|
||||||
|
)
|
||||||
|
|
||||||
|
query_list_raw = query_list['hits']['hits']
|
||||||
|
query_pack = []
|
||||||
|
for singlequery in query_list_raw:
|
||||||
|
query_pack.append(singlequery['_source'])
|
||||||
|
return pd.DataFrame(query_pack)
|
||||||
|
|
||||||
|
|
||||||
def ghhh(kkg): # 555555555555555555555555555
|
def ghhh(kkg): # 555555555555555555555555555
|
||||||
kkg = kkg.fillna('无')
|
kkg = kkg.fillna('无')
|
||||||
a = list()
|
a = list()
|
||||||
@@ -44,8 +92,6 @@ def ghhh(kkg): #555555555555555555555555555
|
|||||||
return a
|
return a
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
def f_del(qq,g):
|
def f_del(qq,g):
|
||||||
|
|
||||||
@@ -58,21 +104,26 @@ def f_del(qq,g):
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
def sample_pool(ct, rl, timd, timm):
|
def sample_pool(ct, rl, timd, timm):
|
||||||
|
|
||||||
query = {"city": ct, "cat": "rent", "region": rl,
|
query = {"city": ct, "cat": "rent", "region": rl,
|
||||||
"p_date": {"$gt": timd, "$lt": timm}}
|
"p_date": {"$gt": timd, "$lt": timm}}
|
||||||
# query=f_del(query,rl)
|
# query=f_del(query,rl)
|
||||||
|
|
||||||
fields = {"total_price":1,"area":1, "city":1,"region":1,'p_date':1,
|
# fields = {"total_price":1,"area":1, "city":1,"region":1,'p_date':1,
|
||||||
"district_name":1,"rent_type":1,"fitment":1,"block":1}
|
# "district_name":1,"rent_type":1,"fitment":1,"block":1}
|
||||||
|
fields = ["total_price", "area", "city", "region", "p_date",
|
||||||
|
"district_name", "rent_type", "fitment", "block"]
|
||||||
#lt= seawater.count(query)
|
#lt= seawater.count(query)
|
||||||
####print(lt)
|
# print(lt)
|
||||||
#pos = list()
|
#pos = list()
|
||||||
# for s in seawater.find(query,fields1).skip(10000).limit(lt):
|
# for s in seawater.find(query,fields1).skip(10000).limit(lt):
|
||||||
|
|
||||||
# print('query=',query)
|
# print('query=',query)
|
||||||
return fangjia.rent_sample(query, fields)
|
# return fangjia.rent_sample(query, fields)
|
||||||
|
return findHouse_region(ct, rl, timd, timm, fields)
|
||||||
|
|
||||||
|
|
||||||
def k_means(pp):
|
def k_means(pp):
|
||||||
from sklearn.cluster import KMeans
|
from sklearn.cluster import KMeans
|
||||||
@@ -95,8 +146,6 @@ def k_means(pp):
|
|||||||
return (round(center, 2))
|
return (round(center, 2))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_weekend():
|
def get_weekend():
|
||||||
|
|
||||||
#from dateutil.parser import parse
|
#from dateutil.parser import parse
|
||||||
@@ -107,7 +156,6 @@ def get_weekend():
|
|||||||
return pacific.localize(before_time)
|
return pacific.localize(before_time)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def disanganf_price(ct, rl, lk, timd, timm):
|
def disanganf_price(ct, rl, lk, timd, timm):
|
||||||
|
|
||||||
fields = {'calc_value': 1, 'weekend': 1, 'district_name': 1}
|
fields = {'calc_value': 1, 'weekend': 1, 'district_name': 1}
|
||||||
@@ -119,28 +167,24 @@ def disanganf_price(ct,rl,lk,timd,timm):
|
|||||||
return fangjia.rent_disanganf_series(query, fields)
|
return fangjia.rent_disanganf_series(query, fields)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def rent_partial_sell(ct, rl, timd, timm):
|
def rent_partial_sell(ct, rl, timd, timm):
|
||||||
|
|
||||||
rele0 = sample_pool(ct, rl, timd, timm)
|
rele0 = sample_pool(ct, rl, timd, timm)
|
||||||
##print('rele0=',rele0)
|
# print('rele0=',rele0)
|
||||||
|
|
||||||
if rele0.shape[0] > 0:
|
if rele0.shape[0] > 0:
|
||||||
|
|
||||||
|
|
||||||
rele1 = rele0[['district_name', 'p_date', 'area', 'total_price']]
|
rele1 = rele0[['district_name', 'p_date', 'area', 'total_price']]
|
||||||
rele1['total_price'] = rele1['total_price'] / rele1['area']
|
rele1['total_price'] = rele1['total_price'] / rele1['area']
|
||||||
##print('up_rele.shape[0]=',rele1.shape[0])
|
# print('up_rele.shape[0]=',rele1.shape[0])
|
||||||
|
|
||||||
|
|
||||||
rele = rele0.drop_duplicates(['district_name'])
|
rele = rele0.drop_duplicates(['district_name'])
|
||||||
p1 = rele['district_name'].dropna()
|
p1 = rele['district_name'].dropna()
|
||||||
p2 = list(set(p1))
|
p2 = list(set(p1))
|
||||||
# print('p2=',p2)
|
# print('p2=',p2)
|
||||||
####print('*****************************************************************')
|
# print('*****************************************************************')
|
||||||
dd = disanganf_price(ct, rl, p2, timd, timm)
|
dd = disanganf_price(ct, rl, p2, timd, timm)
|
||||||
##print('rele.shape[0]=',rele.shape[0])
|
# print('rele.shape[0]=',rele.shape[0])
|
||||||
|
|
||||||
# print('dd=',dd)
|
# print('dd=',dd)
|
||||||
|
|
||||||
@@ -149,7 +193,8 @@ def rent_partial_sell(ct,rl,timd,timm):
|
|||||||
rele['total_price'] = rele['total_price'] / rele['area']
|
rele['total_price'] = rele['total_price'] / rele['area']
|
||||||
# rent_most=k_means(rele['total_price'])
|
# rent_most=k_means(rele['total_price'])
|
||||||
rele['sell_rent_ratio'] = 1
|
rele['sell_rent_ratio'] = 1
|
||||||
rv=rele[['total_price','district_name','area','sell_rent_ratio']].dropna()
|
rv = rele[['total_price', 'district_name',
|
||||||
|
'area', 'sell_rent_ratio']].dropna()
|
||||||
rv1 = rv.values
|
rv1 = rv.values
|
||||||
ro = []
|
ro = []
|
||||||
sell_rent_ratio = []
|
sell_rent_ratio = []
|
||||||
@@ -166,7 +211,7 @@ def rent_partial_sell(ct,rl,timd,timm):
|
|||||||
ppoo = sell / price
|
ppoo = sell / price
|
||||||
sell_rent_ratio.append(ppoo)
|
sell_rent_ratio.append(ppoo)
|
||||||
# rv1[k][3]=sell/price
|
# rv1[k][3]=sell/price
|
||||||
##print('rele0=',rele)
|
# print('rele0=',rele)
|
||||||
rent_most = k_means(pandas.Series(ro))
|
rent_most = k_means(pandas.Series(ro))
|
||||||
# rele=pd.DataFrame(rv1,columns=rv.columns)
|
# rele=pd.DataFrame(rv1,columns=rv.columns)
|
||||||
roseries = pandas.Series(sell_rent_ratio)
|
roseries = pandas.Series(sell_rent_ratio)
|
||||||
@@ -174,10 +219,10 @@ def rent_partial_sell(ct,rl,timd,timm):
|
|||||||
roseries = roseries[roseries > 5]
|
roseries = roseries[roseries > 5]
|
||||||
|
|
||||||
# rele=rele[rele['sell_rent_ratio']>5]
|
# rele=rele[rele['sell_rent_ratio']>5]
|
||||||
###print('sell_rent_ratio=',list(rele['sell_rent_ratio'])[:5])
|
# print('sell_rent_ratio=',list(rele['sell_rent_ratio'])[:5])
|
||||||
###print(rele)
|
# print(rele)
|
||||||
###print('#######################')
|
# print('#######################')
|
||||||
###print(rele.shape[0])
|
# print(rele.shape[0])
|
||||||
|
|
||||||
# print('len(roseries)=',len(roseries))
|
# print('len(roseries)=',len(roseries))
|
||||||
|
|
||||||
@@ -186,8 +231,8 @@ def rent_partial_sell(ct,rl,timd,timm):
|
|||||||
|
|
||||||
# rent_most=k_means(rele['total_price'])
|
# rent_most=k_means(rele['total_price'])
|
||||||
|
|
||||||
###print('rele.shape[0]=',rele.shape[0])
|
# print('rele.shape[0]=',rele.shape[0])
|
||||||
##print('yyyyyyyyyyyyyyyyyyyyyy=',len(roseries))
|
# print('yyyyyyyyyyyyyyyyyyyyyy=',len(roseries))
|
||||||
rent_sell = k_means(roseries.dropna())
|
rent_sell = k_means(roseries.dropna())
|
||||||
|
|
||||||
del rele
|
del rele
|
||||||
@@ -204,12 +249,12 @@ def rent_partial_sell(ct,rl,timd,timm):
|
|||||||
|
|
||||||
def dff(i, j, timd, timm): # 666666666666666666666666666666666666666666666666666666
|
def dff(i, j, timd, timm): # 666666666666666666666666666666666666666666666666666666
|
||||||
reef = rent_partial_sell(i, j, timd, timm)
|
reef = rent_partial_sell(i, j, timd, timm)
|
||||||
###print('$$$$$$$$$$')
|
# print('$$$$$$$$$$')
|
||||||
|
|
||||||
if reef[0] > 0:
|
if reef[0] > 0:
|
||||||
return reef
|
return reef
|
||||||
else:
|
else:
|
||||||
###print('&&&&&&&&&&&&&')
|
# print('&&&&&&&&&&&&&')
|
||||||
return rent_partial_sell(i, None, timd, timm)
|
return rent_partial_sell(i, None, timd, timm)
|
||||||
|
|
||||||
|
|
||||||
@@ -220,7 +265,6 @@ def add_eatype(ppd):
|
|||||||
return ppd
|
return ppd
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def timestamp_to_int(dd):
|
def timestamp_to_int(dd):
|
||||||
|
|
||||||
dd['week1'] = 1
|
dd['week1'] = 1
|
||||||
@@ -231,7 +275,7 @@ def timestamp_to_int(dd):
|
|||||||
f2 = re.sub("\D", "", f1)
|
f2 = re.sub("\D", "", f1)
|
||||||
f3 = int(f2)
|
f3 = int(f2)
|
||||||
dd['week1'][i] = f3
|
dd['week1'][i] = f3
|
||||||
####print(dd)
|
# print(dd)
|
||||||
return dd
|
return dd
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@@ -285,16 +329,18 @@ def before_month_lastday(ti,num):
|
|||||||
|
|
||||||
def region_make_up_price(ct, rl, lk, ti):
|
def region_make_up_price(ct, rl, lk, ti):
|
||||||
|
|
||||||
lgg=fangjia.get_collection("fangjia",config.get_sqm_rentprice_db(), config.get_mongodb_host(),27017)
|
lgg = fangjia.get_collection(
|
||||||
|
"fangjia", config.get_sqm_rentprice_db(), config.get_mongodb_host(), 27017)
|
||||||
# save_lg=client136.fangjia_stat.test_lg5
|
# save_lg=client136.fangjia_stat.test_lg5
|
||||||
|
|
||||||
cc = before_month_lastday(ti, 32)
|
cc = before_month_lastday(ti, 32)
|
||||||
##print('ti=',ti)
|
# print('ti=',ti)
|
||||||
##print('cc=',cc)
|
# print('cc=',cc)
|
||||||
|
|
||||||
#stat= fangjia.get_collection("fangjia_stat","test_lg5", '192.168.0.136',27017)
|
#stat= fangjia.get_collection("fangjia_stat","test_lg5", '192.168.0.136',27017)
|
||||||
stat = lgg
|
stat = lgg
|
||||||
query = {"city":ct,"region":rl,"cat":"region",'weekend':cc,'district_name':None}
|
query = {"city": ct, "region": rl, "cat": "region",
|
||||||
|
'weekend': cc, 'district_name': None}
|
||||||
|
|
||||||
pos1 = list(stat.find(query).sort([("weekend", -1)]).limit(3))
|
pos1 = list(stat.find(query).sort([("weekend", -1)]).limit(3))
|
||||||
|
|
||||||
@@ -303,14 +349,13 @@ def region_make_up_price(ct,rl,lk,ti):
|
|||||||
# pos=timestamp_to_int(pos)
|
# pos=timestamp_to_int(pos)
|
||||||
# pos=pos[pos['week1']>cc]
|
# pos=pos[pos['week1']>cc]
|
||||||
|
|
||||||
###print('5'*10)
|
# print('5'*10)
|
||||||
###print('uuuuuuuuuuuuuuuu=',pos)
|
# print('uuuuuuuuuuuuuuuu=',pos)
|
||||||
|
|
||||||
|
|
||||||
if pos.shape[0] >= 1:
|
if pos.shape[0] >= 1:
|
||||||
pos = pos.sort_values(by='weekend', ascending=False)
|
pos = pos.sort_values(by='weekend', ascending=False)
|
||||||
pp1 = pos['avg_price'].iloc[0]
|
pp1 = pos['avg_price'].iloc[0]
|
||||||
##print('pp1=',pp1)
|
# print('pp1=',pp1)
|
||||||
if type(pp1) != None and type(pp1) != str:
|
if type(pp1) != None and type(pp1) != str:
|
||||||
return pp1
|
return pp1
|
||||||
else:
|
else:
|
||||||
@@ -318,6 +363,7 @@ def region_make_up_price(ct,rl,lk,ti):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def return_operate(ppu, mm):
|
def return_operate(ppu, mm):
|
||||||
|
|
||||||
if ppu == None:
|
if ppu == None:
|
||||||
@@ -342,15 +388,14 @@ def before_month_lastday(ti):
|
|||||||
# dd1=sample_pool(ct,rl,timd,timm)
|
# dd1=sample_pool(ct,rl,timd,timm)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def save_region_feature(ct, rl, timd, timm):
|
def save_region_feature(ct, rl, timd, timm):
|
||||||
# a=time.time()
|
# a=time.time()
|
||||||
region_feature = dff(ct, rl, timd, timm)
|
region_feature = dff(ct, rl, timd, timm)
|
||||||
|
|
||||||
##print('region_feature=',region_feature)
|
# print('region_feature=',region_feature)
|
||||||
|
|
||||||
mmup = region_make_up_price(ct, rl, None, timm)
|
mmup = region_make_up_price(ct, rl, None, timm)
|
||||||
##print('mmup_region=',mmup)
|
# print('mmup_region=',mmup)
|
||||||
#print('this month region price',region_feature[1])
|
#print('this month region price',region_feature[1])
|
||||||
markup = return_operate(mmup, region_feature[1])
|
markup = return_operate(mmup, region_feature[1])
|
||||||
|
|
||||||
@@ -360,9 +405,6 @@ def save_region_feature(ct,rl,timd,timm):
|
|||||||
pacific = pytz.timezone('Asia/Shanghai')
|
pacific = pytz.timezone('Asia/Shanghai')
|
||||||
return pacific.localize(date1)
|
return pacific.localize(date1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_weekend(tt):
|
def get_weekend(tt):
|
||||||
|
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
@@ -370,7 +412,6 @@ def save_region_feature(ct,rl,timd,timm):
|
|||||||
pacific = pytz.timezone('Asia/Shanghai')
|
pacific = pytz.timezone('Asia/Shanghai')
|
||||||
return pacific.localize(bb)
|
return pacific.localize(bb)
|
||||||
|
|
||||||
|
|
||||||
def month_lastday(ti):
|
def month_lastday(ti):
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
today = dateutil.parser.parse(str(ti))
|
today = dateutil.parser.parse(str(ti))
|
||||||
@@ -395,20 +436,17 @@ def save_region_feature(ct,rl,timd,timm):
|
|||||||
return pacific.localize(bb)
|
return pacific.localize(bb)
|
||||||
|
|
||||||
timme = month_lastday(timm)
|
timme = month_lastday(timm)
|
||||||
###print('region_timme=',timme)
|
# print('region_timme=',timme)
|
||||||
|
|
||||||
|
|
||||||
#stat= fangjia.get_collection("fangjia_stat","test_lg5", '192.168.0.136',27017)
|
#stat= fangjia.get_collection("fangjia_stat","test_lg5", '192.168.0.136',27017)
|
||||||
###print("######################## ","ct=",ct,"rl=",rl,"makeup=",make_up)
|
# print("######################## ","ct=",ct,"rl=",rl,"makeup=",make_up)
|
||||||
|
|
||||||
|
|
||||||
#save_lg = fangjia.get_collection("fangjia_stat", "rent_1221", config.get_district_stat_host(), config.get_district_stat_port())
|
#save_lg = fangjia.get_collection("fangjia_stat", "rent_1221", config.get_district_stat_host(), config.get_district_stat_port())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
date = c_date()
|
date = c_date()
|
||||||
|
|
||||||
temp = fangjia.get_collection("fangjia",config.get_rent_temp_db(), '192.168.0.136',27017)
|
temp = fangjia.get_collection(
|
||||||
|
"fangjia", config.get_rent_temp_db(), '192.168.0.136', 27017)
|
||||||
|
|
||||||
temp.replace_one(
|
temp.replace_one(
|
||||||
|
|
||||||
@@ -423,7 +461,8 @@ def save_region_feature(ct,rl,timd,timm):
|
|||||||
|
|
||||||
if avg > 0:
|
if avg > 0:
|
||||||
avg = float(avg)
|
avg = float(avg)
|
||||||
save_lg = fangjia.get_collection("fangjia",config.get_sqm_rentprice_db(), config.get_mongodb_host(),27017)
|
save_lg = fangjia.get_collection(
|
||||||
|
"fangjia", config.get_sqm_rentprice_db(), config.get_mongodb_host(), 27017)
|
||||||
|
|
||||||
save_lg.replace_one(
|
save_lg.replace_one(
|
||||||
|
|
||||||
@@ -434,10 +473,6 @@ def save_region_feature(ct,rl,timd,timm):
|
|||||||
"avg_price": region_feature[1], "c_date": date, "weekend": timme, "cat": 'region'}, True
|
"avg_price": region_feature[1], "c_date": date, "weekend": timme, "cat": 'region'}, True
|
||||||
)
|
)
|
||||||
|
|
||||||
###print(time.time()-a)
|
# print(time.time()-a)
|
||||||
|
|
||||||
####print(len(disname),len(disname))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# print(len(disname),len(disname))
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ rl='闵行'
|
|||||||
lk='上海康城'#上海闵行闵浦新苑一村普陀曹杨一村上海北京东城左安漪园
|
lk='上海康城'#上海闵行闵浦新苑一村普陀曹杨一村上海北京东城左安漪园
|
||||||
#黄浦伯爵居静安泰安里长宁新泾北苑上海奉贤海岸景苑闵行陇兴别墅阳江雅苑养生城二期
|
#黄浦伯爵居静安泰安里长宁新泾北苑上海奉贤海岸景苑闵行陇兴别墅阳江雅苑养生城二期
|
||||||
|
|
||||||
timm=20180430
|
timm=20181130
|
||||||
timd=20170531
|
timd=20171130
|
||||||
a=time.time()
|
a=time.time()
|
||||||
rentPrice.save_to_mongo(ct,rl,lk,timd,timm)
|
rentPrice.save_to_mongo(ct,rl,lk,timd,timm)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user