新文件: feature/__init__.py

新文件:   feature/region_feature.py
This commit is contained in:
罗干
2018-04-24 17:23:22 +08:00
parent ad8a960049
commit 111da4aade
12 changed files with 865 additions and 189 deletions
+177 -113
View File
@@ -29,7 +29,7 @@ import datetime
import config
from fangjia import timer
import fix
import time
# import yesterday
@@ -549,12 +549,12 @@ def commonprice(ct, rl, p):
#return '纬度数据有误,有多个经纬度', 0
else:
# t1=time.time()
t1=time.time()
#####print("location['lng2'][0]",location['lng2'].iloc[0])
dd = neighbor(location['lng2'].iloc[0], location['lat2'].iloc[0], 5, ct, rl, p)
# ####print(time.time()-t1,'t1'*10)
print(time.time()-t1,'t1'*10)
# print('dd=',dd,'dd'*20)
if dd.shape[0] >= factor:
# ####print('$'*50)
@@ -593,9 +593,9 @@ def commonprice(ct, rl, p):
else:
dd6 = neighbor_km(location['lng2'].iloc[0], location['lat2'].iloc[0], 10, ct, rl, p)
# ####print('dd2=',dd2,'@'*60)
if dd6.shape[0] >= 20:
dd6 = neighbor_km(location['lng2'].iloc[0], location['lat2'].iloc[0], 20, ct, rl, p)
#print('dd2=',dd2,'@'*60)
if dd6.shape[0] >= 3:
# svr_time=time.time()
other1 = svr(dd6, lk)
@@ -1006,58 +1006,8 @@ def commonprice(ct, rl, p):
dg22 = middle_operate(junjia_lzf, junjia_anst)
return junjia_max(mmax,dg22)
lk = p[0]
location = take_location(ct, rl, p)
#####print('location',location)
# ttp=time.time()
neighb = no_source_price(ct, rl, location, p)
# ####print(time.time()-ttp,'m'*20)
junjia = dsfjujia(ct, rl, lk)
print('junjia=',junjia)
print('neighb=',neighb)
'''
dglg=dsplg(junjia,neighb,2)
dggg=dsplg(junjia,neighb,1)
'''
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
u=list(b-a)
if len(c) == 2 and len(junjia)>2:
gj=junjia['ganji_esf_price']
ajk=junjia['anjuke_esf_price']
ratio=abs((gj-ajk)/min(gj,ajk))
other=junjia[u[0]]
ott=(other-max(gj,ajk))/min(gj,ajk)
if ratio<0.1 and ott>0.3:
return junjia.drop('ganji_esf_price')
else:
return junjia
else:
return junjia
judp=drop_ganji(junjia)
dglg = dglg_out1(judp, neighb[0])
#print('dglg=',dglg)
# dggg=dglg_out1(junjia,neighb[0])
# ###print('dglg=',dglg)
# ####print('dggg=',dggg)
#tt=time.time()
data = consider_villa(ct, rl, p)
#data.to_excel('data.xls')
def add_weight(s1):
choose_columns=['url','area', 'district_name', 'name', 'p_date', 'region',
@@ -1092,6 +1042,60 @@ def commonprice(ct, rl, p):
else:
return s1
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
u=list(b-a)
if len(c) == 2 and len(junjia)>2:
gj=junjia['ganji_esf_price']
ajk=junjia['anjuke_esf_price']
ratio=abs((gj-ajk)/min(gj,ajk))
other=junjia[u[0]]
ott=(other-max(gj,ajk))/min(gj,ajk)
if ratio<0.1 and ott>0.3:
return junjia.drop('ganji_esf_price')
else:
return junjia
else:
return junjia
lk = p[0]
location = take_location(ct, rl, p)
#####print('location',location)
# ttp=time.time()
neighb = no_source_price(ct, rl, location, p)
# ####print(time.time()-ttp,'m'*20)
junjia = dsfjujia(ct, rl, lk)
#print('junjia=',junjia)
print('neighb=',neighb)
'''
dglg=dsplg(junjia,neighb,2)
dggg=dsplg(junjia,neighb,1)
'''
judp=drop_ganji(junjia)
dglg = dglg_out1(judp, neighb[0])
print('dglg=',dglg)
# dggg=dglg_out1(junjia,neighb[0])
# ###print('dglg=',dglg)
# ####print('dggg=',dggg)
#tt=time.time()
data = consider_villa(ct, rl, p)
#data.to_excel('data.xls')
#data.to_excel('ddw.xls')
##print(time.time()-tt,'<>'*26)
#######################################################
@@ -1114,13 +1118,24 @@ def commonprice(ct, rl, p):
#print(type(ppd1['area'][1]))
#ppd1[['total_price','area']].to_excel('ppd1.xls')
ppd1['total_price'] = ppd1['total_price'] / ppd1['area']
# ####print('ppd1time',time.time()-t3,'o'*36)
# ppd1.loc['total_price']=ppd1['total_price']/ppd1['area']
# ppd2=ppd1
# if type(neighb) is not str:
def take_region_price(ct,rl):
def before_step_time(day):
now = datetime.datetime.now()
front = now - datetime.timedelta(days=day)
return front
aaw=before_step_time(14)
query1 = {"city": ct, "region": rl,'weekend':{'$gt':aaw}}
lf = fangjia.find_region_price(query1)
#print('lf================',lf)
if lf.shape[0]>0:
return lf['calc_value'].iloc[-1]
else:
return -1
if ppd1.shape[0] > 0:
@@ -1129,7 +1144,12 @@ def commonprice(ct, rl, p):
ph = ppd2[ppd2['total_price'] > 0.7 * neighb]
return ph
else:
return ppd2
sss=take_region_price(ct,rl)
if sss>0:
ph1 = ppd2[ppd2['total_price'] > 0.5 *sss]
return ph1
else:
return ppd2
# ppd3=ppd2[ppd2['total_price']>0.6*neighb]
@@ -1159,17 +1179,19 @@ def commonprice(ct, rl, p):
length = len(l_and_z)
length1 = len(allf)
#print('#########')
#a=datetime.datetime.now()
#timeArray = a.strftime("%Y%m%d")
#print('timeArray=',timeArray)
#front_step_time(360)
def ss1(junjia,dglg,ppd3):
sample_size = len(junjia)
if dglg != None:
# ####print('junjia.shape',len(junjia))
dglg_dd=ppd3[(ppd3['total_price']>0.85*dglg) & (ppd3['total_price']<1.2*dglg)]
#dglg_dd.to_excel('dglg_dd.xls')
##print(dglg_dd)
#print(dglg_dd['p_date'])
if dglg_dd.shape[0]>2:
dglg1= k_means_clus(dglg_dd['total_price'].dropna(),3)
@@ -1178,8 +1200,44 @@ def commonprice(ct, rl, p):
return dglg,float('%.2f' % credit['0.85']), value_type['第三方'], sample_size
else:
return 0,float('%.2f' % credit['0.85']), value_type['第三方'], sample_size
dggg=ss1(junjia,dglg,ppd3)
def consider_time_ss1(junjia,dglg,ppd3,day):
sample_size = len(junjia)
if dglg != None:
# ####print('junjia.shape',len(junjia))
dglg_dd=ppd3[(ppd3['total_price']>0.85*dglg) & (ppd3['total_price']<1.2*dglg)]
#dglg_dd.to_excel('dglg_dd.xls')
#print(dglg_dd[['p_date','total_price','url']])
dglg_dd=dglg_dd[dglg_dd['p_date']>=day]
if dglg_dd.shape[0]>2:
dglg1= k_means_clus(dglg_dd['total_price'].dropna(),3)
return dglg1, float('%.2f' % credit['0.85']), value_type['第三方'], sample_size
else:
return -2, float('%.2f' % credit['0.85']), value_type['第三方'], sample_size
else:
return -2,float('%.2f' % credit['0.85']), value_type['第三方'], sample_size
def map_time_price(junjia,dglg,ppd3):
day_15=front_step_time(15)
day_30=front_step_time(30)
day_60=front_step_time(60)
price_15= consider_time_ss1(junjia,dglg,ppd3,day_15)
price_30= consider_time_ss1(junjia,dglg,ppd3,day_30)
price_60= consider_time_ss1(junjia,dglg,ppd3,day_60)
if price_15[0]>0:
print('first_15')
return price_15
elif price_30[0]>0:
print('first_30')
return price_30
elif price_60[0]>0:
print('first_60')
return price_60
else:
return ss1(junjia,dglg,ppd3)
dggg=map_time_price(junjia,dglg,ppd3)
if dggg[0]>0 :
return dggg
@@ -1201,14 +1259,7 @@ def commonprice(ct, rl, p):
return int(gm), float('%.2f' % credit['0.8']), value_type['自身样本'], sample_size # 优质样本
elif data.shape[0] > 0:
#####print('诸葛找房算法')
#####print('neighb',neighb)
# from zhuge import zhuge_consist
data['avg'] = data['total_price'] / data['area']
def guolv_data11(data, neighb):
@@ -1218,19 +1269,19 @@ def commonprice(ct, rl, p):
ddd11 = data[data['avg'] > 0.7 * neighb]
return ddd11
else:
return data
sss=take_region_price(ct,rl)
if sss>0:
ddd22 = data[data['avg'] > 0.5 * sss]
return ddd22
else:
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)
# ####print('s1=',s1)
# s2 = set(s1)
# ####print('s2=',s2)
if ddd11.shape[0] > 3:
from zhuge import zhuge_consist
@@ -1243,10 +1294,10 @@ def commonprice(ct, rl, p):
#cc1 = ddd11['avg'].dropna()
# ####print('cc1=',cc1)
#print(ppd3['total_price'],'ppppppppppppppp')
kmzhuge = k_means_clus(ppd3['total_price'], 3)
#print(ppd3['total_price'])
junjia['zhuge_logic'] = s
junjia['zhuge_logic'] = kmzhuge
junjia['kmzg'] = kmzhuge
@@ -1277,15 +1328,7 @@ def commonprice(ct, rl, p):
return junjia
junjia1 = drop_ganji(junjia)
#####print('ddd11',ddd11)
#print(junjia1)
#print(junjia_front)
#####print('junjia_ganji=',junjia1,'$'*100)
cc = group(junjia_front, junjia1, 1,10)
# junjia_km=k_means(junjia)
#print('cc=',cc)
############
if len(cc) > 0:
cc1 = pandas.DataFrame(cc, columns=['price', 'count'])
cc2 = cc1.sort_values(by='count', ascending=False)
@@ -1293,18 +1336,22 @@ def commonprice(ct, rl, p):
def two_one_choose(cc2):
qwrt=set(cc2['count'])
if len(qwrt)==1:
if len(qwrt)>1:
return cc2['price'].iloc[0]
else :
return junjia['kmzg']
else:
return junjia['zhuge_logic']
sample_size = ddd11.shape[0]
return two_one_choose(cc2) * 1.0, float('%.2f' % credit['0.7']), value_type[
'第三方'], sample_size
else:
#print('777777')
sample_size = ddd11.shape[0]
#print('junjia=',junjia)
return junjia['kmzg'] * 1.0, float('%.2f' % credit['0.6']), value_type[
'自身样本'], sample_size
#print('ddd11=',ddd11)
junjia_km = compelex(ddd11, s, neighb[0], junjia)
return junjia_km
@@ -1317,6 +1364,8 @@ def commonprice(ct, rl, p):
cc1 = ddd11['avg'].dropna()
kmzhuge = k_means_clus(cc1, 2)
sample_size = ddd11.shape[0]
#print('#########')
return kmzhuge, float('%.2f' % credit['0.6']), value_type['自身样本'], sample_size
else:
return neighb[0], float('%.2f' % credit['0.5']), value_type['周边楼盘'], neighb[1]
@@ -1327,6 +1376,10 @@ def commonprice(ct, rl, p):
return dglg, float('%.2f' % credit['0.8']), value_type['第三方'], sample_size # '优质样本'
else:
#print('lgggggg=')
#print('neighb[0]=',neighb[0])
return neighb[0], float('%.2f' % credit['0.5']), value_type['周边楼盘'], neighb[1]
elif dglg != None:
@@ -1357,9 +1410,6 @@ def commonprice(ct, rl, p):
else:
# ####print('*'*100)
# ####print(neighb)
return neighb[0], float('%.2f' % credit['0.5']), value_type['周边楼盘'], neighb[1]
@@ -1379,10 +1429,12 @@ def ghhh(kkg):
return a
stat = fangjia.get_collection("fangjia", "district_stat", config.get_district_stat_host(), config.get_district_stat_port())
pt = fangjia.get_collection("fangjia_log", "problem_command", config.get_log_mongodb_host(), config.get_log_mongodb_port())
#stat = fangjia.get_collection("fangjia", "changzhou_6", config.get_district_stat_host(), config.get_district_stat_port())
#stat = fangjia.get_collection("fangjia", "district_stat", config.get_district_stat_host(), config.get_district_stat_port())
#pt = fangjia.get_collection("fangjia_log", "problem_command", config.get_log_mongodb_host(), config.get_log_mongodb_port())
#stat = fangjia.get_collection("fangjia", "Copy_of_district_stat_shanghai_april_ten", '192.168.10.182', 27017)
stat = fangjia.get_collection("fangjia_stat", "shanghai0419", '192.168.10.182', 27017)
pt = fangjia.get_collection("fangjia_log", "problem_command", '192.168.10.182', 27017)
#################################################################
def region_district_list_lk(ct, rl, lk):
@@ -1420,7 +1472,7 @@ def last_sunday(weekend):
def make_up_price(ct, rl, lk, weekend):
####print('lg=',ct,rl,lk)
# last_sunday=last_sunday(weekend)
# last_sunday=last_sunday(weekend)南湖国际中心二期
# save_lg=client136.fangjia.district_stat
if lk != None:
@@ -1505,13 +1557,13 @@ def pt_down(ct,rl,p,weekend,c_date,cmd_estate_type,mm):
)
@timer
def stat_save(ct, rl, p, weekend, mm, c_date, m_date, make_up, estate_type):
def stat_save(ct, rl, p, weekend, mm, c_date, m_date, make_up, estate_type,avg):
stat.replace_one(
{"city": ct, "region": rl, "district_name": p[0], "weekend": weekend},
{"city": ct, "region": rl, "district_name": p[0], 'credit': mm[1],
"calc_value": int(mm[0]), "weekend": weekend, "c_date": c_date, 'avg_price':int(mm[0]),
"calc_value": int(mm[0]), "weekend": weekend, "c_date": c_date, 'avg_price':int(avg),
"m_date": m_date, 'value_type': int(mm[2]), 'weekend_markup': make_up,
'changed_markup': make_up, 'markup': make_up, 'sample_size': mm[3],
'estate_type': estate_type}, True
@@ -1533,6 +1585,7 @@ def pt_up(ct, rl, p, weekend, c_date, cmd_estate_type):
@timer
def out_put_price(ct, rl, lk, weekend):
lf = region_district_list_lk(ct, rl, lk)
if lf.shape[0]>0:
lf = add_alias(lf)
p = ghhh(lf[['name', 'alias', 'estate_type2']])[0]
@@ -1555,7 +1608,7 @@ def out_put_price(ct, rl, lk, weekend):
##print(type(mm[0]))
if type(mm[0]) != str:
print(ct, rl, lk, mm, '$' * 20)
# ####print(lf['estate_type2'].iloc[0],'*'*10)
@@ -1580,13 +1633,24 @@ def out_put_price(ct, rl, lk, weekend):
#####print('make_up',make_up,'*'*20)
#####print('credic',mm[1])
#avg=fix.price_fix.update(ct,rl,lk,int(mm[0]))
###print('avg_price=',avg)
def avg_compare(ct,rl,lk,mm):
avg=fix.price_fix.update(ct,rl,lk,int(mm[0]))
#print('nihe=',avg)
#print('mm[0]',mm[0])
if avg>0:
return avg
else:
return int(mm[0])
#s1=time.time()
avg=avg_compare(ct,rl,lk,mm)
#print('s1_time=',time.time()-s1)
#avg=mm[0]
print('mm=',mm)
print(ct, rl, lk, avg, 'avg=',avg,'$' * 20)
try:
stat_save(ct,rl,p,weekend,mm,c_date,m_date,make_up,estate_type)
stat_save(ct,rl,p,weekend,mm,c_date,m_date,make_up,estate_type,avg)
pt_up(ct,rl,p,weekend,c_date,cmd_estate_type)
'''
@@ -1616,7 +1680,7 @@ def out_put_price(ct, rl, lk, weekend):
except:
stat_save(ct,rl,p,weekend,mm,c_date,m_date,make_up,estate_type)
stat_save(ct,rl,p,weekend,mm,c_date,m_date,make_up,estate_type,avg)