diff --git a/PriceSystem/CalcCmdSender.py b/PriceSystem/CalcCmdSender.py index 9bed1af..2c69f99 100644 --- a/PriceSystem/CalcCmdSender.py +++ b/PriceSystem/CalcCmdSender.py @@ -5,10 +5,21 @@ import config import datetime import sys import time +import pytz from datetime import date +def get_weekend(tt): + + from dateutil.parser import parse + bb=parse(tt) + pacific = pytz.timezone('Asia/Shanghai') + return pacific.localize(bb) + +weekend = get_weekend('20180527') + + class CJsonEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, datetime.datetime): @@ -20,13 +31,17 @@ class CJsonEncoder(json.JSONEncoder): QUEUE = "calc_cmd" -redisPool = redis.ConnectionPool(host=config.get_redis_host(), port=6379, db=config.get_redis_db()) +#redisPool = redis.ConnectionPool(host=config.get_redis_host(), port=6379, db=config.get_redis_db()) + +redisPool = redis.ConnectionPool(host=config.get_redis_host(), port=6379, db=3) + + client = redis.Redis(connection_pool=redisPool) logger = fangjia.get_logger("CalcCmdSender") def get_district(city): - weekend = fangjia.get_weekend() + #weekend = fangjia.get_weekend() seaweeds = [] keys = {"city": 1, "region": 1, "name": 1, "_id": 0} for dis in fangjia.get_collection("fangjia", "seaweed").find({"cat": "district", "status": 0, "city": city}, keys): @@ -44,6 +59,8 @@ def send_cmd(seaweed): def send_district_calc_cmd(): for city in fangjia.get_all_city(): + #for city in ['上海']: + for seaweed in get_district(city): send_cmd(seaweed) diff --git a/PriceSystem/config/__init__.py b/PriceSystem/config/__init__.py index ad6b538..963d3cb 100644 --- a/PriceSystem/config/__init__.py +++ b/PriceSystem/config/__init__.py @@ -19,7 +19,7 @@ def get_district_stat_port(): def get_redis_db(): - return 1 + return 3 def get_redis_cache_db(): diff --git a/PriceSystem/sell_price/zhuge0118A.py b/PriceSystem/sell_price/zhuge0118A.py index 5acf30f..dbea57a 100644 --- a/PriceSystem/sell_price/zhuge0118A.py +++ b/PriceSystem/sell_price/zhuge0118A.py @@ -14,7 +14,7 @@ Created on Fri Sep 22 18:18:15 2017 import os -####print(os.getcwd()) +#####print(os.getcwd()) import random import collections import pymongo @@ -149,10 +149,10 @@ def commonprice(ct, rl, p,weekend): if ltt > 0: fields1 = {"lat2": 1, "lng2": 1, "city": 1, "region": 1, "cat": 1, "name": 1} lct = seaweed136.find(query1, fields1) - #####print('lct=',lct) + ######print('lct=',lct) lf = pandas.DataFrame(list(lct)) - #####print('lf=',lf) + ######print('lf=',lf) # lf=fangjia.find_seaweed(query1, fields1) le = lf @@ -192,7 +192,7 @@ def commonprice(ct, rl, p,weekend): return numpy.array([]) def lianjia(ur): - # ####print(ur) + # #####print(ur) if 'lianjia' in ur: return 0 else: @@ -245,9 +245,9 @@ def commonprice(ct, rl, p,weekend): x1 = pandas.Series() for i in bb1: a1 = ds[ds['name'] == i] - #####print('^^^^^^^^') + ######print('^^^^^^^^') a2 = a1.sort_values(by='s_date', ascending=False) - #####print('a2=',a2) + ######print('a2=',a2) x1[i] = a2.iloc[0]['fangjia_price'] return x1 @@ -270,7 +270,7 @@ def commonprice(ct, rl, p,weekend): # data=pandas.DataFrame(pos) data = fangjia.find_disanganf_price(query) - # ####print(data) + # #####print(data) if data.shape[0] >= 1: # data=add_block(data) data = add_room(data) @@ -295,14 +295,14 @@ def commonprice(ct, rl, p,weekend): def hh(ppp, df): ppp['price'] = None aa = list(df.index) - # ####print('aa=',aa) + # #####print('aa=',aa) for i in ppp.index: kk = ppp['district_name'][i] - # ####print('kk=',kk) + # #####print('kk=',kk) if kk in aa: # ppp['price'][i]=df[kk] ppp.loc[i, 'price'] = df[kk] - # ####print('df[kk]',df[kk]) + # #####print('df[kk]',df[kk]) return ppp @timer @@ -335,10 +335,10 @@ def commonprice(ct, rl, p,weekend): # lf=pandas.DataFrame(lct) lf = fangjia.find_seaweed(query1, fields1) - #####print('lf',lf[['estate_type2','lng2', 'lat2']]) + ######print('lf',lf[['estate_type2','lng2', 'lat2']]) le = lf[lf['estate_type2'] == estype] - #####print(le['name']) + ######print(le['name']) le.index = le['name'] @@ -349,11 +349,11 @@ def commonprice(ct, rl, p,weekend): def sort_manhaten(lr): lr1=lr.values - ###print(lr1) + ####print(lr1) lr2=[] for m in range(lr1.shape[0]): - #####print(m) + ######print(m) distance=abs(lng-lr1[m][0])+abs(lat-lr1[m][1]) lr2.append(distance/100000) @@ -371,7 +371,7 @@ def commonprice(ct, rl, p,weekend): #random.shuffle(dirst1) dirst = dirst1[:80] - #####print('dirst=',dirst) + ######print('dirst=',dirst) dirst_plus = dirst + [p[0]] @@ -379,17 +379,17 @@ def commonprice(ct, rl, p,weekend): "district_name": {"$in": dirst_plus}} ppp = fangjia.dis_feature(query_feature) - #####print('ox'*10,ppp) + ######print('ox'*10,ppp) - # ####print('小区个数= ',len(dirst)) + # #####print('小区个数= ',len(dirst)) df1 = zhoubian_xiaoqu(ct, rl, dirst) - #####print('df1=',df1,'*'*20) + ######print('df1=',df1,'*'*20) if df1.shape[0] > 1: df = new_data(df1) - ####print('df=',df) + #####print('df=',df) vv = hh(ppp, df) - ####print('#'*36) - #####print('vv=',vv) + #####print('#'*36) + ######print('vv=',vv) return vv else: return numpy.array([]) @@ -423,11 +423,11 @@ def commonprice(ct, rl, p,weekend): # lf=pandas.DataFrame(lct) lf = fangjia.find_seaweed(query1, fields1) - #####print('lf',lf[['estate_type2','lng2', 'lat2']]) + ######print('lf',lf[['estate_type2','lng2', 'lat2']]) #le = lf[lf['estate_type2'] == estype] le = lf - #####print('le',le[['estate_type2','lng2', 'lat2']]) + ######print('le',le[['estate_type2','lng2', 'lat2']]) le.index = le['name'] @@ -437,11 +437,11 @@ def commonprice(ct, rl, p,weekend): def sort_manhaten(lr): lr1=lr.values - ###print(lr1) + ####print(lr1) lr2=[] for m in range(lr1.shape[0]): - #####print(m) + ######print(m) distance=abs(lng-lr1[m][0])+abs(lat-lr1[m][1]) lr2.append(distance/100000) @@ -460,7 +460,7 @@ def commonprice(ct, rl, p,weekend): dirst = dirst1[:80] - # ####print('dirst=',dirst) + # #####print('dirst=',dirst) dirst_plus = dirst + [p[0]] @@ -468,17 +468,17 @@ def commonprice(ct, rl, p,weekend): "district_name": {"$in": dirst_plus}} ppp = fangjia.dis_feature(query_feature) - # ####print('ox'*10,ppp) + # #####print('ox'*10,ppp) - # ####print('小区个数= ',len(dirst)) + # #####print('小区个数= ',len(dirst)) df1 = zhoubian_xiaoqu(ct, rl, dirst) - #####print('df1=',df1,'*'*20) + ######print('df1=',df1,'*'*20) if df1.shape[0] > 1: df = new_data(df1) - #####print('df=',df) + ######print('df=',df) vv = hh(ppp, df) - # ####print('#'*36) - # ####print('vv=',vv) + # #####print('#'*36) + # #####print('vv=',vv) return vv else: return numpy.array([]) @@ -487,7 +487,7 @@ def commonprice(ct, rl, p,weekend): # 提取要计算小区的特征 vk = vv[vv['district_name'] == lk] # 删除要计算小区的空特征 - # ####print('vk=',vk) + # #####print('vk=',vk) if vk.shape[0] > 0: vk1 = vk.iloc[0].dropna() @@ -496,7 +496,7 @@ def commonprice(ct, rl, p,weekend): vk2 = list(set(vk1.index) - {'_id', 'district_name', 'region', 'city'}) - # ####print('vk2=',vk2) + # #####print('vk2=',vk2) if len(vk2) > 1: vvo = vv[vv['district_name'] != lk] vk3 = vk2 + ['price'] @@ -504,9 +504,9 @@ def commonprice(ct, rl, p,weekend): vvo1 = vvo[vk31].dropna() x1 = vvo1.drop('price', axis=1) - # ####print('x1=',x1) + # #####print('x1=',x1) y = vvo1['price'] - # ####print('y',y) + # #####print('y',y) if len(x1) > 2: @@ -514,7 +514,7 @@ def commonprice(ct, rl, p,weekend): clf.fit(x1, y) pp1 = vk[vk31].drop('price', axis=1) result = clf.predict(pp1) - # ####print (result) + # #####print (result) return int(result[0]) else: km = vv['price'].dropna() @@ -558,57 +558,57 @@ def commonprice(ct, rl, p,weekend): else: #t1=time.time() - #####print("location['lng2'][0]",location['lng2'].iloc[0]) + ######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) + ##print(time.time()-t1,'t1'*10) + ##print('dd=',dd,'dd'*20) if dd.shape[0] >= factor: - # ####print('$'*50) + # #####print('$'*50) # dd1=neighbor(location['lng2'][0],location['lat2'][0],5) - # ####print('dd',dd) + # #####print('dd',dd) # svr_time=time.time() other = svr(dd, lk) - # ####print(time.time()-svr_time,'svr'*10) - ####print('other= ', other, '9' * 20) + # #####print(time.time()-svr_time,'svr'*10) + #####print('other= ', other, '9' * 20) return other, dd.shape[0] else: # t2=time.time() dd1 = neighbor(location['lng2'].iloc[0], location['lat2'].iloc[0], 10, ct, rl, p) - # ####print(time.time()-t2,'t2'*10) - # ####print('dd1=',dd1) + # #####print(time.time()-t2,'t2'*10) + # #####print('dd1=',dd1) if dd1.shape[0] >= factor: - # ####print('$'*50) + # #####print('$'*50) # svr_time=time.time() other1 = svr(dd1, lk) - # ####print(time.time()-svr_time,'svr'*10) - #print('other1=',other1) + # #####print(time.time()-svr_time,'svr'*10) + ##print('other1=',other1) return other1, dd1.shape[0] else: # 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(time.time()-t3,'t3'*10) + #print('dd2.shape', dd2 ,'@' * 60) if dd2.shape[0] >= factor: - #####print('$' * 50) + ######print('$' * 50) #svr_time = time.time() other1 = svr(dd2, lk) - #####print(time.time() - svr_time, 'e' * 10) - #print('other1=',other1) + ######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) + ##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) + ######print('#'*20) + # #####print(time.time()-svr_time,'svr'*10) + # #####print('other1=',other1) return other1, dd6.shape[0] else: return '没有周围小区数据', 0 @@ -669,28 +669,28 @@ def commonprice(ct, rl, p,weekend): # estype=p[2] alias = p[1] - # ####print('alias=',alias) + # #####print('alias=',alias) def filt(x): return type(x) == str and len(x) > 1 bb = list(filter(filt, alias)) - # ####print('bb=',bb) + # #####print('bb=',bb) bb.extend([lw]) # lk1=list(set(lk)) - # ####print('本小区名=',lw) + # #####print('本小区名=',lw) - # ####print('type(lw)=',type(bb)) + # #####print('type(lw)=',type(bb)) - # ####print('小区名列表=',bb) + # #####print('小区名列表=',bb) cc1 = some_district_information(ct, rl, bb) cc1 = add_room(cc1) - ####print('cc1本小区数据条数=', cc1.shape[0]) + #####print('cc1本小区数据条数=', cc1.shape[0]) if cc1.shape[0] > 2: @@ -702,7 +702,7 @@ def commonprice(ct, rl, p,weekend): lkk = lw.strip('别墅') cc = region_district_list_name(ct, rl, lkk) - # ####print('cc=',cc) + # #####print('cc=',cc) if cc.shape[0] > 1: cc1 = list(cc['alias'].dropna()) @@ -724,7 +724,7 @@ def commonprice(ct, rl, p,weekend): @timer def consider_villa(ct, rl, p): - # ####print('villa p=',p) + # #####print('villa p=',p) estype = p[2] df = strip_villa(ct, rl, p) @@ -757,7 +757,7 @@ def commonprice(ct, rl, p,weekend): # dd=dd.dropna() d1 = dd[dd['area'] > 150] - # ####print(dd) + # #####print(dd) villa_label = ["独栋", "联排", "叠加", "双拼", "花园面积", "泳池", "别墅", "带花园"] @@ -803,7 +803,7 @@ def commonprice(ct, rl, p,weekend): pdd = data1[i].dropna() # ser[i]=k_means(pdd) ser[i] = list(pdd)[-1] - # ####print('采用抓取的第三方均价') + # #####print('采用抓取的第三方均价') return ser def sfjj(ll_zz, aa_zz, dddf): @@ -847,7 +847,7 @@ def commonprice(ct, rl, p,weekend): centroids = estimator.cluster_centers_ # 获取聚类中心 - #print(centroids,gg) + ##print(centroids,gg) # inertia = estimator.inertia_ # 获取聚类准则的总和 center = centroids[index_max][0] return (int(center)) @@ -858,7 +858,7 @@ def commonprice(ct, rl, p,weekend): bb = [] for i in junjia_lzf.index: - # ####print(junjia_lzf) + # #####print(junjia_lzf) someprice = junjia_lzf[i] def compare15(b): @@ -868,35 +868,35 @@ def commonprice(ct, rl, p,weekend): return 0 countmap = list(map(compare15, junjia_anst)) - #####print('countmap=',countmap) + ######print('countmap=',countmap) countmap1 = pandas.Series(countmap) countmap2 = countmap1[countmap1 > 0] - # ####print('countmap2=',countmap2) + # #####print('countmap2=',countmap2) numb = len(countmap2) - # ####print('len(countmap2)=',len(countmap2)) + # #####print('len(countmap2)=',len(countmap2)) if numb > ctr: bb.append([someprice, numb]) - ##print('bb=',bb) + ###print('bb=',bb) return bb def middle_operate(junjia_lzf, junjia_anst): - # ####print('%%%',ppd3['total_price']) + # #####print('%%%',ppd3['total_price']) - # ####print('junjia_lzf=',junjia_lzf) - # ####print('junjia_anst=',junjia_anst) + # #####print('junjia_lzf=',junjia_lzf) + # #####print('junjia_anst=',junjia_anst) def mid_out_1(junjia_lzf,per): if len(junjia_lzf) > 1: - # ####print('aa1',aa) + # #####print('aa1',aa) bb = group(junjia_lzf, junjia_lzf, 1,per) - # ####print('bb=',bb) + # #####print('bb=',bb) if len(bb) > 0: bb1 = pandas.DataFrame(bb, columns=['price', 'count']) bb2 = bb1.sort_values(by='count', ascending=False) - #####print(bb2) + ######print(bb2) return bb2.iloc[0]['price'] else: return None @@ -908,11 +908,11 @@ def commonprice(ct, rl, p,weekend): if len(junjia_lzf) > 0 and len(junjia_anst) > 0: bb = group(junjia_lzf, junjia_anst, 0,per) - # ####print('bb1=',bb) + # #####print('bb1=',bb) if len(bb) > 0: bb1 = pandas.DataFrame(bb, columns=['price', 'count']) bb2 = bb1.sort_values(by='count', ascending=False) - # ####print(bb2) + # #####print(bb2) return bb2.iloc[0]['price'] else: return None @@ -921,18 +921,18 @@ def commonprice(ct, rl, p,weekend): #a11 = mid_out_1(junjia_lzf,8) - #####print('a11=',a11) + ######print('a11=',a11) #a22 = mid_out_2(junjia_lzf, junjia_anst,8) - #####print('a22=',a22) + ######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) - #####print('a33=',a33) + ######print('a33=',a33) #aa1_6 = pandas.Series([a11, a22, a33,a44,a55,a66]).dropna() aa1_6 = pandas.Series([ a44,a55,a66]).dropna() - #####print('aa1_6=',aa1_6) + ######print('aa1_6=',aa1_6) if len(aa1_6) > 0: return aa1_6.iloc[0] else: @@ -990,8 +990,17 @@ def commonprice(ct, rl, p,weekend): # ppd3dp=ppd3['total_price'].dropna() if type(neighb) != str and neighb != None: + + + def cut_junjia(junjia,neighb): + + if len(junjia)>3: + return junjia[junjia > 0.49* neighb] + else: + return junjia[junjia > 0.6* neighb] + - junjia = junjia[junjia > 0.7 * neighb] + junjia=cut_junjia(junjia,neighb) ''' junjia_lzf=junjia[al].dropna() junjia_anst=junjia[bl].dropna() @@ -1001,7 +1010,7 @@ def commonprice(ct, rl, p,weekend): junjia_lzf = alldi[0] junjia_anst = alldi[1] dg11 = middle_operate(junjia_lzf, junjia_anst) - #print('dg11=',dg11) + ##print('dg11=',dg11) return junjia_max(mmax,dg11) @@ -1031,29 +1040,29 @@ def commonprice(ct, rl, p,weekend): d=s3.tolist() for k in range(len(d)): - ##print(k) + ###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) + ###print(x1) + ###print(d) d=d+x1 - #print(d) + ##print(d) 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) - #print('s3.shape',s3.shape) - #print('d1.shape',d1.shape) + ##print('s3.shape',s3.shape) + ##print('d1.shape',d1.shape) return d1 else: return s1 def drop_ganji(junjia): a = {'ganji_esf_price', 'anjuke_esf_price'} - # ####print('a=',a) + # #####print('a=',a) b = set(list(junjia.index)) - # ####print('b=',b) + # #####print('b=',b) c = a & b u=list(b-a) if len(c) == 2 and len(junjia)>2: @@ -1071,17 +1080,17 @@ def commonprice(ct, rl, p,weekend): lk = p[0] location = take_location(ct, rl, p) - #####print('location',location) + ######print('location',location) # ttp=time.time() neighb = no_source_price(ct, rl, location, p) - # ####print(time.time()-ttp,'m'*20) + # #####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) @@ -1091,39 +1100,39 @@ def commonprice(ct, rl, p,weekend): 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) + # ####print('dglg=',dglg) + # #####print('dggg=',dggg) #tt=time.time() data = consider_villa(ct, rl, p) #data.to_excel('data.xls') - #print('data=',data) + ##print('data=',data) #data.to_excel('ddw.xls') - ##print(time.time()-tt,'<>'*26) + ###print(time.time()-tt,'<>'*26) ####################################################### - #print('rrrr') - #print(data.shape[0]) + ##print('rrrr') + ##print(data.shape[0]) data=add_weight(data) - #print('data=',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##############') - # ####print('ppd=',ppd) + # #####print('ppd##############') + # #####print('ppd=',ppd) ppd = ppd.fillna(method='ffill') ppd1 = ppd.dropna() # t3=time.time() - #print(ppd1[['total_price','area']]) - #print(type(ppd1['total_price'][1])) - #print(type(ppd1['area'][1])) + ##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'] = ppd1['total_price'] / ppd1['area'] @@ -1138,7 +1147,7 @@ def commonprice(ct, rl, p,weekend): aaw=before_step_time(14) query1 = {"city": ct, "region": rl,'weekend':{'$gt':aaw}} lf = fangjia.find_region_price(query1) - #print('lf================',lf) + ##print('lf================',lf) if lf.shape[0]>0: return lf['calc_value'].iloc[-1] @@ -1168,7 +1177,7 @@ def commonprice(ct, rl, p,weekend): ###################################### ldf = label(ppd3, lianjia) - # ####print('ldf=',ldf) + # #####print('ldf=',ldf) ldf1 = label(ppd3, zhuge) @@ -1179,27 +1188,27 @@ def commonprice(ct, rl, p,weekend): ldf5 = label(ppd3, wkzf) l_and_z = ldf | ldf1 - # ####print(l_and_z) - # ####print('l_and_z=',l_and_z) + # #####print(l_and_z) + # #####print('l_and_z=',l_and_z) allf = l_and_z | ldf3 | ldf4 | ldf5 | ldf2 - # ####print('l_and_z_and_i=',l_and_z_and_i) + # #####print('l_and_z_and_i=',l_and_z_and_i) # mm=0 length = len(l_and_z) length1 = len(allf) - #print('#########') + ##print('#########') #a=datetime.datetime.now() #timeArray = a.strftime("%Y%m%d") - #print('timeArray=',timeArray) + ##print('timeArray=',timeArray) #front_step_time(360) def ss1(junjia,dglg,ppd3): sample_size = len(junjia) if dglg != None: - # ####print('junjia.shape',len(junjia)) + # #####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']) + ##print(dglg_dd['p_date']) if dglg_dd.shape[0]>2: dglg1= k_means_clus(dglg_dd['total_price'].dropna(),3) @@ -1212,10 +1221,10 @@ def commonprice(ct, rl, p,weekend): def consider_time_ss1(junjia,dglg,ppd3,day): sample_size = len(junjia) if dglg != None: - # ####print('junjia.shape',len(junjia)) + # #####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']]) + #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) @@ -1234,13 +1243,13 @@ def commonprice(ct, rl, p,weekend): price_60= consider_time_ss1(junjia,dglg,ppd3,day_60) if price_15[0]>0: - print('first_15') + #print('first_15') return price_15 elif price_30[0]>0: - print('first_30') + #print('first_30') return price_30 elif price_60[0]>0: - print('first_60') + #print('first_60') return price_60 else: return ss1(junjia,dglg,ppd3) @@ -1248,7 +1257,7 @@ def commonprice(ct, rl, p,weekend): dggg=map_time_price(junjia,dglg,ppd3) - if len(junjia)>4: + if len(junjia)>4 and dglg!=None: sample_size = len(junjia) return dglg, float('%.2f' % credit['0.88']), value_type['第三方'], sample_size @@ -1259,18 +1268,18 @@ def commonprice(ct, rl, p,weekend): elif length > 3: - # ####print('ldf=',l_and_z_and_i) + # #####print('ldf=',l_and_z_and_i) pppk = ppd3.loc[l_and_z, :] ppp = pppk[['total_price', 'p_date']] - # ####print(ppp) + # #####print(ppp) ppp1 = ppp.sort_values(['p_date'], ascending=False) gdf = ppp1['total_price'][:36].dropna() - #print('链家和诸葛找房合并后的数据集=',gdf) + ##print('链家和诸葛找房合并后的数据集=',gdf) sample_size = len(gdf) gm = k_means_clus(gdf, 2) - #####print('链猪= ', gm) + ######print('链猪= ', gm) return int(gm), float('%.2f' % credit['0.8']), value_type['自身样本'], sample_size # 优质样本 @@ -1280,7 +1289,7 @@ def commonprice(ct, rl, p,weekend): def guolv_data11(data, neighb): if type(neighb) is not str: - #####print('周边价格=', neighb) + ######print('周边价格=', neighb) ddd11 = data[data['avg'] > 0.65 * neighb] return ddd11 else: @@ -1293,7 +1302,7 @@ def commonprice(ct, rl, p,weekend): 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: @@ -1303,33 +1312,33 @@ def commonprice(ct, rl, p,weekend): s = zhuge_consist.zhuge_out(ddd11, 3, 1) - # ####print('s=',s) + # #####print('s=',s) dd22=ddd11['total_price']/ddd11['area'] def compelex(ddd11, s, neighb, junjia): #cc1 = ddd11['avg'].dropna() - # ####print('cc1=',cc1) - #print(ppd3['total_price'],'ppppppppppppppp') - #print('dd22=',dd22) + # #####print('cc1=',cc1) + ##print(ppd3['total_price'],'ppppppppppppppp') + ##print('dd22=',dd22) kmzhuge = k_means_clus(dd22.dropna(), 3) - #print(ppd3['total_price']) + ##print(ppd3['total_price']) junjia['zhuge_logic'] = kmzhuge 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) + # #####print('a=',a) b = set(list(junjia.index)) - # ####print('b=',b) + # #####print('b=',b) c = a & b u=list(b-a) if len(c) == 2 and len(junjia)>2: @@ -1350,7 +1359,7 @@ def commonprice(ct, rl, p,weekend): if len(cc) > 0: cc1 = pandas.DataFrame(cc, columns=['price', 'count']) cc2 = cc1.sort_values(by='count', ascending=False) - #print('cc2=',cc2) + ##print('cc2=',cc2) def two_one_choose(cc2): qwrt=set(cc2['count']) @@ -1364,12 +1373,12 @@ def commonprice(ct, rl, p,weekend): return two_one_choose(cc2) * 1.0, float('%.2f' % credit['0.7']), value_type[ '第三方'], sample_size else: - #print('777777') + ##print('777777') sample_size = ddd11.shape[0] - #print('junjia=',junjia) + ##print('junjia=',junjia) return junjia['kmzg'] * 1.0, float('%.2f' % credit['0.6']), value_type[ '自身样本'], sample_size - #print('ddd11=',ddd11) + ##print('ddd11=',ddd11) junjia_km = compelex(ddd11, s, neighb[0], junjia) return junjia_km @@ -1377,31 +1386,31 @@ def commonprice(ct, rl, p,weekend): else: - ####print('*' * 20, '采用周边算法') + #####print('*' * 20, '采用周边算法') if ddd11.shape[0] > 3: cc1 = ddd11['avg'].dropna() kmzhuge = k_means_clus(cc1, 2) sample_size = ddd11.shape[0] - #print('#########') + ##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: - ####print('优质第三方均价2 = ', dglg) + #####print('优质第三方均价2 = ', dglg) sample_size = len(junjia) return dglg, float('%.2f' % credit['0.8']), value_type['第三方'], sample_size # '优质样本' else: - #print('lgggggg=') + ##print('lgggggg=') - #print('neighb[0]=',neighb[0]) + ##print('neighb[0]=',neighb[0]) return neighb[0], float('%.2f' % credit['0.5']), value_type['周边楼盘'], neighb[1] elif dglg != None: - ####print('优质第三方均价3 = ', dglg) + #####print('优质第三方均价3 = ', dglg) sample_size = len(junjia) return dglg, float('%.2f' % credit['0.8']), value_type['第三方'] # '优质样本' @@ -1411,8 +1420,8 @@ def commonprice(ct, rl, p,weekend): elif dglg != None: - #print('优质第三方均价4 = ', dglg) - #print('neighb[0]',neighb[0]) + ##print('优质第三方均价4 = ', dglg) + ##print('neighb[0]',neighb[0]) def dgneib(dglg,neighb): @@ -1448,8 +1457,8 @@ def ghhh(kkg): 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()) +#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()) @@ -1476,7 +1485,7 @@ def region_district_list_lk(ct, rl, lk): def last_sunday(weekend): - #####print('weekend_up',weekend) + ######print('weekend_up',weekend) # import datetime last_sunday = weekend - datetime.timedelta(days=7) @@ -1484,7 +1493,7 @@ def last_sunday(weekend): #weekend1 = datetime.datetime.strptime(d1, '%Y%m%d') #weekend = weekend1 + datetime.timedelta(hours=-8) - #####print('weekend',last_sunday) + ######print('weekend',last_sunday) return last_sunday @@ -1492,7 +1501,7 @@ def last_sunday(weekend): def make_up_price(ct, rl, lk, weekend): - ####print('lg=',ct,rl,lk) + #####print('lg=',ct,rl,lk) # last_sunday=last_sunday(weekend)南湖国际中心二期 # save_lg=client136.fangjia.district_stat if lk != None: @@ -1513,8 +1522,8 @@ def make_up_price(ct, rl, lk, weekend): # pos=pos[pos['week1']>cc-5] # pos=pos.sort_values(by='week1',ascending=False) - # ####print('5'*10) - # ####print(pos) + # #####print('5'*10) + # #####print(pos) if pos.shape[0] > 0: # pp1""" @@ -1542,8 +1551,8 @@ def make_up_price(ct, rl, lk, weekend): # pos=pos[pos['week1']>cc-5] # pos=pos.sort_values(by='week1',ascending=False) - # ####print('5'*10) - # ####print(pos) + # #####print('5'*10) + # #####print(pos) if pos.shape[0] > 0: # pp1 @@ -1611,37 +1620,37 @@ def out_put_price(ct, rl, lk, weekend): lf = add_alias(lf) p = ghhh(lf[['name', 'alias', 'estate_type2']])[0] - #####print('p=', p) + ######print('p=', p) #t1=time.time() mm = commonprice(ct, rl, p,weekend) - #print('mmjisuantime=',time.time()-t1,'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy') - #####print('mm=',mm) + ##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) + ######print('estate_type',estate_type) estate_type,cmd_estate_type = out_estate_type(estate_type) - ##print('mm=',mm) - ##print(type(mm[0])) + #print('mm=',mm,'$'*20) + ###print(type(mm[0])) if type(mm[0]) != str: - # ####print(lf['estate_type2'].iloc[0],'*'*10) + # #####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(time.time()-t1,'*'*20) - print('last_sunday_price=',last_sunday_price) - # ####print('mm[0]',mm[0]) + #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: @@ -1653,13 +1662,13 @@ def out_put_price(ct, rl, lk, weekend): - #####print('make_up',make_up,'*'*20) - #####print('credic',mm[1]) + ######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) - #print('nihe=',avg) - #print('mm[0]',mm[0]) + ##print('nihe=',avg) + ##print('mm[0]',mm[0]) if avg>0: return avg else: @@ -1673,10 +1682,10 @@ def out_put_price(ct, rl, lk, weekend): make_up = int(make_up(avg,last_sunday_price)) - #print('s1_time=',time.time()-s1) + ##print('s1_time=',time.time()-s1) #avg=mm[0] - print('mm=',mm) - print(ct, rl, lk, avg, 'avg=',avg,'$' * 20) + #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) diff --git a/PriceSystem/test.py b/PriceSystem/test.py index d58b1b7..0b68375 100644 --- a/PriceSystem/test.py +++ b/PriceSystem/test.py @@ -14,7 +14,7 @@ def get_weekend(tt): pacific = pytz.timezone('Asia/Shanghai') return pacific.localize(bb) -weekend = get_weekend('20180401') +weekend = get_weekend('20180527') s = time.time() @@ -41,40 +41,86 @@ print(e - s) +""" +import pymongo +import pandas +client105 = pymongo.MongoClient('192.168.0.105',27777) #'192.168.0.65',27777 +db105 = client105.fangjia +seawater105 = db105.seawater -''' -### -import pandas as pd +client136 = pymongo.MongoClient('192.168.0.136',27017) +db136 = client136.fangjia +dsf136 = db136.average_statistics +seaweed136 = db136.seaweed +#some_district_information -a=pd.read_excel('跑价格(1).xlsx') + +def city_list(): #11111111111111111111111111111111111111111111111111111111111111111 + #client = pymongo.MongoClient('192.168.0.136',27017) #'192.168.0.65',27777 + #db = client.fangjia + city = db136.server_area + #city= fangjia.get_collection("fangjia","server_area", '192.168.0.136',27017) + #seawater.find_one() + + + pos=city.find({"display":{"$ne":"全国"}}, + {"display":1,"city_grade":1,"_id":1}).sort([("city_grade",1),("_id",1)]) + + + + data=pandas.DataFrame(list(pos)) + del pos + return data['display'] + -for i in a.index: - ct=a['城市'][i] - rl=a['区域'][i] - lk=a['小区名'][i] - sellPrice.out_put_price(ct, rl, lk, weekend) +def region_list(city): #22222222222222222222222222222222222222222222222 -''' + client = pymongo.MongoClient('192.168.0.136',27017) + db = client.fangjia + region = db.region_block + #region = fangjia.get_collection("fangjia","region_block", '192.168.0.136',27017) + #seawater.find_one() + query = {"city":city,"category":"region"} + fields1 = {"name":1} + pos = list(region.find(query,fields1)) + + data=pandas.DataFrame(pos) + del pos + return data['name'] + + + +ctii=city_list()#1111111111111111111111111111111111111111111111111111111111 +cti1=list(ctii) +def region_district(ct,rl): + + query = {"city": ct,'status':0,'region':rl} + + ll=seaweed136.find(query) + + ll1=list(ll) + + ll2=pandas.DataFrame(ll1) + + ll3=ll2['name'].dropna() + + return ll3 +for ct in cti1[0:]: + + reg=region_list(ct) + for i in reg: + print(i) + lkk=region_district(ct, i) + for lk in lkk: + sellPrice.out_put_price(ct, i, lk, weekend) + +""" - - - - -''' - -@fangjia.cache(1000) -def sum1(a, b): - print(111) - return a + b - - -print(sum1(1,2)) -'''