<s> import logging <EOL> from collections import Counter <EOL> from totalimpactwebapp . cards_factory import make_summary_cards <EOL> from totalimpactwebapp . cards_factory import make_genre_new_metrics_cards <EOL> from util import cached_property <EOL> from util import dict_from_dir <EOL> from totalimpactwebapp . configs import get_genre_config <EOL> logger = logging . getLogger ( "<STR_LIT>" ) <EOL> def make_genres_list ( profile_id , products ) : <EOL> genres = { } <EOL> for product in products : <EOL> if not product . genre in genres : <EOL> genres [ product . genre ] = Genre ( profile_id = profile_id , genre = product . genre ) <EOL> genres [ product . genre ] . add_product ( product ) <EOL> return genres . values ( ) <EOL> class Genre ( object ) : <EOL> def __init__ ( self , profile_id , genre ) : <EOL> self . profile_id = profile_id <EOL> self . name = genre <EOL> self . products = [ ] <EOL> def add_product ( self , product ) : <EOL> self . products . append ( product ) <EOL> @ cached_property <EOL> def num_products ( self ) : <EOL> return len ( self . products ) <EOL> @ cached_property <EOL> def num_products_with_new_metrics ( self ) : <EOL> return len ( [ p for p in self . products if p . has_diff ] ) <EOL> @ cached_property <EOL> def plural_name ( self ) : <EOL> return get_genre_config ( self . name ) [ "<STR_LIT>" ] <EOL> @ cached_property <EOL> def url_representation ( self ) : <EOL> return get_genre_config ( self . name ) [ "<STR_LIT>" ] <EOL> @ cached_property <EOL> def icon ( self ) : <EOL> return get_genre_config ( self . name ) [ "<STR_LIT>" ] <EOL> @ cached_property <EOL> def cards ( self ) : <EOL> return make_summary_cards ( self . products ) <EOL> @ cached_property <EOL> def cards_new_metrics ( self ) : <EOL> return make_genre_new_metrics_cards ( self . products ) <EOL> def to_dict ( self ) : <EOL> attributes_to_ignore = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> ret = dict_from_dir ( self , attributes_to_ignore ) <EOL> return ret <EOL> def __repr__ ( self ) : <EOL> return u'<STR_LIT>' . format ( <EOL> profile_id = self . profile_id , genre = self . genre , num = self . num_products ) </s>
