-
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 #158 from true-runes/development
v2.2.0
- Loading branch information
Showing
9 changed files
with
263 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RealtimeReportController < ApplicationController | ||
def index | ||
render json: Counting::RealtimeReport.run | ||
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
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,120 @@ | ||
module Counting | ||
class RealtimeReport | ||
def self.run | ||
{ | ||
all_characters: data(Tweet.gensosenkyo_2022_votes_for_api), | ||
unite_attacks: data(Tweet.unite_attacks_votes_for_api), | ||
short_stories: limited_data(Tweet.short_stories_for_api), | ||
fav_quotes: limited_data(Tweet.fav_quotes_for_api), | ||
sosenkyo_campaigns: limited_data(Tweet.sosenkyo_campaigns_for_api) | ||
} | ||
end | ||
|
||
# TODO: リファクタリング | ||
def self.data(tweets) # rubocop:disable Metrics/MethodLength | ||
{ | ||
sum: tweets.count, | ||
votes_per_day: { | ||
'2022-06-24': tweets.where(tweeted_at: Time.zone.parse('2022-06-24 21:00:00')..Time.zone.parse('2022-06-24 23:59:59')).count, | ||
'2022-06-25': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 00:00:00')..Time.zone.parse('2022-06-25 23:59:59')).count, | ||
'2022-06-26': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 00:00:00')..Time.zone.parse('2022-06-26 23:59:59')).count | ||
}, | ||
votes_per_hour: { | ||
'2022-06-24': [ | ||
'00': 0, | ||
'01': 0, | ||
'02': 0, | ||
'03': 0, | ||
'04': 0, | ||
'05': 0, | ||
'06': 0, | ||
'07': 0, | ||
'08': 0, | ||
'09': 0, | ||
'10': 0, | ||
'11': 0, | ||
'12': 0, | ||
'13': 0, | ||
'14': 0, | ||
'15': 0, | ||
'16': 0, | ||
'17': 0, | ||
'18': 0, | ||
'19': 0, | ||
'20': 0, | ||
'21': tweets.where(tweeted_at: Time.zone.parse('2022-06-24 21:00:00')..Time.zone.parse('2022-06-24 21:59:59')).count, | ||
'22': tweets.where(tweeted_at: Time.zone.parse('2022-06-24 22:00:00')..Time.zone.parse('2022-06-24 22:59:59')).count, | ||
'23': tweets.where(tweeted_at: Time.zone.parse('2022-06-24 23:00:00')..Time.zone.parse('2022-06-24 23:59:59')).count, | ||
], | ||
'2022-06-25': [ | ||
'00': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 00:00:00')..Time.zone.parse('2022-06-25 00:59:59')).count, | ||
'01': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 01:00:00')..Time.zone.parse('2022-06-25 01:59:59')).count, | ||
'02': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 02:00:00')..Time.zone.parse('2022-06-25 02:59:59')).count, | ||
'03': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 03:00:00')..Time.zone.parse('2022-06-25 03:59:59')).count, | ||
'04': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 04:00:00')..Time.zone.parse('2022-06-25 04:59:59')).count, | ||
'05': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 05:00:00')..Time.zone.parse('2022-06-25 05:59:59')).count, | ||
'06': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 06:00:00')..Time.zone.parse('2022-06-25 06:59:59')).count, | ||
'07': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 07:00:00')..Time.zone.parse('2022-06-25 07:59:59')).count, | ||
'08': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 08:00:00')..Time.zone.parse('2022-06-25 08:59:59')).count, | ||
'09': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 09:00:00')..Time.zone.parse('2022-06-25 09:59:59')).count, | ||
'10': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 10:00:00')..Time.zone.parse('2022-06-25 10:59:59')).count, | ||
'11': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 11:00:00')..Time.zone.parse('2022-06-25 11:59:59')).count, | ||
'12': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 12:00:00')..Time.zone.parse('2022-06-25 12:59:59')).count, | ||
'13': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 13:00:00')..Time.zone.parse('2022-06-25 13:59:59')).count, | ||
'14': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 14:00:00')..Time.zone.parse('2022-06-25 14:59:59')).count, | ||
'15': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 15:00:00')..Time.zone.parse('2022-06-25 15:59:59')).count, | ||
'16': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 16:00:00')..Time.zone.parse('2022-06-25 16:59:59')).count, | ||
'17': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 17:00:00')..Time.zone.parse('2022-06-25 17:59:59')).count, | ||
'18': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 18:00:00')..Time.zone.parse('2022-06-25 18:59:59')).count, | ||
'19': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 19:00:00')..Time.zone.parse('2022-06-25 19:59:59')).count, | ||
'20': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 20:00:00')..Time.zone.parse('2022-06-25 20:59:59')).count, | ||
'21': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 21:00:00')..Time.zone.parse('2022-06-25 21:59:59')).count, | ||
'22': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 22:00:00')..Time.zone.parse('2022-06-25 22:59:59')).count, | ||
'23': tweets.where(tweeted_at: Time.zone.parse('2022-06-25 23:00:00')..Time.zone.parse('2022-06-25 23:59:59')).count, | ||
], | ||
'2022-06-26': [ | ||
'00': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 00:00:00')..Time.zone.parse('2022-06-26 00:59:59')).count, | ||
'01': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 01:00:00')..Time.zone.parse('2022-06-26 01:59:59')).count, | ||
'02': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 02:00:00')..Time.zone.parse('2022-06-26 02:59:59')).count, | ||
'03': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 03:00:00')..Time.zone.parse('2022-06-26 03:59:59')).count, | ||
'04': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 04:00:00')..Time.zone.parse('2022-06-26 04:59:59')).count, | ||
'05': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 05:00:00')..Time.zone.parse('2022-06-26 05:59:59')).count, | ||
'06': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 06:00:00')..Time.zone.parse('2022-06-26 06:59:59')).count, | ||
'07': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 07:00:00')..Time.zone.parse('2022-06-26 07:59:59')).count, | ||
'08': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 08:00:00')..Time.zone.parse('2022-06-26 08:59:59')).count, | ||
'09': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 09:00:00')..Time.zone.parse('2022-06-26 09:59:59')).count, | ||
'10': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 10:00:00')..Time.zone.parse('2022-06-26 10:59:59')).count, | ||
'11': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 11:00:00')..Time.zone.parse('2022-06-26 11:59:59')).count, | ||
'12': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 12:00:00')..Time.zone.parse('2022-06-26 12:59:59')).count, | ||
'13': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 13:00:00')..Time.zone.parse('2022-06-26 13:59:59')).count, | ||
'14': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 14:00:00')..Time.zone.parse('2022-06-26 14:59:59')).count, | ||
'15': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 15:00:00')..Time.zone.parse('2022-06-26 15:59:59')).count, | ||
'16': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 16:00:00')..Time.zone.parse('2022-06-26 16:59:59')).count, | ||
'17': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 17:00:00')..Time.zone.parse('2022-06-26 17:59:59')).count, | ||
'18': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 18:00:00')..Time.zone.parse('2022-06-26 18:59:59')).count, | ||
'19': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 19:00:00')..Time.zone.parse('2022-06-26 19:59:59')).count, | ||
'20': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 20:00:00')..Time.zone.parse('2022-06-26 20:59:59')).count, | ||
'21': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 21:00:00')..Time.zone.parse('2022-06-26 21:59:59')).count, | ||
'22': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 22:00:00')..Time.zone.parse('2022-06-26 22:59:59')).count, | ||
'23': tweets.where(tweeted_at: Time.zone.parse('2022-06-26 23:00:00')..Time.zone.parse('2022-06-26 23:59:59')).count, | ||
] | ||
}, | ||
# 言語別はここだけとする | ||
votes_per_lang: { | ||
ja: tweets.where(language: 'ja').count, | ||
others: tweets.count - tweets.where(language: 'ja').count | ||
} | ||
} | ||
end | ||
|
||
def self.limited_data(tweets) | ||
{ | ||
sum: tweets.count, | ||
votes_per_lang: { | ||
ja: tweets.where(language: 'ja').count, | ||
others: tweets.count - tweets.where(language: 'ja').count | ||
} | ||
} | ||
end | ||
end | ||
end |
70 changes: 70 additions & 0 deletions
70
app/services/natural_language/suggest_unite_attack_names.rb
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,70 @@ | ||
module NaturalLanguage | ||
class SuggestUniteAttackNames | ||
# 現状、単にデータベースの値を見ているだけなので "NaturalLanguage" ではない | ||
def self.exec(tweet_or_dm) | ||
content_text = tweet_or_dm.content_text | ||
|
||
# 戻り値は {:title=>"幻想水滸伝IV", :attack_name=>"麗しの友情攻撃"} の形になる | ||
exec_by_text(content_text) | ||
end | ||
|
||
# 完全一致で調べている | ||
def self.exec_by_text(content_text) | ||
return { title: '', attack_name: '' } if content_text.nil? || content_text.lines.size < 3 | ||
|
||
content_text_title_name = content_text.lines[0].chomp | ||
content_text_attack_name = content_text.lines[1].chomp | ||
|
||
found_title_name = title_names.find { |title_name| title_name == content_text_title_name } | ||
|
||
attack_names = OnRawSheetUniteAttack.where( | ||
sheet_name: convert_title_name_to_sheet_name(found_title_name) | ||
).pluck(:name, :name_en).flatten | ||
found_attack_name = attack_names.find { |attack_name| attack_name == content_text_attack_name} | ||
|
||
{ title: found_title_name || '', attack_name: found_attack_name || '' } | ||
end | ||
|
||
def self.title_names | ||
[ | ||
'幻想水滸伝', | ||
'Suikoden', | ||
'幻想水滸伝II', | ||
'Suikoden II', | ||
'幻想水滸伝III', | ||
'Suikoden III', | ||
'幻想水滸伝IV', | ||
'Suikoden IV', | ||
'ラプソディア', | ||
'Suikoden Tactics', | ||
'幻想水滸伝V', | ||
'Suikoden V', | ||
'幻想水滸伝ティアクライス', | ||
'Suikoden Tierkreis', | ||
'幻想水滸伝 紡がれし百年の時', | ||
'Suikoden The Woven Web of a Century', | ||
] | ||
end | ||
|
||
def self.convert_title_name_to_sheet_name(title_name) | ||
{ | ||
'幻想水滸伝' => '幻水I', | ||
'Suikoden' => '幻水I', | ||
'幻想水滸伝II' => '幻水II', | ||
'Suikoden II' => '幻水II', | ||
'幻想水滸伝III' => '幻水III', | ||
'Suikoden III' => '幻水III', | ||
'幻想水滸伝IV' => '幻水IV', | ||
'Suikoden IV' => '幻水IV', | ||
'ラプソディア' => 'Rhapsodia', | ||
'Suikoden Tactics' => 'Rhapsodia', | ||
'幻想水滸伝V' => '幻水V', | ||
'Suikoden V' => '幻水V', | ||
'幻想水滸伝ティアクライス' => 'TK', | ||
'Suikoden Tierkreis' => 'TK', | ||
'幻想水滸伝 紡がれし百年の時' => '紡時', | ||
'Suikoden The Woven Web of a Century' => '紡時' | ||
}[title_name] | ||
end | ||
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
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,12 @@ | ||
sheet_names: | ||
- ①オールキャラ部門 | ||
- ②協力攻撃部門 | ||
- DM・①オールキャラ部門 | ||
- DM・②協力攻撃部門 | ||
- ボーナス票・OP・CLイラスト | ||
- ボーナス票・お題小説 | ||
- ボーナス票・開票イラスト | ||
- ボーナス票・推し台詞 | ||
- ボーナス票・選挙運動 | ||
- 開発用スプレッドシート | ||
- 統合用(予定) |
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,6 @@ | ||
used_hashtags: | ||
- '#幻水総選挙2022' | ||
- '#幻水総選挙2022協力攻撃' | ||
- '#幻水総選挙運動' | ||
- '#幻水総選挙お題小説' | ||
- '#幻水総選挙推し台詞' |
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,37 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe RealtimeReportController, type: :request do | ||
describe '#index' do | ||
it '期待通りのレスポンスが返ってくること' do | ||
get realtime_report_path | ||
|
||
expect(response).to have_http_status :ok | ||
|
||
hashed_json = JSON.parse(response.body) | ||
|
||
expect(hashed_json.keys).to match_array %w( | ||
all_characters | ||
unite_attacks | ||
fav_quotes | ||
short_stories | ||
sosenkyo_campaigns | ||
) | ||
|
||
['all_characters', 'unite_attacks'].each do |key| | ||
expect(hashed_json[key].keys).to match_array %w( | ||
sum | ||
votes_per_day | ||
votes_per_hour | ||
votes_per_lang | ||
) | ||
end | ||
|
||
['fav_quotes', 'short_stories', 'sosenkyo_campaigns'].each do |key| | ||
expect(hashed_json[key].keys).to match_array %w( | ||
sum | ||
votes_per_lang | ||
) | ||
end | ||
end | ||
end | ||
end |