diff --git a/PriceSystem/CalcCmdReceiver.py b/PriceSystem/CalcCmdReceiver.py index 0e068a7..f11cb99 100644 --- a/PriceSystem/CalcCmdReceiver.py +++ b/PriceSystem/CalcCmdReceiver.py @@ -11,6 +11,7 @@ import os QUEUE = "calc_cmd" redis_pool = redis.ConnectionPool(host=config.get_redis_host(), port=6379, db=config.get_redis_db()) +#redis_pool = redis.ConnectionPool(host=config.get_redis_host(), port=6379, db=3) logger = fangjia.get_logger("CalcCmdReceiver") diff --git a/PriceSystem/fangjia/__init__.py b/PriceSystem/fangjia/__init__.py index 4decb82..f3eb613 100644 --- a/PriceSystem/fangjia/__init__.py +++ b/PriceSystem/fangjia/__init__.py @@ -152,15 +152,12 @@ def findHouse(query, fields=None): seawater105 = get_collection("fangjia", "seawater", config.get_seawater_host(), 27777) for err_count in range(0, 10): try: -<<<<<<< HEAD + lt = 100 # seawater.find(query,{"p_date":-1}).sort([("p_date",-1)]) pos = list(seawater105.find(query, fields).sort([("p_date",-1)]).limit(lt)) #pos = list(seawater105.find(query, fields).limit(lt)) -======= - lt = 1000 - pos = list(seawater105.find(query, fields).limit(lt)) ->>>>>>> 9b39a072aff955aeed773a2c859e1d355ec52231 + data = pandas.DataFrame(pos) del pos # print("==================>", time.time() - s) diff --git a/PriceSystem/sell_price/zhuge0118A.py b/PriceSystem/sell_price/zhuge0118A.py index 6aa2d5e..9d666b2 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 @@ -58,7 +58,7 @@ dsfjujia_time = front_step_time(200) // 100 ############################################################ ############################################################ -credit = pandas.Series([0.9,0.85, 0.8, 0.7, 0.6, 0.5], index=['0.9', '0.85','0.8', '0.7', '0.6', '0.5']) +credit = pandas.Series([0.9,0.85, 0.8,0.75, 0.7, 0.6, 0.5], index=['0.9', '0.85','0.8','0.75', '0.7', '0.6', '0.5']) value_type = pandas.Series([1, 2, 3, 4, 5, 6, 7], index=['指导价', '自身样本', '第三方', '交易数据', '周边楼盘', '推导', '优质样本']) @@ -142,10 +142,10 @@ def commonprice(ct, rl, p): 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 @@ -185,7 +185,7 @@ def commonprice(ct, rl, p): return numpy.array([]) def lianjia(ur): - # ###print(ur) + # ####print(ur) if 'lianjia' in ur: return 0 else: @@ -238,9 +238,9 @@ def commonprice(ct, rl, p): 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 @@ -263,7 +263,7 @@ def commonprice(ct, rl, p): # 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) @@ -288,14 +288,14 @@ def commonprice(ct, rl, p): 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 @@ -328,24 +328,25 @@ def commonprice(ct, rl, p): # 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'] lr = le[['lng2', 'lat2']] + lr['name1']=le['name'] 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) @@ -363,7 +364,7 @@ def commonprice(ct, rl, p): #random.shuffle(dirst1) dirst = dirst1[:80] - ####print('dirst=',dirst) + #####print('dirst=',dirst) dirst_plus = dirst + [p[0]] @@ -371,17 +372,17 @@ def commonprice(ct, rl, p): "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([]) @@ -407,7 +408,7 @@ def commonprice(ct, rl, p): "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)) @@ -415,11 +416,11 @@ def commonprice(ct, rl, p): # 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'] @@ -429,11 +430,11 @@ def commonprice(ct, rl, p): 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) @@ -452,7 +453,7 @@ def commonprice(ct, rl, p): dirst = dirst1[:80] - # ###print('dirst=',dirst) + # ####print('dirst=',dirst) dirst_plus = dirst + [p[0]] @@ -460,17 +461,17 @@ def commonprice(ct, rl, p): "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([]) @@ -479,7 +480,7 @@ def commonprice(ct, rl, p): # 提取要计算小区的特征 vk = vv[vv['district_name'] == lk] # 删除要计算小区的空特征 - # ###print('vk=',vk) + # ####print('vk=',vk) if vk.shape[0] > 0: vk1 = vk.iloc[0].dropna() @@ -488,7 +489,7 @@ def commonprice(ct, rl, p): 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'] @@ -496,9 +497,9 @@ def commonprice(ct, rl, p): 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: @@ -506,7 +507,7 @@ def commonprice(ct, rl, p): 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() @@ -516,7 +517,7 @@ def commonprice(ct, rl, p): else: km = vv['price'].dropna() return int(k_means(km)) - +# else: km = vv['price'].dropna() return int(k_means(km)) @@ -550,57 +551,57 @@ def commonprice(ct, rl, p): 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.shape[0], '@' * 60) + # ####print(time.time()-t3,'t3'*10) + #####print('dd2.shape', dd2.shape[0], '@' * 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], 10, ct, rl, p) - # ###print('dd2=',dd2,'@'*60) + # ####print('dd2=',dd2,'@'*60) if dd6.shape[0] >= 20: # 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 @@ -661,28 +662,28 @@ def commonprice(ct, rl, p): # 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: @@ -694,7 +695,7 @@ def commonprice(ct, rl, p): 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()) @@ -716,7 +717,7 @@ def commonprice(ct, rl, p): @timer def consider_villa(ct, rl, p): - # ###print('villa p=',p) + # ####print('villa p=',p) estype = p[2] df = strip_villa(ct, rl, p) @@ -749,7 +750,7 @@ def commonprice(ct, rl, p): # dd=dd.dropna() d1 = dd[dd['area'] > 150] - # ###print(dd) + # ####print(dd) villa_label = ["独栋", "联排", "叠加", "双拼", "花园面积", "泳池", "别墅", "带花园"] @@ -795,7 +796,7 @@ def commonprice(ct, rl, p): 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): @@ -838,6 +839,8 @@ def commonprice(ct, rl, p): index_max = gg.index(max(gg)) centroids = estimator.cluster_centers_ # 获取聚类中心 + + #print(centroids,gg) # inertia = estimator.inertia_ # 获取聚类准则的总和 center = centroids[index_max][0] return (int(center)) @@ -848,7 +851,7 @@ def commonprice(ct, rl, p): bb = [] for i in junjia_lzf.index: - # ###print(junjia_lzf) + # ####print(junjia_lzf) someprice = junjia_lzf[i] def compare15(b): @@ -858,35 +861,35 @@ def commonprice(ct, rl, p): 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 @@ -898,11 +901,11 @@ def commonprice(ct, rl, p): 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 @@ -911,18 +914,18 @@ def commonprice(ct, rl, p): #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,16) - a55 = mid_out_2(junjia_lzf, junjia_anst,16) - a66 = mid_out_1(junjia_anst,16) - ####print('a33=',a33) + 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() - ####print('aa1_6=',aa1_6) + #####print('aa1_6=',aa1_6) if len(aa1_6) > 0: return aa1_6.iloc[0] else: @@ -965,11 +968,23 @@ def commonprice(ct, rl, p): 'ganji_esf_price' ] - + + mmax=junjia.max() + def junjia_max(mmax,dg12): + if dg12!=None and mmax!=None: + ratiog=dg12/mmax + if 0.5 0.55 * neighb] + junjia = junjia[junjia > 0.7 * neighb] ''' junjia_lzf=junjia[al].dropna() junjia_anst=junjia[bl].dropna() @@ -979,7 +994,8 @@ def commonprice(ct, rl, p): junjia_lzf = alldi[0] junjia_anst = alldi[1] dg11 = middle_operate(junjia_lzf, junjia_anst) - return dg11 + #print('dg11=',dg11) + return junjia_max(mmax,dg11) else: @@ -989,53 +1005,116 @@ def commonprice(ct, rl, p): junjia_anst = alldi[1] dg22 = middle_operate(junjia_lzf, junjia_anst) - return dg22 + return junjia_max(mmax,dg22) 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('junjia=',junjia) + print('neighb=',neighb) ''' dglg=dsplg(junjia,neighb,2) dggg=dsplg(junjia,neighb,1) ''' - dglg = dglg_out1(junjia, neighb[0]) + + 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) + # ####print('dggg=',dggg) - tt=time.time() + #tt=time.time() data = consider_villa(ct, rl, p) - #data.to_excel('dd.xls') - #print(time.time()-tt,'<>'*26) + + #data.to_excel('data.xls') + def add_weight(s1): + + 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() + 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(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) + return d1 + else: + return s1 + + #data.to_excel('ddw.xls') + ##print(time.time()-tt,'<>'*26) ####################################################### - + #print('rrrr') + #print(data.shape[0]) + data=add_weight(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])) + #ppd1[['total_price','area']].to_excel('ppd1.xls') ppd1['total_price'] = ppd1['total_price'] / ppd1['area'] - # ###print('ppd1time',time.time()-t3,'o'*36) + # ####print('ppd1time',time.time()-t3,'o'*36) # ppd1.loc['total_price']=ppd1['total_price']/ppd1['area'] @@ -1047,7 +1126,7 @@ def commonprice(ct, rl, p): def guolv_data(ppd2, neighb): if type(neighb) is not str: - ph = ppd2[ppd2['total_price'] > 0.5 * neighb] + ph = ppd2[ppd2['total_price'] > 0.7 * neighb] return ph else: return ppd2 @@ -1061,7 +1140,7 @@ def commonprice(ct, rl, p): ###################################### ldf = label(ppd3, lianjia) - # ###print('ldf=',ldf) + # ####print('ldf=',ldf) ldf1 = label(ppd3, zhuge) @@ -1072,43 +1151,53 @@ def commonprice(ct, rl, p): 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) - - if dglg != None: - - # ###print('junjia.shape',len(junjia)) + #print('#########') + + def ss1(junjia,dglg,ppd3): sample_size = len(junjia) - - dglg_dd=ppd3[(ppd3['total_price']>0.85*dglg) & (ppd3['total_price']<1.3*dglg)] - - ##print(dglg_dd) - - if dglg_dd.shape[0]>3: - dglg1=gm = k_means_clus(dglg_dd['total_price'].dropna(), 3) - return dglg1, float('%.2f' % credit['0.85']), value_type['第三方'], sample_size + 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) + + 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 else: - return dglg,float('%.2f' % credit['0.85']), value_type['第三方'], sample_size - + return 0,float('%.2f' % credit['0.85']), value_type['第三方'], sample_size + dggg=ss1(junjia,dglg,ppd3) + + + if dggg[0]>0 : + return dggg + 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, 3) - ####print('链猪= ', gm) + gm = k_means_clus(gdf, 2) + #####print('链猪= ', gm) return int(gm), float('%.2f' % credit['0.8']), value_type['自身样本'], sample_size # 优质样本 @@ -1117,84 +1206,99 @@ def commonprice(ct, rl, p): elif data.shape[0] > 0: - ####print('诸葛找房算法') - ####print('neighb',neighb) + #####print('诸葛找房算法') + #####print('neighb',neighb) # from zhuge import zhuge_consist data['avg'] = data['total_price'] / data['area'] def guolv_data11(data, neighb): if type(neighb) is not str: - ####print('周边价格=', neighb) - ddd11 = data[data['avg'] > 0.5 * neighb] + #####print('周边价格=', neighb) + ddd11 = data[data['avg'] > 0.7 * neighb] return ddd11 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) + # ####print('s1=',s1) # s2 = set(s1) - # ###print('s2=',s2) + # ####print('s2=',s2) if ddd11.shape[0] > 3: from zhuge import zhuge_consist s = zhuge_consist.zhuge_out(ddd11, 3, 1) - # ###print('s=',s) + # ####print('s=',s) def compelex(ddd11, s, neighb, junjia): #cc1 = ddd11['avg'].dropna() - # ###print('cc1=',cc1) + # ####print('cc1=',cc1) - kmzhuge = zhuge_consist.zhuge_out(ddd11, 3, 0) + kmzhuge = k_means_clus(ppd3['total_price'], 3) + #print(ppd3['total_price']) 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) + # ####print('a=',a) b = set(list(junjia.index)) - # ###print('b=',b) + # ####print('b=',b) c = a & b - - # ###print('c=',c) - if len(c) == 2: - # ###print('o'*100) - 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) - ####print('ddd11',ddd11) - - ####print('junjia_ganji=',junjia1,'$'*100) - cc = group(junjia_front, junjia1, 1,16) + #####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) + #print('cc=',cc) ############ if len(cc) > 0: cc1 = pandas.DataFrame(cc, columns=['price', 'count']) cc2 = cc1.sort_values(by='count', ascending=False) - # ###print(bb2) + #print('cc2=',cc2) + + def two_one_choose(cc2): + qwrt=set(cc2['count']) + if len(qwrt)==1: + return junjia['kmzg'] + else: + return junjia['zhuge_logic'] sample_size = ddd11.shape[0] - return cc2.iloc[0]['price'] * 1.0, float('%.2f' % credit['0.7']), value_type[ + return two_one_choose(cc2) * 1.0, float('%.2f' % credit['0.7']), value_type[ '第三方'], sample_size else: sample_size = ddd11.shape[0] @@ -1208,7 +1312,7 @@ def commonprice(ct, rl, p): else: - ###print('*' * 20, '采用周边算法') + ####print('*' * 20, '采用周边算法') if ddd11.shape[0] > 3: cc1 = ddd11['avg'].dropna() kmzhuge = k_means_clus(cc1, 2) @@ -1218,7 +1322,7 @@ def commonprice(ct, rl, p): 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 # '优质样本' @@ -1226,7 +1330,7 @@ def commonprice(ct, rl, p): 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['第三方'] # '优质样本' @@ -1236,13 +1340,26 @@ def commonprice(ct, rl, p): elif dglg != None: - ###print('优质第三方均价4 = ', dglg) - return dglg, float('%.2f' % credit['0.8']), value_type['第三方'], len(junjia) # '优质样本' + #print('优质第三方均价4 = ', dglg) + #print('neighb[0]',neighb[0]) + + 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) + else: - # ###print('*'*100) - # ###print(neighb) + # ####print('*'*100) + # ####print(neighb) return neighb[0], float('%.2f' % credit['0.5']), value_type['周边楼盘'], neighb[1] @@ -1263,9 +1380,9 @@ 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()) -#stat = fangjia.get_collection("fangjia", "changzhou", config.get_district_stat_host(), config.get_district_stat_port()) -#pt = fangjia.get_collection("fangjia_log", "calc_command_changzhou", 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", "changzhou_6", 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()) ################################################################# def region_district_list_lk(ct, rl, lk): @@ -1286,7 +1403,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) @@ -1294,7 +1411,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 @@ -1302,7 +1419,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: @@ -1323,8 +1440,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""" @@ -1352,8 +1469,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 @@ -1420,36 +1537,36 @@ 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) mm = commonprice(ct, rl, p) - ####print('mm=',mm) + #####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) + ##print(type(mm[0])) if type(mm[0]) != str: print(ct, rl, lk, mm, '$' * 20) - # ###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(): if type(last_sunday_price) != str and last_sunday_price != None and mm[0] != None and type(mm[0]) != str: @@ -1461,11 +1578,11 @@ def out_put_price(ct, rl, lk, weekend): make_up = int(make_up()) - ####print('make_up',make_up,'*'*20) - ####print('credic',mm[1]) + #####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) + ###print('avg_price=',avg) try: @@ -1521,5 +1638,3 @@ def out_put_price(ct, rl, lk, weekend): ''' - - diff --git a/PriceSystem/test.py b/PriceSystem/test.py index 643ac0a..48162e3 100644 --- a/PriceSystem/test.py +++ b/PriceSystem/test.py @@ -7,55 +7,6 @@ import time import sell_price.zhuge0118A as sellPrice -s = time.time() - - -#上海 闵行上海康城 - -#深圳龙岗葵涌供销社综合商住楼 -''' -ct = '深圳' -rl = '龙岗' -lk = '葵涌供销社综合商住楼' -ct = '杭州' -rl = '桐庐' -lk = '金色港湾度假村' - -ct = '成都' -rl = '武侯' -lk = '中海国际社区林汀别墅' - - -ct = '成都' -rl = '双流' -lk = '长滩壹号' - -ct = '广州' -rl = '海珠' -lk = '会展世界城三期' -''' -#成都- 都江堰- 溪岭雪#上海徐汇 灞桥沁水新城百汇园西 安 未央 兴乐园 弘和美邻馆 雁塔鸿景花园上海 奉贤 万隆花苑# -""" -ct='洛阳'天宁青山湾常州 新北 中央花园 -rl='涧西' 常州新北中央花园天宁新天地花苑钟楼项家花园常州 新北 世茂香槟湖 (1 -lk='奥阳康城'上海浦东龚家阁龚家花园绍兴越城辕门新村上海长宁绿地海怡公寓新北 典雅花园 -南区亨纳斯花园杨浦上海嘉定浏翔花苑北京 昌平 回龙观三期'东华苑'上海', '普陀', "['科普院' -""" -<<<<<<< HEAD -ct='常州' -rl='天宁' -lk='青山湾' - -======= -ct='上海' -rl='长宁' -lk='绿地海怡公寓' ->>>>>>> 9b39a072aff955aeed773a2c859e1d355ec52231 -#成都双流长滩一号 上海 奉贤 朝阳新村##上海 奉贤 棕榈滩别墅深圳龙岗丽皇阁 -#洛阳涧西奥阳康城 - -#未央 - def get_weekend(tt): from dateutil.parser import parse @@ -64,25 +15,38 @@ def get_weekend(tt): return pacific.localize(bb) weekend = get_weekend('20180415') -#for i in range(0, 100): + +s = time.time() + +ct='深圳' +rl='福田' +lk='世纪豪庭' + + + +#for i in range(0, 100):深圳福田世纪豪庭 sellPrice.out_put_price(ct, rl, lk, weekend) e = time.time() print(e - s) + ''' + + ### import pandas as pd -a=pd.read_csv('fangjia.seaweed.csv') +a=pd.read_excel('小区调查.xlsx') for i in a.index: - ct=a['city'][i] - rl=a['region'][i] - lk=a['name'][i] + ct=a['城市'][i] + rl=a['区域'][i] + lk=a['小区名'][i] sellPrice.out_put_price(ct, rl, lk, weekend) - -''' + +''' + ''' @fangjia.cache(1000)