package main

import (
	qu "qfw/util"
	"time"
)


func dealWithSiteSpiderData()(map[string]interface{}) {

	defer qu.Catch()
	now:=time.Now() //当前天
	lt_time:= time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
	gte_time := lt_time-86400

	q := map[string]interface{}{
		"comeintime": map[string]interface{}{
			"$gte":  gte_time,
			"$lt": lt_time,
		},
	}
	sess := data_mgo.GetMgoConn()
	defer data_mgo.DestoryMongoConn(sess)
	//细节才需要遍历
	it := sess.DB(data_mgo.DbName).C(data_coll_name).Find(&q).Select(map[string]interface{}{
		"site":1,
	}).Iter()
	total,dict:=0,make(map[string]interface{},0)
	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
		site := qu.ObjToString(tmp["site"])
		if dict[site] == nil {
			dict[site] = 1
		}else {
			num := qu.IntAll(dict[site])+1
			dict[site] = num
		}
		tmp = make(map[string]interface{})
	}



	return map[string]interface{}{
		"num":total,
		"data":dict,
		"date":qu.FormatDateByInt64(&gte_time, qu.DATEFORMAT),
	}
}

