From 56790f85588ff7e1a5762dcbb4ddaa40ffc48078 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 31 Mar 2023 11:18:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=B4=A1=E7=8C=AE?= =?UTF-8?q?=E5=BA=A6=E8=AF=BB=E5=8F=96=E6=95=B0=E6=8D=AE=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users/headmaps_controller.rb | 14 ++++++++++++-- app/views/users/headmaps/index.json.jbuilder | 8 ++++---- 2 files changed, 16 insertions(+), 6 deletions(-) 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