Exemple #1
0
 def get(self, ranking, name, cq_stats_key): # pylint: disable=R0201
   cq_stats = CQStats.get_by_id(int(cq_stats_key))
   assert cq_stats, '%s must match a CQStats entry.' % cq_stats_key
   for stats in cq_stats.count_stats + cq_stats.list_stats:
     if stats.name == name:
       if ranking == 'lowest':
         return stats.lowest_100
       assert ranking == 'highest'
       return stats.highest_100
   assert False, '%s must match a stat in the specified CQStats entry.' % name
Exemple #2
0
 def get(self, ranking, name, cq_stats_key): # pylint: disable=R0201
   cq_stats = CQStats.get_by_id(int(cq_stats_key))
   assert cq_stats, '%s must match a CQStats entry.' % cq_stats_key
   for stats in cq_stats.count_stats + cq_stats.list_stats:
     if stats.name == name:
       if ranking == 'lowest':
         return stats.lowest_100
       assert ranking == 'highest'
       return stats.highest_100
   assert False, '%s must match a stat in the specified CQStats entry.' % name
Exemple #3
0
def post(handler):  # pragma: no cover
    if handler.request.get('all'):
        stats_list = CQStats.query()
    else:
        stats_list = []
        for key in handler.request.get('keys').split(','):
            stats = CQStats.get_by_id(int(key))
            assert stats, '%s must exist.' % key
            stats_list.append(stats)

    handler.response.write('CQStats removed: [\n')
    for stats in stats_list:
        handler.response.write('  %s,\n' % stats)
        stats.key.delete()
    handler.response.write(']\n')
Exemple #4
0
def post(handler): # pragma: no cover
  if handler.request.get('all'):
    stats_list = CQStats.query()
  else:
    stats_list = []
    for key in handler.request.get('keys').split(','):
      stats = CQStats.get_by_id(int(key))
      assert stats, '%s must exist.' % key
      stats_list.append(stats)

  handler.response.write('CQStats removed: [\n')
  for stats in stats_list:
    handler.response.write('  %s,\n' % stats)
    stats.key.delete()
  handler.response.write(']\n')
def execute_query(key, project, interval_minutes, begin, end, names, count,
                  cursor):
    stats_list = []
    next_cursor = ''
    if key and count > 0:
        stats = CQStats.get_by_id(key)
        if stats and (  # pragma: no branch
            (not project or stats.project == project) and
            (not interval_minutes
             or stats.interval_minutes == interval_minutes) and
            (not begin or stats.begin >= begin) and
            (not end or stats.end <= end) and
            (not names or stats.has_any_names(names))):
            stats_list.append(stats)
        more = False
    else:
        more = True
        while more and len(stats_list) < count:
            filters = []
            if project:
                filters.append(CQStats.project == project)
            if interval_minutes:
                filters.append(CQStats.interval_minutes == interval_minutes)
            if begin:
                filters.append(CQStats.begin >= begin)
            if end:
                filters.append(CQStats.begin <= end)
            query = CQStats.query().filter(*filters).order(-CQStats.begin)
            page_stats, next_cursor, more = query.fetch_page(
                count - len(stats_list),
                start_cursor=Cursor(urlsafe=next_cursor or cursor))
            next_cursor = next_cursor.urlsafe() if next_cursor else ''
            for stats in page_stats:
                if not names or stats.has_any_names(names):
                    stats_list.append(stats)

    ensure_last_change_timestamp(interval_minutes)

    return {
        'results': [stats.to_dict(names) for stats in stats_list],
        'cursor': next_cursor,
        'more': more,
    }
Exemple #6
0
def execute_query(key, project, interval_minutes, begin, end, names,
    count, cursor): # pragma: no cover
  stats_list = []
  next_cursor = ''
  if key and count > 0:
    stats = CQStats.get_by_id(key)
    if stats and (
        (not project or stats.project == project) and
        (not interval_minutes or stats.interval_minutes == interval_minutes) and
        (not begin or stats.begin >= begin) and
        (not end or stats.end <= end) and
        (not names or stats.has_any_names(names))):
      stats_list.append(stats)
    more = False
  else:
    more = True
    while more and len(stats_list) < count:
      filters = []
      if project:
        filters.append(CQStats.project == project)
      if interval_minutes:
        filters.append(CQStats.interval_minutes == interval_minutes)
      if begin:
        filters.append(CQStats.begin >= begin)
      if end:
        filters.append(CQStats.begin <= end)
      query = CQStats.query().filter(*filters).order(-CQStats.begin)
      page_stats, next_cursor, more = query.fetch_page(count - len(stats_list),
          start_cursor=Cursor(urlsafe=next_cursor or cursor))
      next_cursor = next_cursor.urlsafe() if next_cursor else ''
      for stats in page_stats:
        if not names or stats.has_any_names(names):
          stats_list.append(stats)

  ensure_last_change_timestamp(interval_minutes)

  return {
    'results': [stats.to_dict(names) for stats in stats_list],
    'cursor': next_cursor,
    'more': more,
  }