更改:贡献度读取数据规则
This commit is contained in:
parent
53458dab8f
commit
56790f8558
|
@ -2,6 +2,16 @@ class Users::HeadmapsController < Users::BaseController
|
|||
def index
|
||||
result = Gitea::User::HeadmapService.call(observed_user.login, start_stamp, end_stamp, observed_user&.gitea_token)
|
||||
@headmaps = result[2].blank? ? [] : result[2]
|
||||
headmaps_result = {}
|
||||
@headmaps.each do |entry|
|
||||
date = Time.at(entry["timestamp"]).strftime("%Y-%m-%d")
|
||||
if headmaps_result[date].nil?
|
||||
headmaps_result[date] = { "contributions" => entry["contributions"] }
|
||||
else
|
||||
headmaps_result[date]["contributions"] += entry["contributions"]
|
||||
end
|
||||
end
|
||||
@headmaps = headmaps_result
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
|
@ -18,9 +28,9 @@ class Users::HeadmapsController < Users::BaseController
|
|||
|
||||
def end_stamp
|
||||
if params[:year].present?
|
||||
(Date.new(params[:year].to_i, 1) + 1.years).to_time.to_i
|
||||
(Date.new(params[:year].to_i, 1) + 1.years).to_time.end_of_day.to_i
|
||||
else
|
||||
Date.today.to_time.to_i
|
||||
Date.today.to_time.end_of_day.to_i
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
json.total_contributions @headmaps.collect{|map| map["contributions"]}.reduce(0, :+)
|
||||
json.headmaps @headmaps.each do |map|
|
||||
json.date Time.at(map["timestamp"].to_i).strftime("%Y-%m-%d")
|
||||
json.contributions map["contributions"]
|
||||
json.total_contributions @headmaps.collect{|k, value| value["contributions"]}.reduce(0, :+)
|
||||
json.headmaps @headmaps.each do |k, value|
|
||||
json.date k
|
||||
json.contributions value["contributions"]
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue