#NEWLINE# def get_most_recent_metrics( tiids , most_recent_metric_date = None ) : #NEWLINE# #INDENT# for tiid in tiids : #NEWLINE# #INDENT# for e in tiid : #NEWLINE# #INDENT# if ( not e . isalnum ( ) ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not most_recent_metric_date ) : #NEWLINE# #INDENT# most_recent_metric_date = datetime . datetime . utcnow ( ) . isoformat ( ) #NEWLINE# #UNINDENT# tiid_string = ',' . join ( [ ( ( "'" + tiid ) + "'" ) for tiid in tiids ] ) #NEWLINE# metric_objects = item_module . Snap . query . from_statement ( "\n        WITH max_collect AS \n            (SELECT tiid, provider, interaction, max(last_collected_date) AS last_collected_date\n                FROM snap\n                WHERE tiid in ({tiid_string})\n                AND last_collected_date <= '{most_recent_metric_date}'::date + 1               \n                GROUP BY tiid, provider, interaction\n                ORDER by tiid, provider)\n            SELECT max_collect.*, m.raw_value, m.drilldown_url, m.snap_id\n                FROM snap m\n                NATURAL JOIN max_collect" . format ( tiid_string = tiid_string , most_recent_metric_date = most_recent_metric_date ) ) . all ( ) #NEWLINE# return metric_objects