def __get_unsafes_with_confirmed(self): total_unsafes = {} verdicts = UnsafeVerdicts() # Collect unsafes for d_id, v, total, confirmed in ReportUnsafeCache.objects\ .filter(report__decision_id__in=self._decisions_ids).values('report__decision_id', 'verdict')\ .annotate(total=Count('id'), confirmed=Count(Case(When(marks_confirmed__gt=0, then=1))))\ .values_list('report__decision_id', 'verdict', 'total', 'confirmed'): # Collect total number total_unsafes.setdefault(d_id, {'total': 0, 'confirmed': 0}) total_unsafes[d_id]['total'] += total total_unsafes[d_id]['confirmed'] += confirmed if total > 0: total = html_link(construct_url('reports:unsafes', self._core[d_id], verdict=v), total) if v == verdicts.unassociated: html_value = str(total) elif confirmed > 0: confirmed_url = construct_url('reports:unsafes', self._core[d_id], verdict=v, confirmed=1) html_value = '{} ({})'.format(html_link(confirmed_url, confirmed), total) else: html_value = '0 ({})'.format(total) self._values_data[d_id][verdicts.column(v)] = {'html': html_value} # Add numbers of total safes of the decision for d_id, total_data in total_unsafes.items(): total, confirmed = total_data['total'], total_data['confirmed'] if total > 0: total = html_link(construct_url('reports:unsafes', self._core[d_id]), total) if confirmed > 0: confirmed = html_link(construct_url('reports:unsafes', self._core[d_id], confirmed=1), confirmed) self._values_data[d_id]['unsafe:total'] = {'html': '{} ({})'.format(confirmed, total)}
def __collect_unknowns(self): numbers = {} unmarked = {} totals = {} for d_id, component, problems in ReportUnknownCache.objects\ .filter(report__decision_id__in=self._decisions_ids)\ .values_list('report__decision_id', 'report__component', 'problems'): numbers.setdefault(d_id, {}) for problem, number in problems.items(): numbers[d_id].setdefault((component, problem), 0) numbers[d_id][(component, problem)] += 1 if len(problems) == 0: unmarked.setdefault(d_id, {}) unmarked[d_id].setdefault(component, 0) unmarked[d_id][component] += 1 totals.setdefault(d_id, {}) totals[d_id].setdefault(component, 0) totals[d_id][component] += 1 # Get numbers of problems for d_id in numbers: for component, problem in numbers[d_id]: column = 'problem:{}:{}'.format(self.slugify(component), self.slugify(problem)) url = construct_url('reports:unknowns', self._core[d_id], component=component, problem=problem) value = numbers[d_id][(component, problem)] self._values_data[d_id][column] = cell_value(value, url=url) # Get numbers of unknowns without marks for d_id in unmarked: for component in unmarked[d_id]: column = 'problem:{}:no_mark'.format(self.slugify(component)) url = construct_url('reports:unknowns', self._core[d_id], component=component, problem=0) value = unmarked[d_id][component] self._values_data[d_id][column] = cell_value(value, url=url) # Get total numbers of unknowns for d_id in totals: total_number = 0 for component, number in totals[d_id].items(): column = 'problem:{}:total'.format(self.slugify(component)) url = construct_url('reports:unknowns', self._core[d_id], component=component) self._values_data[d_id][column] = cell_value(number, url=url) total_number += number self._values_data[d_id]['problem:total'] = cell_value( total_number, url=reverse('reports:unknowns', args=[self._core[d_id]]) )
def __collect_detailed_unsafes(self): queryset = ReportUnsafeCache.objects\ .filter(report__decision_id__in=self._decisions_ids).values('report__decision_id', 'verdict')\ .annotate(total=Count('id'), manual=Count(Case(When(marks_confirmed__gt=0, then=1))))\ .values_list('report__decision_id', 'verdict', 'total', 'manual') total_unsafes = {} for d_id, v, total, manual in queryset: # Collect total number total_unsafes.setdefault(d_id, 0) total_unsafes[d_id] += total if self._unsafes_columns.is_detailed(v): # Get manual value manual_url = None if manual > 0: manual_url = construct_url('reports:unsafes', self._core[d_id], verdict=v, manual=1) manual_column = self._unsafes_columns.get_verdict_column(v, manual=True) self._values_data[d_id][manual_column] = cell_value(manual, url=manual_url) # Get automatic value automatic_url = None if manual < total: automatic_url = construct_url('reports:unsafes', self._core[d_id], verdict=v, manual=0) automatic_column = self._unsafes_columns.get_verdict_column(v, manual=False) self._values_data[d_id][automatic_column] = cell_value(total - manual, url=automatic_url) else: total_link = None if total > 0: total_link = construct_url('reports:unsafes', self._core[d_id], verdict=v) self._values_data[d_id][self._unsafes_columns.get_verdict_column(v)] = cell_value(total, url=total_link) # Add number of total unsafes of the decision for d_id, total in total_unsafes.items(): total_url = None if total > 0: total_url = construct_url('reports:unsafes', self._core[d_id]) self._values_data[d_id][self._unsafes_columns.get_verdict_column()] = cell_value(total, url=total_url)
def __collect_simple_unsafes(self): queryset = ReportUnsafeCache.objects.filter(report__decision_id__in=self._decisions_ids)\ .values('report__decision_id', 'verdict').annotate(number=Count('id'))\ .values_list('report__decision_id', 'verdict', 'number') total_unsafes = {} for d_id, v, number in queryset: # Collect total number total_unsafes.setdefault(d_id, 0) total_unsafes[d_id] += number unsafes_url = None if number > 0: unsafes_url = construct_url('reports:unsafes', self._core[d_id], verdict=v) self._values_data[d_id][self._unsafes_columns.get_verdict_column(v)] = cell_value(number, url=unsafes_url) # Add numbers of total unsafes of the decision for d_id, number in total_unsafes.items(): unsafes_url = None if number > 0: unsafes_url = construct_url('reports:unsafes', self._core[d_id]) self._values_data[d_id][self._unsafes_columns.get_verdict_column()] = cell_value(number, url=unsafes_url)
def __get_unsafes_without_confirmed(self): total_unsafes = {} verdicts = UnsafeVerdicts() for d_id, v, number in ReportUnsafeCache.objects.filter(report__decision_id__in=self._decisions_ids)\ .values('report__decision_id', 'verdict').annotate(number=Count('id'))\ .values_list('report__decision_id', 'verdict', 'number'): unsafes_url = None if number > 0: unsafes_url = construct_url('reports:unsafes', self._core[d_id], verdict=v) self._values_data[d_id][verdicts.column(v)] = cell_value(number, url=unsafes_url) # Collect total number total_unsafes.setdefault(d_id, 0) total_unsafes[d_id] += number # Add numbers of total unsafes of the decision for d_id, number in total_unsafes.items(): unsafes_url = None if number > 0: unsafes_url = construct_url('reports:unsafes', self._core[d_id]) self._values_data[d_id]['unsafe:total'] = cell_value(number, url=unsafes_url)
def coverages(self): cov_qs = self.coverage_queryset() coverages_list = [] for cov in cov_qs: cov_data = { 'name': cov.identifier, 'total': cov.total, 'url': self.coverage_api(cov.id), 'details_url': construct_url('reports:coverage', cov.report_id, coverage_id=cov.id) } if self.with_report_link: cov_data['report'] = (cov.name, construct_url('reports:component', cov.report_id)) coverages_list.append(cov_data) return coverages_list
def __collect_tags(self, cache_model, tags_type): """ Collect tags data for decisions. :param cache_model: ReportSafeCache or ReportUnsafeCache :param tags_type: "safe" or "unsafe" :return: nothing """ tags_qs = cache_model.objects\ .filter(report__decision_id__in=self._decisions_ids)\ .values_list('report__decision_id', 'tags') numbers = {} for d_id, tags in tags_qs: numbers.setdefault(d_id, {}) for tag, number in tags.items(): numbers[d_id].setdefault(tag, 0) numbers[d_id][tag] += 1 for d_id in numbers: for tag, num in numbers[d_id].items(): column = 'tag:{}:{}'.format(tags_type, self.slugify(tag)) url = construct_url('reports:{}s'.format(tags_type), self._core[d_id], tag=tag) self._values_data[d_id][column] = cell_value(num, url=url)
def coverage_api(self, coverage_id): return construct_url('reports:api-coverage-table', self._report.id)
def coverage_api(self, coverage_id): return construct_url('jobs:api-get-coverage', self._decision.id, coverage_id=coverage_id)