Skip to content

Commit

Permalink
Merge pull request #271 from true-runes/development
Browse files Browse the repository at this point in the history
v3.6.0
  • Loading branch information
nikukyugamer authored Jul 14, 2022
2 parents df4220f + e5672b4 commit 9f87ab9
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 49 deletions.
16 changes: 16 additions & 0 deletions app/lib/presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ def self.character_names(attack)
end
end

class ResultIllustrations
def self.convert_character_name_in_sheet_to_character_name_in_db(character_name_in_sheet)
in_db_to_in_sheet = YAML.load_file(
Rails.root.join('config/character_names_on_result_illustrations_sheet.yml')
)['on_database_character_name_to_on_sheet_character_name']
in_sheet_to_in_db = in_db_to_in_sheet.invert

in_sheet_to_in_db.each do |in_sheet_names, in_db_name|
return in_db_name if character_name_in_sheet.in?(in_sheet_names)
end

# このメソッドはあくまで辞書に載っているものだけを対象にした変換メソッドで、辞書に載っていない場合は nil が返る
nil
end
end

class Common
def self.japanese_date_strftime(time, with_day_of_the_week: false)
days_of_the_week = ['日', '月', '火', '水', '木', '金', '土']
Expand Down
9 changes: 4 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
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
Expand Down
16 changes: 16 additions & 0 deletions app/services/counting/checkers/result_illustrations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Counting
module Checkers
class ResultIllustrations
def initialize
@excluded_character_names = Rails.application.credentials.excluded_not_in_db_character_names
end

def is_in_sheet_character_name_in_db?(in_sheet_character_name)
return true if in_sheet_character_name.in?(@excluded_character_names)
return true if Character.find_by(name: in_sheet_character_name).present?

Presenter::ResultIllustrations.convert_character_name_in_sheet_to_character_name_in_db(in_sheet_character_name).present?
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
Expand Up @@ -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?
Expand All @@ -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!
Expand All @@ -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
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion clasp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"devDependencies": {
"@google/clasp": "2.4.1",
"@types/google-apps-script": "1.0.51"
"@types/google-apps-script": "1.0.52"
},
"license": "MIT",
"main": "index.js"
Expand Down
8 changes: 4 additions & 4 deletions clasp/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@
"@types/node" "*"
"@types/responselike" "*"

"@types/[email protected].51":
version "1.0.51"
resolved "https://registry.yarnpkg.com/@types/google-apps-script/-/google-apps-script-1.0.51.tgz#bbaaedf688951c644cd18f6f3a1a08d539ee1c4c"
integrity sha512-v4wg/PasZptA0Lt3TyZMlftA5cc7vP02ytDuuNghh5MCJNDIaYTjokbagi3uCvNKKmSZASjKjfrUQdpER9hACA==
"@types/[email protected].52":
version "1.0.52"
resolved "https://registry.yarnpkg.com/@types/google-apps-script/-/google-apps-script-1.0.52.tgz#3f3793b660e84b11caa064d2e3196d1c9b757ac8"
integrity sha512-2KJGTdBmrYYeIIbC3QwGKBKPMoUve/9yJJ60mGPnR5PfBVUFFMt8hJFhCWol2sbvVhu7TlhRGQG50Mn0MzLU2Q==

"@types/http-cache-semantics@*":
version "4.0.1"
Expand Down
58 changes: 30 additions & 28 deletions config/character_names_on_result_illustrations_sheet.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
on_database_character_name_to_on_sheet_character_name:
シーザー・シルバーバーグ: シーザー
アルシュタート・ファレナス: アルシュタート
アルベルト・シルバーバーグ: アルベルト
ワイアット・ライトフェロー(ジンバ): ジンバ
ジョウイ・アトレイド(ブライト): ジョウイ
ジル・ブライト: ジル
リムスレーア・ファレナス: リムスレーア
幻水1主人公(坊ちゃん): 1主人公
イリア・バルカイ: イリア
ルセリナ・バロウズ: ルセリナ
シエラ・ミケーネ: シエラ
フレッド・マクシミリアン: フレッド
幻水4主人公(4様): 4主人公
ルカ・ブライト: ルカ
フリード・Y: フリード・Y
ゲオルグ・プライム: ゲオルグ
ナッシュ・ラトキエ(クロービス): ナッシュ
幻水5主人公(王子): 5主人公
アルシュタート・ファレナス: アルシュタート
オデッサ・シルバーバーグ: オデッサ
カーン・マリィ: カーン
キルキス・シャナ・クエス・ラビアンカーナ: キルキス
クラウス・ウィンダミア: クラウス
クリス・ライトフェロー: クリス
ゲオルグ・プライム: ゲオルグ
サイアリーズ・ファレナス: サイアリーズ
ザジ・キュイロス: ザジ
幻水2主人公(2主): 2主人公
サロメ・ハラス: サロメ
シーザー・シルバーバーグ: シーザー
シエラ・ミケーネ: シエラ
ジョウイ・アトレイド(ブライト): ジョウイ
ジル・ブライト: ジル
スノウ・フィンガーフート: スノウ
ソロン・ジー: ソロン
ティアクライス主人公(団長): TK主人公
ナッシュ・ラトキエ(クロービス): ナッシュ
パーシヴァル・フロイライン: パーシヴァル
フリード・Y: フリード・Y
フレッド・マクシミリアン: フレッド
ペック(暗器使い): ペック
ボルス・レッドラム: ボルス
サロメ・ハラス: サロメ
パーシヴァル・フロイライン: パーシヴァル
ルイス・キファーソン: ルイス
クラウス・ウィンダミア: クラウス
ティアクライス主人公(団長): TK主人公
カーン・マリィ: カーン
ヨシュア・レーベンハイト: ヨシュア
ユーラム・バロウズ: ユーラム
サイアリーズ・ファレナス: サイアリーズ
オデッサ・シルバーバーグ: オデッサ
ヨシュア・レーベンハイト: ヨシュア
リウ・シエン: リウ
スノウ・フィンガーフート: スノウ
キルキス・シャナ・クエス・ラビアンカーナ: キルキス
リムスレーア・ファレナス: リムスレーア
ルイス・キファーソン: ルイス
ルカ・ブライト: ルカ
ルセリナ・バロウズ: ルセリナ
ワイアット・ライトフェロー(ジンバ): ジンバ
幻水1主人公(坊ちゃん):
- 1主人公
- 坊ちゃん
幻水2主人公(2主): 2主人公
幻水4主人公(4様): 4主人公
幻水5主人公(王子): 5主人公
Loading

0 comments on commit 9f87ab9

Please sign in to comment.