1
0
Fork 0
forked from OpenNeo/impress

Update missing body ID prediction to handle, say, the Maraquan Mynci.

It turns out that some pets for seemingly nonstandard colors have the
standard body type anyway, and vice-versa. This implies that we should
stop relying on a color's standardness, but, for the time being, we've
just revised the prediction model:

Old model:
    * If I see a body_id, I find the corresponding color_ids, and it's wearable
      by all pet types with those color_ids.

New model:
    * If I see a body_id,
        * If it also belongs to a basic pet type, it's a standard body ID.
            * It therefore fits all pet types of standard color (if there's
              more than one body ID modeled already). (Not really,
              because of weird exceptions like Orange Chia. Should that be
              standard or not?)
        * If it doesn't also belong to a basic pet type, it's a nonstandard
          body ID.
            * It therefore only belongs to one color, and therefore the item
              fits all pet types of the same color.
This commit is contained in:
Emi Matchu 2014-01-20 15:29:01 -06:00
parent fb6df82570
commit 03c76fe882
2 changed files with 47 additions and 41 deletions

View file

@ -219,16 +219,12 @@ class Item < ActiveRecord::Base
map(&:color_id) map(&:color_id)
end end
def modeled_colors def basic_body_ids
@modeled_colors ||= Color.select([:id, :standard]).find(modeled_color_ids) @basic_body_ids ||= begin
basic_color_ids ||= Color.select([:id]).basic.map(&:id)
PetType.select('DISTINCT body_id').
where(color_id: basic_color_ids).map(&:body_id)
end end
def modeled_standard_colors?
modeled_colors.any?(&:standard)
end
def modeled_nonstandard_colors
modeled_colors.reject(&:standard)
end end
def predicted_body_ids def predicted_body_ids
@ -249,10 +245,23 @@ class Item < ActiveRecord::Base
# all bodies of the same color. (To my knowledge, anyway. I'm not aware # all bodies of the same color. (To my knowledge, anyway. I'm not aware
# of any exceptions.) So, let's find those bodies by first finding those # of any exceptions.) So, let's find those bodies by first finding those
# colors. # colors.
PetType.select('DISTINCT body_id'). basic_modeled_body_ids, nonbasic_modeled_body_ids = modeled_body_ids.
where(color_id: modeled_color_ids). partition { |bi| basic_body_ids.include?(bi) }
output = []
if basic_modeled_body_ids.present?
output += basic_body_ids
end
if nonbasic_modeled_body_ids.present?
nonbasic_modeled_color_ids = PetType.select('DISTINCT color_id').
where(body_id: nonbasic_modeled_body_ids).
map(&:color_id)
output += PetType.select('DISTINCT body_id').
where(color_id: nonbasic_modeled_color_ids).
map(&:body_id) map(&:body_id)
end end
output
end
end end
def predicted_missing_body_ids def predicted_missing_body_ids
@ -277,7 +286,7 @@ class Item < ActiveRecord::Base
def predicted_missing_nonstandard_body_pet_types def predicted_missing_nonstandard_body_pet_types
PetType.joins(:color). PetType.joins(:color).
where(body_id: predicted_missing_body_ids, where(body_id: predicted_missing_body_ids - basic_body_ids,
colors: {standard: false}) colors: {standard: false})
end end

View file

@ -71,10 +71,7 @@
= latest_contribution_description(@latest_contribution) = latest_contribution_description(@latest_contribution)
%abbr#latest-contribution-created-at{:title => @latest_contribution.created_at.getutc.iso8601} %abbr#latest-contribution-created-at{:title => @latest_contribution.created_at.getutc.iso8601}
-#
#whats-new #whats-new
-# TODO: i18n all the things
-# TODO: cache this entire block? or just request newest items every time? -# TODO: cache this entire block? or just request newest items every time?
- if @newest_unmodeled_items.present? - if @newest_unmodeled_items.present?
#modeling-neopets-users{'data-usernames' => @neopets_usernames.to_json} #modeling-neopets-users{'data-usernames' => @neopets_usernames.to_json}