#NEWLINE# def get_time_series_runs_by_key_value( key , value , start_date = None , stop_date = None , session = None ) : #NEWLINE# #INDENT# "Get a time series of runs with meta for all runs with a key value pai\n\n    :param str key: the metadata key to use for matching the runs\n    :param str value: the metadata value to use for matching the runs\n    :param start_date: Optional start date to filter results on\n    :param str stop_date: Optional stop date to filter results on\n    :param session: optional session object if one isn't provided a new session\n                    will be acquired for the duration of this operation\n\n\n    :return runs: a time series dictionary (where the top level key is a\n                  timestamp) that contains all the runs which\n    :rtype: dict\n    " #NEWLINE# session = ( session or get_session ( ) ) #NEWLINE# sub_query = session . query ( models . RunMetadata . run_id ) . filter ( ( models . RunMetadata . key == key ) , ( models . RunMetadata . value == value ) ) . subquery ( ) #NEWLINE# run_query = db_utils . model_query ( models . Run , session ) . join ( models . RunMetadata , ( models . Run . id == models . RunMetadata . run_id ) ) . filter ( models . Run . id . in_ ( sub_query ) ) #NEWLINE# run_query = _filter_runs_by_date ( run_query , start_date , update_index ) #NEWLINE# run_query = run_query . values ( models . Run . uuid , models . Run . passes , models . Run . fails , models . Run . skips , models . Run . run_time , models . Run . run_at , models . RunMetadata . key , models . RunMetadata . value ) #NEWLINE# runs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for run in run_query : #NEWLINE# #INDENT# run_at = run . run_at #NEWLINE# run_id = run . uuid #NEWLINE# if ( run_at not in runs ) : #NEWLINE# #INDENT# runs [ run_at ] = [ ] #NEWLINE# run_dict = { #NEWLINE# #INDENT# 'id' : run_id , #NEWLINE# 'pass' : run . passes , #NEWLINE# 'fail' : run . fails , #NEWLINE# 'skip' : run . skips , #NEWLINE# 'run_time' : run . run_time , #NEWLINE# 'metadata' : { #NEWLINE# #INDENT# run . key : run . value , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# runs [ run_at ] . append ( run_dict ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( run_id not in [ loc_run [ 'id' ] for loc_run in runs [ run_at ] ] ) : #NEWLINE# #INDENT# run_dict = { #NEWLINE# #INDENT# 'id' : run_id , #NEWLINE# 'pass' : run . passes , #NEWLINE# 'fail' : run . fails , #NEWLINE# 'skip' : run . skips , #NEWLINE# 'run_time' : run . run_time , #NEWLINE# 'metadata' : { #NEWLINE# #INDENT# run . key : run . value , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# runs [ run_at ] . append ( run_dict ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# update_index = None #NEWLINE# for ( index , run_dict ) in list ( enumerate ( runs [ run_at ] ) ) : #NEWLINE# #INDENT# if ( run_dict [ 'id' ] == run_id ) : #NEWLINE# #INDENT# update_index = index #NEWLINE# #UNINDENT# #UNINDENT# runs [ run_at ] [ update_index ] [ 'metadata' ] [ run . key ] = run . value #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return runs