<s> from util import cached_property <EOL> from util import dict_from_dir <EOL> import logging <EOL> import configs <EOL> logger = logging . getLogger ( "<STR_LIT>" ) <EOL> def make_list ( metrics ) : <EOL> """<STR_LIT>""" <EOL> awards = [ ] <EOL> for engagement_type in configs . award_configs [ "<STR_LIT>" ] . keys ( ) : <EOL> for audience in configs . award_configs [ "<STR_LIT>" ] . keys ( ) : <EOL> this_award = Award ( engagement_type , audience , metrics ) <EOL> if len ( this_award . metrics ) : <EOL> awards . append ( this_award ) <EOL> return awards <EOL> class Award ( object ) : <EOL> def __init__ ( self , engagement_type , audience , metrics ) : <EOL> self . engagement_type = engagement_type <EOL> self . audience = audience <EOL> self . metrics = [ ] <EOL> for metric in metrics : <EOL> self . add_metric ( metric ) <EOL> def add_metric ( self , metric ) : <EOL> same_audience = metric . audience == self . audience <EOL> same_engagement_type = metric . engagement_type == self . engagement_type <EOL> if same_audience and same_engagement_type and not metric . hide_badge : <EOL> self . metrics . append ( metric ) <EOL> return True <EOL> else : <EOL> return False <EOL> @ cached_property <EOL> def is_highly ( self ) : <EOL> return self . top_metric_by_percentile . is_highly <EOL> @ cached_property <EOL> def top_metric_by_percentile ( self ) : <EOL> s = sorted ( self . metrics , key = lambda metric : metric . percentile , reverse = True ) <EOL> return s [ <NUM_LIT:0> ] <EOL> @ cached_property <EOL> def top_metric_by_count ( self ) : <EOL> s = sorted ( self . metrics , key = lambda metric : metric . display_count , reverse = True ) <EOL> return s [ <NUM_LIT:0> ] <EOL> @ cached_property <EOL> def top_metric_by_diff ( self ) : <EOL> s = sorted ( <EOL> self . metrics , <EOL> key = lambda metric : metric . diff_value , <EOL> reverse = True <EOL> ) <EOL> return s [ <NUM_LIT:0> ] <EOL> @ cached_property <EOL> def metrics_with_diff ( self ) : <EOL> return [ m for m in self . metrics if m . diff_value > <NUM_LIT:0> ] <EOL> @ cached_property <EOL> def has_diff ( self ) : <EOL> return len ( self . metrics_with_diff ) > <NUM_LIT:0> <EOL> @ cached_property <EOL> def is_highly_classname ( self ) : <EOL> if self . is_highly : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> @ cached_property <EOL> def highly_string ( self ) : <EOL> if self . is_highly : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> @ cached_property <EOL> def sort_score ( self ) : <EOL> if self . is_highly : <EOL> return <NUM_LIT:3> <EOL> else : <EOL> return <NUM_LIT:1> <EOL> @ cached_property <EOL> def display_audience ( self ) : <EOL> return self . audience . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> @ cached_property <EOL> def display_order ( self ) : <EOL> ret = configs . award_configs [ "<STR_LIT>" ] [ self . engagement_type ] [ <NUM_LIT:1> ] <EOL> if self . audience == "<STR_LIT>" : <EOL> ret += <NUM_LIT:10> <EOL> if self . is_highly : <EOL> ret += <NUM_LIT:100> <EOL> return ret <EOL> def to_dict ( self ) : <EOL> return dict_from_dir ( self ) </s>
