Skip to content

Commit

Permalink
feat: 🎸 最終集計まわりをリファクタリングした (v18) (#270)
Browse files Browse the repository at this point in the history
nikukyugamer authored Jul 14, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 2c383bf commit e5672b4
Showing 8 changed files with 96 additions and 16 deletions.
9 changes: 4 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -42,16 +42,15 @@ def self.did_vote_without_not_public
self.select { |user| user.tweets.gensosenkyo_2021_votes.is_public.count > 0 }
end

def all_counting_records
# TODO: 集計対象となっている全てのレコードを引っ張ってこられる
end

def on_all_character_division_all_character_names
counting_all_characters.map(&:three_chara_names).flatten.compact_blank
end

def on_all_character_division_voting_over_three?
on_all_character_division_all_character_names.size > 3
op_cl_illustrator_screen_names = Rails.application.credentials.op_cl_illustrator_screen_names
limit_number_of_votes = screen_name.in?(op_cl_illustrator_screen_names) ? 4 : 3

on_all_character_division_all_character_names.size > limit_number_of_votes
end

def on_all_character_division_voting_to_the_same_characters?
15 changes: 12 additions & 3 deletions app/services/counting/checkers/bonus_votes.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
module Counting
module Checkers
class BonusVotes
def self.vote_to_the_same_characters_users
# TODO: 書く
# 票数に影響はない
def initialize
@excluded_character_names = Rails.application.credentials.excluded_not_in_db_character_names
end

def character_names_who_not_exist_in_chara_db
in_local_db_character_names = CountingBonusVote.all.pluck(:character_name).compact_blank.uniq

in_local_db_character_names.each do |character_name|
next if character_name.in?(@excluded_character_names)

raise StandardError, "#{character_name} は キャラDB の中に存在しません。" unless o.in_local_db_character_names?(character_name)
end
end
end
end
27 changes: 21 additions & 6 deletions app/services/sheets/result_illustration_applications.rb
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ def self.import_totallings_data_to_database
end
end

# シートから持ってきたレコードのうち、無効なレコードを除外する
# シートから持ってきたレコードのうち、無効なレコードを除外する(TEMP_ は含まれていることに注意する)
valid_character_name_for_public_rows = []
rows.each_with_index do |row, i|
next if i == 0 || row[cloumn_names_and_sheet_index_number['character_name_for_public']].blank?
@@ -85,24 +85,30 @@ def self.import_totallings_data_to_database
valid_character_name_by_sheet_totalling_rows = rows.map.with_index { |row, index| row[7] unless index.zero? }.compact_blank

# 更新がなければメソッドを抜ける
return '[NOT MODIFIED] Sheets::ResultIllustrationApplications.import_totallings_data_to_database' if valid_character_name_for_public_rows.count == OnRawSheetResultIllustrationTotalling.count && valid_character_name_by_sheet_totalling_rows.count == OnRawSheetResultIllustrationTotalling.pluck(:character_name_by_sheet_totalling).reject { |cell| cell.start_with?('TEMP_') }.count
return '[NOT MODIFIED] Sheets::ResultIllustrationApplications.import_totallings_data_to_database' if not_modified?(
valid_character_name_for_public_rows,
valid_character_name_by_sheet_totalling_rows
)

ActiveRecord::Base.transaction do
# 主キーがないから問答無用で全削除して入れ直す
OnRawSheetResultIllustrationTotalling.destroy_all

rows.each_with_index do |row, i|
next if i == 0 || row[cloumn_names_and_sheet_index_number['character_name_for_public']].blank?
next if i == 0 ||
(row[cloumn_names_and_sheet_index_number['character_name_for_public']].blank? && row[cloumn_names_and_sheet_index_number['character_name_for_sheet_totalling']].blank?)

# FIXME: ワークアラウンドなので要修正
temporary_inserted_data = "TEMP_#{SecureRandom.uuid}"
temporary_inserted_data_for_totalling = "TEMP_TOTALLING_#{SecureRandom.uuid}"
temporary_inserted_data_for_public = "TEMP_PUBLIC_#{SecureRandom.uuid}"

character_name_by_sheet_totalling_data = row[cloumn_names_and_sheet_index_number['character_name_for_sheet_totalling']].presence || temporary_inserted_data
character_name_by_sheet_totalling_data = row[cloumn_names_and_sheet_index_number['character_name_for_sheet_totalling']].presence || temporary_inserted_data_for_totalling
character_name_for_public = row[cloumn_names_and_sheet_index_number['character_name_for_public']].presence || temporary_inserted_data_for_public

obj = OnRawSheetResultIllustrationTotalling.new(
character_name_by_sheet_totalling: character_name_by_sheet_totalling_data,
number_of_applications: row[cloumn_names_and_sheet_index_number['number_of_applications']],
character_name_for_public: row[cloumn_names_and_sheet_index_number['character_name_for_public']]
character_name_for_public: character_name_for_public
)

obj.save!
@@ -111,5 +117,14 @@ def self.import_totallings_data_to_database

'[DONE] Sheets::ResultIllustrationApplications.import_totallings_data_to_database'
end

def self.not_modified?(public_rows, sheet_totalling_rows)
public_rows.count == without_temp_records(OnRawSheetResultIllustrationTotalling.pluck(:character_name_for_public)).count &&
sheet_totalling_rows.count == without_temp_records(OnRawSheetResultIllustrationTotalling.pluck(:character_name_by_sheet_totalling)).count
end

def self.without_temp_records(source_records)
source_records.reject { |cell| cell.start_with?('TEMP_') }
end
end
end
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ module WriteAndUpdate
module FinalSummary
class FavQuotes
def initialize
@sheet_name = 'まとめ'
@sheet_name = '最終まとめ'
@column_name_to_index_hash = {
id: 0,
シートid: 1,
Loading

0 comments on commit e5672b4

Please sign in to comment.