更改:贡献度读取数据规则

This commit is contained in:
yystopf 2023-03-31 11:18:58 +08:00
parent 53458dab8f
commit 56790f8558
2 changed files with 16 additions and 6 deletions

View File

@ -2,6 +2,16 @@ class Users::HeadmapsController < Users::BaseController
def index def index
result = Gitea::User::HeadmapService.call(observed_user.login, start_stamp, end_stamp, observed_user&.gitea_token) result = Gitea::User::HeadmapService.call(observed_user.login, start_stamp, end_stamp, observed_user&.gitea_token)
@headmaps = result[2].blank? ? [] : result[2] @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 rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception(e.message) tip_exception(e.message)
@ -18,9 +28,9 @@ class Users::HeadmapsController < Users::BaseController
def end_stamp def end_stamp
if params[:year].present? 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 else
Date.today.to_time.to_i Date.today.to_time.end_of_day.to_i
end end
end end
end end

View File

@ -1,5 +1,5 @@
json.total_contributions @headmaps.collect{|map| map["contributions"]}.reduce(0, :+) json.total_contributions @headmaps.collect{|k, value| value["contributions"]}.reduce(0, :+)
json.headmaps @headmaps.each do |map| json.headmaps @headmaps.each do |k, value|
json.date Time.at(map["timestamp"].to_i).strftime("%Y-%m-%d") json.date k
json.contributions map["contributions"] json.contributions value["contributions"]
end end