#NEWLINE# def calc_basic_ticket_stats( Tickets ) : #NEWLINE# #INDENT# all_open_tickets = Tickets . exclude ( status = Ticket . CLOSED_STATUS ) #NEWLINE# today = datetime . today ( ) #NEWLINE# date_30 = date_rel_to_today ( today , 30 ) #NEWLINE# date_60 = date_rel_to_today ( today , 60 ) #NEWLINE# date_30_str = date_30 . strftime ( '%Y-%m-%d' ) #NEWLINE# date_60_str = date_60 . strftime ( '%Y-%m-%d' ) #NEWLINE# ota_le_30 = all_open_tickets . filter ( created__gte = date_30_str ) #NEWLINE# N_ota_le_30 = len ( ota_le_30 ) #NEWLINE# ota_le_60_ge_30 = all_open_tickets . filter ( created__gte = date_60_str , created__lte = date_30_str ) #NEWLINE# N_ota_le_60_ge_30 = len ( ota_le_60_ge_30 ) #NEWLINE# ota_ge_60 = all_open_tickets . filter ( created__lte = date_60_str ) #NEWLINE# N_ota_ge_60 = len ( ota_ge_60 ) #NEWLINE# ots = list ( ) #NEWLINE# ots . append ( [ '< 30 days' , N_ota_le_30 , get_color_for_nbr_days ( N_ota_le_30 ) , sort_string ( date_30_str , '' ) ] ) #NEWLINE# ots . append ( [ '30 - 60 days' , N_ota_le_60_ge_30 , get_color_for_nbr_days ( N_ota_le_60_ge_30 ) , sort_string ( date_60_str , date_30_str ) ] ) #NEWLINE# ots . append ( [ '> 60 days' , N_ota_ge_60 , get_color_for_nbr_days ( N_ota_ge_60 ) , sort_string ( '' , date_60_str ) ] ) #NEWLINE# all_closed_tickets = Tickets . filter ( status = Ticket . CLOSED_STATUS ) #NEWLINE# average_nbr_days_until_ticket_closed = calc_average_nbr_days_until_ticket_resolved ( all_closed_tickets ) #NEWLINE# all_closed_last_60_days = all_closed_tickets . filter ( created__gte = date_60_str ) #NEWLINE# average_nbr_days_until_ticket_closed_last_60_days = calc_average_nbr_days_until_ticket_resolved ( N_ota_ge_60 ) #NEWLINE# basic_ticket_stats = { #NEWLINE# #INDENT# 'average_nbr_days_until_ticket_closed' : average_nbr_days_until_ticket_closed , #NEWLINE# 'average_nbr_days_until_ticket_closed_last_60_days' : average_nbr_days_until_ticket_closed_last_60_days , #NEWLINE# 'open_ticket_stats' : ots , #NEWLINE# #UNINDENT# } #NEWLINE# return basic_ticket_stats