mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-09 05:15:53 +10:00
32 lines
948 B
Ruby
32 lines
948 B
Ruby
class Api::V1::DataAnalysisController < Api::V1::ApplicationController
|
|
|
|
skip_before_action :authenticate_user_from_token
|
|
|
|
before_action :load_target_user, only: [:user_info_statistics]
|
|
|
|
def user_info_statistics
|
|
share_hashs = ShareInstance.where(user_id: @target_user.id).group_by_week(:created_at, last: 6, format: "%m-%d").count
|
|
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: 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
|