このコミットが含まれているのは:
2026-06-10 20:02:08 +09:00
コミット 7fe7dbd909
14個のファイルの変更606行の追加41行の削除
+28 -2
ファイルの表示
@@ -2,7 +2,11 @@ class GekanatorQuestionsController < ApplicationController
def index
return head :not_found unless current_user&.admin?
questions = GekanatorQuestion.accepted.order(priority_weight: :desc, id: :asc)
questions =
GekanatorQuestion
.accepted
.includes(:gekanator_question_examples)
.order(priority_weight: :desc, id: :asc)
render json: {
questions: questions.map { |question| question_json(question) }
@@ -12,7 +16,7 @@ class GekanatorQuestionsController < ApplicationController
private
def question_json question
{
json = {
id: question_id_for(question),
text: question.text,
kind: question.kind,
@@ -20,6 +24,10 @@ class GekanatorQuestionsController < ApplicationController
source: question.source,
priority_weight: question.priority_weight
}
if question.kind == 'post_similarity'
json[:example_answers] = example_answers_json(question)
end
json
end
def question_id_for question
@@ -40,6 +48,8 @@ class GekanatorQuestionsController < ApplicationController
"title:length-greater-than:#{ condition[:length] }"
when 'title-has-ascii'
'title:ascii'
when 'post-similarity'
"post-similarity:#{ question.id }"
else
"catalog:#{ question.id }"
end
@@ -54,4 +64,20 @@ class GekanatorQuestionsController < ApplicationController
json
end
def example_answers_json question
question
.gekanator_question_examples
.group_by(&:post_id)
.transform_values { |examples| aggregate_answer(examples) }
end
def aggregate_answer examples
examples
.group_by(&:answer)
.map { |answer, grouped| [answer, grouped.sum(&:weight), grouped.max_by(&:updated_at)&.updated_at] }
.sort_by { |(_answer, weight, updated_at)| [-weight, -(updated_at&.to_f || 0)] }
.first
&.first
end
end