Beispiel #1
0
def GetReport(template_id, revisions):
    with timing.WallTimeLogger('GetReport'), timing.CpuTimeLogger('GetReport'):
        try:
            template = ndb.Key('ReportTemplate', template_id).get()
        except AssertionError:
            # InternalOnlyModel._post_get_hook asserts that the user can access the
            # entity.
            return None

        result = {'editable': False}
        if template:
            result['owners'] = template.owners
            result['editable'] = utils.GetEmail() in template.owners
            result['report'] = report_query.ReportQuery(
                template.template, revisions).FetchSync()
        else:
            for handler in ListStaticTemplates():
                if handler.template.key.id() != template_id:
                    continue
                template = handler.template
                report = handler(revisions)
                if isinstance(report, report_query.ReportQuery):
                    report = report.FetchSync()
                result['report'] = report
                break
            if template is None:
                return None

        result['id'] = template.key.id()
        result['name'] = template.name
        result['internal'] = template.internal_only
        return result
Beispiel #2
0
def List():
    with timing.WallTimeLogger('List'), timing.CpuTimeLogger('List'):
        templates = ReportTemplate.query().fetch()
        templates += [handler.template for handler in ListStaticTemplates()]
        templates = [{
            'id': template.key.id(),
            'name': template.name,
            'modified': template.modified.isoformat(),
        } for template in templates]
        return sorted(templates, key=lambda d: d['name'])
Beispiel #3
0
    def _FetchRowsForTest(self, test_key):
        test_desc = yield descriptor.Descriptor.FromTestPathAsync(
            utils.TestPath(test_key))
        projection, limit = self._RowQueryProjection(test_desc.statistic)
        query = graph_data.Row.query(projection=projection)
        query = query.filter(graph_data.Row.parent_test == test_key)
        query = self._FilterRowQuery(query)

        with timing.WallTimeLogger('fetch_test'):
            rows = yield query.fetch_async(limit)

        with timing.CpuTimeLogger('rows'):
            for row in rows:
                # Sometimes the dev environment just ignores some filters.
                if self._min_revision and row.revision < self._min_revision:
                    continue
                if self._min_timestamp and row.timestamp < self._min_timestamp:
                    continue
                if self._max_revision and row.revision > self._max_revision:
                    continue
                if self._max_timestamp and row.timestamp > self._max_timestamp:
                    continue
                datum = self._Datum(row.revision)
                if test_desc.statistic is None:
                    datum['avg'] = self.Round(row.value)
                    if hasattr(row, 'error') and row.error:
                        datum['std'] = self.Round(row.error)
                else:
                    datum[test_desc.statistic] = self.Round(row.value)
                for stat in self._statistic_columns:
                    if hasattr(row, 'd_' + stat):
                        datum[stat] = self.Round(getattr(row, 'd_' + stat))
                if 'timestamp' in self._columns:
                    datum['timestamp'] = row.timestamp.isoformat()
                if 'revisions' in self._columns:
                    datum['revisions'] = {
                        attr: value
                        for attr, value in row.to_dict().items()
                        if attr.startswith('r_')
                    }
                if 'annotations' in self._columns:
                    datum['annotations'] = {
                        attr: value
                        for attr, value in row.to_dict().items()
                        if attr.startswith('a_')
                    }

        if 'histogram' in self._columns and test_desc.statistic == None:
            with timing.WallTimeLogger('fetch_histograms'):
                yield [
                    self._FetchHistogram(test_key, row.revision)
                    for row in rows
                ]