#NEWLINE# def dashboard( request ) : #NEWLINE# #INDENT# '\n    Render HTML for dashboard/metrics view.\n    ' #NEWLINE# dataset_count = Dataset . objects . all ( ) . count ( ) #NEWLINE# datasets_without_descriptions = [ ( unquote ( dataset [ 'name' ] ) , dataset [ 'slug' ] ) for dataset in Dataset . objects . filter ( description = '' ) . values ( 'name' , 'slug' ) ] #NEWLINE# datasets_without_categories = [ ( unquote ( dataset [ 'name' ] ) , dataset [ 'slug' ] ) for dataset in Dataset . objects . filter ( categories = None ) . values ( 'name' , 'slug' ) ] #NEWLINE# user_count = UserProxy . objects . all ( ) . count ( ) #NEWLINE# activated_user_count = UserProxy . objects . filter ( is_active = True ) . count ( ) #NEWLINE# today = now ( ) . date ( ) #NEWLINE# thirty_days_ago = ( today - datetime . timedelta ( days = 30 ) ) #NEWLINE# active_users = list ( UserProxy . objects . raw ( 'SELECT auth_user.*, count(panda_activitylog.id) AS activity_logs__count FROM auth_user LEFT JOIN panda_activitylog ON panda_activitylog.user_id = auth_user.id WHERE auth_user.is_active = True AND panda_activitylog.when > %s GROUP BY auth_user.id ORDER BY activity_logs__count DESC, auth_user.id ASC' , [ thirty_days_ago ] ) ) #NEWLINE# most_active_users = active_users [ : 10 ] #NEWLINE# if ( len ( active_users ) > 10 ) : #NEWLINE# #INDENT# least_active_users = active_users [ ( - 10 ) : ] #NEWLINE# least_active_users . reverse ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# least_active_users = [ ] #NEWLINE# #UNINDENT# inactive_users = UserProxy . objects . all ( ) . annotate ( Count ( 'activity_logs' ) ) . filter ( activity_logs__count = 0 ) #NEWLINE# _active_users_by_day = list ( ActivityLog . objects . filter ( when__gt = thirty_days_ago ) . values ( 'when' ) . annotate ( Count ( 'id' ) ) . order_by ( 'when' ) ) #NEWLINE# dates = [ ( thirty_days_ago + datetime . timedelta ( days = x ) ) for x in range ( 0 , 31 ) ] #NEWLINE# active_users_by_day = [ ] #NEWLINE# for d in dates : #NEWLINE# #INDENT# if ( _active_users_by_day and ( _active_users_by_day [ 0 ] [ 'when' ] == d ) ) : #NEWLINE# #INDENT# _d = _active_users_by_day . pop ( 0 ) #NEWLINE# active_users_by_day . append ( _d ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# active_users_by_day . append ( { #NEWLINE# #INDENT# 'when' : d , #NEWLINE# 'id__count' : 0 , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# total_searches = SearchLog . objects . count ( ) #NEWLINE# most_searched_datasets = [ ( unquote ( dataset [ 'name' ] ) , dataset [ 'slug' ] , dataset [ 'searches__count' ] ) for dataset in Dataset . objects . all ( ) . annotate ( Count ( 'searches' ) ) . filter ( searches__count__gt = 0 ) . order_by ( '-searches__count' ) . values ( 'name' , 'slug' , 'searches__count' ) [ : 10 ] ] #NEWLINE# _searches_by_day = list ( SearchLog . objects . filter ( when__gt = thirty_days_ago ) . extra ( select = { #NEWLINE# #INDENT# 'day' : '"when"::date' , #NEWLINE# #UNINDENT# } ) . values ( 'day' ) . annotate ( Count ( 'when' ) ) . order_by ( 'day' ) ) #NEWLINE# dates = [ ( thirty_days_ago + datetime . timedelta ( days = x ) ) for x in range ( 0 , 31 ) ] #NEWLINE# searches_by_day = [ ] #NEWLINE# for d in dates : #NEWLINE# #INDENT# if ( _searches_by_day and ( _searches_by_day [ 0 ] [ 'day' ] == d ) ) : #NEWLINE# #INDENT# _d = _searches_by_day . pop ( 0 ) #NEWLINE# searches_by_day . append ( _d ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# searches_by_day . append ( { #NEWLINE# #INDENT# 'day' : d , #NEWLINE# 'when__count' : 0 , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# root_disk = os . stat ( '/' ) . st_dev #NEWLINE# upload_disk = os . stat ( settings . MEDIA_ROOT ) . st_dev #NEWLINE# indices_disk = os . stat ( settings . SOLR_DIRECTORY ) . st_dev #NEWLINE# root_disk_total = utils . get_total_disk_space ( '/' ) #NEWLINE# root_disk_free = utils . get_free_disk_space ( '/' ) #NEWLINE# root_disk_percent_used = ( 100 - ( ( float ( root_disk_free ) / root_disk_total ) * 100 ) ) #NEWLINE# if ( upload_disk != root_disk ) : #NEWLINE# #INDENT# upload_disk_total = utils . get_total_disk_space ( settings . MEDIA_ROOT ) #NEWLINE# upload_disk_free = utils . get_free_disk_space ( settings . MEDIA_ROOT ) #NEWLINE# upload_disk_percent_used = ( 100 - ( ( float ( upload_disk_free ) / upload_disk_total ) * 100 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# upload_disk_total = None #NEWLINE# upload_disk_free = None #NEWLINE# upload_disk_percent_used = None #NEWLINE# #UNINDENT# if ( indices_disk != root_disk ) : #NEWLINE# #INDENT# indices_disk_total = utils . get_total_disk_space ( settings . SOLR_DIRECTORY ) #NEWLINE# indices_disk_free = utils . get_free_disk_space ( settings . SOLR_DIRECTORY ) #NEWLINE# indices_disk_percent_used = ( 100 - ( ( float ( indices_disk_free ) / indices_disk_total ) * 100 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# indices_disk_total = None #NEWLINE# indices_disk_free = None #NEWLINE# indices_disk_percent_used = None #NEWLINE# #UNINDENT# return render_to_response ( 'dashboard.html' , { #NEWLINE# #INDENT# 'settings' : settings , #NEWLINE# 'dataset_count' : dataset_count , #NEWLINE# 'datasets_without_descriptions' : datasets_without_descriptions , #NEWLINE# 'datasets_without_categories' : datasets_without_categories , #NEWLINE# 'user_count' : user_count , #NEWLINE# 'activated_user_count' : activated_user_count , #NEWLINE# 'most_active_users' : most_active_users , #NEWLINE# 'least_active_users' : least_active_users , #NEWLINE# 'inactive_users' : inactive_users , #NEWLINE# 'active_users_by_day' : active_users_by_day , #NEWLINE# 'total_searches' : total_searches , #NEWLINE# 'most_searched_datasets' : most_searched_datasets , #NEWLINE# 'searches_by_day' : searches_by_day , #NEWLINE# 'root_disk_total' : root_disk_total , #NEWLINE# 'root_disk_free' : root_disk_free , #NEWLINE# 'root_disk_percent_used' : root_disk_percent_used , #NEWLINE# 'upload_disk_total' : upload_disk_total , #NEWLINE# 'upload_disk_free' : upload_disk_free , #NEWLINE# 'upload_disk_percent_used' : dates , #NEWLINE# 'indices_disk_total' : indices_disk_total , #NEWLINE# 'indices_disk_free' : indices_disk_free , #NEWLINE# 'indices_disk_percent_used' : indices_disk_percent_used , #NEWLINE# 'storage_documentation_url' : ( 'http://panda.readthedocs.org/en/%s/storage.html' % settings . PANDA_VERSION ) , #NEWLINE# #UNINDENT# } )