From ba5a047035e2e3f38c69f3f457d34ff7b5e08cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E5=B9=B2?= Date: Mon, 9 Apr 2018 11:16:53 +0800 Subject: [PATCH] =?UTF-8?q?=09=E6=96=B0=E6=96=87=E4=BB=B6=EF=BC=9A=20=20?= =?UTF-8?q?=20PriceSystem/fix/=5F=5Finit=5F=5F.py=20=09=E6=96=B0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=9A=20=20=20PriceSystem/fix/=5F=5Fpycache=5F=5F/?= =?UTF-8?q?=5F=5Finit=5F=5F.cpython-36.pyc=20=09=E6=96=B0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=9A=20=20=20PriceSystem/fix/=5F=5Fpycache=5F=5F/?= =?UTF-8?q?price=5Ffix.cpython-36.pyc=20=09=E6=96=B0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=9A=20=20=20PriceSystem/fix/price=5Ffix.py=20=09=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=9A=20=20=20=20=20PriceSystem/ones=5FSender.py?= =?UTF-8?q?=20=09=E4=BF=AE=E6=94=B9=EF=BC=9A=20=20=20=20=20PriceSystem/sel?= =?UTF-8?q?l=5Fprice/zhuge0118A.py=20=09=E4=BF=AE=E6=94=B9=EF=BC=9A=20=20?= =?UTF-8?q?=20=20=20PriceSystem/test.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PriceSystem/.~lock.ppd4.xls# | 1 + PriceSystem/fangjia/__init__.py | 13 +- PriceSystem/fix/__init__.py | 1 + .../fix/__pycache__/__init__.cpython-36.pyc | Bin 0 -> 199 bytes .../fix/__pycache__/price_fix.cpython-36.pyc | Bin 0 -> 2870 bytes PriceSystem/fix/price_fix.py | 226 ++++++++++++ PriceSystem/ones_Sender.py | 33 +- PriceSystem/sell_price/zhuge0118A.py | 329 ++++++++++-------- PriceSystem/test.py | 22 +- logs/myeasylog.log | 0 10 files changed, 454 insertions(+), 171 deletions(-) create mode 100644 PriceSystem/.~lock.ppd4.xls# create mode 100644 PriceSystem/fix/__init__.py create mode 100644 PriceSystem/fix/__pycache__/__init__.cpython-36.pyc create mode 100644 PriceSystem/fix/__pycache__/price_fix.cpython-36.pyc create mode 100644 PriceSystem/fix/price_fix.py create mode 100644 logs/myeasylog.log diff --git a/PriceSystem/.~lock.ppd4.xls# b/PriceSystem/.~lock.ppd4.xls# new file mode 100644 index 0000000..e8a31cf --- /dev/null +++ b/PriceSystem/.~lock.ppd4.xls# @@ -0,0 +1 @@ +,luogan,luogan-Precision-Tower-3620,09.04.2018 09:15,file:///home/luogan/.config/libreoffice/4; \ No newline at end of file diff --git a/PriceSystem/fangjia/__init__.py b/PriceSystem/fangjia/__init__.py index 05a81ca..8f9fd16 100644 --- a/PriceSystem/fangjia/__init__.py +++ b/PriceSystem/fangjia/__init__.py @@ -25,7 +25,7 @@ def get_logger(name): file_handler = logging.FileHandler("/home/goojia/logs/" + name + ".log") file_handler.setFormatter(formatter) logger.addHandler(file_handler) - logger.setLevel("INFO") + logger.setLevel("ERROR") return logger @@ -39,7 +39,7 @@ def get_performance_logger(name): file_handler = logging.FileHandler("/home/goojia/logs/" + name + ".performance.log") file_handler.setFormatter(formatter) logger.addHandler(file_handler) - logger.setLevel("INFO") + logger.setLevel("ERROR") return logger now = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) @@ -152,16 +152,17 @@ def findHouse(query, fields=None): seawater105 = get_collection("fangjia", "seawater", config.get_seawater_host(), 27777) for err_count in range(0, 10): try: - lt = 1000 + lt = 100 # seawater.find(query,{"p_date":-1}).sort([("p_date",-1)]) - pos = list(seawater105.find(query, fields).limit(lt)) + pos = list(seawater105.find(query, fields).sort([("p_date",-1)]).limit(lt)) + #pos = list(seawater105.find(query, fields).limit(lt)) data = pandas.DataFrame(pos) del pos # print("==================>", time.time() - s) return data except: - lt = seawater105.count(query) - pos = list(seawater105.find(query).limit(lt)) + lt = 100 + pos = list(seawater105.find(query, fields).sort([("p_date",-1)]).limit(lt)) data = pandas.DataFrame(pos) del pos return data diff --git a/PriceSystem/fix/__init__.py b/PriceSystem/fix/__init__.py new file mode 100644 index 0000000..6f16543 --- /dev/null +++ b/PriceSystem/fix/__init__.py @@ -0,0 +1 @@ +from fix import price_fix diff --git a/PriceSystem/fix/__pycache__/__init__.cpython-36.pyc b/PriceSystem/fix/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c77574c65cc70046346d1db4c868a80d41456af4 GIT binary patch literal 199 zcmXr!<>kt|b}~wefq~&M5W@izkmUfx#R5Pgg&~D8has0Sijk2ag(;Xplldi3ltGj6 z7H2_GW^!tLT4sfxCetluAYBB~xssuX1xSI3uRcJQenx(7s(wysetKe_eonf6a(+sx z{?obbPj+vIQl*yJU3+k literal 0 HcmV?d00001 diff --git a/PriceSystem/fix/__pycache__/price_fix.cpython-36.pyc b/PriceSystem/fix/__pycache__/price_fix.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..be76a2de0e8ebe032278f9bf8005b701ff8958ce GIT binary patch literal 2870 zcmZWrO>7)V74E9)zv&rIY{$vQ$?js%^3#X4<1D*cLbM44f{<7X$%qww8QN1lrSE^=CBFiY&<_&sfeQ&ZsXk5!psMkqc>O zPVPls?nl0vcQTQ;qE;S6ff>75JMToDlf6#ln7vD*Zgk zqFjS~L5f`~yma_la91U9oyd){*mw)#Ub44w8#bSj0&Lmbk*r`&Q@})eAu*ht-3XGkE~s*@K1XZqp-6R3T^k(dZt~K4AZjEOERr$ zmG1WmU=*Fzr-lkif^8SIdJ&CejWx2yuIe^WO5Q+o3jm@|R~0+z0#<2WlrV?4 zFi(XpmxEte>N(8)^G!5c`(>VNEzGo)4Y&HGOtwDw@wfi^n_r!XSFdkH<_kZCvn#T##RFz@pB=uiSeXH@&07E=&Z;*y&(_n;_GZWb zK?%75L0!YP|-o!oy3KVD@D*~r`nGviEh)f1@4vR6G>n^vW46y}4T^($=H?Ou@WFXs*m{|e01s{0$@a6LJG5_`+_a*wutXQmrrW=o?Z1D7}SRM*1>H@3-fa@oVniIZER^Z?l<|mHTP<`0C5}U zeDEEZ%s5aBZqvGE%>yteA3I7m0iH+GYq|J3&J_{!pD@P7V4zanS2(;KT_idYXSci9fpIzZLTNbuZ zU%}iNwk-@O+>9Ii9GwNW#tC5h5kd|bfdPrfKo+PXkNCjW!N@kF7DjF(=AMLZBtWna z8|;)0_K7js0XgL49D#FcvV=s=L0&-)8gOI}TJN3Ly#2HP*A@2gl&pgtL-vXy)L3Ex z+%gRfdMnf;K3tHZWB5gV1PX1Zh(2|R<_L+fr9Mjik5Th+G{{#-L!ddSy&{PfGSfM; ze2JD(GFUW*>RRQrUL>V=F>wNZhj&HS?%K8p#4_*Nt6~k@r@n?2XW$d?XW$c^o`TUK#pj01Y==iZePi`iY*lYj^UTfM=|tj9^E*scCYnIED#9pyQG30fEc?A4 zC}?J$8;a;xI|$s#Y!TldrXydXhKNzo35xEkh&=QKI(k~C*`|5BDCLoMC68-jp)B1) zf?M#|LaJLd-v)zbNgp0uRNAgnJdnHrqG6QAcq1S=mAUrmWHaUV&5KH3IeRtW`Be9i zw~FC@oc5%8p6)~0!_b=vDPvaymHF0lpcr_J&HP(=DW_TT23@+kj>bkZ^6^{7k9r`^ W^S^dr``mxYzvy4}Kjer0#(x2ewZBjR literal 0 HcmV?d00001 diff --git a/PriceSystem/fix/price_fix.py b/PriceSystem/fix/price_fix.py new file mode 100644 index 0000000..519f44d --- /dev/null +++ b/PriceSystem/fix/price_fix.py @@ -0,0 +1,226 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Feb 28 16:40:25 2018 + +@author: luogan +""" + + +from pymongo import MongoClient +import numpy as np +import pandas as pd +from pandas import DataFrame,Series +from numpy import row_stack,column_stack +from dateutil.parser import parse +import pandas +import matplotlib.pyplot as plt +import numpy as np +import numpy +import collections +import time +import fangjia +import random +import datetime + + +''' +ct='上海' +rl='闵行' +lk=['上海康城'] +estype='普通住宅' +#上海闵行上海康城上海青浦南山雨果 +''' + +client = MongoClient('luogan.mongo.com',27017) +#dt=client.fangjia.district_stat_test + + +dt=client.fangjia.district_stat_shanghai_d + +def price_list(ct,rl,lk): + + + #query = {'city':ct,'region':rl,'district_name':lk} + + query = {'city':ct,'region':rl ,'district_name': lk } + + fields={'_id':1,'calc_value':1,'weekend':1,'block':1,'level':1,'avg_price':1,'credit':1} + + dl = dt.find(query,fields).sort([("weekend",-1)] ).limit(10) + #dl = dt.find(query).sort([("weekend",1)] ).limit(100) + dl1=list(dl) + ##print(len(dl1)) + df=pandas.DataFrame(dl1) + + if df.shape[0]>0: + def add_block(df): + + if 'block' in df.columns: + return df + else: + df['block']='no' + return df + + df=add_block(df) + + #df2=df[['_id','calc_value','weekend','block','']] + df3=df.sort_values(by='weekend') + if df.shape[0]>1: + return df3 + else: + return pd.DataFrame() + else: + return pd.DataFrame() + + +def plot1(x,y): + + + z1 = np.polyfit(x, y,3) + # 生成多项式对象 + p1 = np.poly1d(z1) + pp1=p1(x) + + + ################################## + #plt.plot(x,y,color='g',linestyle='-',marker='',label=u'理想曲线') + plt.plot(x,y,color='m',linestyle='-',marker='o',label=u'拟合数据') + plt.plot(x,pp1,color='b',linestyle='-',marker='.',label=u"拟合曲线") + # 把拟合的曲线在这里画出来 + plt.legend(loc='upper left') + plt.show() + + + +def line_regre(x,y,num): + + z1 = np.polyfit(x, y, num)#用3次多项式拟合 + p1 = np.poly1d(z1) + + oe=p1(len(x)) + return oe + ##print(p1) #在屏幕上打印拟合多项式 + +#上海经济建设小区崇明 + +''' +ct='上海' +rl='闵行' +lk='上海康城' +estype='普通住宅' +''' + +''' +ct='上海' +rl='崇明' +lk='上海经济建设小区' +estype='普通住宅' +''' + + +def compare(dd1,name,credit,calc_value): + y=list(dd1[name].dropna()) + ##print('y=',y) + kk=len(y) + + + + kk1=kk + y1=y[:kk1] + x1=list(range(kk1)) + ##print('y1=',y1) + fo=line_regre(x1,y1,1) + + ##print('fo=',fo) + + ##print('y[-1]',y[-1]) + + #plot1(list(range(kk)) ,y) + + ratio=calc_value/fo + if credit>=0.8 and(ratio>0.8 and ratio<1.4) : + ##print('calc_value1',calc_value) + return calc_value + elif ratio>0.9 and ratio<1.1: + ##print('ratio',ratio) + ##print('calc_value2',calc_value) + return calc_value + else: + ##print('fo',y[-1]) + return fo + +def out_price(ct,rl,lk,calc): + dd=price_list(ct,rl,lk) + #print('dd',dd) + if dd.shape[0]>0: + + + near_id=dd['_id'].iloc[-1] + + ##print('near_id',near_id) + + credit=dd['credit'].iloc[-1] + ##print('credit',credit) + + #calc_value=dd['calc_value'].iloc[-1] + calc_value=calc + ##print('calc_value',calc_value) + + if 'level' in dd.columns: + + #dd1=dd[(dd['level']==1) |(dd['credit']>=0.8)] + dd1=dd[dd['level']==1] + + if dd1.shape[0]>1: + + ##print('####################') + + return compare(dd1,'calc_value',credit,calc_value),near_id + + else: + return compare(dd,'avg_price',credit,calc_value),near_id + else: + return compare(dd,'avg_price',credit,calc_value),near_id + else: + return [] + + + +#pp=out_price(ct,rl,lk) + + + +def update(ct,rl,lk,calc): + dd= out_price(ct,rl,lk,calc) + return dd[0] + ''' + print(dd) + if len(dd)>0: + data={} + data['avg_price']=int(dd[0]) + ##print(data) + + if len(dd)>0: + dt.update_one({"_id": dd[1]}, + {"$set": data}) + ''' + + +#洛阳西工人名西路8号院 +''' +ct='洛阳' +rl='西工' +lk='人民西路8号院' + +update(ct,rl,lk) +''' + +''' +ct='上海' +rl='闵行' +lk='上海康城' +estype='普通住宅' +calc=38000 +update(ct,rl,lk,calc) +''' diff --git a/PriceSystem/ones_Sender.py b/PriceSystem/ones_Sender.py index 318433b..6371125 100644 --- a/PriceSystem/ones_Sender.py +++ b/PriceSystem/ones_Sender.py @@ -20,7 +20,8 @@ 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") @@ -38,9 +39,31 @@ def get_weekend(tt): pacific = pytz.timezone('Asia/Shanghai') return pacific.localize(bb) +def get_district(): + seaweeds = [] + keys = {"city": 1, "region": 1, "name": 1, "_id": 0} + for dis in fangjia.get_collection("fangjia", "seaweed").find({ "cat": "district", "status": 0,'city':'常州'}, keys): + #for dis in fangjia.get_collection("fangjia", "seaweed").find({ "city": "上海","cat": "district", "status": 0}, keys): + seaweeds.append(dis) + return seaweeds -if __name__ == "__main__": - weekend = "" + +weekend = get_weekend('20180408') #send_cmd({"city": "西安", "region": "雁塔", "name": "鸿景花园", "weekend": get_weekend('20180325')}) - send_cmd({"city": "绍兴", "region": "越城", "name": "辕门新村南区", "weekend": get_weekend('20180401')}) - #sys.exit(0) +if __name__ == "__main__": + for seaweed in get_district(): + + + send_cmd({"city":seaweed['city'],"region":seaweed['region'],"name":seaweed['name'],'weekend':weekend}) + + + + + + + + + + + + diff --git a/PriceSystem/sell_price/zhuge0118A.py b/PriceSystem/sell_price/zhuge0118A.py index 816c0fa..6aa2d5e 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 @@ -28,6 +28,7 @@ import sklearn.svm import datetime import config from fangjia import timer +import fix # import yesterday @@ -141,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 @@ -184,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: @@ -237,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 @@ -262,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) @@ -287,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 @@ -327,10 +328,10 @@ 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'] @@ -340,11 +341,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) @@ -362,7 +363,7 @@ def commonprice(ct, rl, p): #random.shuffle(dirst1) dirst = dirst1[:80] - ###print('dirst=',dirst) + ####print('dirst=',dirst) dirst_plus = dirst + [p[0]] @@ -370,17 +371,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([]) @@ -393,7 +394,7 @@ def commonprice(ct, rl, p): ################### ################### - estype = p[2] + #estype = p[2] # client1 = pymongo.MongoClient('192.168.0.136',27017) # db1 = client1.fangjia # seaweed1 = db1.seaweed @@ -414,11 +415,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'] @@ -428,11 +429,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) @@ -451,7 +452,7 @@ def commonprice(ct, rl, p): dirst = dirst1[:80] - # ##print('dirst=',dirst) + # ###print('dirst=',dirst) dirst_plus = dirst + [p[0]] @@ -459,17 +460,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([]) @@ -478,7 +479,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() @@ -487,7 +488,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'] @@ -495,9 +496,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: @@ -505,7 +506,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() @@ -549,57 +550,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], 50, ct, rl, p) - # ##print(time.time()-t3,'t3'*10) - ###print('dd2.shape', dd2.shape[0], '@' * 60) + 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) 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 @@ -660,28 +661,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: @@ -693,7 +694,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()) @@ -715,7 +716,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) @@ -748,7 +749,7 @@ def commonprice(ct, rl, p): # dd=dd.dropna() d1 = dd[dd['area'] > 150] - # ##print(dd) + # ###print(dd) villa_label = ["独栋", "联排", "叠加", "双拼", "花园面积", "泳池", "别墅", "带花园"] @@ -794,7 +795,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): @@ -847,7 +848,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): @@ -857,35 +858,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 @@ -897,11 +898,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 @@ -910,18 +911,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) + ####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: @@ -961,6 +962,7 @@ def commonprice(ct, rl, p): bl = ['anjuke_esf_price', 'soufang_esf_price', 'tuboshi_esf_price', + 'ganji_esf_price' ] @@ -992,38 +994,40 @@ def commonprice(ct, rl, p): 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) ''' dglg=dsplg(junjia,neighb,2) dggg=dsplg(junjia,neighb,1) ''' dglg = dglg_out1(junjia, neighb[0]) + #print('dglg=',dglg) # dggg=dglg_out1(junjia,neighb[0]) - # ##print('dglg=',dglg) - # ##print('dggg=',dggg) + # ###print('dglg=',dglg) + # ###print('dggg=',dggg) - # tt=time.time() + tt=time.time() data = consider_villa(ct, rl, p) - # ##print(time.time()-tt,'<>'*26) + #data.to_excel('dd.xls') + #print(time.time()-tt,'<>'*26) ####################################################### 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() @@ -1031,7 +1035,7 @@ def commonprice(ct, rl, p): # t3=time.time() 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'] @@ -1052,10 +1056,12 @@ def commonprice(ct, rl, p): ###################################### ppd3 = guolv_data(ppd1, neighb[0]) + + #ppd3.to_excel('ppd4.xls') ###################################### ldf = label(ppd3, lianjia) - # ##print('ldf=',ldf) + # ###print('ldf=',ldf) ldf1 = label(ppd3, zhuge) @@ -1066,47 +1072,60 @@ 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('junjia.shape',len(junjia)) sample_size = len(junjia) - return dglg, float('%.2f' % credit['0.85']), value_type['第三方'], sample_size + + 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 + else: + return dglg,float('%.2f' % credit['0.85']), value_type['第三方'], sample_size + 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) + gm = k_means_clus(gdf, 3) + ####print('链猪= ', gm) return int(gm), float('%.2f' % credit['0.8']), value_type['自身样本'], sample_size # 优质样本 + + + 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) + ####print('周边价格=', neighb) ddd11 = data[data['avg'] > 0.5 * neighb] return ddd11 else: @@ -1114,27 +1133,27 @@ def commonprice(ct, rl, p): 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) junjia['zhuge_logic'] = s @@ -1143,37 +1162,37 @@ def commonprice(ct, rl, p): 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) + # ###print('c=',c) if len(c) == 2: - # ##print('o'*100) + # ###print('o'*100) return junjia.drop('ganji_esf_price') else: return junjia junjia1 = drop_ganji(junjia) - ###print('ddd11',ddd11) + ####print('ddd11',ddd11) - ###print('junjia_ganji=',junjia1,'$'*100) + ####print('junjia_ganji=',junjia1,'$'*100) cc = group(junjia_front, junjia1, 1,16) # 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(bb2) sample_size = ddd11.shape[0] return cc2.iloc[0]['price'] * 1.0, float('%.2f' % credit['0.7']), value_type[ '第三方'], sample_size @@ -1189,7 +1208,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) @@ -1199,7 +1218,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 # '优质样本' @@ -1207,7 +1226,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['第三方'] # '优质样本' @@ -1217,13 +1236,13 @@ def commonprice(ct, rl, p): elif dglg != None: - ##print('优质第三方均价4 = ', dglg) + ###print('优质第三方均价4 = ', dglg) return dglg, float('%.2f' % credit['0.8']), value_type['第三方'], len(junjia) # '优质样本' else: - # ##print('*'*100) - # ##print(neighb) + # ###print('*'*100) + # ###print(neighb) return neighb[0], float('%.2f' % credit['0.5']), value_type['周边楼盘'], neighb[1] @@ -1245,8 +1264,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()) - - +#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()) ################################################################# def region_district_list_lk(ct, rl, lk): @@ -1267,7 +1286,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) @@ -1275,7 +1294,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 @@ -1283,7 +1302,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: @@ -1304,8 +1323,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""" @@ -1333,8 +1352,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 @@ -1375,7 +1394,7 @@ def stat_save(ct, rl, p, weekend, mm, c_date, m_date, make_up, estate_type): {"city": ct, "region": rl, "district_name": p[0], "weekend": weekend}, {"city": ct, "region": rl, "district_name": p[0], 'credit': mm[1], - "calc_value": int(mm[0]), "weekend": weekend, "c_date": c_date, 'avg_price': int(mm[0]), + "calc_value": int(mm[0]), "weekend": weekend, "c_date": c_date, 'avg_price':int(mm[0]), "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 @@ -1401,35 +1420,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])) if type(mm[0]) != str: - ##print(ct, rl, lk, mm, '$' * 20) - # ##print(lf['estate_type2'].iloc[0],'*'*10) + print(ct, rl, lk, mm, '$' * 20) + # ###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: @@ -1441,8 +1461,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) try: diff --git a/PriceSystem/test.py b/PriceSystem/test.py index 3b71771..58eaf6a 100644 --- a/PriceSystem/test.py +++ b/PriceSystem/test.py @@ -1,5 +1,6 @@ import datetime import fangjia +import pytz #fangjia.send_dingding_msg("测试") import time @@ -35,21 +36,28 @@ lk = '会展世界城三期' ''' #成都- 都江堰- 溪岭雪#上海徐汇 灞桥沁水新城百汇园西 安 未央 兴乐园 弘和美邻馆 雁塔鸿景花园上海 奉贤 万隆花苑# """ -ct='洛阳' -rl='涧西' -lk='奥阳康城'上海浦东龚家阁龚家花园绍兴越城辕门新村 +ct='洛阳'天宁青山湾常州 新北 中央花园 +rl='涧西' 常州新北中央花园天宁新天地花苑钟楼项家花园常州 新北 世茂香槟湖 (1 +lk='奥阳康城'上海浦东龚家阁龚家花园绍兴越城辕门新村上海长宁绿地海怡公寓新北 典雅花园 南区亨纳斯花园杨浦上海嘉定浏翔花苑北京 昌平 回龙观三期'东华苑'上海', '普陀', "['科普院' """ -ct='上海' -rl='普陀' -lk='科普院' +ct='常州' +rl='天宁' +lk='青山湾' #成都双流长滩一号 上海 奉贤 朝阳新村##上海 奉贤 棕榈滩别墅深圳龙岗丽皇阁 #洛阳涧西奥阳康城 #未央 -weekend = datetime.datetime.strptime("2018-04-01", "%Y-%m-%d") +def get_weekend(tt): + + from dateutil.parser import parse + bb=parse(tt) + pacific = pytz.timezone('Asia/Shanghai') + return pacific.localize(bb) + +weekend = get_weekend('20180415') #for i in range(0, 100): sellPrice.out_put_price(ct, rl, lk, weekend) diff --git a/logs/myeasylog.log b/logs/myeasylog.log new file mode 100644 index 0000000..e69de29