修改: PriceSystem/config/__init__.py
修改: PriceSystem/sell_price/zhuge0118A.py 修改: PriceSystem/test.py
This commit is contained in:
@@ -10,8 +10,8 @@ import pytz
|
||||
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=2)
|
||||
#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=9)
|
||||
logger = fangjia.get_logger("CalcCmdReceiver")
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import pytz
|
||||
from datetime import date
|
||||
|
||||
|
||||
'''
|
||||
|
||||
def get_weekend(tt):
|
||||
|
||||
from dateutil.parser import parse
|
||||
@@ -19,7 +19,7 @@ def get_weekend(tt):
|
||||
return pacific.localize(bb)
|
||||
|
||||
weekend = get_weekend('20180527')
|
||||
'''
|
||||
|
||||
|
||||
class CJsonEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
@@ -32,8 +32,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=9)
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ 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):
|
||||
@@ -59,8 +59,8 @@ def send_cmd(seaweed):
|
||||
|
||||
|
||||
def send_district_calc_cmd():
|
||||
for city in fangjia.get_all_city():
|
||||
#for city in ['上海']:
|
||||
#for city in fangjia.get_all_city():
|
||||
for city in ['上海']:
|
||||
|
||||
for seaweed in get_district(city):
|
||||
send_cmd(seaweed)
|
||||
@@ -88,8 +88,10 @@ def save_city_calc_command(city, region, weekend):
|
||||
|
||||
|
||||
def send_city_calc_cmd():
|
||||
weekend = fangjia.get_weekend()
|
||||
for city in fangjia.get_all_city():
|
||||
#weekend = fangjia.get_weekend()
|
||||
|
||||
for city in ['上海']:
|
||||
#for city in fangjia.get_all_city():
|
||||
for region in fangjia.get_region(city):
|
||||
save_city_calc_command(city, region, weekend)
|
||||
save_city_calc_command(city, None, weekend)
|
||||
|
||||
@@ -8,7 +8,7 @@ def get_worker_num():
|
||||
|
||||
|
||||
def get_redis_host():
|
||||
return "192.168.0.144"
|
||||
return "192.168.0.210"
|
||||
|
||||
def get_district_stat_host():
|
||||
return "avgprice.mongo.db.fangjia.com"
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Tue Jan 2 13:24:07 2018
|
||||
|
||||
@author: Administrator
|
||||
"""
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Fri Sep 22 18:18:15 2017
|
||||
|
||||
@author: Administrator
|
||||
"""
|
||||
@author: 罗干
|
||||
|
||||
1;本算法在构建的过程中得到王文艳的很多帮助
|
||||
特此鸣谢!
|
||||
|
||||
"""
|
||||
#导入相关的库
|
||||
import os
|
||||
|
||||
#####print(os.getcwd())
|
||||
@@ -24,6 +21,7 @@ import numpy
|
||||
import numpy as np
|
||||
import time
|
||||
import fangjia
|
||||
#svm向量回归用于计算无房源小区的房价
|
||||
import sklearn.svm
|
||||
import datetime
|
||||
import config
|
||||
@@ -33,6 +31,8 @@ import time
|
||||
|
||||
# import yesterday
|
||||
|
||||
#本函数用于时间处理,即时间前推或后推处理,并且按照int类型输出
|
||||
|
||||
def front_step_time(weekend,day):
|
||||
#now = datetime.datetime.now()
|
||||
now=weekend
|
||||
@@ -52,8 +52,18 @@ def front_step_time(weekend,day):
|
||||
############################################################
|
||||
############################################################
|
||||
|
||||
#均价的可信度定义
|
||||
# 0.9表示人工指导价,本算法还未加入
|
||||
#0.88 当第三方价格样本量在5个及以上时,通过函数置换出的价格,由于由第三方均价所出的价格已经非常准确,避免不良房源的干扰,房源不参与计算
|
||||
#0.85 第三方均价可以置换出某个价格,并且参考房源所出的价格
|
||||
#0.80 采用链家和诸葛找房合并后的样本
|
||||
#0.75 未采用
|
||||
#0.7 同时参考样本和未能置换出价格的第三方均价
|
||||
#0.6 仅仅采用房源样本聚类
|
||||
#0.5 无房源也无第三方均价,采用周边小区计算
|
||||
credit = pandas.Series([0.9,0.88,0.85, 0.8,0.75, 0.7, 0.6, 0.5], index=['0.9', '0.88','0.85','0.8','0.75', '0.7', '0.6', '0.5'])
|
||||
|
||||
#计算来源
|
||||
value_type = pandas.Series([1, 2, 3, 4, 5, 6, 7],
|
||||
index=['指导价', '自身样本', '第三方', '交易数据', '周边楼盘', '推导', '优质样本'])
|
||||
|
||||
@@ -61,6 +71,7 @@ value_type = pandas.Series([1, 2, 3, 4, 5, 6, 7],
|
||||
# 1:指导价 2:自身样本 3:第三方 4:交易数据 5:周边楼盘, 6:推导
|
||||
|
||||
|
||||
#计算均价函数入口
|
||||
def commonprice(ct, rl, p,weekend):
|
||||
|
||||
|
||||
@@ -74,18 +85,20 @@ def commonprice(ct, rl, p,weekend):
|
||||
# 第三方均价的数据时间上限,如从201703之后的数据
|
||||
dsfjujia_time = front_step_time(weekend,200) // 100
|
||||
|
||||
|
||||
#增加DataFrame的板块 block
|
||||
def add_block(ppd):
|
||||
if 'block' not in ppd.columns:
|
||||
ppd['block'] = '没有'
|
||||
return ppd
|
||||
|
||||
#增加DataFrame的 room
|
||||
def add_room(ppd):
|
||||
if 'room' not in ppd.columns:
|
||||
ppd['room'] = 2
|
||||
return ppd
|
||||
|
||||
@timer
|
||||
|
||||
#从数据库中读取房源数据,seawater
|
||||
def some_district_information(ct, rl, lk):
|
||||
|
||||
query = {"city": ct, "cat": "sell", "region": rl,
|
||||
@@ -101,7 +114,7 @@ def commonprice(ct, rl, p,weekend):
|
||||
return fangjia.find_house_from_elastic_search(ct, rl, lk,
|
||||
"lianjia.com", some_district_information_time)
|
||||
"""
|
||||
|
||||
#从数据库中读取第三方均价,"fangjia", "average_statistics"
|
||||
def disanganf_price(ct, rl, lk, tt):
|
||||
# db1 = client1.fangjia
|
||||
# dsf = db1.average_statistics
|
||||
@@ -130,7 +143,7 @@ def commonprice(ct, rl, p,weekend):
|
||||
return numpy.array([])
|
||||
else:
|
||||
return numpy.array([])
|
||||
|
||||
#提取某个小区的经纬度
|
||||
def take_location(ct, rl, p):
|
||||
|
||||
dirlt = p[0]
|
||||
@@ -190,38 +203,39 @@ def commonprice(ct, rl, p,weekend):
|
||||
|
||||
else:
|
||||
return numpy.array([])
|
||||
|
||||
#以下几个函数用来判断数据来源
|
||||
#判断某条房源是否来自链家
|
||||
def lianjia(ur):
|
||||
# #####print(ur)
|
||||
if 'lianjia' in ur:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
#判断某条房源是否来自诸葛找房
|
||||
def zhuge(ur):
|
||||
if 'zhuge' in ur:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
#判断某条房源是否来自我爱我家
|
||||
def wawj(ur):
|
||||
if '5i5j' in ur:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
#爱屋及屋
|
||||
def iwjw(ur):
|
||||
if 'iwjw' in ur:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
#房估估
|
||||
def fangdd(ur):
|
||||
if 'fangdd' in ur:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
#悟空找房
|
||||
def wkzf(ur):
|
||||
if 'wkzf' in ur:
|
||||
return 0
|
||||
@@ -239,6 +253,7 @@ def commonprice(ct, rl, p,weekend):
|
||||
return set(aa)
|
||||
|
||||
@timer
|
||||
#最新的一条数据
|
||||
def new_data(ds):
|
||||
bb = set(ds['name'])
|
||||
bb1 = list(bb)
|
||||
@@ -304,16 +319,18 @@ def commonprice(ct, rl, p,weekend):
|
||||
ppp.loc[i, 'price'] = df[kk]
|
||||
# #####print('df[kk]',df[kk])
|
||||
return ppp
|
||||
|
||||
|
||||
#搜索周边小区,并且输出周边小区的房价
|
||||
@timer
|
||||
def neighbor(lng, lat, scale, ct, rl, p):
|
||||
|
||||
|
||||
#搜索周边小区
|
||||
###################
|
||||
###################
|
||||
# timm=20171122
|
||||
###################
|
||||
###################
|
||||
|
||||
#小区的物业类型,有普通住宅和别墅
|
||||
estype = p[2]
|
||||
# client1 = pymongo.MongoClient('192.168.0.136',27017)
|
||||
# db1 = client1.fangjia
|
||||
@@ -321,7 +338,7 @@ def commonprice(ct, rl, p,weekend):
|
||||
kkk = scale / 1000
|
||||
longtitude = lng
|
||||
latitude = lat
|
||||
|
||||
#搜索周边的一定经纬度范围内的小区
|
||||
query1 = {"status": 0, "cat": "district",
|
||||
"lat2": {"$gt": int(latitude - kkk * 10 ** 10 / 0.86), "$lt": int(latitude + kkk * 10 ** 10 / 0.86)},
|
||||
"lng2": {"$gt": int(longtitude - kkk * 10 ** 10), "$lt": int(longtitude + kkk * 10 ** 10)}}
|
||||
@@ -346,7 +363,7 @@ def commonprice(ct, rl, p,weekend):
|
||||
|
||||
lr['name1']=le['name']
|
||||
|
||||
|
||||
#计算周边小区距离中心小区的距离,本距离为曼哈顿距离
|
||||
def sort_manhaten(lr):
|
||||
lr1=lr.values
|
||||
####print(lr1)
|
||||
@@ -482,7 +499,7 @@ def commonprice(ct, rl, p,weekend):
|
||||
return vv
|
||||
else:
|
||||
return numpy.array([])
|
||||
|
||||
#向量回归计算小区均价
|
||||
def svr(vv, lk):
|
||||
# 提取要计算小区的特征
|
||||
vk = vv[vv['district_name'] == lk]
|
||||
@@ -507,7 +524,7 @@ def commonprice(ct, rl, p,weekend):
|
||||
# #####print('x1=',x1)
|
||||
y = vvo1['price']
|
||||
# #####print('y',y)
|
||||
|
||||
#向量回归
|
||||
if len(x1) > 2:
|
||||
|
||||
clf = sklearn.svm.SVR()
|
||||
@@ -517,6 +534,7 @@ def commonprice(ct, rl, p,weekend):
|
||||
# #####print (result)
|
||||
return int(result[0])
|
||||
else:
|
||||
#聚类
|
||||
km = vv['price'].dropna()
|
||||
return int(k_means(km))
|
||||
|
||||
@@ -524,11 +542,11 @@ def commonprice(ct, rl, p,weekend):
|
||||
else:
|
||||
km = vv['price'].dropna()
|
||||
return int(k_means(km))
|
||||
#
|
||||
|
||||
else:
|
||||
km = vv['price'].dropna()
|
||||
return int(k_means(km))
|
||||
|
||||
#计算无房源小区的均价
|
||||
def no_source_price(ct, rl, location, p):
|
||||
|
||||
|
||||
@@ -979,11 +997,15 @@ def commonprice(ct, rl, p,weekend):
|
||||
mmax=junjia.max()
|
||||
def junjia_max(mmax,dg12):
|
||||
if dg12!=None and mmax!=None:
|
||||
|
||||
return dg12
|
||||
'''
|
||||
ratiog=dg12/mmax
|
||||
if 0.5<ratiog<0.7:
|
||||
return mmax
|
||||
else:
|
||||
return dg12
|
||||
'''
|
||||
else:
|
||||
return dg12
|
||||
|
||||
@@ -1089,7 +1111,7 @@ def commonprice(ct, rl, p,weekend):
|
||||
# #####print(time.time()-ttp,'m'*20)
|
||||
|
||||
junjia = dsfjujia(ct, rl, lk)
|
||||
#print('junjia=',junjia)
|
||||
print('junjia=',junjia)
|
||||
#print('neighb=',neighb)
|
||||
|
||||
'''
|
||||
@@ -1100,7 +1122,7 @@ 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)
|
||||
@@ -1635,7 +1657,7 @@ def out_put_price(ct, rl, lk, weekend):
|
||||
|
||||
estate_type,cmd_estate_type = out_estate_type(estate_type)
|
||||
|
||||
#print('mm=',mm,'$'*20)
|
||||
print('mm=',mm,'$'*20)
|
||||
###print(type(mm[0]))
|
||||
if type(mm[0]) != str:
|
||||
|
||||
|
||||
+5
-4
@@ -20,11 +20,12 @@ weekend = get_weekend('20180527')
|
||||
s = time.time()
|
||||
|
||||
|
||||
ct='深圳'
|
||||
rl='福田'
|
||||
lk='东方银座'
|
||||
ct='上海'
|
||||
rl='长宁'
|
||||
lk='江苏北路105弄小区'
|
||||
'''
|
||||
'深圳', 'region': '福田', 'name': '东方银座'
|
||||
'深圳', 'region': '福田', 'name': '东方银座'$ 上海长宁江苏北路105弄小区
|
||||
|
||||
'''
|
||||
|
||||
#杨浦凤城四村闵行上海康城厦门同安大唐世家二期青岛市北东方小区合肥庐阳海亮红玺台青岛市北东方小区
|
||||
|
||||
Reference in New Issue
Block a user