"""
Created on Wed Sep 20 10:51:47 2017
@author: Administrator
"""
import pymongo
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
from matplotlib.pylab import date2num
import random
def commonprice(ct,rl):
client1 = MongoClient('192.168.0.136',27017)
db1 = client1.fangjia
seaweed1 = db1.seaweed
query1 = {"status":0,"cat":"district","city":ct,"region":rl}
fields1 = {"lat2":1,"lng2":1, "city":1,"region":1,"cat":1,"name":1}
lct= list()
for s in seaweed1.find(query1, fields1):
lct.append(s)
lf=DataFrame(lct)
print(lf)
lk=list(lf['name'])
client = MongoClient('192.168.10.88',27777)
db = client.fangjia
seawater = db.seawater
seawater.find_one()
import random
from collections import Counter
for i in range(len(lk)):
query = {"city":ct,"cat":"sell","region":rl,
"district_name":lk[i],"p_date":{"$gt":20170701}}
lt= seawater.count(query)
pos = list()
for s in seawater.find(query).limit(lt):
pos.append(s)
data=DataFrame(pos)
if data.shape[0]>3:
ppd=data[['total_price','area','district_name']]
ppd1=ppd.dropna()
avv=ppd1['total_price']/ppd1['area']
avv1=list(avv)
avv2=(np.array(avv1)//2000)*2000
mostn=Counter(avv2).most_common(1)
mm=mostn[0][0]
nn=mostn[0][1]
print(mm,ppd1['district_name'][1],nn,rl)
client1 = MongoClient('192.168.0.136',27017)
db1 = client1.fangjia_stat
stat = db1.district_stat
stat.save({"city":ct,"region":rl,"district_name":ppd1['district_name'][1],
"avg_price":mm, "weeedend":"2017-09-22","acuracy":nn})
cti=["上海"]
region_list=["黄浦","徐汇","长宁","虹口","静安","普陀",
"杨浦","闵行","宝山","嘉定","浦东新","金山","松江",
"青浦","奉贤"]
for i in region_list:
commonprice(cti[0],i)