diff --git a/app/controllers/users/headmaps_controller.rb b/app/controllers/users/headmaps_controller.rb
new file mode 100644
index 000000000..81bd5771c
--- /dev/null
+++ b/app/controllers/users/headmaps_controller.rb
@@ -0,0 +1,26 @@
+class Users::HeadmapsController < Users::BaseController
+ def index
+ result = Gitea::User::HeadmapService.call(observed_user.login, start_stamp, end_stamp)
+ @headmaps = result[2]
+ rescue Exception => e
+ uid_logger_error(e.message)
+ tip_exception(e.message)
+ end
+
+ private
+ def start_stamp
+ if params[:year].present?
+ Date.new(params[:year], 1).to_time.to_i
+ else
+ Date.today.to_time.to_i - 365*24*60*60
+ end
+ end
+
+ def end_stamp
+ if params[:year].present?
+ Date.new(params[:year], 1).to_time.to_i + 365*24*60*60
+ else
+ Date.today.to_time.to_i
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/docs/slate/source/includes/_users.md b/app/docs/slate/source/includes/_users.md
index 1d1afc028..982543fdc 100644
--- a/app/docs/slate/source/includes/_users.md
+++ b/app/docs/slate/source/includes/_users.md
@@ -1,7 +1,7 @@
# Users
@@ -47,6 +47,128 @@ await octokit.request('GET /api/users/me.json')
Success Data.
+## 获取用户贡献度
+获取用户贡献度
+
+> 示例:
+
+```shell
+curl -X GET http://localhost:3000/api/users/yystopf/headmaps.json
+```
+
+```javascript
+await octokit.request('GET /api/users/:login/headmaps.json')
+```
+
+### HTTP 请求
+`GET api/users/:login/headmaps.json`
+
+### 返回字段说明:
+参数 | 类型 | 字段说明
+--------- | ----------- | -----------
+|total_contributions |int |所选时间内的总贡献度 |
+|headmaps.date |string|时间|
+|headmaps.contributions |int|贡献度|
+
+
+> 返回的JSON示例:
+
+```json
+{
+ "total_contributions": 139,
+ "headmaps": [
+ {
+ "date": 1612627200,
+ "contributions": 1
+ },
+ {
+ "date": 1613836800,
+ "contributions": 13
+ },
+ {
+ "date": 1614182400,
+ "contributions": 5
+ },
+ {
+ "date": 1614528000,
+ "contributions": 2
+ },
+ {
+ "date": 1614787200,
+ "contributions": 1
+ },
+ {
+ "date": 1615737600,
+ "contributions": 9
+ },
+ {
+ "date": 1616342400,
+ "contributions": 14
+ },
+ {
+ "date": 1616515200,
+ "contributions": 1
+ },
+ {
+ "date": 1617033600,
+ "contributions": 11
+ },
+ {
+ "date": 1617638400,
+ "contributions": 1
+ },
+ {
+ "date": 1618156800,
+ "contributions": 1
+ },
+ {
+ "date": 1618243200,
+ "contributions": 2
+ },
+ {
+ "date": 1618761600,
+ "contributions": 3
+ },
+ {
+ "date": 1619107200,
+ "contributions": 37
+ },
+ {
+ "date": 1619280000,
+ "contributions": 2
+ },
+ {
+ "date": 1619366400,
+ "contributions": 6
+ },
+ {
+ "date": 1619539200,
+ "contributions": 1
+ },
+ {
+ "date": 1619625600,
+ "contributions": 18
+ },
+ {
+ "date": 1619712000,
+ "contributions": 9
+ },
+ {
+ "date": 1620057600,
+ "contributions": 1
+ },
+ {
+ "date": 1620230400,
+ "contributions": 1
+ }
+ ]
+}
+```
+
+
+
## 待办事项-用户通知信息
待办事项-用户通知信息
diff --git a/app/services/gitea/user/headmap_service.rb b/app/services/gitea/user/headmap_service.rb
new file mode 100644
index 000000000..611a8b9d0
--- /dev/null
+++ b/app/services/gitea/user/headmap_service.rb
@@ -0,0 +1,23 @@
+class Gitea::User::HeadmapService < Gitea::ClientService
+ attr_reader :start_time, :end_time, :username
+
+ def initialize(username, start_time, end_time)
+ @username = username
+ @start_time = start_time
+ @end_time = end_time
+ end
+
+ def call
+ response = get(url, params)
+ render_response(response)
+ end
+
+ private
+ def params
+ Hash.new.merge(start: start_time, end: end_time)
+ end
+
+ def url
+ "/users/#{username}/heatmap".freeze
+ 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
new file mode 100644
index 000000000..7011b2559
--- /dev/null
+++ b/app/views/users/headmaps/index.json.jbuilder
@@ -0,0 +1,5 @@
+json.total_contributions @headmaps.collect{|map| map["contributions"]}.reduce(0, :+)
+json.headmaps @headmaps.each do |map|
+ json.date map["timestamp"]
+ json.contributions map["contributions"]
+end
diff --git a/config/routes.rb b/config/routes.rb
index a8c97effc..ae121bb08 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -265,6 +265,7 @@ Rails.application.routes.draw do
post :refuse
end
end
+ resources :headmaps, only: [:index]
resources :organizations, only: [:index]
# resources :projects, only: [:index]
# resources :subjects, only: [:index]
diff --git a/public/docs/api.html b/public/docs/api.html
index f970ea84d..9f52b9066 100644
--- a/public/docs/api.html
+++ b/public/docs/api.html
@@ -331,6 +331,9 @@
获取当前登陆用户信息
+
+ 获取用户贡献度
+
待办事项-用户通知信息
@@ -587,7 +590,7 @@ Success — a happy kitten is an authenticated kitten!
Users
获取当前登陆用户信息
@@ -649,6 +652,137 @@ Success — a happy kitten is an authenticated kitten!
+获取用户贡献度
+获取用户贡献度
+
+
+示例:
+
+curl -X GET http://localhost:3000/api/users/yystopf/headmaps.json
+
await octokit.request('GET /api/users/:login/headmaps.json')
+
HTTP 请求
+GET api/users/:login/headmaps.json
+返回字段说明:
+
+
+参数 |
+类型 |
+字段说明 |
+
+
+
+total_contributions |
+int |
+所选时间内的总贡献度 |
+
+
+headmaps.date |
+string |
+时间 |
+
+
+headmaps.contributions |
+int |
+贡献度 |
+
+
+
+
+返回的JSON示例:
+
+{
+ "total_contributions": 139,
+ "headmaps": [
+ {
+ "date": 1612627200,
+ "contributions": 1
+ },
+ {
+ "date": 1613836800,
+ "contributions": 13
+ },
+ {
+ "date": 1614182400,
+ "contributions": 5
+ },
+ {
+ "date": 1614528000,
+ "contributions": 2
+ },
+ {
+ "date": 1614787200,
+ "contributions": 1
+ },
+ {
+ "date": 1615737600,
+ "contributions": 9
+ },
+ {
+ "date": 1616342400,
+ "contributions": 14
+ },
+ {
+ "date": 1616515200,
+ "contributions": 1
+ },
+ {
+ "date": 1617033600,
+ "contributions": 11
+ },
+ {
+ "date": 1617638400,
+ "contributions": 1
+ },
+ {
+ "date": 1618156800,
+ "contributions": 1
+ },
+ {
+ "date": 1618243200,
+ "contributions": 2
+ },
+ {
+ "date": 1618761600,
+ "contributions": 3
+ },
+ {
+ "date": 1619107200,
+ "contributions": 37
+ },
+ {
+ "date": 1619280000,
+ "contributions": 2
+ },
+ {
+ "date": 1619366400,
+ "contributions": 6
+ },
+ {
+ "date": 1619539200,
+ "contributions": 1
+ },
+ {
+ "date": 1619625600,
+ "contributions": 18
+ },
+ {
+ "date": 1619712000,
+ "contributions": 9
+ },
+ {
+ "date": 1620057600,
+ "contributions": 1
+ },
+ {
+ "date": 1620230400,
+ "contributions": 1
+ }
+ ]
+}
+
+
待办事项-用户通知信息
待办事项-用户通知信息
@@ -657,7 +791,7 @@ Success — a happy kitten is an authenticated kitten!
curl -X GET http://localhost:3000/api/users/yystopf/applied_messages.json
await octokit.request('GET /api/users/:login/applied_messages.json')
-
HTTP 请求
+HTTP 请求
GET /api/users/:login/applied_messages.json
请求字段说明:
@@ -673,7 +807,7 @@ Success — a happy kitten is an authenticated kitten!
用户标识 |
-返回字段说明:
+返回字段说明:
参数 |
@@ -894,7 +1028,7 @@ Success — a happy kitten is an authenticated kitten!
curl -X GET http://localhost:3000/api/users/yystopf/applied_transfer_projects.json
await octokit.request('GET /api/users/:login/applied_transfer_projects.json')
-
HTTP 请求
+HTTP 请求
GET /api/users/:login/applied_transfer_projects.json
请求字段说明:
@@ -910,7 +1044,7 @@ Success — a happy kitten is an authenticated kitten!
用户标识 |
-返回字段说明:
+返回字段说明:
参数 |
@@ -1086,7 +1220,7 @@ Success — a happy kitten is an authenticated kitten!
curl -X POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/accept.json
await octokit.request('GET /api/users/:login/applied_transfer_projects/:id/accept.json')
-
HTTP 请求
+HTTP 请求
GET /api/users/:login/applied_transfer_projects/:id/accept.json
请求字段说明:
@@ -1107,7 +1241,7 @@ Success — a happy kitten is an authenticated kitten!
迁移id |
-返回字段说明:
+返回字段说明:
参数 |
@@ -1277,7 +1411,7 @@ Success — a happy kitten is an authenticated kitten!
curl -X POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/refuse.json
await octokit.request('GET /api/users/:login/applied_transfer_projects/:id/refuse.json')
-
HTTP 请求
+HTTP 请求
GET /api/users/:login/applied_transfer_projects/:id/refuse.json
请求字段说明:
@@ -1298,7 +1432,7 @@ Success — a happy kitten is an authenticated kitten!
迁移id |
-返回字段说明:
+返回字段说明: