#NEWLINE# def user_stats( username ) : #NEWLINE# #INDENT# user = github . get_user ( username ) #NEWLINE# if ( not user . active ) : #NEWLINE# #INDENT# return flask . abort ( 404 ) #NEWLINE# #UNINDENT# repo_counts = db . session . query ( Repo , func . count ( ) ) . select_from ( Event ) . filter ( ( Event . user_id == user . id ) ) . join ( Repo ) . group_by ( Repo . id ) . order_by ( desc ( func . count ( ) ) ) . all ( ) #NEWLINE# langs = defaultdict ( int ) #NEWLINE# for ( r , c ) in repo_counts : #NEWLINE# #INDENT# if ( r . language is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# langs [ _ . language . name ] += c #NEWLINE# #UNINDENT# week_hist = defaultdict ( ( lambda : list ( [ 0 for _ in range ( 7 ) ] ) ) ) #NEWLINE# for ( _ , k , t , v ) in db . session . query ( Event . user_id , Event . day , Event . event_type , func . count ( ) ) . filter_by ( user_id = user . id ) . group_by ( Event . user_id , Event . event_type , Event . day ) : #NEWLINE# #INDENT# week_hist [ t ] [ k ] = v #NEWLINE# #UNINDENT# day_hist = defaultdict ( ( lambda : list ( [ 0 for _ in range ( 24 ) ] ) ) ) #NEWLINE# for ( _ , k , t , v ) in db . session . query ( Event . user_id , Event . hour , Event . event_type , func . count ( ) ) . filter_by ( user_id = user . id ) . group_by ( Event . user_id , Event . event_type , Event . hour ) . all ( ) : #NEWLINE# #INDENT# day_hist [ t ] [ k ] = v #NEWLINE# #UNINDENT# return dict ( user . basic_dict ( ) , week = dict ( week_hist ) , day = dict ( day_hist ) , languages = dict ( langs ) , repos = [ { #NEWLINE# #INDENT# 'name' : r . fullname , #NEWLINE# 'count' : c , #NEWLINE# #UNINDENT# } for ( r , c ) in repo_counts [ : 5 ] ] )