Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

week3zhangruochen #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions week3大作业提交/zhangruochen/homework1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

# coding: utf-8

# In[1]:

#一定时间内北京各城区发贴量最多的三大类目


# In[1]:

import pymongo
import charts
from datetime import timedelta,date


# In[2]:

client = pymongo.MongoClient('localhost', 27017)
test = client['test']
homework = test['homework']
homework_output = test['homework_output']

In[18]:

for i in homework.find():
if (i['area']==[]) or (i['area'] == None):
area_dist = None
else:
area_dist = i['area'][0]
homework.update_one({'_id':i['_id']},{'$set':{'area_dist':area_dist}})

In[24]:

for i in homework.find():
frags = i['pub_date'].split('.')
if len(frags) == 1:
date = frags[0]
else:
date = '%s-%s-%s'%(frags[0],frags[1],frags[2])
homework.update_one({'_id':i['_id']},{'$set':{'pub_date':date}})


# In[3]:

def get_all_dates(date1,date2):
the_date = date(int(date1.split('-')[0]),int(date1.split('-')[1]),int(date1.split('-')[2]))
end_date = date(int(date2.split('-')[0]),int(date2.split('-')[1]),int(date2.split('-')[2]))
days = timedelta(days=1)
while the_date <= end_date:
yield (str(the_date))
the_date += days

# In[4]:

def get_data_within(date1,date2,cates,area_dist):
data_list = []
for cate in cates:
total_post = 0
for date in get_all_dates(date1,date2):
a = list(homework.find({'area_dist':area_dist,'cates':cate,'pub_date':date}))
each_day_post = len(a)
total_post += each_day_post
# print(area_dist,cate,total_post)
data_ori = {
'name':cate,
'data':[total_post],
'type':'column'
}
data_list.append(data_ori)
data_list.sort(key=lambda x:x['data'][0])
data = data_list[-3:]
for i in data:
yield i
# print(data_list)


# In[5]:

cates=[]
dists=[]
for i in homework.find():
cates.append(i['cates'])
dists.append(i['area_dist'])
cates_index = list(set(cates))
dists_index = list(set(dists))
# print(cates_index,dists_index)


# In[6]:
for dist in dists_index:
series = [i for i in get_data_within('2015-12-21','2016-01-15',cates_index,dist)]
charts.plot(series, options=dict(title=dict(text='各大区排名前三类目及发帖量'), subtitle=dict(text=dist), yAxis=dict(title=dict(text='发帖量'))))
122 changes: 122 additions & 0 deletions week3大作业提交/zhangruochen/homework2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

# coding: utf-8

# In[2]:

#各类目中成色与均价(全,99,95,9,8,7及以下)


# In[1]:

import pymongo
import charts


# In[31]:

client = pymongo.MongoClient('localhost',27017)
test = client['test']
homework = test['homework']
look = test['look']


# In[35]:

for i in homework.find():
try:
if i['price'] == '面议':
int_price = False
elif u' 元' in i['price']:
int_price = int(i['price'][:-2])
elif u'元' in i['price']:
int_price = int(i['price'][:-1])
elif i['price'] == '${info.paramsMap.minprice}':
int_price = False
else:
int_price = int(i['price'])
except ValueError:
int_price = False
homework.update_one({'_id':i['_id']},{'$set':{'int_price':int_price}})


# In[50]:

look_list=[]
for i in homework.find():
look_list.append(i['look'])
look_index_org = set(look_list)
look_index_org.discard('-')
look_index_org.discard('${info.paramsMap.oldlevel}')
look_index_org.discard('报废机/尸体')
look_index = list(look_index_org)
look_index.sort()
look_index.remove('9成新')
look_index.insert(2,'9成新')
print(look_index)


# In[51]:

counts=[]
for index in look_index:
counts.append(look_list.count(index))
print(counts)


# In[5]:

cates_list = []
for i in homework.find():
cates_list.append(i['cates'])
cates_index = set(cates_list)
print(cates_index)


# In[74]:

def get_all_price(cates):
avg_list=[]
for look in look_index:
price_list = []
for i in homework.find(({'cates':cates,'look':look})):
if i['int_price'] != False:
price_list.append(i['int_price'])
else:
pass
count = float(len(price_list))
sum = 0
for i in price_list:
sum += i
try:
avg = sum/count
avg_list.append(avg)
data = {
'name':'均价',
'data':avg_list,
'type':'line'
}
except ZeroDivisionError:
pass
yield data


# In[77]:

for cates in cates_index:
options={
'chart' : {'zoomType':'xy'},
'title' : {'text': '二手%s成色对应的平均价格'%cates},
'xAxis' : {'categories': [i for i in look_index]},
'yAxis' : {'title': {'text': '价格'}}
}
series = [i for i in get_all_price(cates)]
charts.plot(series, options=options)


# In[68]:

def get_details(cates):
for look in look_index:
for i in homework.find(({'cates':cates,'look':look})):
print(i)

66 changes: 66 additions & 0 deletions week3大作业提交/zhangruochen/result1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{"_id":{"$oid":"56ac9d5a3bd98f7f15a22c9b"},"area":"����","name":"����/����/����","data":110,"rank":1}
{"_id":{"$oid":"56ac9d5a3bd98f7f15a22c9c"},"area":"����","name":"�ҵ�","data":66,"rank":2}
{"_id":{"$oid":"56ac9d5a3bd98f7f15a22c9d"},"area":"����","name":"�����Ʒ","data":40,"rank":3}
{"_id":{"$oid":"56ac9d753bd98f7f15a22c9e"},"area":"����","name":"�ҵ�","data":3892,"rank":1}
{"_id":{"$oid":"56ac9d753bd98f7f15a22c9f"},"area":"����","name":"����/����/����","data":1905,"rank":2}
{"_id":{"$oid":"56ac9d753bd98f7f15a22ca0"},"area":"����","name":"��װ/Ьñ/���","data":1766,"rank":3}
{"_id":{"$oid":"56ac9d8d3bd98f7f15a22ca1"},"area":"����","name":"����/����/����","data":113,"rank":1}
{"_id":{"$oid":"56ac9d8d3bd98f7f15a22ca2"},"area":"����","name":"�����Ʒ","data":49,"rank":2}
{"_id":{"$oid":"56ac9d8d3bd98f7f15a22ca3"},"area":"����","name":"�ҵ�","data":46,"rank":3}
{"_id":{"$oid":"56ac9da33bd98f7f15a22ca4"},"area":"����","name":"�ҵ�","data":1676,"rank":1}
{"_id":{"$oid":"56ac9da33bd98f7f15a22ca5"},"area":"����","name":"�Ҿ�","data":455,"rank":2}
{"_id":{"$oid":"56ac9da33bd98f7f15a22ca6"},"area":"����","name":"����/����/����","data":431,"rank":3}
{"_id":{"$oid":"56ac9db93bd98f7f15a22ca7"},"area":"�����ܱ�","name":"��װ/Ьñ/���","data":78,"rank":1}
{"_id":{"$oid":"56ac9db93bd98f7f15a22ca8"},"area":"�����ܱ�","name":"����/����/����","data":71,"rank":2}
{"_id":{"$oid":"56ac9db93bd98f7f15a22ca9"},"area":"�����ܱ�","name":"�豸","data":64,"rank":3}
{"_id":{"$oid":"56ac9dcf3bd98f7f15a22caa"},"area":"˳��","name":"�ҵ�","data":386,"rank":1}
{"_id":{"$oid":"56ac9dcf3bd98f7f15a22cab"},"area":"˳��","name":"����/����/����","data":349,"rank":2}
{"_id":{"$oid":"56ac9dcf3bd98f7f15a22cac"},"area":"˳��","name":"�칫��Ʒ/�豸","data":147,"rank":3}
{"_id":{"$oid":"56ac9de43bd98f7f15a22cad"},"area":"ʯ��ɽ","name":"�ҵ�","data":578,"rank":1}
{"_id":{"$oid":"56ac9de43bd98f7f15a22cae"},"area":"ʯ��ɽ","name":"����/����/����","data":163,"rank":2}
{"_id":{"$oid":"56ac9de43bd98f7f15a22caf"},"area":"ʯ��ɽ","name":"��װ/Ьñ/���","data":152,"rank":3}
{"_id":{"$oid":"56ac9dfa3bd98f7f15a22cb0"},"area":"��ͷ��","name":"�ҵ�","data":135,"rank":1}
{"_id":{"$oid":"56ac9dfa3bd98f7f15a22cb1"},"area":"��ͷ��","name":"�����Ʒ","data":53,"rank":2}
{"_id":{"$oid":"56ac9dfa3bd98f7f15a22cb2"},"area":"��ͷ��","name":"����/����/����","data":49,"rank":3}
{"_id":{"$oid":"56ac9e123bd98f7f15a22cb3"},"area":"����","name":"�ҵ�","data":2271,"rank":1}
{"_id":{"$oid":"56ac9e123bd98f7f15a22cb4"},"area":"����","name":"�����Ʒ","data":1591,"rank":2}
{"_id":{"$oid":"56ac9e123bd98f7f15a22cb5"},"area":"����","name":"����/����/����","data":945,"rank":3}
{"_id":{"$oid":"56ac9e283bd98f7f15a22cb6"},"area":"����","name":"�ҵ�","data":378,"rank":1}
{"_id":{"$oid":"56ac9e283bd98f7f15a22cb7"},"area":"����","name":"��װ/Ьñ/���","data":200,"rank":2}
{"_id":{"$oid":"56ac9e283bd98f7f15a22cb8"},"area":"����","name":"����/����/����","data":177,"rank":3}
{"_id":{"$oid":"56ac9e3e3bd98f7f15a22cb9"},"area":"��ɽ","name":"�ҵ�","data":456,"rank":1}
{"_id":{"$oid":"56ac9e3e3bd98f7f15a22cba"},"area":"��ɽ","name":"����/����/����","data":185,"rank":2}
{"_id":{"$oid":"56ac9e3e3bd98f7f15a22cbb"},"area":"��ɽ","name":"ĸӤ/��ͯ��Ʒ","data":134,"rank":3}
{"_id":{"$oid":"56ac9e553bd98f7f15a22cbc"},"area":"��̨","name":"�ҵ�","data":2355,"rank":1}
{"_id":{"$oid":"56ac9e553bd98f7f15a22cbd"},"area":"��̨","name":"����/����/����","data":838,"rank":2}
{"_id":{"$oid":"56ac9e553bd98f7f15a22cbe"},"area":"��̨","name":"�Ҿ�","data":651,"rank":3}
{"_id":{"$oid":"56ac9e6b3bd98f7f15a22cbf"},"area":"����","name":"�Ҿ�","data":3,"rank":1}
{"_id":{"$oid":"56ac9e6b3bd98f7f15a22cc0"},"area":"����","name":"ƽ�����","data":0,"rank":2}
{"_id":{"$oid":"56ac9e6b3bd98f7f15a22cc1"},"area":"����","name":"�ֻ�","data":0,"rank":3}
{"_id":{"$oid":"56ac9e823bd98f7f15a22cc2"},"area":null,"name":"ͼ��/����/����","data":2134,"rank":1}
{"_id":{"$oid":"56ac9e823bd98f7f15a22cc3"},"area":null,"name":"��װ/Ьñ/���","data":1918,"rank":2}
{"_id":{"$oid":"56ac9e823bd98f7f15a22cc4"},"area":null,"name":"�����Ʒ","data":1607,"rank":3}
{"_id":{"$oid":"56ac9e993bd98f7f15a22cc5"},"area":"��ƽ","name":"�ҵ�","data":1129,"rank":1}
{"_id":{"$oid":"56ac9e993bd98f7f15a22cc6"},"area":"��ƽ","name":"����/����/����","data":460,"rank":2}
{"_id":{"$oid":"56ac9e993bd98f7f15a22cc7"},"area":"��ƽ","name":"ĸӤ/��ͯ��Ʒ","data":427,"rank":3}
{"_id":{"$oid":"56ac9eae3bd98f7f15a22cc8"},"area":"�ོ","name":"�ҵ�","data":170,"rank":1}
{"_id":{"$oid":"56ac9eae3bd98f7f15a22cc9"},"area":"�ོ","name":"����/����/����","data":58,"rank":2}
{"_id":{"$oid":"56ac9eae3bd98f7f15a22cca"},"area":"�ོ","name":"�����Ʒ","data":48,"rank":3}
{"_id":{"$oid":"56ac9ec33bd98f7f15a22ccb"},"area":"����","name":"�����Ʒ","data":34,"rank":1}
{"_id":{"$oid":"56ac9ec33bd98f7f15a22ccc"},"area":"����","name":"����/����/����","data":32,"rank":2}
{"_id":{"$oid":"56ac9ec33bd98f7f15a22ccd"},"area":"����","name":"ĸӤ/��ͯ��Ʒ","data":18,"rank":3}
{"_id":{"$oid":"56ac9edb3bd98f7f15a22cce"},"area":"����","name":"�ҵ�","data":560,"rank":1}
{"_id":{"$oid":"56ac9edb3bd98f7f15a22ccf"},"area":"����","name":"��װ/Ьñ/���","data":558,"rank":2}
{"_id":{"$oid":"56ac9edb3bd98f7f15a22cd0"},"area":"����","name":"����/����/����","data":354,"rank":3}
{"_id":{"$oid":"56ac9ef23bd98f7f15a22cd1"},"area":"����","name":"�ҵ�","data":188,"rank":1}
{"_id":{"$oid":"56ac9ef23bd98f7f15a22cd2"},"area":"����","name":"����/����/����","data":135,"rank":2}
{"_id":{"$oid":"56ac9ef23bd98f7f15a22cd3"},"area":"����","name":"�칫��Ʒ/�豸","data":114,"rank":3}
{"_id":{"$oid":"56ac9f083bd98f7f15a22cd4"},"area":"ƽ��","name":"����/����/����","data":74,"rank":1}
{"_id":{"$oid":"56ac9f083bd98f7f15a22cd5"},"area":"ƽ��","name":"�����Ʒ","data":33,"rank":2}
{"_id":{"$oid":"56ac9f083bd98f7f15a22cd6"},"area":"ƽ��","name":"̨ʽ��/���","data":21,"rank":3}
{"_id":{"$oid":"56ac9f1f3bd98f7f15a22cd7"},"area":"����","name":"�ҵ�","data":501,"rank":1}
{"_id":{"$oid":"56ac9f1f3bd98f7f15a22cd8"},"area":"����","name":"����/����/����","data":382,"rank":2}
{"_id":{"$oid":"56ac9f1f3bd98f7f15a22cd9"},"area":"����","name":"��װ/Ьñ/���","data":330,"rank":3}
{"_id":{"$oid":"56ac9f373bd98f7f15a22cda"},"area":"ͨ��","name":"�ҵ�","data":1149,"rank":1}
{"_id":{"$oid":"56ac9f373bd98f7f15a22cdb"},"area":"ͨ��","name":"����/����/����","data":638,"rank":2}
{"_id":{"$oid":"56ac9f373bd98f7f15a22cdc"},"area":"ͨ��","name":"ĸӤ/��ͯ��Ʒ","data":389,"rank":3}
Loading