diff --git a/PriceSystem/sell_price/zhuge0118A.py b/PriceSystem/sell_price/zhuge0118A.py index 0276587..241617c 100644 --- a/PriceSystem/sell_price/zhuge0118A.py +++ b/PriceSystem/sell_price/zhuge0118A.py @@ -8,7 +8,7 @@ Created on Fri Sep 22 18:18:15 2017 特此鸣谢! """ -#导入相关的库 +# 导入相关的库 import os #####print(os.getcwd()) @@ -21,7 +21,7 @@ import numpy import numpy as np import time import fangjia -#svm向量回归用于计算无房源小区的房价 +# svm向量回归用于计算无房源小区的房价 import sklearn.svm import datetime import config @@ -29,20 +29,19 @@ from fangjia import timer import fix import time + # import yesterday -#本函数用于时间处理,即时间前推或后推处理,并且按照int类型输出 +# 本函数用于时间处理,即时间前推或后推处理,并且按照int类型输出 -def front_step_time(weekend,day): - #now = datetime.datetime.now() - now=weekend +def front_step_time(weekend, day): + # now = datetime.datetime.now() + now = weekend front = now - datetime.timedelta(days=day) d1 = front.strftime('%Y%m%d') return int(d1) - - ############################################################ ############################################################ # 存到数据库的日期 @@ -52,18 +51,19 @@ def front_step_time(weekend,day): ############################################################ ############################################################ -#均价的可信度定义 +# 均价的可信度定义 # 0.9表示人工指导价,本算法还未加入 -#0.88 当第三方价格样本量在5个及以上时,通过函数置换出的价格,由于由第三方均价所出的价格已经非常准确,避免不良房源的干扰,房源不参与计算 -#0.85 第三方均价可以置换出某个价格,并且参考房源所出的价格 -#0.80 采用链家和诸葛找房合并后的样本 -#0.75 未采用 -#0.7 同时参考样本和未能置换出价格的第三方均价 -#0.6 仅仅采用房源样本聚类 -#0.5 无房源也无第三方均价,采用周边小区计算 -credit = pandas.Series([0.9,0.88,0.85, 0.8,0.75, 0.7, 0.6, 0.5], index=['0.9', '0.88','0.85','0.8','0.75', '0.7', '0.6', '0.5']) +# 0.88 当第三方价格样本量在5个及以上时,通过函数置换出的价格,由于由第三方均价所出的价格已经非常准确,避免不良房源的干扰,房源不参与计算 +# 0.85 第三方均价可以置换出某个价格,并且参考房源所出的价格 +# 0.80 采用链家和诸葛找房合并后的样本 +# 0.75 未采用 +# 0.7 同时参考样本和未能置换出价格的第三方均价 +# 0.6 仅仅采用房源样本聚类 +# 0.5 无房源也无第三方均价,采用周边小区计算 +credit = pandas.Series([0.9, 0.88, 0.85, 0.8, 0.75, 0.7, 0.6, 0.5], + index=['0.9', '0.88', '0.85', '0.8', '0.75', '0.7', '0.6', '0.5']) -#计算来源 +# 计算来源 value_type = pandas.Series([1, 2, 3, 4, 5, 6, 7], index=['指导价', '自身样本', '第三方', '交易数据', '周边楼盘', '推导', '优质样本']) @@ -71,34 +71,31 @@ value_type = pandas.Series([1, 2, 3, 4, 5, 6, 7], # 1:指导价 2:自身样本 3:第三方 4:交易数据 5:周边楼盘, 6:推导 -#计算均价函数入口 -def commonprice(ct, rl, p,weekend): - - - +# 计算均价函数入口 +def commonprice(ct, rl, p, weekend): # 提取房源的数据时间上限,如从20170301之后的数据 - some_district_information_time = front_step_time(weekend,360) - + some_district_information_time = front_step_time(weekend, 360) + # 提周边小区均价的数据时间上限,如从20170801之后的数据 - zhoubian_xiaoqu_time = front_step_time(weekend,200) - + zhoubian_xiaoqu_time = front_step_time(weekend, 200) + # 第三方均价的数据时间上限,如从201703之后的数据 - dsfjujia_time = front_step_time(weekend,200) // 100 - - #增加DataFrame的板块 block + dsfjujia_time = front_step_time(weekend, 200) // 100 + + # 增加DataFrame的板块 block def add_block(ppd): if 'block' not in ppd.columns: ppd['block'] = '没有' return ppd - #增加DataFrame的 room + + # 增加DataFrame的 room def add_room(ppd): if 'room' not in ppd.columns: ppd['room'] = 2 return ppd @timer - - #从数据库中读取房源数据,seawater + # 从数据库中读取房源数据,seawater def some_district_information(ct, rl, lk): query = {"city": ct, "cat": "sell", "region": rl, @@ -114,7 +111,8 @@ def commonprice(ct, rl, p,weekend): return fangjia.find_house_from_elastic_search(ct, rl, lk, "lianjia.com", some_district_information_time) """ - #从数据库中读取第三方均价,"fangjia", "average_statistics" + + # 从数据库中读取第三方均价,"fangjia", "average_statistics" def disanganf_price(ct, rl, lk, tt): # db1 = client1.fangjia # dsf = db1.average_statistics @@ -143,7 +141,8 @@ def commonprice(ct, rl, p,weekend): return numpy.array([]) else: return numpy.array([]) - #提取某个小区的经纬度 + + # 提取某个小区的经纬度 def take_location(ct, rl, p): dirlt = p[0] @@ -164,7 +163,7 @@ def commonprice(ct, rl, p,weekend): lct = seaweed136.find(query1, fields1) ######print('lct=',lct) lf = pandas.DataFrame(list(lct)) - + ######print('lf=',lf) # lf=fangjia.find_seaweed(query1, fields1) @@ -203,39 +202,45 @@ def commonprice(ct, rl, p,weekend): else: return numpy.array([]) - #以下几个函数用来判断数据来源 - #判断某条房源是否来自链家 + + # 以下几个函数用来判断数据来源 + # 判断某条房源是否来自链家 def lianjia(ur): # #####print(ur) if 'lianjia' in ur: return 0 else: return 1 - #判断某条房源是否来自诸葛找房 + + # 判断某条房源是否来自诸葛找房 def zhuge(ur): if 'zhuge' in ur: return 0 else: return 1 - #判断某条房源是否来自我爱我家 + + # 判断某条房源是否来自我爱我家 def wawj(ur): if '5i5j' in ur: return 0 else: return 1 - #爱屋及屋 + + # 爱屋及屋 def iwjw(ur): if 'iwjw' in ur: return 0 else: return 1 - #房估估 + + # 房估估 def fangdd(ur): if 'fangdd' in ur: return 0 else: return 1 - #悟空找房 + + # 悟空找房 def wkzf(ur): if 'wkzf' in ur: return 0 @@ -253,7 +258,7 @@ def commonprice(ct, rl, p,weekend): return set(aa) @timer - #最新的一条数据 + # 最新的一条数据 def new_data(ds): bb = set(ds['name']) bb1 = list(bb) @@ -319,19 +324,19 @@ def commonprice(ct, rl, p,weekend): ppp.loc[i, 'price'] = df[kk] # #####print('df[kk]',df[kk]) return ppp - - #搜索周边小区,并且输出周边小区的房价 - #在提取周边小区时,按照距离远近进行排序,距离的定义是曼哈顿距离 + + # 搜索周边小区,并且输出周边小区的房价 + # 在提取周边小区时,按照距离远近进行排序,距离的定义是曼哈顿距离 @timer def neighbor(lng, lat, scale, ct, rl, p): - - #搜索周边小区 + + # 搜索周边小区 ################### ################### # timm=20171122 ################### ################### - #小区的物业类型,有普通住宅和别墅 + # 小区的物业类型,有普通住宅和别墅 estype = p[2] # client1 = pymongo.MongoClient('192.168.0.136',27017) # db1 = client1.fangjia @@ -339,68 +344,66 @@ def commonprice(ct, rl, p,weekend): kkk = scale / 1000 longtitude = lng latitude = lat - #搜索周边的一定经纬度范围内的小区 + # 搜索周边的一定经纬度范围内的小区 query1 = {"status": 0, "cat": "district", "lat2": {"$gt": int(latitude - kkk * 10 ** 10 / 0.86), "$lt": int(latitude + kkk * 10 ** 10 / 0.86)}, "lng2": {"$gt": int(longtitude - kkk * 10 ** 10), "$lt": int(longtitude + kkk * 10 ** 10)}} # fields1 = {"lat2":1,"lng2":1, "city":1,"region":1,"cat":1,"name":1} - + fields1 = {"lat2": 1, "lng2": 1, "city": 1, "region": 1, "cat": 1, "name": 1, 'estate_type2': 1} - + # lct= list( seaweed136.find(query1, fields1)) - + # lf=pandas.DataFrame(lct) lf = fangjia.find_seaweed(query1, fields1) - + ######print('lf',lf[['estate_type2','lng2', 'lat2']]) - - #在提取周边小区时需要考虑小区的物业类型 + + # 在提取周边小区时需要考虑小区的物业类型 le = lf[lf['estate_type2'] == estype] ######print(le['name']) - + le.index = le['name'] - + lr = le[['lng2', 'lat2']] - - lr['name1']=le['name'] - - #计算周边小区距离中心小区的距离,本距离为曼哈顿距离 + + lr['name1'] = le['name'] + + # 计算周边小区距离中心小区的距离,本距离为曼哈顿距离 def sort_manhaten(lr): - lr1=lr.values + lr1 = lr.values ####print(lr1) - lr2=[] - + lr2 = [] + for m in range(lr1.shape[0]): ######print(m) - distance=abs(lng-lr1[m][0])+abs(lat-lr1[m][1]) - lr2.append(distance/100000) - - lr3=np.c_[lr1,lr2] - lrr=lr3[lr3[:,3].argsort()] - - - return lrr - - - lr1=sort_manhaten(lr) - - dirst1 = list(lr1[:,2]) - - #random.shuffle(dirst1) + distance = abs(lng - lr1[m][0]) + abs(lat - lr1[m][1]) + lr2.append(distance / 100000) - #提取周边的80个小区 + lr3 = np.c_[lr1, lr2] + lrr = lr3[lr3[:, 3].argsort()] + + return lrr + + lr1 = sort_manhaten(lr) + + dirst1 = list(lr1[:, 2]) + + # random.shuffle(dirst1) + + # 提取周边的80个小区 dirst = dirst1[:80] ######print('dirst=',dirst) - + dirst_plus = dirst + [p[0]] - + query_feature = {"city": ct, "region": rl, "district_name": {"$in": dirst_plus}} - + ppp = fangjia.dis_feature(query_feature) ######print('ox'*10,ppp) - + # #####print('小区个数= ',len(dirst)) df1 = zhoubian_xiaoqu(ct, rl, dirst) ######print('df1=',df1,'*'*20) @@ -414,9 +417,9 @@ def commonprice(ct, rl, p,weekend): else: return numpy.array([]) - #本函数与上一个函数基本相同,仅仅缺少一行代码,le = lf[lf['estate_type2'] == estype] - #读取周边小区价格,不考虑其物业类型,原因是别墅或商住楼周边的同物业类型的小区非常少 - #故而提取周边小区时不考虑其物业类型 + # 本函数与上一个函数基本相同,仅仅缺少一行代码,le = lf[lf['estate_type2'] == estype] + # 读取周边小区价格,不考虑其物业类型,原因是别墅或商住楼周边的同物业类型的小区非常少 + # 故而提取周边小区时不考虑其物业类型 def neighbor_km(lng, lat, scale, ct, rl, p): ################### @@ -425,7 +428,7 @@ def commonprice(ct, rl, p,weekend): ################### ################### - #estype = p[2] + # estype = p[2] # client1 = pymongo.MongoClient('192.168.0.136',27017) # db1 = client1.fangjia # seaweed1 = db1.seaweed @@ -438,49 +441,46 @@ def commonprice(ct, rl, p,weekend): "lng2": {"$gt": int(longtitude - kkk * 10 ** 10), "$lt": int(longtitude + kkk * 10 ** 10)}} # fields1 = {"lat2":1,"lng2":1, "city":1,"region":1,"cat":1,"name":1} - fields1 = {"lat2": 1, "lng2": 1, "city": 1, "region": 1,# + fields1 = {"lat2": 1, "lng2": 1, "city": 1, "region": 1, # "cat": 1, "name": 1, 'estate_type2': 1} # lct= list( seaweed136.find(query1, fields1)) # lf=pandas.DataFrame(lct) lf = fangjia.find_seaweed(query1, fields1) - + ######print('lf',lf[['estate_type2','lng2', 'lat2']]) - #le = lf[lf['estate_type2'] == estype] + # le = lf[lf['estate_type2'] == estype] le = lf ######print('le',le[['estate_type2','lng2', 'lat2']]) le.index = le['name'] - + lr = le[['lng2', 'lat2']] - lr['name1']=le['name'] - - + lr['name1'] = le['name'] + def sort_manhaten(lr): - lr1=lr.values + lr1 = lr.values ####print(lr1) - lr2=[] - + lr2 = [] + for m in range(lr1.shape[0]): ######print(m) - distance=abs(lng-lr1[m][0])+abs(lat-lr1[m][1]) - lr2.append(distance/100000) - - lr3=np.c_[lr1,lr2] - lrr=lr3[lr3[:,3].argsort()] - - + distance = abs(lng - lr1[m][0]) + abs(lat - lr1[m][1]) + lr2.append(distance / 100000) + + lr3 = np.c_[lr1, lr2] + lrr = lr3[lr3[:, 3].argsort()] + return lrr - - - lr1=sort_manhaten(lr) - - dirst1 = list(lr1[:,2]) - - #random.shuffle(dirst1) - + + lr1 = sort_manhaten(lr) + + dirst1 = list(lr1[:, 2]) + + # random.shuffle(dirst1) + dirst = dirst1[:80] # #####print('dirst=',dirst) @@ -505,7 +505,8 @@ def commonprice(ct, rl, p,weekend): return vv else: return numpy.array([]) - #向量回归计算小区均价 + + # 向量回归计算小区均价 def svr(vv, lk): # 提取要计算小区的特征 vk = vv[vv['district_name'] == lk] @@ -530,7 +531,7 @@ def commonprice(ct, rl, p,weekend): # #####print('x1=',x1) y = vvo1['price'] # #####print('y',y) - #向量回归 + # 向量回归 if len(x1) > 2: clf = sklearn.svm.SVR() @@ -540,7 +541,7 @@ def commonprice(ct, rl, p,weekend): # #####print (result) return int(result[0]) else: - #聚类 + # 聚类 km = vv['price'].dropna() return int(k_means(km)) @@ -552,13 +553,13 @@ def commonprice(ct, rl, p,weekend): else: km = vv['price'].dropna() return int(k_means(km)) - #计算无房源小区的均价 + + # 计算无房源小区的均价 def no_source_price(ct, rl, location, p): - - + lk = p[0] hg = location.shape[0] - + ''' def choose_factor(p): @@ -568,22 +569,22 @@ def commonprice(ct, rl, p,weekend): else: return 5 ''' - - #factor=choose_factor(p) - - factor=20 + + # factor=choose_factor(p) + + factor = 20 if hg == 0: return '没有经纬度数据', 0 - - #elif hg > 1: - #return '纬度数据有误,有多个经纬度', 0 - + + # elif hg > 1: + # 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('dd=',dd,'dd'*20) @@ -613,23 +614,23 @@ def commonprice(ct, rl, p,weekend): # t3=time.time() dd2 = neighbor(location['lng2'].iloc[0], location['lat2'].iloc[0], 20, ct, rl, p) # #####print(time.time()-t3,'t3'*10) - #print('dd2.shape', dd2 ,'@' * 60) + # print('dd2.shape', dd2 ,'@' * 60) if dd2.shape[0] >= factor: ######print('$' * 50) - #svr_time = time.time() + # svr_time = time.time() other1 = svr(dd2, lk) ######print(time.time() - svr_time, 'e' * 10) ##print('other1=',other1) return other1, dd2.shape[0] else: - #不考虑物业类型 + # 不考虑物业类型 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) - + ######print('#'*20) # #####print(time.time()-svr_time,'svr'*10) # #####print('other1=',other1) @@ -652,7 +653,7 @@ def commonprice(ct, rl, p,weekend): lf = fangjia.find_seaweed(query1, fields1) return lf - #聚类算法 + # 聚类算法 def k_means(pp1): from sklearn.cluster import KMeans pv = list(pp1) @@ -672,7 +673,7 @@ def commonprice(ct, rl, p,weekend): return (int(center)) else: return int(pp1.mean()) - + def region_district_list_name(ct, rl, lkk): # import pandas # client1 = pymongo.MongoClient('192.168.0.136',27017) @@ -688,7 +689,7 @@ def commonprice(ct, rl, p,weekend): # lf=pandas.DataFrame(lct) lf = fangjia.find_seaweed(query1, fields1) return lf - + def strip_villa(ct, rl, p): lw = p[0] # estype=p[2] @@ -745,9 +746,9 @@ def commonprice(ct, rl, p,weekend): return cc1 else: return cc1 - - #在同一个小区里,可能同时有别墅和普通住宅两种房源 - #本函数就是根据本小区的物业类型提取房源 + + # 在同一个小区里,可能同时有别墅和普通住宅两种房源 + # 本函数就是根据本小区的物业类型提取房源 @timer def consider_villa(ct, rl, p): @@ -778,7 +779,8 @@ def commonprice(ct, rl, p,weekend): return df else: return df - #本函数用于判断本小区是否是别墅,并提取别墅在DataFrame 中的index + + # 本函数用于判断本小区是否是别墅,并提取别墅在DataFrame 中的index def fetch_villa_index(dd): # dd=dd.dropna() @@ -803,15 +805,14 @@ def commonprice(ct, rl, p,weekend): return villa - #本函数就是提取进6个月以来某个小区第三方均价最新的一条 + # 本函数就是提取进6个月以来某个小区第三方均价最新的一条 def dsfjujia(ct, rl, lk): query = {"city": ct, "region": rl, "name": lk, "s_date": {"$gt": dsfjujia_time}} data = fangjia.find_disanganf_price(query) - - alist = ['lianjia_esf_price', + alist = ['lianjia_esf_price', 'anjuke_esf_price', 'fangdoudou_esf_price', 'leyoujia_esf_price', @@ -823,6 +824,7 @@ def commonprice(ct, rl, p,weekend): 'fanggugu_esf_price', 'qfang_esf_price', 'soufang_esf_price'] + a1list = set(alist) blist = set(data.columns) @@ -865,7 +867,8 @@ def commonprice(ct, rl, p,weekend): aa_zz=set(junjia.index) jiaji_lz= list(ll_zz & aa_zz) """ - #聚类算法 + + # 聚类算法 def k_means_clus(pp1, clus): from sklearn.cluster import KMeans @@ -881,7 +884,7 @@ def commonprice(ct, rl, p,weekend): index_max = gg.index(max(gg)) centroids = estimator.cluster_centers_ # 获取聚类中心 - + ##print(centroids,gg) # inertia = estimator.inertia_ # 获取聚类准则的总和 center = centroids[index_max][0] @@ -889,12 +892,12 @@ def commonprice(ct, rl, p,weekend): else: return int(pp1.mean()) - #判断两个群体是否可以协商出一个可行的价格 - #junjia_lzf群体1 - #junjia_anst,群体2 + # 判断两个群体是否可以协商出一个可行的价格 + # junjia_lzf群体1 + # junjia_anst,群体2 # ctr控制参数 - #per控制百分比 - def group(junjia_lzf, junjia_anst, ctr,per): + # per控制百分比 + def group(junjia_lzf, junjia_anst, ctr, per): bb = [] for i in junjia_lzf.index: @@ -919,7 +922,8 @@ def commonprice(ct, rl, p,weekend): bb.append([someprice, numb]) ###print('bb=',bb) return bb - #两个群体是否可以协调出最优价格 + + # 两个群体是否可以协调出最优价格 def middle_operate(junjia_lzf, junjia_anst): # #####print('%%%',ppd3['total_price']) @@ -927,11 +931,11 @@ def commonprice(ct, rl, p,weekend): # #####print('junjia_lzf=',junjia_lzf) # #####print('junjia_anst=',junjia_anst) - def mid_out_1(junjia_lzf,per): + def mid_out_1(junjia_lzf, per): if len(junjia_lzf) > 1: # #####print('aa1',aa) - bb = group(junjia_lzf, junjia_lzf, 1,per) + bb = group(junjia_lzf, junjia_lzf, 1, per) # #####print('bb=',bb) if len(bb) > 0: bb1 = pandas.DataFrame(bb, columns=['price', 'count']) @@ -943,11 +947,11 @@ def commonprice(ct, rl, p,weekend): else: return None - def mid_out_2(junjia_lzf, junjia_anst,per): + def mid_out_2(junjia_lzf, junjia_anst, per): if len(junjia_lzf) > 0 and len(junjia_anst) > 0: - bb = group(junjia_lzf, junjia_anst, 0,per) + bb = group(junjia_lzf, junjia_anst, 0, per) # #####print('bb1=',bb) if len(bb) > 0: bb1 = pandas.DataFrame(bb, columns=['price', 'count']) @@ -959,25 +963,26 @@ def commonprice(ct, rl, p,weekend): else: return None - #a11 = mid_out_1(junjia_lzf,8) - + # a11 = mid_out_1(junjia_lzf,8) + ######print('a11=',a11) - #a22 = mid_out_2(junjia_lzf, junjia_anst,8) + # a22 = mid_out_2(junjia_lzf, junjia_anst,8) ######print('a22=',a22) - #a33 = mid_out_1(junjia_anst,8) - a44 = mid_out_1(junjia_lzf,12) - a55 = mid_out_2(junjia_lzf, junjia_anst,12) - a66 = mid_out_1(junjia_anst,12) + # a33 = mid_out_1(junjia_anst,8) + a44 = mid_out_1(junjia_lzf, 12) + a55 = mid_out_2(junjia_lzf, junjia_anst, 12) + a66 = mid_out_1(junjia_anst, 12) ######print('a33=',a33) - #aa1_6 = pandas.Series([a11, a22, a33,a44,a55,a66]).dropna() - aa1_6 = pandas.Series([ a44,a55,a66]).dropna() - + # aa1_6 = pandas.Series([a11, a22, a33,a44,a55,a66]).dropna() + aa1_6 = pandas.Series([a44, a55, a66]).dropna() + ######print('aa1_6=',aa1_6) if len(aa1_6) > 0: return aa1_6.iloc[0] else: return None - #把第三方均价分成两个群体 + + # 把第三方均价分成两个群体 def devide_group(al, bl, junjia): alls = set(junjia.index) @@ -992,9 +997,10 @@ def commonprice(ct, rl, p,weekend): anst = set_div(bl, alls) return lzf, anst - #本函数通过输入第三方均价和周边价格来计算小区均价 - #junjia 是一个Series index 是网站的名称 - #neighb 是周边小区的价格 + + # 本函数通过输入第三方均价和周边价格来计算小区均价 + # junjia 是一个Series index 是网站的名称 + # neighb 是周边小区的价格 def dglg_out1(junjia, neighb): """ @@ -1009,7 +1015,7 @@ def commonprice(ct, rl, p,weekend): 'lianjia_esf_price', 'zhugezhaofang_esf_price', 'fanggugu_esf_price' - ] + ] # 一般的样本源 bl = ['anjuke_esf_price', 'soufang_esf_price', @@ -1021,13 +1027,14 @@ def commonprice(ct, rl, p,weekend): 'fangtan_esf_price', 'zhongyuan_esf_price', 'qfang_esf_price' - ] - - mmax=junjia.max() - #次函数已经放弃采用 - def junjia_max(mmax,dg12): - if dg12!=None and mmax!=None: - + ] + + mmax = junjia.max() + + # 次函数已经放弃采用 + def junjia_max(mmax, dg12): + if dg12 != None and mmax != None: + return dg12 ''' ratiog=dg12/mmax @@ -1038,33 +1045,31 @@ def commonprice(ct, rl, p,weekend): ''' else: return dg12 - - + # ppd3dp=ppd3['total_price'].dropna() if type(neighb) != str and neighb != None: - - #参考周边对junjia进行预处理 - def cut_junjia(junjia,neighb): - - if len(junjia)>3: - return junjia[junjia > 0.49* neighb] - else: - return junjia[junjia > 0.6* neighb] - - junjia=cut_junjia(junjia,neighb) + # 参考周边对junjia进行预处理 + def cut_junjia(junjia, neighb): + + if len(junjia) > 3: + return junjia[junjia > 0.49 * neighb] + else: + return junjia[junjia > 0.6 * neighb] + + junjia = cut_junjia(junjia, neighb) ''' junjia_lzf=junjia[al].dropna() junjia_anst=junjia[bl].dropna() ''' - #对junjia 分成两个group + # 对junjia 分成两个group alldi = devide_group(al, bl, junjia) junjia_lzf = alldi[0] junjia_anst = alldi[1] dg11 = middle_operate(junjia_lzf, junjia_anst) ##print('dg11=',dg11) - return junjia_max(mmax,dg11) + return junjia_max(mmax, dg11) else: @@ -1074,34 +1079,33 @@ def commonprice(ct, rl, p,weekend): junjia_anst = alldi[1] dg22 = middle_operate(junjia_lzf, junjia_anst) - return junjia_max(mmax,dg22) - - #由于链家和诸葛找房的数据准确度比较高,增加链家和诸葛找房数据的权重,即放大20倍. + return junjia_max(mmax, dg22) + + # 由于链家和诸葛找房的数据准确度比较高,增加链家和诸葛找房数据的权重,即放大20倍. def add_weight(s1): - - choose_columns=['url','area', 'district_name', 'name', 'p_date', 'region', - 'total_price', 'room'] - - all_set=set(s1.columns) - - + + choose_columns = ['url', 'area', 'district_name', 'name', 'p_date', 'region', + 'total_price', 'room'] + + all_set = set(s1.columns) + if set(choose_columns).issubset(all_set): - - s2=s1[choose_columns] - - s3=s2.values - - d=s3.tolist() + + s2 = s1[choose_columns] + + s3 = s2.values + + d = s3.tolist() for k in range(len(d)): - ###print(k) - if type( d[k][0])==str: - if 'lianjia.com' in d[k][0] or 'zhuge' in d[k][0]: - x1=[d[k]]*20 - ###print(x1) - ###print(d) - d=d+x1 + ###print(k) + if type(d[k][0]) == str: + if 'lianjia.com' in d[k][0] or 'zhuge' in d[k][0]: + x1 = [d[k]] * 20 + ###print(x1) + ###print(d) + d = d + x1 ##print(d) - d1=pandas.DataFrame(np.array(d),columns=s2.columns) + d1 = pandas.DataFrame(np.array(d), columns=s2.columns) d1[['area']] = d1[['area']].astype(float) d1[['total_price']] = d1[['total_price']].astype(float) d1[['p_date']] = d1[['p_date']].astype(float) @@ -1110,79 +1114,81 @@ def commonprice(ct, rl, p,weekend): return d1 else: return s1 - #在第三方 均价中安居客的价格和赶集网的价格大概率的相同,在采用第三方均价计算价格时如果 - #赶集和安居客几乎相同并且和其他数据不同,就drop赶集网 的均价 + + # 在第三方 均价中安居客的价格和赶集网的价格大概率的相同,在采用第三方均价计算价格时如果 + # 赶集和安居客几乎相同并且和其他数据不同,就drop赶集网 的均价 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') + 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) + print('junjia=', junjia) + # print('neighb=',neighb) ''' dglg=dsplg(junjia,neighb,2) dggg=dsplg(junjia,neighb,1) ''' - - #在第三方 均价中安居客的价格和赶集网的价格大概率的相同,在采用第三方均价计算价格时如果 - #赶集和安居客几乎相同并且和其他数据不同,就drop赶集网 的均价 - judp=drop_ganji(junjia) - - #通过第三方均价计算小区均价 + # 在第三方 均价中安居客的价格和赶集网的价格大概率的相同,在采用第三方均价计算价格时如果 + # 赶集和安居客几乎相同并且和其他数据不同,就drop赶集网 的均价 + + judp = drop_ganji(junjia) + + # 通过第三方均价计算小区均价 dglg = dglg_out1(judp, neighb[0]) - print('dglg=',dglg) + print('dglg=', dglg) # dggg=dglg_out1(junjia,neighb[0]) # ####print('dglg=',dglg) # #####print('dggg=',dggg) - #tt=time.time() - #通过物业类型对房源进行分类 + # tt=time.time() + # 通过物业类型对房源进行分类 data = consider_villa(ct, rl, p) - - #data.to_excel('data.xls') + + # data.to_excel('data.xls') ##print('data=',data) - - #data.to_excel('ddw.xls') + + # data.to_excel('ddw.xls') ###print(time.time()-tt,'<>'*26) ####################################################### ##print('rrrr') ##print(data.shape[0]) - #增加优质样本的权重 - data=add_weight(data) + # 增加优质样本的权重 + data = add_weight(data) ##print('data=',data) if data.shape[0] > 3: - + paa = add_block(data) ppd = paa[['total_price', 'area', 'region', 'district_name', 'url', 'block', 'p_date']] # #####print('ppd##############') @@ -1195,40 +1201,40 @@ def commonprice(ct, rl, p,weekend): ##print(ppd1[['total_price','area']]) ##print(type(ppd1['total_price'][1])) ##print(type(ppd1['area'][1])) - #ppd1[['total_price','area']].to_excel('ppd1.xls') + # ppd1[['total_price','area']].to_excel('ppd1.xls') ppd1['total_price'] = ppd1['total_price'] / ppd1['area'] - #提取某个小区的区域价格 - #一般情况下,用周边的价格对房源进行预处理,过滤那些极小值 - #但有时候周边价格计算不出来,就需要用区域价格进行过滤 - def take_region_price(ct,rl): - - + # 提取某个小区的区域价格 + # 一般情况下,用周边的价格对房源进行预处理,过滤那些极小值 + # 但有时候周边价格计算不出来,就需要用区域价格进行过滤 + def take_region_price(ct, rl): + def before_step_time(day): now = datetime.datetime.now() - front = now - datetime.timedelta(days=day) + front = now - datetime.timedelta(days=day) return front - aaw=before_step_time(14) - query1 = {"city": ct, "region": rl,'weekend':{'$gt':aaw}} + + 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: + + if lf.shape[0] > 0: return lf['calc_value'].iloc[-1] else: return -1 if ppd1.shape[0] > 0: - - #通过周边价格或区域价格对房源进行过滤 + + # 通过周边价格或区域价格对房源进行过滤 def guolv_data(ppd2, neighb): if type(neighb) is not str: ph = ppd2[ppd2['total_price'] > 0.7 * neighb] return ph else: - sss=take_region_price(ct,rl) - if sss>0: - ph1 = ppd2[ppd2['total_price'] > 0.5 *sss] + sss = take_region_price(ct, rl) + if sss > 0: + ph1 = ppd2[ppd2['total_price'] > 0.5 * sss] return ph1 else: return ppd2 @@ -1237,8 +1243,8 @@ def commonprice(ct, rl, p,weekend): ###################################### ppd3 = guolv_data(ppd1, neighb[0]) - - #ppd3.to_excel('ppd4.xls') + + # ppd3.to_excel('ppd4.xls') ###################################### ldf = label(ppd3, lianjia) @@ -1260,85 +1266,86 @@ def commonprice(ct, rl, p,weekend): # mm=0 length = len(l_and_z) length1 = len(allf) + ##print('#########') - #a=datetime.datetime.now() - #timeArray = a.strftime("%Y%m%d") - + # a=datetime.datetime.now() + # timeArray = a.strftime("%Y%m%d") + ##print('timeArray=',timeArray) - - #front_step_time(360) - def ss1(junjia,dglg,ppd3): + + # 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') + 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']) - - if dglg_dd.shape[0]>2: - dglg1= k_means_clus(dglg_dd['total_price'].dropna(),3) + + 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 dglg,float('%.2f' % credit['0.85']), value_type['第三方'], sample_size + return dglg, float('%.2f' % credit['0.85']), value_type['第三方'], sample_size else: - return 0,float('%.2f' % credit['0.85']), value_type['第三方'], sample_size - - def consider_time_ss1(junjia,dglg,ppd3,day): + return 0, float('%.2f' % credit['0.85']), value_type['第三方'], sample_size + + 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) + 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 - - #在计算均价时,同是参考第三方均价计算出的价格和房源价格 - #dglg:第三方均价计算出的价格 - def map_time_price(junjia,dglg,ppd3): - - day_15=front_step_time(weekend,15) - day_30=front_step_time(weekend,30) - day_60=front_step_time(weekend,60) - #考虑最近15天的房价和dglg - price_15= consider_time_ss1(junjia,dglg,ppd3,day_15) - #考虑最近30天的房价和dglg - price_30= consider_time_ss1(junjia,dglg,ppd3,day_30) - #考虑最近60天的房价和dglg - price_60= consider_time_ss1(junjia,dglg,ppd3,day_60) - - if price_15[0]>0: - #print('first_15') + return -2, float('%.2f' % credit['0.85']), value_type['第三方'], sample_size + + # 在计算均价时,同是参考第三方均价计算出的价格和房源价格 + # dglg:第三方均价计算出的价格 + def map_time_price(junjia, dglg, ppd3): + + day_15 = front_step_time(weekend, 15) + day_30 = front_step_time(weekend, 30) + day_60 = front_step_time(weekend, 60) + # 考虑最近15天的房价和dglg + price_15 = consider_time_ss1(junjia, dglg, ppd3, day_15) + # 考虑最近30天的房价和dglg + price_30 = consider_time_ss1(junjia, dglg, ppd3, day_30) + # 考虑最近60天的房价和dglg + 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') + elif price_30[0] > 0: + # print('first_30') return price_30 - elif price_60[0]>0: - #print('first_60') + elif price_60[0] > 0: + # print('first_60') return price_60 else: - return ss1(junjia,dglg,ppd3) - - dggg=map_time_price(junjia,dglg,ppd3) - - #当第三方均价的样本量比较大,就可以得出一个非常准确的均价,故直接输出这个价格不考虑房源 - #这一步计算出的价格可信度最高为0.88 - if len(junjia)>4 and dglg!=None: + return ss1(junjia, dglg, ppd3) + + dggg = map_time_price(junjia, dglg, ppd3) + + # 当第三方均价的样本量比较大,就可以得出一个非常准确的均价,故直接输出这个价格不考虑房源 + # 这一步计算出的价格可信度最高为0.88 + if len(junjia) > 4 and dglg != None: sample_size = len(junjia) return dglg, float('%.2f' % credit['0.88']), value_type['第三方'], sample_size - - - #这一步在第三方均价算出一个价格之后,并参考房源,计算均价,可信度0.85 - elif dggg[0]>0 : + + + # 这一步在第三方均价算出一个价格之后,并参考房源,计算均价,可信度0.85 + elif dggg[0] > 0: return dggg - - #这个一步采用链家和诸葛找房房源聚类出一个价格 + + # 这个一步采用链家和诸葛找房房源聚类出一个价格 elif length > 3: # #####print('ldf=',l_and_z_and_i) pppk = ppd3.loc[l_and_z, :] @@ -1353,12 +1360,12 @@ def commonprice(ct, rl, p,weekend): gm = k_means_clus(gdf, 2) ######print('链猪= ', gm) return int(gm), float('%.2f' % credit['0.8']), value_type['自身样本'], sample_size # 优质样本 - - + + elif data.shape[0] > 0: data['avg'] = data['total_price'] / data['area'] @@ -1369,16 +1376,16 @@ def commonprice(ct, rl, p,weekend): ddd11 = data[data['avg'] > 0.65 * neighb] return ddd11 else: - sss=take_region_price(ct,rl) - if sss>0: + sss = take_region_price(ct, rl) + if sss > 0: ddd22 = data[data['avg'] > 0.5 * sss] return ddd22 - else: + else: return data ddd11 = guolv_data11(data, neighb[0]) - #print('ddd11=',ddd11[['total_price','area','url']]) + # print('ddd11=',ddd11[['total_price','area','url']]) if ddd11.shape[0] > 2: @@ -1389,21 +1396,20 @@ def commonprice(ct, rl, p,weekend): s = zhuge_consist.zhuge_out(ddd11, 3, 1) # #####print('s=',s) - - dd22=ddd11['total_price']/ddd11['area'] - - - #这个函数已经弃用,可以直接去掉 - #原来方案是聚类成三类,拿出前两类与周边价格和第三方均价进行比较, - #后来发现这样会引入其他问题,就直接聚类了 - #怕改了以后引起其他问题,期待新算法工程是的杰作 + + dd22 = ddd11['total_price'] / ddd11['area'] + + # 这个函数已经弃用,可以直接去掉 + # 原来方案是聚类成三类,拿出前两类与周边价格和第三方均价进行比较, + # 后来发现这样会引入其他问题,就直接聚类了 + # 怕改了以后引起其他问题,期待新算法工程是的杰作 def compelex(ddd11, s, neighb, junjia): - #cc1 = ddd11['avg'].dropna() + # cc1 = ddd11['avg'].dropna() # #####print('cc1=',cc1) ##print(ppd3['total_price'],'ppppppppppppppp') ##print('dd22=',dd22) - kmzhuge = k_means_clus(dd22.dropna(), 3) + kmzhuge = k_means_clus(dd22.dropna(), 3) ##print(ppd3['total_price']) junjia['zhuge_logic'] = kmzhuge @@ -1421,33 +1427,34 @@ def commonprice(ct, rl, p,weekend): 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') + 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 junjia1 = drop_ganji(junjia) - cc = group(junjia_front, junjia1, 1,10) + cc = group(junjia_front, junjia1, 1, 10) if len(cc) > 0: cc1 = pandas.DataFrame(cc, columns=['price', 'count']) cc2 = cc1.sort_values(by='count', ascending=False) + ##print('cc2=',cc2) - + def two_one_choose(cc2): - qwrt=set(cc2['count']) - - if len(qwrt)>1: + qwrt = set(cc2['count']) + + if len(qwrt) > 1: return cc2['price'].iloc[0] - else : + else: return junjia['kmzg'] sample_size = ddd11.shape[0] @@ -1459,9 +1466,10 @@ def commonprice(ct, rl, p,weekend): ##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 @@ -1474,21 +1482,21 @@ def commonprice(ct, rl, p,weekend): 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] elif dglg != None: - #这几行代码应该可以去掉,懒得改了 + # 这几行代码应该可以去掉,懒得改了 sample_size = len(junjia) 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] @@ -1505,26 +1513,26 @@ def commonprice(ct, rl, p,weekend): elif dglg != None: ##print('优质第三方均价4 = ', dglg) ##print('neighb[0]',neighb[0]) - - def dgneib(dglg,neighb): - - if type(neighb[0])!=str: - - if dglg/neighb[0]>0.75: + + def dgneib(dglg, neighb): + + if type(neighb[0]) != str: + + if dglg / neighb[0] > 0.75: return dglg, float('%.2f' % credit['0.75']), value_type['第三方'], len(junjia) # '优质样本' else: return neighb[0], float('%.2f' % credit['0.5']), value_type['周边楼盘'], neighb[1] else: - return dglg,float('%.2f' % credit['0.75']), value_type['第三方'], len(junjia) # '优质样本' - return dgneib(dglg,neighb) - + return dglg, float('%.2f' % credit['0.75']), value_type['第三方'], len(junjia) # '优质样本' + + return dgneib(dglg, neighb) + else: - #本价格通过周边楼盘计算 得到 + # 本价格通过周边楼盘计算 得到 return neighb[0], float('%.2f' % credit['0.5']), value_type['周边楼盘'], neighb[1] - def add_alias(ppd): if 'alias' not in ppd.columns: ppd['alias'] = '无' @@ -1540,18 +1548,19 @@ 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", "calc_command", config.get_log_mongodb_host(), config.get_log_mongodb_port()) -pt = fangjia.get_collection("fangjia_log", "problem_command", config.get_log_mongodb_host(), config.get_log_mongodb_port()) +stat = fangjia.get_collection("fangjia", "district_stat", config.get_district_stat_host(), + config.get_district_stat_port()) +# pt = fangjia.get_collection("fangjia_log", "calc_command", config.get_log_mongodb_host(), config.get_log_mongodb_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", config.get_save_db(), '192.168.10.182', 27017) -#pt = fangjia.get_collection("fangjia_log", "problem_command", '192.168.10.182', 27017) +# stat = fangjia.get_collection("fangjia", "Copy_of_district_stat_shanghai_april_ten", '192.168.10.182', 27017) +# stat = fangjia.get_collection("fangjia", config.get_save_db(), '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): # import pandas # client1 = pymongo.MongoClient('192.168.0.136',27017) @@ -1567,27 +1576,26 @@ def region_district_list_lk(ct, rl, lk): lf = fangjia.find_seaweed(query1, fields1) return lf -#本函数用于计算上一周的时间 + +# 本函数用于计算上一周的时间 def last_sunday(weekend): - ######print('weekend_up',weekend) # import datetime last_sunday = weekend - datetime.timedelta(days=7) - #d1 = future_time.strftime('%Y%m%d') - #weekend1 = datetime.datetime.strptime(d1, '%Y%m%d') - #weekend = weekend1 + datetime.timedelta(hours=-8) - + # d1 = future_time.strftime('%Y%m%d') + # weekend1 = datetime.datetime.strptime(d1, '%Y%m%d') + # weekend = weekend1 + datetime.timedelta(hours=-8) + ######print('weekend',last_sunday) return last_sunday # last_sunday=last_sunday(weekend) -#计算小区的周涨跌幅度 -#在计算时锁定上一周与这一周的时间限制 +# 计算小区的周涨跌幅度 +# 在计算时锁定上一周与这一周的时间限制 def make_up_price(ct, rl, lk, weekend): - #####print('lg=',ct,rl,lk) # last_sunday=last_sunday(weekend)南湖国际中心二期 # save_lg=client136.fangjia.district_stat @@ -1595,16 +1603,16 @@ def make_up_price(ct, rl, lk, weekend): # cc=last_sunday - #提取上一周的时间 + # 提取上一周的时间 ly = last_sunday(weekend) # stat= fangjia.get_collection("fangjia_stat","test_lg5", '192.168.0.136',27017) - #stat = stat + # stat = stat query = {"city": ct, "region": rl, "district_name": lk, 'weekend': ly } pos1 = list(stat.find(query).limit(30)) - - #提取上一周的价格 + + # 提取上一周的价格 pos = pandas.DataFrame(pos1) # pos=timestamp_to_int(pos) @@ -1628,7 +1636,7 @@ def make_up_price(ct, rl, lk, weekend): else: # stat= fangjia.get_collection("fangjia_stat","test_lg5", '192.168.0.136',27017) - + query = {"city": ct, "region": rl, "district_name": lk, 'weekend': last_sunday } @@ -1659,35 +1667,38 @@ def make_up_price(ct, rl, lk, weekend): def out_estate_type(estate_type): if estate_type is not None and "别墅" in estate_type: - return '别墅','别墅' - else: - return '小区',"普通住宅" + return '别墅', '别墅' + else: + return '小区', "普通住宅" + @timer -def pt_down(ct,rl,p,weekend,c_date,cmd_estate_type,mm): +def pt_down(ct, rl, p, weekend, c_date, cmd_estate_type, mm): pt.replace_one( - {"city": ct, "region": rl, "name": p[0], "calc_date": weekend}, + {"city": ct, "region": rl, "name": p[0], "calc_date": weekend}, + + {"city": ct, "region": rl, "name": p[0], "c_date": c_date, 'status': int(3), + 'remark': 'week', 'category': 'sell', "calc_date": weekend, 'priority': int(0), + 'problem': mm[0], 'estate_type': cmd_estate_type, "calc_type": int(0) + }, True + ) - {"city": ct, "region": rl, "name": p[0], "c_date": c_date, 'status': int(3), - 'remark': 'week', 'category': 'sell', "calc_date": weekend, 'priority': int(0), - 'problem': mm[0], 'estate_type': cmd_estate_type, "calc_type": int(0) - }, True - ) @timer -def stat_save(ct, rl, p, weekend, mm, c_date, m_date, make_up, estate_type,avg): +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(avg), + "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 ) + @timer def pt_up(ct, rl, p, weekend, c_date, cmd_estate_type): pt.replace_one( @@ -1700,91 +1711,87 @@ def pt_up(ct, rl, p, weekend, c_date, cmd_estate_type): }, True ) -#本函数用于将计算出的价格保存到数据库 + +# 本函数用于将计算出的价格保存到数据库 @timer def out_put_price(ct, rl, lk, weekend): - #提取本小区的信息 + # 提取本小区的信息 lf = region_district_list_lk(ct, rl, lk) - - if lf.shape[0]>0: - + + if lf.shape[0] > 0: + lf = add_alias(lf) - #p是一个列表['小区名','小区别名','物业类型'] + # p是一个列表['小区名','小区别名','物业类型'] p = ghhh(lf[['name', 'alias', 'estate_type2']])[0] - + ######print('p=', p) - #t1=time.time() - #下面函数用于计算价格 - mm = commonprice(ct, rl, p,weekend) + # t1=time.time() + # 下面函数用于计算价格 + mm = commonprice(ct, rl, p, weekend) ##print('mmjisuantime=',time.time()-t1,'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy') ######print('mm=',mm) c_date = datetime.datetime.utcnow() m_date = datetime.datetime.utcnow() estate_type = lf['estate_type2'].iloc[0] - - + ######print('estate_type',estate_type) - - - estate_type,cmd_estate_type = out_estate_type(estate_type) - - print('mm=',mm,'$'*20) + + estate_type, cmd_estate_type = out_estate_type(estate_type) + + print('mm=', mm, '$' * 20) ###print(type(mm[0])) if type(mm[0]) != str: - # #####print(lf['estate_type2'].iloc[0],'*'*10) - - + # last_sunday=last_sunday() # t1=time.time() last_sunday_price = make_up_price(ct, rl, lk, weekend) - + # #####print(time.time()-t1,'*'*20) - - #print('last_sunday_price=',last_sunday_price) + + # print('last_sunday_price=',last_sunday_price) # #####print('mm[0]',mm[0]) - - #计算小区的涨跌幅度 - def make_up(avg,last_sunday_price): - if type(last_sunday_price) != str and last_sunday_price != None and mm[0] != None and type(mm[0]) != str: - + + # 计算小区的涨跌幅度 + def make_up(avg, last_sunday_price): + if type(last_sunday_price) != str and last_sunday_price != None and mm[0] != None and type( + mm[0]) != str: + make_up = 10000 * (avg - last_sunday_price) / last_sunday_price return make_up else: return 0 - - - + ######print('make_up',make_up,'*'*20) ######print('credic',mm[1]) - #对数据进行处理,控制其涨跌幅度 - def avg_compare(ct,rl,lk,mm,weekend): - avg=fix.price_fix.update(ct,rl,lk,int(mm[0]),weekend) + # 对数据进行处理,控制其涨跌幅度 + def avg_compare(ct, rl, lk, mm, weekend): + avg = fix.price_fix.update(ct, rl, lk, int(mm[0]), weekend) ##print('nihe=',avg) ##print('mm[0]',mm[0]) - if avg>0: + if avg > 0: return avg else: return int(mm[0]) - #s1=time.time() - - - avg=avg_compare(ct,rl,lk,mm,weekend) - - #avg=int(mm[0]) - - #计算小区的涨跌幅度 - make_up = int(make_up(avg,last_sunday_price)) + + # s1=time.time() + + avg = avg_compare(ct, rl, lk, mm, weekend) + + # avg=int(mm[0]) + + # 计算小区的涨跌幅度 + make_up = int(make_up(avg, last_sunday_price)) ##print('s1_time=',time.time()-s1) - #avg=mm[0] - #print('mm=',mm) - #print(ct, rl, lk, avg, 'avg=',avg,'$' * 20) + # 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,avg) - #pt_up(ct,rl,p,weekend,c_date,cmd_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) + ''' stat.replace_one( @@ -1809,17 +1816,17 @@ def out_put_price(ct, rl, lk, weekend): }, True ) ''' - - + + except: - stat_save(ct,rl,p,weekend,mm,c_date,m_date,make_up,estate_type,avg) - - - - + stat_save(ct, rl, p, weekend, mm, c_date, m_date, make_up, estate_type, avg) + + + + else: - - pt_down(ct,rl,p,weekend,c_date,cmd_estate_type,mm) + + pt_down(ct, rl, p, weekend, c_date, cmd_estate_type, mm) ''' # pt.replace_one( @@ -1832,5 +1839,3 @@ def out_put_price(ct, rl, lk, weekend): }, True ) ''' - -