parameters: (request, test_id_1, test_id_2)
return_statement: return JsonResponse(response, safe=False)
docstring: Return comparasion data for all actions in two tests
docstring_summary: Return comparasion data for all actions in two tests
docstring_tokens: Return comparasion data for all actions in two tests
function: def tests_compare_aggregate_new(request, test_id_1, test_id_2):
      '''Return comparasion data for all actions in two tests'''
      response = []
      action_data_1 = TestActionAggregateData.objects.annotate(
          action_name=F('action__url')).annotate(
              mean=RawSQL("((data->>%s)::numeric)", (
                  'mean', ))).filter(test_id=test_id_1).values(
                      'action_id', 'action_name', 'mean')
      for action in action_data_1:
          action_id = action['action_id']
          if TestActionAggregateData.objects.filter(
                  action_id=action_id, test_id=test_id_2).exists():
              action_data_2 = TestActionAggregateData.objects.annotate(
                  action_name=F('action__url')).annotate(
                      mean=RawSQL("((data->>%s)::numeric)", ('mean', ))).filter(
                          action_id=action_id, test_id=test_id_2).values(
                              'action_name', 'mean')[0]
              mean_1 = action['mean']
              mean_2 = action_data_2['mean']
              mean_diff_percent = (mean_1 - mean_2) / mean_2 * 100
          else:
              mean_diff_percent = 0
          response.append({
              'action_name': action['action_name'],
              'mean_diff_percent': mean_diff_percent
          })
      return JsonResponse(response, safe=False)
function_tokens: def tests_compare_aggregate_new ( request , test_id_1 , test_id_2 ) : response = [ ] action_data_1 = TestActionAggregateData . objects . annotate ( action_name = F ( 'action__url' ) ) . annotate ( mean = RawSQL ( "((data->>%s)::numeric)" , ( 'mean' , ) ) ) . filter ( test_id = test_id_1 ) . values ( 'action_id' , 'action_name' , 'mean' ) for action in action_data_1 : action_id = action [ 'action_id' ] if TestActionAggregateData . objects . filter ( action_id = action_id , test_id = test_id_2 ) . exists ( ) : action_data_2 = TestActionAggregateData . objects . annotate ( action_name = F ( 'action__url' ) ) . annotate ( mean = RawSQL ( "((data->>%s)::numeric)" , ( 'mean' , ) ) ) . filter ( action_id = action_id , test_id = test_id_2 ) . values ( 'action_name' , 'mean' ) [ 0 ] mean_1 = action [ 'mean' ] mean_2 = action_data_2 [ 'mean' ] mean_diff_percent = ( mean_1 - mean_2 ) / mean_2 * 100 else : mean_diff_percent = 0 response . append ( { 'action_name' : action [ 'action_name' ] , 'mean_diff_percent' : mean_diff_percent } ) return JsonResponse ( response , safe = False )