diff --git a/app/assets/stylesheets/application/rainbow-pool.sass b/app/assets/stylesheets/application/rainbow-pool.sass index c852a41e..74f228f2 100644 --- a/app/assets/stylesheets/application/rainbow-pool.sass +++ b/app/assets/stylesheets/application/rainbow-pool.sass @@ -55,6 +55,9 @@ position: relative z-index: 1 + .info + font-size: .85em + .rainbow-pool-pagination margin-block: .5em display: flex diff --git a/app/controllers/pet_types_controller.rb b/app/controllers/pet_types_controller.rb index 181207c5..b38d37ef 100644 --- a/app/controllers/pet_types_controller.rb +++ b/app/controllers/pet_types_controller.rb @@ -13,7 +13,7 @@ class PetTypesController < ApplicationController end @pet_types = PetType. - includes(:color, :species). + includes(:color, :species, :pet_states). order(created_at: :desc). paginate(page: params[:page], per_page: 30) @@ -59,11 +59,12 @@ class PetTypesController < ApplicationController # # If no main poses are available, then we just make all the poses # "canonical", and show the whole mish-mash! - MAIN_POSES = %w(HAPPY_FEM HAPPY_MASC SAD_FEM SAD_MASC SICK_FEM SICK_MASC) def group_pet_states(pet_states) pose_groups = pet_states.emotion_order.group_by(&:pose) - main_groups = pose_groups.select { |k| MAIN_POSES.include?(k) }.values - other_groups = pose_groups.reject { |k| MAIN_POSES.include?(k) }.values + main_groups = + pose_groups.select { |k| PetState::MAIN_POSES.include?(k) }.values + other_groups = + pose_groups.reject { |k| PetState::MAIN_POSES.include?(k) }.values if main_groups.empty? return {canonical: other_groups.flatten(1).sort_by(&:pose), other: []} diff --git a/app/helpers/pet_types_helper.rb b/app/helpers/pet_types_helper.rb new file mode 100644 index 00000000..8826a02c --- /dev/null +++ b/app/helpers/pet_types_helper.rb @@ -0,0 +1,16 @@ +module PetTypesHelper + def moon_progress(num, total) + nearest_quarter = (4.0 * num / total).round / 4.0 + if nearest_quarter >= 1 + "🌕️" + elsif nearest_quarter >= 0.75 + "🌔" + elsif nearest_quarter >= 0.5 + "🌓" + elsif nearest_quarter >= 0.25 + "🌒" + else + "🌑" + end + end +end diff --git a/app/models/pet_state.rb b/app/models/pet_state.rb index 8e86b50d..27c27c87 100644 --- a/app/models/pet_state.rb +++ b/app/models/pet_state.rb @@ -1,5 +1,7 @@ class PetState < ApplicationRecord SwfAssetType = 'biology' + + MAIN_POSES = %w(HAPPY_FEM HAPPY_MASC SAD_FEM SAD_MASC SICK_FEM SICK_MASC) has_many :contributions, :as => :contributed, :inverse_of => :contributed # in case of duplicates being merged diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index 37fb1eed..f4dd1c09 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -116,6 +116,23 @@ class PetType < ApplicationRecord "#{color.human_name}-#{species.human_name}" end + def fully_labeled? + num_missing_poses == 0 + end + + def num_poses + all_poses = pet_states.map(&:pose) + PetState::MAIN_POSES.count { |pose| all_poses.include? pose } + end + + def num_missing_poses + PetState::MAIN_POSES.count - num_poses + end + + def num_unlabeled_states + pet_states.count { |ps| ps.pose == "UNKNOWN" } + end + def self.basic_body_ids PetType.basic.distinct.pluck(:body_id) end diff --git a/app/views/pet_types/_pet_type.html.haml b/app/views/pet_types/_pet_type.html.haml index 91116e83..66293e61 100644 --- a/app/views/pet_types/_pet_type.html.haml +++ b/app/views/pet_types/_pet_type.html.haml @@ -2,3 +2,14 @@ = link_to pet_type do = pet_type_image pet_type, :happy, :thumb, class: "preview" .name= pet_type.human_name + - if support_staff? + .info + - if pet_type.num_unlabeled_states > 0 + %span{title: "Unlabeled states"} + ❓️ #{pet_type.num_unlabeled_states} + + %span{title: "Labeled main poses"} + - if pet_type.fully_labeled? + ✅ #{pet_type.num_poses}/#{pet_type.num_poses} + - else + = moon_progress pet_type.num_poses, pet_type.num_poses + pet_type.num_missing_poses + #{pet_type.num_poses}/#{pet_type.num_poses + pet_type.num_missing_poses}