diff --git a/app/controllers/users/headmaps_controller.rb b/app/controllers/users/headmaps_controller.rb index 83efd99fb..15ce56769 100644 --- a/app/controllers/users/headmaps_controller.rb +++ b/app/controllers/users/headmaps_controller.rb @@ -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 \ No newline at end of file diff --git a/app/views/users/headmaps/index.json.jbuilder b/app/views/users/headmaps/index.json.jbuilder index 0e6a540b5..30f3ff4b4 100644 --- a/app/views/users/headmaps/index.json.jbuilder +++ b/app/views/users/headmaps/index.json.jbuilder @@ -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