mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-09 05:15:53 +10:00
#5 extract stats hashs into label and value two parts
This commit is contained in:
@@ -9,11 +9,23 @@ class Api::V1::DataAnalysisController < Api::V1::ApplicationController
|
||||
like_hashs = Like.where(user_id: @target_user.id).group_by_week(:created_at, last: 6, format: "%m-%d").count
|
||||
bookmark_hashs = Favorite.where(user_id: @target_user.id).group_by_week(:created_at, last: 6, format: "%m-%d").count
|
||||
render json: {
|
||||
shares: share_hashs,
|
||||
likes: like_hashs,
|
||||
bookmarks: bookmark_hashs
|
||||
shares: hash_to_obj(share_hashs),
|
||||
likes: hash_to_obj(like_hashs),
|
||||
bookmarks: hash_to_obj(bookmark_hashs)
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def hash_to_obj hash
|
||||
stats_obj = []
|
||||
hash.each do |key, value|
|
||||
temp = { :label => key, :value => value}
|
||||
stats_obj.push temp
|
||||
end
|
||||
stats_obj
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user