コミットを比較
3 コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
| fb2b2a632c | |||
| de21141f5a | |||
| 96df2a4eaa |
@@ -0,0 +1,23 @@
|
|||||||
|
class GekanatorGamesController < ApplicationController
|
||||||
|
def create
|
||||||
|
return head :unauthorized unless current_user
|
||||||
|
|
||||||
|
guessed_post_id = params.require(:guessed_post_id)
|
||||||
|
correct_post_id = params[:correct_post_id].presence
|
||||||
|
answers = params.require(:answers).as_json
|
||||||
|
|
||||||
|
game = GekanatorGame.new(
|
||||||
|
user: current_user,
|
||||||
|
guessed_post_id:,
|
||||||
|
correct_post_id:,
|
||||||
|
won: correct_post_id.present? && guessed_post_id.to_i == correct_post_id.to_i,
|
||||||
|
question_count: params.require(:question_count),
|
||||||
|
answers:)
|
||||||
|
|
||||||
|
if game.save
|
||||||
|
render json: { id: game.id }, status: :created
|
||||||
|
else
|
||||||
|
render json: { errors: game.errors.full_messages }, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
class GekanatorGame < ApplicationRecord
|
||||||
|
belongs_to :user
|
||||||
|
belongs_to :guessed_post, class_name: 'Post'
|
||||||
|
belongs_to :correct_post, class_name: 'Post'
|
||||||
|
|
||||||
|
validates :answers, presence: true
|
||||||
|
validates :question_count, numericality: { greater_than_or_equal_to: 0 }
|
||||||
|
validates :won, inclusion: { in: [true, false] }
|
||||||
|
end
|
||||||
@@ -11,6 +11,16 @@ class Post < ApplicationRecord
|
|||||||
has_many :user_post_views, dependent: :delete_all
|
has_many :user_post_views, dependent: :delete_all
|
||||||
has_many :post_similarities, dependent: :delete_all
|
has_many :post_similarities, dependent: :delete_all
|
||||||
has_many :post_versions
|
has_many :post_versions
|
||||||
|
has_many :gekanator_guessed_games,
|
||||||
|
class_name: 'GekanatorGame',
|
||||||
|
foreign_key: :guessed_post_id,
|
||||||
|
dependent: :delete_all,
|
||||||
|
inverse_of: :guessed_post
|
||||||
|
has_many :gekanator_correct_games,
|
||||||
|
class_name: 'GekanatorGame',
|
||||||
|
foreign_key: :correct_post_id,
|
||||||
|
dependent: :nullify,
|
||||||
|
inverse_of: :correct_post
|
||||||
|
|
||||||
has_many :parent_post_implications,
|
has_many :parent_post_implications,
|
||||||
class_name: 'PostImplication',
|
class_name: 'PostImplication',
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
namespace :gekanator do
|
||||||
|
resources :games, only: [:create], controller: '/gekanator_games'
|
||||||
|
end
|
||||||
|
|
||||||
resources :users, only: [:create, :update] do
|
resources :users, only: [:create, :update] do
|
||||||
collection do
|
collection do
|
||||||
post :verify
|
post :verify
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
class CreateGekanatorGames < ActiveRecord::Migration[8.0]
|
||||||
|
def change
|
||||||
|
create_table :gekanator_games do |t|
|
||||||
|
t.references :user, foreign_key: true
|
||||||
|
t.references :guessed_post, null: false, foreign_key: { to_table: :posts }
|
||||||
|
t.references :correct_post, foreign_key: { to_table: :posts }
|
||||||
|
t.boolean :won, null: false
|
||||||
|
t.integer :question_count, null: false
|
||||||
|
t.json :answers, null: false
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_check_constraint :gekanator_games,
|
||||||
|
'question_count >= 0',
|
||||||
|
name: 'chk_gekanator_games_question_count_nonnegative'
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
class RequireGekanatorGameUserAndCorrectPost < ActiveRecord::Migration[8.0]
|
||||||
|
def up
|
||||||
|
execute <<~SQL.squish
|
||||||
|
UPDATE gekanator_games
|
||||||
|
SET correct_post_id = guessed_post_id
|
||||||
|
WHERE correct_post_id IS NULL
|
||||||
|
SQL
|
||||||
|
|
||||||
|
change_column_null :gekanator_games, :user_id, false
|
||||||
|
change_column_null :gekanator_games, :correct_post_id, false
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
change_column_null :gekanator_games, :correct_post_id, true
|
||||||
|
change_column_null :gekanator_games, :user_id, true
|
||||||
|
end
|
||||||
|
end
|
||||||
生成ファイル
+38
-1
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2026_06_06_000000) do
|
ActiveRecord::Schema[8.0].define(version: 2026_06_08_000000) do
|
||||||
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "record_type", null: false
|
t.string "record_type", null: false
|
||||||
@@ -48,6 +48,21 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_06_000000) do
|
|||||||
t.index ["tag_id"], name: "index_deerjikists_on_tag_id"
|
t.index ["tag_id"], name: "index_deerjikists_on_tag_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "gekanator_games", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
|
t.bigint "user_id", null: false
|
||||||
|
t.bigint "guessed_post_id", null: false
|
||||||
|
t.bigint "correct_post_id", null: false
|
||||||
|
t.boolean "won", null: false
|
||||||
|
t.integer "question_count", null: false
|
||||||
|
t.json "answers", null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["correct_post_id"], name: "index_gekanator_games_on_correct_post_id"
|
||||||
|
t.index ["guessed_post_id"], name: "index_gekanator_games_on_guessed_post_id"
|
||||||
|
t.index ["user_id"], name: "index_gekanator_games_on_user_id"
|
||||||
|
t.check_constraint "`question_count` >= 0", name: "chk_gekanator_games_question_count_nonnegative"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "ip_addresses", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
create_table "ip_addresses", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
t.binary "ip_address", limit: 16, null: false
|
t.binary "ip_address", limit: 16, null: false
|
||||||
t.datetime "banned_at"
|
t.datetime "banned_at"
|
||||||
@@ -137,6 +152,19 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_06_000000) do
|
|||||||
t.index ["target_post_id"], name: "index_post_similarities_on_target_post_id"
|
t.index ["target_post_id"], name: "index_post_similarities_on_target_post_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "post_tag_sections", primary_key: ["post_id", "tag_id", "begin_ms"], charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
|
t.bigint "post_id", null: false
|
||||||
|
t.bigint "tag_id", null: false
|
||||||
|
t.integer "begin_ms", null: false
|
||||||
|
t.integer "end_ms", null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["post_id", "begin_ms"], name: "idx_post_tag_sections_post_id_begin_ms"
|
||||||
|
t.index ["tag_id"], name: "fk_rails_8be3847903"
|
||||||
|
t.check_constraint "`begin_ms` < `end_ms`", name: "chk_post_tag_sections_end_ms_after_begin_ms"
|
||||||
|
t.check_constraint "`begin_ms` >= 0", name: "chk_post_tag_sections_begin_ms_natural"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "post_tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
create_table "post_tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
t.bigint "post_id", null: false
|
t.bigint "post_id", null: false
|
||||||
t.bigint "tag_id", null: false
|
t.bigint "tag_id", null: false
|
||||||
@@ -187,8 +215,11 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_06_000000) do
|
|||||||
t.datetime "original_created_before"
|
t.datetime "original_created_before"
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.integer "version_no", null: false
|
t.integer "version_no", null: false
|
||||||
|
t.integer "video_ms"
|
||||||
t.index ["uploaded_user_id"], name: "index_posts_on_uploaded_user_id"
|
t.index ["uploaded_user_id"], name: "index_posts_on_uploaded_user_id"
|
||||||
t.index ["url"], name: "index_posts_on_url", unique: true
|
t.index ["url"], name: "index_posts_on_url", unique: true
|
||||||
|
t.index ["video_ms", "id"], name: "idx_posts_video_ms_id"
|
||||||
|
t.check_constraint "(`video_ms` is null) or (`video_ms` > 0)", name: "chk_posts_video_ms_positive"
|
||||||
t.check_constraint "`version_no` > 0", name: "chk_posts_version_no_positive"
|
t.check_constraint "`version_no` > 0", name: "chk_posts_version_no_positive"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -339,6 +370,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_06_000000) do
|
|||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.index ["expires_at"], name: "index_theatre_watching_users_on_expires_at"
|
t.index ["expires_at"], name: "index_theatre_watching_users_on_expires_at"
|
||||||
|
t.index ["theatre_id", "expires_at"], name: "idx_on_theatre_id_skip_expires_at_4c8de1dd42"
|
||||||
t.index ["theatre_id", "expires_at"], name: "index_theatre_watching_users_on_theatre_id_and_expires_at"
|
t.index ["theatre_id", "expires_at"], name: "index_theatre_watching_users_on_theatre_id_and_expires_at"
|
||||||
t.index ["theatre_id"], name: "index_theatre_watching_users_on_theatre_id"
|
t.index ["theatre_id"], name: "index_theatre_watching_users_on_theatre_id"
|
||||||
t.index ["user_id"], name: "index_theatre_watching_users_on_user_id"
|
t.index ["user_id"], name: "index_theatre_watching_users_on_user_id"
|
||||||
@@ -478,6 +510,9 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_06_000000) do
|
|||||||
|
|
||||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||||
|
add_foreign_key "gekanator_games", "posts", column: "correct_post_id"
|
||||||
|
add_foreign_key "gekanator_games", "posts", column: "guessed_post_id"
|
||||||
|
add_foreign_key "gekanator_games", "users"
|
||||||
add_foreign_key "material_versions", "materials"
|
add_foreign_key "material_versions", "materials"
|
||||||
add_foreign_key "material_versions", "materials", column: "parent_id"
|
add_foreign_key "material_versions", "materials", column: "parent_id"
|
||||||
add_foreign_key "material_versions", "tags"
|
add_foreign_key "material_versions", "tags"
|
||||||
@@ -495,6 +530,8 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_06_000000) do
|
|||||||
add_foreign_key "post_implications", "posts", column: "parent_post_id"
|
add_foreign_key "post_implications", "posts", column: "parent_post_id"
|
||||||
add_foreign_key "post_similarities", "posts"
|
add_foreign_key "post_similarities", "posts"
|
||||||
add_foreign_key "post_similarities", "posts", column: "target_post_id"
|
add_foreign_key "post_similarities", "posts", column: "target_post_id"
|
||||||
|
add_foreign_key "post_tag_sections", "posts"
|
||||||
|
add_foreign_key "post_tag_sections", "tags"
|
||||||
add_foreign_key "post_tags", "posts"
|
add_foreign_key "post_tags", "posts"
|
||||||
add_foreign_key "post_tags", "tags"
|
add_foreign_key "post_tags", "tags"
|
||||||
add_foreign_key "post_tags", "users", column: "created_user_id"
|
add_foreign_key "post_tags", "users", column: "created_user_id"
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe 'Gekanator games API', type: :request do
|
||||||
|
let!(:user) { create_member_user! }
|
||||||
|
let!(:guessed_post) { Post.create!(title: 'guess', url: 'https://example.com/guess') }
|
||||||
|
let!(:correct_post) { Post.create!(title: 'correct', url: 'https://example.com/correct') }
|
||||||
|
|
||||||
|
describe 'POST /gekanator/games' do
|
||||||
|
it 'stores a won game' do
|
||||||
|
sign_in_as user
|
||||||
|
|
||||||
|
post '/gekanator/games', params: {
|
||||||
|
guessed_post_id: guessed_post.id,
|
||||||
|
correct_post_id: guessed_post.id,
|
||||||
|
question_count: 3,
|
||||||
|
answers: [{ question_id: 'tag:1', answer: 'yes' }] }
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:created)
|
||||||
|
game = GekanatorGame.find(json['id'])
|
||||||
|
expect(game.user).to eq(user)
|
||||||
|
expect(game.guessed_post).to eq(guessed_post)
|
||||||
|
expect(game.correct_post).to eq(guessed_post)
|
||||||
|
expect(game.won).to eq(true)
|
||||||
|
expect(game.answers).to eq([{ 'question_id' => 'tag:1', 'answer' => 'yes' }])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'stores a lost game with the correct post' do
|
||||||
|
sign_in_as user
|
||||||
|
|
||||||
|
post '/gekanator/games', params: {
|
||||||
|
guessed_post_id: guessed_post.id,
|
||||||
|
correct_post_id: correct_post.id,
|
||||||
|
question_count: 4,
|
||||||
|
answers: [{ question_id: 'tag:1', answer: 'no' }] }
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:created)
|
||||||
|
game = GekanatorGame.find(json['id'])
|
||||||
|
expect(game.correct_post).to eq(correct_post)
|
||||||
|
expect(game.won).to eq(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'rejects a game without the correct post' do
|
||||||
|
sign_in_as user
|
||||||
|
|
||||||
|
post '/gekanator/games', params: {
|
||||||
|
guessed_post_id: guessed_post.id,
|
||||||
|
question_count: 4,
|
||||||
|
answers: [{ question_id: 'tag:1', answer: 'no' }] }
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'requires a user' do
|
||||||
|
post '/gekanator/games', params: {
|
||||||
|
guessed_post_id: guessed_post.id,
|
||||||
|
correct_post_id: guessed_post.id,
|
||||||
|
question_count: 1,
|
||||||
|
answers: [] }
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:unauthorized)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -18,6 +18,7 @@ import MaterialListPage from '@/pages/materials/MaterialListPage'
|
|||||||
import MaterialNewPage from '@/pages/materials/MaterialNewPage'
|
import MaterialNewPage from '@/pages/materials/MaterialNewPage'
|
||||||
// import MaterialSearchPage from '@/pages/materials/MaterialSearchPage'
|
// import MaterialSearchPage from '@/pages/materials/MaterialSearchPage'
|
||||||
import MorePage from '@/pages/MorePage'
|
import MorePage from '@/pages/MorePage'
|
||||||
|
import GekanatorPage from '@/pages/GekanatorPage'
|
||||||
import NicoTagListPage from '@/pages/tags/NicoTagListPage'
|
import NicoTagListPage from '@/pages/tags/NicoTagListPage'
|
||||||
import NotFound from '@/pages/NotFound'
|
import NotFound from '@/pages/NotFound'
|
||||||
import TOSPage from '@/pages/TOSPage.mdx'
|
import TOSPage from '@/pages/TOSPage.mdx'
|
||||||
@@ -80,6 +81,7 @@ const RouteTransitionWrapper = ({ user, setUser }: {
|
|||||||
<Route path="/users/settings" element={<SettingPage user={user} setUser={setUser}/>}/>
|
<Route path="/users/settings" element={<SettingPage user={user} setUser={setUser}/>}/>
|
||||||
<Route path="/settings" element={<Navigate to="/users/settings" replace/>}/>
|
<Route path="/settings" element={<Navigate to="/users/settings" replace/>}/>
|
||||||
<Route path="/tos" element={<TOSPage/>}/>
|
<Route path="/tos" element={<TOSPage/>}/>
|
||||||
|
<Route path="/gekanator" element={<GekanatorPage/>}/>
|
||||||
<Route path="/more" element={<MorePage/>}/>
|
<Route path="/more" element={<MorePage/>}/>
|
||||||
<Route path="*" element={<NotFound/>}/>
|
<Route path="*" element={<NotFound/>}/>
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ export const menuOutline = ({ tag, wikiId, user, pathName }: {
|
|||||||
{ name: '履歴', to: `/wiki/changes?id=${ wikiId }`, visible: wikiPageFlg },
|
{ name: '履歴', to: `/wiki/changes?id=${ wikiId }`, visible: wikiPageFlg },
|
||||||
{ name: '編輯', to: `/wiki/${ wikiId || wikiTitle }/edit`, visible: wikiPageFlg }] },
|
{ name: '編輯', to: `/wiki/${ wikiId || wikiTitle }/edit`, visible: wikiPageFlg }] },
|
||||||
{ name: 'おたのしみ', visible: false, subMenu: [
|
{ name: 'おたのしみ', visible: false, subMenu: [
|
||||||
|
{ name: 'グカネータ', to: '/gekanator' },
|
||||||
{ name: '上映会 (β)', to: '/theatres/1' }] },
|
{ name: '上映会 (β)', to: '/theatres/1' }] },
|
||||||
{ name: 'ユーザ', to: '/users/settings', visible: false, subMenu: [
|
{ name: 'ユーザ', to: '/users/settings', visible: false, subMenu: [
|
||||||
{ name: '一覧', to: '/users', visible: false },
|
{ name: '一覧', to: '/users', visible: false },
|
||||||
|
|||||||
@@ -0,0 +1,215 @@
|
|||||||
|
import { apiPost } from '@/lib/api'
|
||||||
|
import { fetchPosts } from '@/lib/posts'
|
||||||
|
|
||||||
|
import type { Post } from '@/types'
|
||||||
|
|
||||||
|
export type GekanatorAnswerValue =
|
||||||
|
| 'yes'
|
||||||
|
| 'no'
|
||||||
|
| 'partial'
|
||||||
|
| 'probably_no'
|
||||||
|
| 'unknown'
|
||||||
|
|
||||||
|
export type GekanatorAnswerLog = {
|
||||||
|
questionId: string
|
||||||
|
questionText: string
|
||||||
|
answer: GekanatorAnswerValue }
|
||||||
|
|
||||||
|
export type GekanatorQuestionKind =
|
||||||
|
| 'tag'
|
||||||
|
| 'source'
|
||||||
|
| 'title'
|
||||||
|
| 'original_date'
|
||||||
|
|
||||||
|
export type GekanatorQuestion = {
|
||||||
|
id: string
|
||||||
|
text: string
|
||||||
|
kind: GekanatorQuestionKind
|
||||||
|
test: (post: Post) => boolean }
|
||||||
|
|
||||||
|
const countBy = <T extends string | number> (values: T[]): Map<T, number> => {
|
||||||
|
const counts = new Map<T, number> ()
|
||||||
|
values.forEach (value => counts.set (value, (counts.get (value) ?? 0) + 1))
|
||||||
|
return counts
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const median = (values: number[]): number => {
|
||||||
|
const sorted = [...values].sort ((a, b) => a - b)
|
||||||
|
return sorted[Math.floor (sorted.length / 2)] ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const hostOf = (post: Post): string | null => {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new URL (post.url).hostname.replace (/^www\./, '')
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const originalYearOf = (post: Post): number | null => {
|
||||||
|
const value = post.originalCreatedFrom || post.originalCreatedBefore
|
||||||
|
if (!(value))
|
||||||
|
return null
|
||||||
|
|
||||||
|
const date = new Date (value)
|
||||||
|
if (Number.isNaN (date.getTime ()))
|
||||||
|
return null
|
||||||
|
|
||||||
|
return date.getFullYear ()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const tagQuestionKey = ({ category, name }: { category: string; name: string }): string =>
|
||||||
|
`${ category }:${ name }`
|
||||||
|
|
||||||
|
|
||||||
|
const tagFromQuestionKey = (key: string): { category: string; name: string } => {
|
||||||
|
const [category, ...rest] = key.split (':')
|
||||||
|
return { category: category ?? '', name: rest.join (':') }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const nicoTagLabel = (name: string): string => name.replace (/^nico:/, '')
|
||||||
|
|
||||||
|
|
||||||
|
const questionableTag = (post: Post, key: string): boolean => {
|
||||||
|
const { category, name } = tagFromQuestionKey (key)
|
||||||
|
|
||||||
|
return (
|
||||||
|
post.tags.some (tag =>
|
||||||
|
tag.name === name
|
||||||
|
&& tag.category === category
|
||||||
|
&& !(tag.category === 'meta')
|
||||||
|
&& !(tag.name.includes ('タグ希望'))
|
||||||
|
&& !(tag.name.includes ('bot操作'))))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const fetchGekanatorPosts = async (): Promise<Post[]> => {
|
||||||
|
const limit = 200
|
||||||
|
const first = await fetchPosts ({
|
||||||
|
url: '', title: '', tags: '', match: 'all',
|
||||||
|
originalCreatedFrom: '', originalCreatedTo: '',
|
||||||
|
createdFrom: '', createdTo: '', updatedFrom: '', updatedTo: '',
|
||||||
|
page: 1, limit, order: 'original_created_at:desc' })
|
||||||
|
const posts = [...first.posts]
|
||||||
|
const totalPages = Math.ceil (first.count / limit)
|
||||||
|
|
||||||
|
for (let page = 2; page <= totalPages; page++)
|
||||||
|
{
|
||||||
|
const data = await fetchPosts ({
|
||||||
|
url: '', title: '', tags: '', match: 'all',
|
||||||
|
originalCreatedFrom: '', originalCreatedTo: '',
|
||||||
|
createdFrom: '', createdTo: '', updatedFrom: '', updatedTo: '',
|
||||||
|
page, limit, order: 'original_created_at:desc' })
|
||||||
|
posts.push (...data.posts)
|
||||||
|
}
|
||||||
|
|
||||||
|
return posts
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const buildGekanatorQuestions = (posts: Post[]): GekanatorQuestion[] => {
|
||||||
|
const tagCounts = countBy (posts.flatMap (post =>
|
||||||
|
post.tags
|
||||||
|
.filter (tag =>
|
||||||
|
!(tag.category === 'meta')
|
||||||
|
&& !(tag.name.includes ('タグ希望'))
|
||||||
|
&& !(tag.name.includes ('bot操作')))
|
||||||
|
.map (tag => tagQuestionKey (tag))))
|
||||||
|
const hosts = countBy (posts.map (hostOf).filter ((host): host is string => Boolean (host)))
|
||||||
|
const originalYears = countBy (
|
||||||
|
posts
|
||||||
|
.map (originalYearOf)
|
||||||
|
.filter ((year): year is number => year !== null))
|
||||||
|
const titleLengthMedian = median (posts.map (post => post.title?.length ?? 0))
|
||||||
|
|
||||||
|
const usefulEntries = <T extends string | number> (counts: Map<T, number>) =>
|
||||||
|
[...counts.entries ()]
|
||||||
|
.filter (([, count]) => count > 0 && count < posts.length)
|
||||||
|
.sort ((a, b) => Math.abs (posts.length / 2 - a[1])
|
||||||
|
- Math.abs (posts.length / 2 - b[1]))
|
||||||
|
.slice (0, 80)
|
||||||
|
|
||||||
|
const tagQuestions = usefulEntries (tagCounts)
|
||||||
|
.filter (([, count]) => count >= 2 && count <= Math.max (2, posts.length * .7))
|
||||||
|
.slice (0, 80)
|
||||||
|
.map (([key]) => {
|
||||||
|
const { category, name } = tagFromQuestionKey (String (key))
|
||||||
|
const label = category === 'nico' ? nicoTagLabel (name) : name
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: `tag:${ key }`,
|
||||||
|
text: category === 'nico'
|
||||||
|
? `ニコニコに「${ label }」といふタグが付いてゐる?`
|
||||||
|
: `内容として「${ label }」に関係しさう?`,
|
||||||
|
kind: 'tag' as const,
|
||||||
|
test: (post: Post) => questionableTag (post, String (key)) }
|
||||||
|
})
|
||||||
|
|
||||||
|
const sourceQuestions = usefulEntries (hosts)
|
||||||
|
.filter (([, count]) => count >= 2 && count <= Math.max (2, posts.length * .7))
|
||||||
|
.slice (0, 20)
|
||||||
|
.map (([host]) => ({
|
||||||
|
id: `source:${ host }`,
|
||||||
|
text: `${ host } の投稿を思ひ浮かべてゐる?`,
|
||||||
|
kind: 'source' as const,
|
||||||
|
test: (post: Post) => hostOf (post) === host }))
|
||||||
|
|
||||||
|
const originalYearQuestions = usefulEntries (originalYears)
|
||||||
|
.filter (([, count]) => count >= 2 && count <= Math.max (2, posts.length * .7))
|
||||||
|
.slice (0, 20)
|
||||||
|
.map (([year]) => ({
|
||||||
|
id: `original-year:${ year }`,
|
||||||
|
text: `オリジナルの投稿年は ${ year } 年?`,
|
||||||
|
kind: 'original_date' as const,
|
||||||
|
test: (post: Post) => originalYearOf (post) === year }))
|
||||||
|
|
||||||
|
const titleQuestions = [
|
||||||
|
{
|
||||||
|
id: 'title:long',
|
||||||
|
text: '題名が長めの投稿?',
|
||||||
|
kind: 'title' as const,
|
||||||
|
test: (post: Post) => (post.title?.length ?? 0) > titleLengthMedian },
|
||||||
|
{
|
||||||
|
id: 'title:ascii',
|
||||||
|
text: '題名に英数字が混じってゐる?',
|
||||||
|
kind: 'title' as const,
|
||||||
|
test: (post: Post) => /[A-Za-z0-9]/.test (post.title ?? '') }]
|
||||||
|
.filter (question => {
|
||||||
|
const yes = posts.filter (post => question.test (post)).length
|
||||||
|
const no = posts.length - yes
|
||||||
|
return yes >= 2 && no >= 2 && yes <= posts.length * .7 && no <= posts.length * .7
|
||||||
|
})
|
||||||
|
|
||||||
|
return [
|
||||||
|
...sourceQuestions,
|
||||||
|
...originalYearQuestions,
|
||||||
|
...titleQuestions,
|
||||||
|
...tagQuestions]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const saveGekanatorGame = async ({
|
||||||
|
guessedPostId,
|
||||||
|
correctPostId,
|
||||||
|
answers,
|
||||||
|
}: {
|
||||||
|
guessedPostId: number
|
||||||
|
correctPostId: number
|
||||||
|
answers: GekanatorAnswerLog[]
|
||||||
|
}): Promise<{ id: number }> =>
|
||||||
|
await apiPost ('/gekanator/games', {
|
||||||
|
guessed_post_id: guessedPostId,
|
||||||
|
correct_post_id: correctPostId,
|
||||||
|
question_count: answers.length,
|
||||||
|
answers: answers.map (answer => ({
|
||||||
|
question_id: answer.questionId,
|
||||||
|
question_text: answer.questionText,
|
||||||
|
answer: answer.answer })) })
|
||||||
@@ -8,6 +8,10 @@ export const postsKeys = {
|
|||||||
changes: (p: { post?: string; tag?: string; page: number; limit: number }) =>
|
changes: (p: { post?: string; tag?: string; page: number; limit: number }) =>
|
||||||
['posts', 'changes', p] as const }
|
['posts', 'changes', p] as const }
|
||||||
|
|
||||||
|
export const gekanatorKeys = {
|
||||||
|
root: ['gekanator'] as const,
|
||||||
|
posts: () => ['gekanator', 'posts'] as const }
|
||||||
|
|
||||||
export const tagsKeys = {
|
export const tagsKeys = {
|
||||||
root: ['tags'] as const,
|
root: ['tags'] as const,
|
||||||
index: (p: FetchTagsParams) => ['tags', 'index', p] as const,
|
index: (p: FetchTagsParams) => ['tags', 'index', p] as const,
|
||||||
|
|||||||
ファイル差分が大きすぎるため省略します
差分を読込み
新しい課題から参照
ユーザをブロックする