-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from true-runes/development
v3.2.0
- Loading branch information
Showing
22 changed files
with
604 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ vendor/ | |
.vscode/ | ||
.history/ | ||
.env | ||
.envrc | ||
node_modules | ||
.clasp.* | ||
.clasprc.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module CountingTools | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
scope :other_tweets_exists, -> { where.not(other_tweet_ids_text: '') } | ||
end | ||
|
||
module ClassMethods | ||
def foobar; end | ||
end | ||
|
||
def three_chara_names | ||
[chara_1, chara_2, chara_3] | ||
end | ||
|
||
def convert_chara_names_to_array_in_character_and_products_hashes(chara_names) | ||
result_array = [] | ||
|
||
chara_names.each do |chara_name| | ||
inserted_hash = {} | ||
|
||
inserted_hash['character'] = Character.find_by(name: chara_name) | ||
inserted_hash['products'] = Character.find_by(name: chara_name).products | ||
|
||
result_array << inserted_hash | ||
end | ||
|
||
result_array | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
class CountingAllCharacter < ApplicationRecord | ||
include CountingTools | ||
|
||
belongs_to :tweet, optional: true | ||
belongs_to :direct_message, optional: true | ||
belongs_to :user # 鍵でも User のレコードは取得できるので optional 指定は不要 | ||
|
||
scope :invisible, -> { where(is_invisible: true) } | ||
scope :out_of_counting, -> { where(is_out_of_counting: true) } | ||
scope :valid_records, -> { where(is_out_of_counting: false).where(is_invisible: false) } | ||
|
||
enum vote_method: { by_tweet: 0, by_direct_message: 1, by_others: 99 } | ||
|
||
def self.tweets_whose_invisible_status_is_different_between_sheet_and_database | ||
sheet_invisible_tweet_ids = CountingAllCharacter.invisible.pluck(:tweet_id) | ||
|
||
result = [] | ||
sheet_invisible_tweet_ids.each do |tweet_id| | ||
database_tweet = Tweet.find_by(id: tweet_id) | ||
|
||
result << CountingAllCharacter.find_by(tweet_id: tweet_id) if CountingAllCharacter.find_by(tweet_id: tweet_id).is_invisible == database_tweet.is_public | ||
end | ||
|
||
result | ||
end | ||
|
||
# キャラ1〜3は、AIがsuggestしたものに含まれるか否か? | ||
# キャラ名はキャラデータベースにあるものと一致しているか? | ||
# 同一人物の複数ツイートで複数計上していないか | ||
def self.tweeted_all_characters | ||
chara_1_column_characters = CountingAllCharacter.pluck(:chara_1) | ||
chara_2_column_characters = CountingAllCharacter.pluck(:chara_2) | ||
chara_3_column_characters = CountingAllCharacter.pluck(:chara_3) | ||
|
||
(chara_1_column_characters + chara_2_column_characters + chara_3_column_characters).uniq.compact.sort | ||
end | ||
|
||
def self.character_db_diff | ||
result = [] | ||
|
||
tweeted_all_characters.each do |character| | ||
result << character if Character.where(name: character).blank? | ||
end | ||
|
||
result | ||
end | ||
|
||
# もとの行の内容が知りたい | ||
# どうだったらOKでどうだったらNGなのか? | ||
# キャラ計上数が4以上だとNG | ||
# other_tweetがvalid_recordsでないならスルー | ||
def self.check_other_tweets | ||
result = [] | ||
|
||
CountingAllCharacter.valid_records.other_tweets_exists.each do |c| | ||
c.other_tweets.each do |t| | ||
# tweet = Tweet.find_by(id: t.tweet_id) | ||
|
||
# result << tweet if tweet.is_public? | ||
|
||
result << t if !t.is_out_of_counting && !t.is_invisible? | ||
end | ||
end | ||
|
||
result | ||
end | ||
|
||
def other_tweets | ||
# CountingAllCharacter.where('other_tweet_ids_text like ?', '%|%') | ||
CountingAllCharacter.includes(:tweet).where( | ||
tweet: | ||
{ | ||
id_number: other_tweet_ids_text.split(',') | ||
} | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CountingUniteAttack < ApplicationRecord | ||
include CountingTools | ||
|
||
belongs_to :tweet, optional: true | ||
belongs_to :direct_message, optional: true | ||
belongs_to :user # 鍵でも User のレコードは取得できるので optional 指定は不要 | ||
|
||
scope :invisible, -> { where(is_invisible: true) } | ||
scope :out_of_counting, -> { where(is_out_of_counting: true) } | ||
scope :valid_records, -> { where(is_out_of_counting: false).where(is_invisible: false) } | ||
|
||
enum vote_method: { by_tweet: 0, by_direct_message: 1, by_others: 99 } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
module Sheets | ||
module Counting | ||
class AllCharacters | ||
def self.import_via_tweet | ||
sheet_names = YAML.load_file(Rails.root.join('config/counting_sheet_names.yml'))['names'] | ||
|
||
ActiveRecord::Base.transaction do | ||
sheet_names.each_with_index do |sheet_name, i| | ||
rows = SheetData.get_rows(sheet_id: ENV.fetch('COUNTING_ALL_CHARACTERS_SHEET_ID', nil), range: "#{sheet_names[i]}!A2:Q101") | ||
|
||
rows.each do |row| | ||
# TODO: 設定ファイルを用いてよりスマートに定義したい | ||
column_vs_value = { | ||
id_on_sheet: row[0], | ||
tweet_id_number: row[2], | ||
other_tweet_ids_text: row[5], | ||
is_invisible: row[7], # "FALSE" のような文字列なので注意 | ||
is_out_of_counting: row[8], # "FALSE" のような文字列なので注意 | ||
contents: row[11], | ||
memo: row[12], | ||
chara_1: row[14], | ||
chara_2: row[15], | ||
chara_3: row[16] | ||
} | ||
|
||
next if column_vs_value[:id_on_sheet].blank? || column_vs_value[:tweet_id_number].blank? || column_vs_value[:contents].blank? | ||
|
||
tweet = Tweet.find_by(id_number: column_vs_value[:tweet_id_number]) | ||
tweet_id = tweet.id | ||
user_id = tweet.user.id | ||
|
||
unique_attrs = { | ||
id_on_sheet: column_vs_value[:id_on_sheet], | ||
user_id: user_id, | ||
vote_method: :by_tweet, | ||
tweet_id: tweet_id, | ||
contents: column_vs_value[:contents], | ||
memo: column_vs_value[:memo] | ||
} | ||
|
||
mutable_attrs = { | ||
# 123456,654321,777777 のような文字列になる | ||
other_tweet_ids_text: column_vs_value[:other_tweet_ids_text].split('|').map(&:strip).join(','), | ||
is_invisible: column_vs_value[:is_invisible].to_boolean, | ||
is_out_of_counting: column_vs_value[:is_out_of_counting].to_boolean, | ||
chara_1: column_vs_value[:chara_1], | ||
chara_2: column_vs_value[:chara_2], | ||
chara_3: column_vs_value[:chara_3] | ||
} | ||
|
||
CountingAllCharacter.find_or_initialize_by(unique_attrs).update!(mutable_attrs) | ||
end | ||
end | ||
end | ||
|
||
'[DONE] Sheets::Counting::AllCharacters.import_via_tweet' | ||
end | ||
|
||
def self.import_via_dm | ||
sheet_names = YAML.load_file(Rails.root.join('config/counting_sheet_names.yml'))['names'] | ||
|
||
# rubocop:disable Metrics/BlockLength | ||
ActiveRecord::Base.transaction do | ||
sheet_names.each_with_index do |sheet_name, i| | ||
rows = SheetData.get_rows(sheet_id: ENV.fetch('COUNTING_DIRECT_MESSAGES_SHEET_ID', nil), range: "#{sheet_names[i]}!A2:Q101") | ||
|
||
rows.each do |row| | ||
# TODO: 設定ファイルを用いてスマートに定義したい | ||
column_vs_value = { | ||
id_on_sheet: row[0], | ||
dm_id_number: row[2], | ||
is_invisible: row[5], # "FALSE" のような文字列なので注意 | ||
is_out_of_counting: row[6], # "FALSE" のような文字列なので注意 | ||
category: row[9], | ||
contents: row[10], | ||
memo: row[11], | ||
input_01: row[13], | ||
input_02: row[14], | ||
input_03: row[15], | ||
input_04: row[16], | ||
input_05: row[17], | ||
input_06: row[18], | ||
input_07: row[19], | ||
input_08: row[20], | ||
input_09: row[21], | ||
input_10: row[22] | ||
} | ||
|
||
# DMの書式が自由すぎるので、こちらで条件を吸収する | ||
next if column_vs_value[:category] != '①オールキャラ部門' && column_vs_value[:category] != '両部門' | ||
|
||
next if column_vs_value[:id_on_sheet].blank? || column_vs_value[:dm_id_number].blank? || column_vs_value[:contents].blank? | ||
|
||
dm = DirectMessage.find_by(id_number: column_vs_value[:dm_id_number]) | ||
dm_id = dm.id | ||
user_id = dm.user.id | ||
|
||
unique_attrs = { | ||
id_on_sheet: column_vs_value[:id_on_sheet], | ||
user_id: user_id, | ||
vote_method: :by_direct_message, | ||
direct_message_id: dm_id, | ||
other_tweet_ids_text: nil, | ||
contents: column_vs_value[:contents], | ||
memo: column_vs_value[:memo] | ||
} | ||
|
||
# 「両部門の場合は、N列とO列に協力攻撃、P列Q列R列にオールキャラ部門を入力する」という例外規定 | ||
case column_vs_value[:category] | ||
when '①オールキャラ部門' | ||
chara_1 = column_vs_value[:input_01] | ||
chara_2 = column_vs_value[:input_02] | ||
chara_3 = column_vs_value[:input_03] | ||
when '両部門' | ||
chara_1 = column_vs_value[:input_03] | ||
chara_2 = column_vs_value[:input_04] | ||
chara_3 = column_vs_value[:input_05] | ||
end | ||
|
||
mutable_attrs = { | ||
is_invisible: column_vs_value[:is_invisible].to_boolean, | ||
is_out_of_counting: column_vs_value[:is_out_of_counting].to_boolean, | ||
chara_1: chara_1, | ||
chara_2: chara_2, | ||
chara_3: chara_3 | ||
} | ||
|
||
CountingAllCharacter.find_or_initialize_by(unique_attrs).update!(mutable_attrs) | ||
end | ||
|
||
puts "#{sheet_names[i]} is Done." # rubocop:disable Rails/Output | ||
end | ||
end | ||
# rubocop:enable Metrics/BlockLength | ||
|
||
'[DONE] Sheets::Counting::AllCharacters.import_via_dm' | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.