优化均价算法

This commit is contained in:
2018-03-09 17:34:54 +08:00
parent d94f79a570
commit 742bad7de9
3 changed files with 61 additions and 71 deletions
+6 -6
View File
@@ -63,7 +63,7 @@ def get_seawater_index_name(city, region):
return es.get_index_name(city, region)
@timer
def findHouse(query, fields=None):
# s = time.time()
seawater105 = get_collection("fangjia", "seawater", config.get_seawater_host(), 27777)
@@ -76,7 +76,7 @@ def findHouse(query, fields=None):
# print('flag1')
lt = 1000
# seawater.find(query,{"p_date":-1}).sort([("p_date",-1)])
pos = list(seawater105.find(query).limit(lt))
pos = list(seawater105.find(query, fields).limit(lt))
data = pandas.DataFrame(pos)
del pos
# print("==================>", time.time() - s)
@@ -91,8 +91,8 @@ def findHouse(query, fields=None):
raise Exception("样本查询失败!")
@timer
def find_house_from_elastic_search(city, region, alias, roots=None, pdate=None, cat="sell", limit=100):
def find_house_from_elastic_search(city, region, alias, roots=None, pdate=None, cat="sell", limit=1000):
index_name = get_seawater_index_name(city, region)
routing_set = [cat + "_" + city + "_" + region + "_" + alia for alia in alias]
@@ -132,7 +132,7 @@ def find_house_from_elastic_search(city, region, alias, roots=None, pdate=None,
return pandas.DataFrame([doc["_source"] for doc in response["hits"]["hits"]])
@timer
def find_sample_pool(query, fields=None):
# s = time.time()
seawater105 = get_collection("fangjia", "seawater", config.get_seawater_host(), 27777)
@@ -221,7 +221,7 @@ def dis_feature(query, fields=None):
raise Exception("yang ben cha xun shi bai1")
@timer
def find_seaweed(query, fields=None):
# dirlt=p[0]
+50 -52
View File
@@ -51,8 +51,6 @@ dsfjujia_time = front_step_time(430) // 100
# 存到数据库的日期
# date="2018-02-04"
############################################################
############################################################
@@ -65,7 +63,7 @@ value_type = pandas.Series([1, 2, 3, 4, 5, 6, 7],
# 1:指导价 2:自身样本 3:第三方 4:交易数据 5:周边楼盘, 6:推导
@timer
def commonprice(ct, rl, p):
def add_block(ppd):
if 'block' not in ppd.columns:
@@ -77,17 +75,18 @@ def commonprice(ct, rl, p):
ppd['room'] = 2
return ppd
@timer
def some_district_information(ct, rl, lk):
query = {"city": ct, "cat": "sell", "region": rl,
"district_name": {"$in": lk},
"p_date": {"$gt": some_district_information_time}}
#['total_price', 'area', 'region', 'district_name', 'url', 'block', 'p_date']
fields1 = {'total_price':1, 'area':1, 'region':1, 'district_name':1, 'url':1, 'p_date':1}
return fangjia.findHouse(query,fields1)
# ['total_price', 'area', 'region', 'district_name', 'url', 'block', 'p_date']
fields1 = {'total_price': 1, 'area': 1, 'region': 1, 'district_name': 1, 'url': 1, 'p_date': 1, "name": 1}
return fangjia.findHouse(query, fields1)
"""
return fangjia.find_house_from_elastic_search(ct, rl, lk,
"lianjia.com", some_district_information_time)
@@ -121,7 +120,7 @@ def commonprice(ct, rl, p):
return numpy.array([])
else:
return numpy.array([])
@timer
def take_location(ct, rl, p):
dirlt = p[0]
@@ -226,6 +225,7 @@ def commonprice(ct, rl, p):
aa.append(i)
return set(aa)
@timer
def new_data(ds):
bb = set(ds['name'])
bb1 = list(bb)
@@ -399,7 +399,7 @@ def commonprice(ct, rl, p):
else:
km = vv['price'].dropna()
return int(k_means(km))
@timer
def no_source_price(ct, rl, location, p):
lk = p[0]
hg = location.shape[0]
@@ -567,6 +567,7 @@ def commonprice(ct, rl, p):
return cc1
else:
return cc1
@timer
def consider_villa(ct, rl, p):
@@ -622,7 +623,6 @@ def commonprice(ct, rl, p):
return villa
@timer
def dsfjujia(ct, rl, lk):
query = {"city": ct, "region": rl,
@@ -788,7 +788,6 @@ def commonprice(ct, rl, p):
return lzf, anst
@timer
def dglg_out1(junjia, neighb):
"""
@@ -943,9 +942,9 @@ def commonprice(ct, rl, p):
elif data.shape[0] > 0:
print('诸葛找房算法')
#from zhuge import zhuge_consist
# from zhuge import zhuge_consist
data['avg'] = data['total_price'] / data['area']
@timer
def guolv_data11(data, neighb):
if type(neighb) is not str:
@@ -956,58 +955,57 @@ def commonprice(ct, rl, p):
return data
ddd11 = guolv_data11(data, neighb[0])
#print('ddd11=',ddd11)
# print('ddd11=',ddd11)
if ddd11.shape[0] > 2:
#s = zhuge_consist.url_lable(ddd11)
#s1 = zhuge_consist.drop_rubbish(s)
# s = zhuge_consist.url_lable(ddd11)
# s1 = zhuge_consist.drop_rubbish(s)
# print('s1=',s1)
#s2 = set(s1)
# s2 = set(s1)
# print('s2=',s2)
if ddd11.shape[0] > 3:
from zhuge import zhuge_consist
s = zhuge_consist.zhuge_out(ddd11,3,1)
#print('s=',s)
s = zhuge_consist.zhuge_out(ddd11, 3, 1)
# print('s=',s)
def compelex(ddd11, s, neighb, junjia):
#cc1 = ddd11['avg'].dropna()
#print('cc1=',cc1)
# cc1 = ddd11['avg'].dropna()
kmzhuge = zhuge_consist.zhuge_out(ddd11,3,0)
# print('cc1=',cc1)
kmzhuge = zhuge_consist.zhuge_out(ddd11, 3, 0)
junjia['zhuge_logic'] = s
junjia['kmzg'] = kmzhuge
if type(neighb) != str and (neighb) != None:
junjia['neighb'] = neighb
#print('junjia',junjia)
# print('junjia',junjia)
junjia_front = junjia[['zhuge_logic', 'kmzg']]
def drop_ganji(junjia):
a={'ganji_esf_price','anjuke_esf_price'}
#print('a=',a)
b=set(list(junjia.index))
#print('b=',b)
c=a & b
#print('c=',c)
if len(c)==2:
#print('o'*100)
a = {'ganji_esf_price', 'anjuke_esf_price'}
# print('a=',a)
b = set(list(junjia.index))
# print('b=',b)
c = a & b
# print('c=',c)
if len(c) == 2:
# print('o'*100)
return junjia.drop('ganji_esf_price')
else:
return junjia
junjia1=drop_ganji(junjia)
#print('junjia_ganji=',junjia1,'$'*100)
junjia1 = drop_ganji(junjia)
# print('junjia_ganji=',junjia1,'$'*100)
cc = group(junjia_front, junjia1, 1)
# junjia_km=k_means(junjia)
# print('cc=',cc)
@@ -1084,7 +1082,7 @@ dsf = db136.district_stat
# client136 = pymongo.MongoClient('192.168.0.136',27017)
# db136 = client136.fangjia
@timer
def region_district_list(ct, rl):
# import pandas
# client1 = pymongo.MongoClient('192.168.0.136',27017)
@@ -1130,13 +1128,13 @@ def region_list(city):
data = pandas.DataFrame(pos)
return data['name']
@timer
def add_alias(ppd):
if 'alias' not in ppd.columns:
ppd['alias'] = '无'
return ppd
@timer
def ghhh(kkg):
kkg = kkg.fillna('无')
a = list()
@@ -1154,7 +1152,7 @@ pt = client1.fangjia_log.calc_command
#################################################################
@timer
def region_district_list_lk(ct, rl, lk):
# import pandas
# client1 = pymongo.MongoClient('192.168.0.136',27017)
@@ -1257,14 +1255,14 @@ def make_up_price(ct, rl, lk, weekend):
# weekend=weekend00()
@fangjia.timer
@timer
def out_put_price(ct, rl, lk, weekend):
lf = region_district_list_lk(ct, rl, lk)
lf = add_alias(lf)
p = ghhh(lf[['name', 'alias', 'estate_type2']])[0]
print('p=',p)
print('p=', p)
mm = commonprice(ct, rl, p)
@@ -1315,7 +1313,7 @@ def out_put_price(ct, rl, lk, weekend):
{"city": ct, "region": rl, "district_name": p[0], "c_date": c_date, 'status': int(102),
'remark': 'week', 'category': 'sell', "calc_date": weekend, 'priority': int(0),
'problem': None, "calc_type" : int(0)
'problem': None, "calc_type": int(0)
}, True
)
@@ -1340,6 +1338,6 @@ def out_put_price(ct, rl, lk, weekend):
{"city": ct, "region": rl, "district_name": p[0], "c_date": c_date, 'status': int(3),
'remark': 'week', 'category': 'sell', "calc_date": weekend, 'priority': int(0),
'problem': mm[0], "calc_type" : int(0)
'problem': mm[0], "calc_type": int(0)
}, True
)
)
+5 -13
View File
@@ -4,20 +4,12 @@ import time
import sell_price.zhuge0118A as sellPrice
s = time.time()
#上海嘉定莱茵北郡
ct='上海'
rl='嘉定'
lk='莱茵北郡'
#上海闵行上海康城
ct = '上海'
rl = '嘉定'
lk = '莱茵北郡'
weekend = datetime.datetime.strptime("2018-03-11", "%Y-%m-%d")
sellPrice.out_put_price(ct, rl, lk, weekend)
for i in range(0, 100):
sellPrice.out_put_price(ct, rl, lk, weekend)
e = time.time()
print(e - s)