attach body id to newest unmodeled item species names
This commit is contained in:
parent
1b0a636fab
commit
99b2acd419
3 changed files with 34 additions and 23 deletions
|
@ -55,12 +55,15 @@ class OutfitsController < ApplicationController
|
|||
@newest_unmodeled_items_predicted_missing_species_by_color = {}
|
||||
@newest_unmodeled_items_predicted_modeled_ratio = {}
|
||||
@newest_unmodeled_items.each do |item|
|
||||
h = item.predicted_missing_nonstandard_body_species_by_color(
|
||||
h = item.predicted_missing_nonstandard_body_ids_by_species_by_color(
|
||||
Color.includes(:translations).select([:id]),
|
||||
Species.includes(:translations).select([:id]))
|
||||
standard_species = item.predicted_missing_standard_body_species.
|
||||
select([:id]).includes(:translations)
|
||||
h[:standard] = standard_species if standard_species.present?
|
||||
standard_body_ids_by_species = item.
|
||||
predicted_missing_standard_body_ids_by_species(
|
||||
Species.select([:id]).includes(:translations))
|
||||
if standard_body_ids_by_species.present?
|
||||
h[:standard] = standard_body_ids_by_species
|
||||
end
|
||||
@newest_unmodeled_items_predicted_missing_species_by_color[item] = h
|
||||
@newest_unmodeled_items_predicted_modeled_ratio[item] = item.predicted_modeled_ratio
|
||||
end
|
||||
|
|
|
@ -57,8 +57,8 @@ module OutfitsHelper
|
|||
def render_predicted_missing_species_by_color(species_by_color)
|
||||
key_prefix = 'outfits.new.newest_items.unmodeled.content'
|
||||
|
||||
# Transform the Color => Array<Species> map into an Array<Pair<Color's
|
||||
# human name (empty if standard), Array<Species>>>.
|
||||
# Transform the Color => (Species => Int) map into an Array<Pair<Color's
|
||||
# human name (empty if standard), (Species => Int)>>.
|
||||
standard = species_by_color.delete(:standard)
|
||||
sorted_pairs = species_by_color.to_a.map { |k, v| [k.human_name, v] }.
|
||||
sort_by { |k, v| k }
|
||||
|
@ -66,14 +66,18 @@ module OutfitsHelper
|
|||
species_by_color[:standard] = standard # undo parameter mutation
|
||||
|
||||
first = true
|
||||
contents = sorted_pairs.map { |color_human_name, species|
|
||||
species_list = species.map(&:human_name).sort.to_sentence(
|
||||
contents = sorted_pairs.map { |color_human_name, body_ids_by_species|
|
||||
species_list = body_ids_by_species.keys.sort_by(&:human_name).map { |species|
|
||||
body_id = body_ids_by_species[species]
|
||||
content_tag(:span, species.human_name, 'data-body-id' => body_id)
|
||||
}.to_sentence(
|
||||
words_connector: t("#{key_prefix}.species_list.words_connector"),
|
||||
two_words_connector: t("#{key_prefix}.species_list.two_words_connector"),
|
||||
last_word_connector: t("#{key_prefix}.species_list.last_word_connector"))
|
||||
last_word_connector: t("#{key_prefix}.species_list.last_word_connector")
|
||||
)
|
||||
key = first ? 'first' : 'other'
|
||||
content = t("#{key_prefix}.body.#{key}", color: color_human_name,
|
||||
species_list: species_list)
|
||||
species_list: species_list).html_safe
|
||||
first = false
|
||||
content
|
||||
}
|
||||
|
|
|
@ -259,16 +259,20 @@ class Item < ActiveRecord::Base
|
|||
@predicted_missing_body_ids ||= predicted_body_ids - modeled_body_ids
|
||||
end
|
||||
|
||||
def predicted_missing_standard_body_species_ids
|
||||
PetType.select('DISTINCT species_id').
|
||||
joins(:color).
|
||||
where(body_id: predicted_missing_body_ids,
|
||||
colors: {standard: true}).
|
||||
map(&:species_id)
|
||||
def predicted_missing_standard_body_ids_by_species_id
|
||||
@predicted_missing_standard_body_ids_by_species_id ||=
|
||||
PetType.select('DISTINCT body_id, species_id').
|
||||
joins(:color).
|
||||
where(body_id: predicted_missing_body_ids,
|
||||
colors: {standard: true}).
|
||||
inject({}) { |h, pt| h[pt.species_id] = pt.body_id; h }
|
||||
end
|
||||
|
||||
def predicted_missing_standard_body_species
|
||||
Species.where(id: predicted_missing_standard_body_species_ids)
|
||||
def predicted_missing_standard_body_ids_by_species(species_scope=Species.scoped)
|
||||
species = species_scope.where(id: predicted_missing_standard_body_ids_by_species_id.keys)
|
||||
species_by_id = species.inject({}) { |h, s| h[s.id] = s; h }
|
||||
predicted_missing_standard_body_ids_by_species_id.inject({}) { |h, (sid, bid)|
|
||||
h[species_by_id[sid]] = bid; h }
|
||||
end
|
||||
|
||||
def predicted_missing_nonstandard_body_pet_types
|
||||
|
@ -277,7 +281,7 @@ class Item < ActiveRecord::Base
|
|||
colors: {standard: false})
|
||||
end
|
||||
|
||||
def predicted_missing_nonstandard_body_species_by_color(colors_scope=Color.scoped, species_scope=Species.scoped)
|
||||
def predicted_missing_nonstandard_body_ids_by_species_by_color(colors_scope=Color.scoped, species_scope=Species.scoped)
|
||||
pet_types = predicted_missing_nonstandard_body_pet_types
|
||||
|
||||
species_by_id = {}
|
||||
|
@ -290,13 +294,13 @@ class Item < ActiveRecord::Base
|
|||
colors_by_id[color.id] = color
|
||||
end
|
||||
|
||||
species_by_color = {}
|
||||
body_ids_by_species_by_color = {}
|
||||
pet_types.each do |pt|
|
||||
color = colors_by_id[pt.color_id]
|
||||
species_by_color[color] ||= []
|
||||
species_by_color[color] << species_by_id[pt.species_id]
|
||||
body_ids_by_species_by_color[color] ||= {}
|
||||
body_ids_by_species_by_color[color][species_by_id[pt.species_id]] = pt.body_id
|
||||
end
|
||||
species_by_color
|
||||
body_ids_by_species_by_color
|
||||
end
|
||||
|
||||
def predicted_fully_modeled?
|
||||
|
|
Loading…
Reference in a new issue