fix error
This commit is contained in:
parent
bae6f2cf17
commit
89c065b047
|
@ -72,6 +72,9 @@ class Site
|
||||||
mount_uploader :favicon, ImageUploader
|
mount_uploader :favicon, ImageUploader
|
||||||
mount_uploader :mobile_icon, ImageUploader
|
mount_uploader :mobile_icon, ImageUploader
|
||||||
Impression.class_eval{
|
Impression.class_eval{
|
||||||
|
def self.create_date_for_group(date)
|
||||||
|
{'_id'=>{'year'=>date.year,'month'=>date.month,'day'=>date.day},'count'=>0}
|
||||||
|
end
|
||||||
def self.group_by(field,day_limit,start_day=Date.today,format = 'day')
|
def self.group_by(field,day_limit,start_day=Date.today,format = 'day')
|
||||||
limit_ele = self.desc(:id).where({ created_at: { "$lt" => start_day-(day_limit-2).days }}).first || self.first
|
limit_ele = self.desc(:id).where({ created_at: { "$lt" => start_day-(day_limit-2).days }}).first || self.first
|
||||||
key_op = [['year','$year'],['month', '$month'], ['day', '$dayOfMonth']]
|
key_op = [['year','$year'],['month', '$month'], ['day', '$dayOfMonth']]
|
||||||
|
@ -84,7 +87,11 @@ class Site
|
||||||
{"$group" => {"_id" => group_id_fields,"count" => {"$sum" => 1}}},
|
{"$group" => {"_id" => group_id_fields,"count" => {"$sum" => 1}}},
|
||||||
{"$sort" => {"_id"=>-1}}
|
{"$sort" => {"_id"=>-1}}
|
||||||
]
|
]
|
||||||
collection.aggregate(pipeline)
|
tmp = collection.aggregate(pipeline)
|
||||||
|
if tmp.count < day_limit
|
||||||
|
tmp.concat(Array.new(day_limit-tmp.count).map.with_index.map{|v,i| create_date_for_group(start_day+i.days)})
|
||||||
|
end
|
||||||
|
tmp
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
after_initialize do
|
after_initialize do
|
||||||
|
|
Loading…
Reference in New Issue