Beispiel #1
0
def get_result(testcase, end, block, days, group_by):
    """Get slots for crash stats."""
    query = crash_stats.Query()
    query.group_by = group_by
    query.sort_by = 'total_count'
    query.set_time_params(end, days, block)

    query.filter('crash_type', testcase.crash_type)
    query.filter('crash_state', testcase.crash_state)
    query.filter('security_flag', testcase.security_flag)

    _, rows = crash_stats.get(query, crash_stats.Query(), 0, 1)

    if not rows:
        return {'end': end, 'days': days, 'block': block, 'groups': []}

    return rows[0]
Beispiel #2
0
def get_result():
  """Get the result for the crash stats page."""
  params = dict(request.iterparams())
  page = helpers.cast(request.get('page') or 1, int, "'page' is not an int.")
  group_by = params.get('group', 'platform')
  params['group'] = group_by
  sort_by = params.get('sort', 'total_count')
  params['sort'] = sort_by
  params['number'] = params.get('number', 'count')

  # Conditions for individual records.
  query = crash_stats.Query()
  query.group_by = group_by
  query.sort_by = sort_by
  crash_access.add_scope(query, params, 'security_flag', 'job_type',
                         'fuzzer_name')
  filters.add(query, params, FILTERS)

  # Conditions after grouping.
  group_query = crash_stats.Query()
  filters.add(group_query, params, GROUP_FILTERS)

  try:
    total_count, rows = crash_stats.get(
        query=query,
        group_query=group_query,
        offset=(page - 1) * PAGE_SIZE,
        limit=PAGE_SIZE)
  except ValueError:
    raise helpers.EarlyExitException('Invalid filters', 400)

  attach_testcases(rows)

  helpers.log('CrashStats', helpers.VIEW_OPERATION)

  result = {
      'totalPages': (total_count // PAGE_SIZE) + 1,
      'page': page,
      'pageSize': PAGE_SIZE,
      'items': rows,
      'totalCount': total_count
  }
  return result, params