Mattias Bodlund 7 months ago
parent
commit
ba3f93eee9
3 changed files with 23 additions and 13 deletions
  1. +5
    -5
      Gemfile.lock
  2. +12
    -4
      app/controllers/questions_controller.rb
  3. +6
    -4
      app/models/node.rb

+ 5
- 5
Gemfile.lock View File

@ -129,7 +129,7 @@ GEM
jbuilder (2.13.0) jbuilder (2.13.0)
actionview (>= 5.0.0) actionview (>= 5.0.0)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
json (2.11.3)
json (2.12.0)
kaminari (1.2.2) kaminari (1.2.2)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2) kaminari-actionview (= 1.2.2)
@ -143,7 +143,7 @@ GEM
kaminari-core (= 1.2.2) kaminari-core (= 1.2.2)
kaminari-core (1.2.2) kaminari-core (1.2.2)
logger (1.7.0) logger (1.7.0)
loofah (2.24.0)
loofah (2.24.1)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.12.0) nokogiri (>= 1.12.0)
mail (2.8.1) mail (2.8.1)
@ -205,15 +205,15 @@ GEM
activesupport (>= 7.0.0) activesupport (>= 7.0.0)
rack rack
railties (>= 7.0.0) railties (>= 7.0.0)
psych (5.2.4)
psych (5.2.5)
date date
stringio stringio
public_suffix (6.0.2) public_suffix (6.0.2)
puma (6.6.0) puma (6.6.0)
nio4r (~> 2.0) nio4r (~> 2.0)
racc (1.8.1) 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) base64 (>= 0.1.0)
rack (>= 3.0.0) rack (>= 3.0.0)
rack-test (2.2.0) rack-test (2.2.0)


+ 12
- 4
app/controllers/questions_controller.rb View File

@ -18,8 +18,6 @@ class QuestionsController < ApplicationController
def result def result
not_found if result_node.blank? or current_player.answers.count < questions.size not_found if result_node.blank? or current_player.answers.count < questions.size
planet_score = 0 planet_score = 0
@ -33,15 +31,25 @@ class QuestionsController < ApplicationController
end end
end end
people_score = questions.count - planet_score
score_diff = people_score - planet_score
attachment_index = case attachment_index = case
when planet_score < 2
when score_diff >= 2
0 # People 0 # People
when planet_score > 3
when score_diff <= -2
1 # Planet 1 # Planet
else else
2 # Balanced 2 # Balanced
end 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 @result_attachment = result_node.attachments.offset(attachment_index).first
@stats_attachment = result_node.attachments.offset(3).first @stats_attachment = result_node.attachments.offset(3).first


+ 6
- 4
app/models/node.rb View File

@ -57,10 +57,12 @@ class Node < ApplicationRecord
# scope :not_excluded, -> { where "NOT(? = ANY (excluded_locales))", I18n.locale.to_s } # 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 :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]) } scope :of_template, ->(tmpl) { where(template: Node.templates[tmpl.to_s]) }


Loading…
Cancel
Save