From f86ac37680e2bfb83feb67ecc7dc61326e0ccecf Mon Sep 17 00:00:00 2001 From: jiangwei Date: Thu, 5 Sep 2019 22:55:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8A=93=E5=8F=96=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Query.js | 35 +++++++++++++++++++++++++---------- entrance/zhilian.go | 8 ++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Query.js b/Query.js index 41bbff4..16392d2 100644 --- a/Query.js +++ b/Query.js @@ -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" }, } }, { @@ -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 } } ]); @@ -112,4 +126,5 @@ db.lianjia_zufang.aggregate([ { '$sort': {count: -1} } -]); \ No newline at end of file +]); + diff --git a/entrance/zhilian.go b/entrance/zhilian.go index 00ff3a0..563f816 100644 --- a/entrance/zhilian.go +++ b/entrance/zhilian.go @@ -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 { @@ -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("接口返回错误!")