From ba3f93eee95a19046f8df09eb54b65803b746706 Mon Sep 17 00:00:00 2001 From: Mattias Bodlund Date: Mon, 12 May 2025 18:24:16 +0200 Subject: [PATCH] na --- Gemfile.lock | 10 +++++----- app/controllers/questions_controller.rb | 16 ++++++++++++---- app/models/node.rb | 10 ++++++---- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 938f1f2..10ee345 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -129,7 +129,7 @@ GEM jbuilder (2.13.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) - json (2.11.3) + json (2.12.0) kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -143,7 +143,7 @@ GEM kaminari-core (= 1.2.2) kaminari-core (1.2.2) logger (1.7.0) - loofah (2.24.0) + loofah (2.24.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -205,15 +205,15 @@ GEM activesupport (>= 7.0.0) rack railties (>= 7.0.0) - psych (5.2.4) + psych (5.2.5) date stringio public_suffix (6.0.2) puma (6.6.0) nio4r (~> 2.0) racc (1.8.1) - rack (3.1.13) - rack-session (2.1.0) + rack (3.1.14) + rack-session (2.1.1) base64 (>= 0.1.0) rack (>= 3.0.0) rack-test (2.2.0) diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index c28b0aa..09d4cc6 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -18,8 +18,6 @@ class QuestionsController < ApplicationController def result - - not_found if result_node.blank? or current_player.answers.count < questions.size planet_score = 0 @@ -33,15 +31,25 @@ class QuestionsController < ApplicationController end end + people_score = questions.count - planet_score + score_diff = people_score - planet_score + attachment_index = case - when planet_score < 2 + when score_diff >= 2 0 # People - when planet_score > 3 + when score_diff <= -2 1 # Planet else 2 # Balanced end + + + # logger.info(">>> score_diff #{score_diff}") + # logger.info(">>> people_score #{people_score}") + # logger.info(">>> planet_score #{planet_score}") + # logger.info(">>> attachment_index #{attachment_index}") + @result_attachment = result_node.attachments.offset(attachment_index).first @stats_attachment = result_node.attachments.offset(3).first diff --git a/app/models/node.rb b/app/models/node.rb index 98744fa..2c8807d 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -57,10 +57,12 @@ class Node < ApplicationRecord # scope :not_excluded, -> { where "NOT(? = ANY (excluded_locales))", I18n.locale.to_s } - scope :for_current_locale, -> { where("(cardinality(excluded_locales) = 0 AND is_allowlist = false) OR - (is_allowlist = true AND ? = ANY(excluded_locales)) OR - (is_allowlist = false AND NOT(? = ANY(excluded_locales)))", - I18n.locale.to_s, I18n.locale.to_s ) } + scope :for_current_locale, -> { + where("(cardinality(excluded_locales) = 0 AND is_allowlist = false) OR + (is_allowlist = true AND ? = ANY(excluded_locales)) OR + (is_allowlist = false AND NOT(? = ANY(excluded_locales)))", + I18n.locale.to_s, I18n.locale.to_s ) + } scope :viewable, -> { status_published.for_current_locale.where('published_at <= ? AND (expires_at IS NULL OR expires_at > ?)', Time.current, Time.current) } scope :of_template, ->(tmpl) { where(template: Node.templates[tmpl.to_s]) }