Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 投票結果確認用の各種クラスやメソッドを追加した #154

Merged
merged 1 commit into from
Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def target_tweets(hashtag, options={})
tweeted_at: beginning_at..end_at
)
active_record_relation = active_record_relation.not_retweet if options[:remove_rt] == true
active_record_relation = active_record_relation.not_by_gensosenkyo_families if options[:not_by_gensosenkyo_families] == true
active_record_relation = active_record_relation.not_by_gensosenkyo_family if options[:not_by_gensosenkyo_family] == true
active_record_relation = active_record_relation.not_by_gensosenkyo_main if options[:not_by_gensosenkyo_main] == true
active_record_relation = active_record_relation.not_by_gensosenkyo_sub if options[:not_by_gensosenkyo_sub] == true

Expand Down
38 changes: 38 additions & 0 deletions app/lib/suikoden_database/check_all_votes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# rubocop:disable Rails/Output
module SuikodenDatabase
class CheckAllVotes
class << self
def user_list_who_has_two_or_more_tweets
users = users_has_two_or_more_tweets

users.each do |user|
puts "#{user.name} (@#{user.screen_name} / #{user.id_number})"
end
end

def tweets_by_user_who_has_two_or_more_tweets(user)
user.tweets
.valid_term_votes
.not_retweet
.contains_hashtag('幻水総選挙2021')
.not_by_gensosenkyo_main
.order(tweeted_at: :asc)
.order(id_number: :asc)
end

def users_has_two_or_more_tweets
User.all.select do |user|
user.tweets
.valid_term_votes
.not_retweet
.contains_hashtag('幻水総選挙2021')
.not_by_gensosenkyo_main
.order(tweeted_at: :asc)
.order(id_number: :asc)
.count > 1
end
end
end
end
end
# rubocop:enable Rails/Output
51 changes: 51 additions & 0 deletions app/lib/suikoden_database/check_bonus_votes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module SuikodenDatabase
class CheckBonusVotes
class << self
def odai_shosetsu_user_vs_number_of_posts_sorted_by_number_of_posts
Hash[odai_shosetsu_user_vs_number_of_posts.sort_by { |_, v| -v }]
end

# odai_shosetsu_user_vs_number_of_posts.keys.count: 総投稿人数
# odai_shosetsu_user_vs_number_of_posts.values.sum: 総投稿数
def odai_shosetsu_user_vs_number_of_posts
odai_shosetsu_user_vs_number_of_posts = {}
user_ids = users_who_posted_odai_shosetsu.pluck(:id_number).uniq

user_ids.each do |user_id|
user = User.find_by(id_number: user_id)

odai_shosetsu_user_vs_number_of_posts[user.id_number.to_s] = user.tweets.odai_shosetsu.is_public.count
end

odai_shosetsu_user_vs_number_of_posts
end

def users_who_posted_odai_shosetsu
User.all.select { |user| user.tweets.odai_shosetsu.is_public.count > 0 }
end

def oshi_serifu_user_vs_number_of_posts_sorted_by_number_of_posts
Hash[oshi_serifu_user_vs_number_of_posts.sort_by { |_, v| -v }]
end

# oshi_serifu_user_vs_number_of_posts.keys.count: 総投稿人数
# oshi_serifu_user_vs_number_of_posts.values.sum: 総投稿数
def oshi_serifu_user_vs_number_of_posts
oshi_serifu_user_vs_number_of_posts = {}
user_ids = users_who_posted_oshi_serifu.pluck(:id_number).uniq

user_ids.each do |user_id|
user = User.find_by(id_number: user_id)

oshi_serifu_user_vs_number_of_posts[user.id_number.to_s] = user.tweets.oshi_serifu.is_public.count
end

oshi_serifu_user_vs_number_of_posts
end

def users_who_posted_oshi_serifu
User.all.select { |user| user.tweets.oshi_serifu.is_public.count > 0 }
end
end
end
end
35 changes: 35 additions & 0 deletions app/lib/suikoden_database/check_votes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module SuikodenDatabase
class CheckVotes
class << self
def user_vs_number_of_votes_sorted_by_number_of_votes
Hash[vote_two_or_more_user_vs_number_of_votes.sort_by { |_, v| -v }]
end

def vote_two_or_more_user_vs_number_of_votes
vote_two_or_more_user_vs_number_of_votes = {}
user_ids = User.who_vote_two_or_more_without_not_public.pluck(:id_number).uniq

user_ids.each do |user_id|
user = User.find_by(id_number: user_id)

vote_two_or_more_user_vs_number_of_votes[user.id_number.to_s] = user.tweets.gensosenkyo_2021_votes.is_public.count
end

vote_two_or_more_user_vs_number_of_votes
end

def vote_user_vs_number_of_votes
vote_user_vs_number_of_votes = {}
user_ids = User.did_vote_without_not_public.pluck(:id_number).uniq

user_ids.each do |user_id|
user = User.find_by(id_number: user_id)

vote_user_vs_number_of_votes[user.id_number.to_s] = user.tweets.gensosenkyo_2021_votes.is_public.count
end

vote_user_vs_number_of_votes
end
end
end
end
30 changes: 29 additions & 1 deletion app/models/tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ class Tweet < ApplicationRecord
scope :be_retweet, -> { where(is_retweet: true) }
scope :contains_hashtag, ->(hashtag) { joins(:hashtags).where(hashtags: { text: hashtag }) }
scope :mentioned_user, ->(user) { joins(:mentions).where(mentions: { user_id_number: user.id_number }) }
scope :is_public, -> { where(is_public: true) }

# TODO: TweetStorage の方にも書く
def self.filter_by_tweeted_at(from, to)
where(tweeted_at: from..to)
end

def self.not_by_gensosenkyo_families
def self.gensosenkyo_2021_votes
valid_term_votes
.not_retweet
.contains_hashtag('幻水総選挙2021')
.not_by_gensosenkyo_main
.order(tweeted_at: :asc)
.order(id_number: :asc)
end

def self.not_by_gensosenkyo_family
# gensosenkyo: 1471724029,
# sub_gensosenkyo: 1388758231825018881

Expand Down Expand Up @@ -55,6 +65,24 @@ def self.valid_term_votes
where(tweeted_at: begin_datetime..end_datetime)
end

def self.odai_shosetsu
not_retweet
.not_by_gensosenkyo_main
.contains_hashtag('幻水総選挙お題小説')
.where(tweeted_at: ..Time.zone.parse('2021-06-07 02:20:00'))
.order(tweeted_at: :asc)
.order(id_number: :asc)
end

def self.oshi_serifu
not_retweet
.not_by_gensosenkyo_main
.contains_hashtag('幻水総選挙推し台詞')
.where(tweeted_at: ..Time.zone.parse('2021-06-10 23:59:59'))
.order(tweeted_at: :asc)
.order(id_number: :asc)
end

def valid_term_vote?
begin_datetime = Time.zone.parse('2021-06-11 21:00:00')
end_datetime = Time.zone.parse('2021-06-13 11:59:59')
Expand Down
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ def gensosenkyo_admin?

id_number.in?(gensosenkyo_admin_user_id_numbers.values)
end

def self.who_vote_two_or_more_without_not_public
self.select { |user| user.tweets.gensosenkyo_2021_votes.is_public.count > 1 }
end

def self.did_vote_without_not_public
self.select { |user| user.tweets.gensosenkyo_2021_votes.is_public.count > 0 }
end
end