"""
Created on Thu Aug 24 15:14:07 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
client1 = MongoClient('192.168.0.136',27017)
db1 = client1.fangjia
seaweed1 = db1.seaweed
cy_rg=["成都","锦江"]
query1 = {"status":0,"cat":"district","city":cy_rg[0],"region":cy_rg[1]}
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)
lk=list(lf['name'])
client = MongoClient('192.168.10.88',27777)
db = client.fangjia
seawater = db.seawater
seawater.find_one()
for i in range(len(lk)):
query = {"city":cy_rg[0],"cat":"sell","region":cy_rg[1],
"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=ppd['total_price']/ppd['area']
avp=int(avv.mean())
print(avp,ppd1['district_name'][1])
client1 = MongoClient('192.168.0.136',27017)
db1 = client1.fangjia_stat
stat = db1.district_stat
stat.save({"city":cy_rg[0],"region":cy_rg[1],"district_name":ppd1['district_name'][1],
"avg_price":avp, "weeedend":"2017-09-08"})