#NEWLINE# def get_flaky_tests( self , project_id , query_date ) : #NEWLINE# #INDENT# subquery = db . session . query ( FlakyTestStat , TestCase ) . filter ( ( FlakyTestStat . project_id == project_id ) ) . join ( TestCase ) #NEWLINE# flakytests_query = subquery . filter ( ( FlakyTestStat . date == query_date ) ) #NEWLINE# flaky_map = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( flaky_test , test_run ) in flakytests_query : #NEWLINE# #INDENT# flaky_map [ test_run . name_sha ] = { #NEWLINE# #INDENT# 'id' : test_run . id , #NEWLINE# 'job_id' : test_run . job_id , #NEWLINE# 'build_id' : test_run . job . build_id , #NEWLINE# 'project_id' : test_run . project_id , #NEWLINE# 'name' : flaky_test . name , #NEWLINE# 'short_name' : test_run . short_name , #NEWLINE# 'package' : test_run . package , #NEWLINE# 'hash' : test_run . name_sha , #NEWLINE# 'flaky_runs' : flaky_test . flaky_runs , #NEWLINE# 'double_reruns' : flaky_test . double_reruns , #NEWLINE# 'passing_runs' : flaky_test . passing_runs , #NEWLINE# 'first_run' : str ( flaky_test . first_run ) , #NEWLINE# 'output' : test_run . message , #NEWLINE# 'history' : [ ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if flaky_map : #NEWLINE# #INDENT# history_query = subquery . filter ( ( FlakyTestStat . date <= query_date ) , ( FlakyTestStat . date > ( query_date - timedelta ( days = CHART_DATA_LIMIT ) ) ) , FlakyTestStat . name . in_ ( [ flaky_test [ 'name' ] for flaky_test in flaky_map . values ( ) ] ) ) #NEWLINE# calendar = [ ( query_date - timedelta ( days = delta ) ) for delta in range ( 0 , CHART_DATA_LIMIT ) ] #NEWLINE# history = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for day in calendar : #NEWLINE# #INDENT# history [ str ( day ) ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# for ( flaky_test , test_run ) in history_query : #NEWLINE# #INDENT# history [ str ( flaky_test . date ) ] [ test_run . name_sha ] = { #NEWLINE# #INDENT# 'date' : str ( flaky_test . date ) , #NEWLINE# 'flaky_runs' : flaky_test . flaky_runs , #NEWLINE# 'double_reruns' : flaky_test . double_reruns , #NEWLINE# 'passing_runs' : flaky_test . passing_runs , #NEWLINE# 'test_existed' : True , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# for day in reversed ( sorted ( history ) ) : #NEWLINE# #INDENT# for sha in flaky_map : #NEWLINE# #INDENT# test_existed = ( flaky_map [ sha ] [ 'first_run' ] and ( day > flaky_map [ sha ] [ 'first_run' ] ) ) #NEWLINE# default_data = { #NEWLINE# #INDENT# 'date' : day , #NEWLINE# 'flaky_runs' : 0 , #NEWLINE# 'double_reruns' : 0 , #NEWLINE# 'passing_runs' : 0 , #NEWLINE# 'test_existed' : test_existed , #NEWLINE# #UNINDENT# } #NEWLINE# flaky_map [ sha ] [ 'history' ] . append ( history [ day ] . get ( sha , default_data ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# flaky_tests = [ flaky_map [ sha ] for sha in flaky_map ] #NEWLINE# return sorted ( flaky_tests , key = ( lambda x : ( x [ 'double_reruns' ] , x [ 'flaky_runs' ] ) ) , reverse = True )