Browse Source

feat: 年度数据统计

closed-social-v3
欧醚 3 weeks ago
parent
commit
fd8dd1498d
4 changed files with 88 additions and 3 deletions
  1. +23
    -1
      app/controllers/about_controller.rb
  2. +10
    -2
      app/helpers/home_helper.rb
  3. +53
    -0
      app/views/about/my_data.html.haml
  4. +2
    -0
      config/routes.rb

+ 23
- 1
app/controllers/about_controller.rb View File

@ -7,7 +7,7 @@ class AboutController < ApplicationController
before_action :set_body_classes, only: :show
before_action :set_instance_presenter
before_action :set_expires_in, only: [:show, :more, :terms]
before_action :authenticate_user!, only: :jump
before_action :authenticate_user!, only: [:jump, :my_data]
skip_before_action :require_functional!, only: [:more, :terms]
@ -29,6 +29,28 @@ class AboutController < ApplicationController
@jump_url = "https://#{request.fullpath[6..-1]}"
end
def my_data
@account = current_account
year = params[:year].to_i
year = nil unless year > 2000
@year_text = year or ''
y = year ? "statuses.created_at >= '#{year}-1-1' and statuses.created_at < '#{year+1}-1-1'" : nil
y2 = year ? "s2.created_at >= '#{year}-1-1' and s2.created_at < '#{year+1}-1-1'" : nil
def raw_to_list(r)
r.map{|k,v| {:account => Account.find(k), :num => v.to_s}}
end
@total = @account.statuses.where(y).count
@most_times = @account.statuses.where(y).group('cast (created_at as date)').reorder('count_id desc').limit(1).count(:id).map{ |k,v| {:date => k.to_s, :num => v.to_s}}
@most_fav = @account.statuses.where(y).joins(:status_stat).reorder('status_stats.favourites_count desc').first
@like_me_most = raw_to_list(@account.statuses.where(y).joins(:favourites).group('favourites.account_id').reorder('count_id desc').limit(5).count(:id))
@i_like_most = raw_to_list(@account.favourites.where(y).joins(:status).group('statuses.account_id').reorder('count_id desc').limit(5).count(:id))
@communi_most = raw_to_list(@account.statuses.where(y).where(y2).joins('join statuses as s2 on statuses.account_id != s2.account_id and (statuses.in_reply_to_id = s2.id or s2.in_reply_to_id = statuses.id)').group('s2.account_id').reorder('count_id desc').limit(3).count(:id))
end
helper_method :display_blocks?
helper_method :display_blocks_rationale?
helper_method :public_fetch_mode?

+ 10
- 2
app/helpers/home_helper.rb View File

@ -7,7 +7,7 @@ module HomeHelper
}
end
def account_link_to(account, button = '', path: nil)
def account_link_to(account, button = '', path: nil, full: true)
content_tag(:div, class: 'account') do
content_tag(:div, class: 'account__wrapper') do
section = if account.nil?
@ -20,7 +20,7 @@ module HomeHelper
content_tag(:span, t('about.contact_unavailable'), class: 'display-name__account')
end
end
else
elsif full
link_to(path || ActivityPub::TagManager.instance.url_for(account), class: 'account__display-name') do
content_tag(:div, class: 'account__avatar-wrapper') do
image_tag(full_asset_url(current_account&.user&.setting_auto_play_gif ? account.avatar_original_url : account.avatar_static_url), class: 'account__avatar')
@ -32,6 +32,14 @@ module HomeHelper
content_tag(:span, "@#{account.acct}", class: 'display-name__account')
end
end
else
link_to(path || ActivityPub::TagManager.instance.url_for(account), class: 'account__display-name') do
content_tag(:span, class: 'display-name') do
content_tag(:bdi) do
content_tag(:strong, display_name(account, custom_emojify: true), class: 'display-name__html emojify')
end
end
end
end
section + button

+ 53
- 0
app/views/about/my_data.html.haml View File

@ -0,0 +1,53 @@
- content_for :page_title do
= '我的'
.grid
.column-0
.box-widget
.rich-formatting
%h2= "#{@year_text}在闭社:"
%p
我总共发布了
%strong
#{@total}
嘟文
- if @total > 0
%p
我发得最多的一天是
%strong
#{@most_times[0][:date]}
,一下子发了
%strong
#{@most_times[0][:num]}
- if @most_fav&.favourites_count or 0 > 0
%p
其中最高赞是“
=link_to @most_fav.text[0..8]+'...', @most_fav.uri
”,收获了
%strong
#{@most_fav.favourites_count}
- if @like_me_most.size > 0
%p
给我点赞最多的是他们:
%ul
- @like_me_most.each do |a|
%li= account_link_to(a[:account], a[:num], full: a == @like_me_most.first)
- if @i_like_most.size > 0
%p
收到我的赞最多的是他们:
%ul
- @i_like_most.each do |a|
%li= account_link_to(a[:account], a[:num], full: a == @i_like_most.first)
- if @communi_most.size > 0
%p
和我互相交流最频繁的是:
%ul
- @communi_most.each do |a|
%li= account_link_to(a[:account], a[:num], full: a == @communi_most.first)
%br
%br
%p= '感谢陪伴,新的一年,祝平安喜乐'
.column-1
= render 'application/sidebar'

+ 2
- 0
config/routes.rb View File

@ -513,6 +513,8 @@ Rails.application.routes.draw do
get '/jump/:destin/(*path)', to: 'about#jump', :constraints => { :destin => /[0-9a-zA-Z\._-]+/ }, :format => 'html'
get '/my_data/:year', to: 'about#my_data'
match '/', via: [:post, :put, :patch, :delete], to: 'application#raise_not_found', format: false
match '*unmatched_route', via: :all, to: 'application#raise_not_found', format: false
end

Loading…
Cancel
Save