Skip to content

Commit

Permalink
添加抓取时间记录
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinnrry committed Sep 5, 2019
1 parent 8d382ef commit f86ac37
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
35 changes: 25 additions & 10 deletions Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@

// 房价均价查询语句
db.lianjia.aggregate([
{'$match': {"address.0": {$exists: true}}},
{
'$match': {
$and: [
{ "address.0": { $exists: true } },
//统计数据的的时间区间,使用的挂牌时间统计
{
"guapaitime": {
$gt: ISODate("2019-07-01T00:00:00.000+0000"),
$lt: ISODate("2019-08-01T00:00:00.000+0000")
}
},
{ "address.0": "成都" }
]
},
},
{
$group: {
_id: {$substr: ["$Link", 0, 22]},
city: {$first: "$address"},
count: {$sum: 1},
avg_UnitPrice: {$avg: "$UnitPrice"},
std: {$stdDevPop: "$UnitPrice"},
_id: { $substr: ["$Link", 0, 22] },
city: { $first: "$address" },
count: { $sum: 1 },
avg_UnitPrice: { $avg: "$UnitPrice" },
std: { $stdDevPop: "$UnitPrice" },
}
},
{
Expand All @@ -19,12 +33,12 @@ db.lianjia.aggregate([
count: 1, //总数
avg_UnitPrice: 1, //每平米均价
std: 1, //标准差
ratio: {$divide: ["$std", "$avg_UnitPrice"]}, //标准差与均价的比值
city: {$slice: ['$city', 0, 1]}
ratio: { $divide: ["$std", "$avg_UnitPrice"] }, //标准差与均价的比值
city: { $slice: ['$city', 0, 1] }
}
},
{
'$sort': {count: -1}
'$sort': { count: -1 }
}
]);

Expand Down Expand Up @@ -112,4 +126,5 @@ db.lianjia_zufang.aggregate([
{
'$sort': {count: -1}
}
]);
]);

8 changes: 8 additions & 0 deletions entrance/zhilian.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func Start_zhilian() {
res := get(apiUrl)
var mapResult map[string]interface{}
err = json.Unmarshal([]byte(res), &mapResult)

if err != nil {
fmt.Println("JsonToMapDemo err: ", err)
} else {
Expand All @@ -50,6 +51,13 @@ func Start_zhilian() {
numTotal := data["numTotal"]
total = int(numTotal.(float64))
results := data["results"].([]interface{})
for index := range results {
var itemTime string
loc, _ := time.LoadLocation("Local")
itemTime = results[index].(map[string]interface{})["updateDate"].(string)
results[index].(map[string]interface{})["updateDate"], _ = time.ParseInLocation("2006-01-02 15:04:05", itemTime, loc)
results[index].(map[string]interface{})["crawler_time"] = time.Now()
}
db.AddZLItem(results)
} else {
fmt.Println("接口返回错误!")
Expand Down

0 comments on commit f86ac37

Please sign in to comment.