def DashboardDetail(self, **unused_args):
        """Returns a dict of time to measurement type to count."""
        start_time = self.request.get('start_time')
        end_time = self.request.get('start_time')
        limit = self.request.get('limit')

        entries = model.ValidationEntry.all()

        if start_time:
            start_time = util.MicrosecondsSinceEpochToTime(int(start_time))
        if end_time:
            end_time = util.MicrosecondsSinceEpochToTime(int(end_time))
        if limit:
            limit = int(limit)
        else:
            limit = 1000

        # TODO(drc): Incorporate date limits.
        time_to_type_to_cnt = SortedDict()

        # group by time
        for ent in entries.fetch(limit):
            ms_time = ent.summary.timestamp_start
            meas_type = ent.summary.measurement_type
            time_to_type_to_cnt.setdefault(ms_time, dict()).setdefault(
                meas_type, {'details': []})
            time_to_type_to_cnt[ms_time][meas_type][
                'count'] = ent.summary.error_count
            # links to ids for eventually showing more detail
            time_to_type_to_cnt[ms_time][meas_type]['details'].append([
                ent.measurement.key().id(),
                ent.measurement.device_properties.device_info.id
            ])

        # now sort by time
        sorted_results = SortedDict()
        for k in sorted(time_to_type_to_cnt.iterkeys()):
            sorted_results[k] = time_to_type_to_cnt[k]

        return sorted_results
Ejemplo n.º 2
0
  def DashboardDetail(self, **unused_args):
    """Returns a dict of time to measurement type to count."""
    start_time = self.request.get('start_time')
    end_time = self.request.get('start_time')
    limit = self.request.get('limit')

    entries = model.ValidationEntry.all()

    if start_time:
      start_time = util.MicrosecondsSinceEpochToTime(int(start_time))
    if end_time:
      end_time = util.MicrosecondsSinceEpochToTime(int(end_time))
    if limit:
      limit = int(limit)
    else:
      limit = 1000

    # TODO(drc): Incorporate date limits.
    time_to_type_to_cnt = SortedDict()

    # group by time
    for ent in entries.fetch(limit):
      ms_time = ent.summary.timestamp_start
      meas_type = ent.summary.measurement_type
      time_to_type_to_cnt.setdefault(ms_time, dict()).setdefault(
          meas_type, {'details': []})
      time_to_type_to_cnt[ms_time][meas_type]['count'] = ent.summary.error_count
      # links to ids for eventually showing more detail
      time_to_type_to_cnt[ms_time][meas_type]['details'].append(
        [ent.measurement.key().id(),
         ent.measurement.device_properties.device_info.id])

    # now sort by time
    sorted_results = SortedDict()
    for k in sorted(time_to_type_to_cnt.iterkeys()):
      sorted_results[k] = time_to_type_to_cnt[k]

    return sorted_results
Ejemplo n.º 3
0
class CrossGridReport(object):
    def __init__(self,
                 title,
                 row_reduce,
                 row_map,
                 col_reduce,
                 agg_function,
                 header_map,
                 row_sort=None):
        """
        row_reduce:   reference to row reduce function
                      it take element and should return row key

        row_map:      function to map row basic object;
                      take 1 argument: object;
                      value, returned by this function will be used when
                      printing row

        col_reduce:   same as row_reduce but for columns

        agg_function: funciton will call when apped value to the column
                      for extract data from object;
                      take 2 arguments: object, current value

        header_map: function will call when adding new key into column header
                    take 1 argument: object

        """
        self.title = title
        self.row_reduce = row_reduce
        self.row_map = row_map
        self.col_reduce = col_reduce
        self.agg_function = agg_function
        self.header_map = header_map
        self.row_sort = row_sort

        self.row = SortedDict()
        self.columns = SortedDict()

    def append(self, obj):
        row_key = self.row_reduce(obj)
        col_key = self.col_reduce(obj)

        if col_key not in self.columns:
            self.columns[col_key] = self.header_map(obj)

        row_obj = self.row_map(obj)
        row = self.append_row(row_obj, row_key)
        row.append(col_key, obj)

    def append_row(self, row_obj, row_key):
        return self.row.setdefault(row_key, ReportRow(self, row_obj, row_key))

    def append_column(self, col_obj, col_key):
        self.columns.setdefault(col_key, col_obj)

    def iter_columns(self):
        return self.columns.itervalues()

    def iter_columns_key(self):
        return self.columns.iterkeys()

    def iter_rows(self):
        return self.row.itervalues()