Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void popularity(Long id) {
- Brand brand = Brand.findById(id);
- notFoundIfNull(brand);
- List<Outfit> outfits = Outfit.listByBrand(brand.id);
- Map<Long, Integer> counter = new HashMap<Long, Integer>();
- int view = 0;
- for (Outfit outfit : outfits) {
- incrementValue(counter, outfit.contact.id);
- view += outfit.view;
- }
- List sorted = sortByValue(counter);
- int i = 0;
- List<Contact> contacts = new ArrayList<Contact>();
- for (Iterator it = sorted.iterator(); i < 15 && it.hasNext();) {
- i++;
- Map.Entry entry = (Map.Entry)it.next();
- Contact contact = Contact.findById((Long) entry.getKey());
- contacts.add(contact);
- }
- brand.bestOutfiter = contacts;
- brand.view = view;
- brand.score = (view * outfits.size() / 2);
- brand.update();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement