示例#1
0
def report_resources(user, report):
    if all(x is not None for x in [report.wall_time, report.cpu_time, report.memory]):
        return {
            'wall_time': HumanizedValue(report.wall_time, user=user).timedelta,
            'cpu_time': HumanizedValue(report.cpu_time, user=user).timedelta,
            'memory': HumanizedValue(report.memory, user=user).memory
        }
    return None
示例#2
0
    def __unsafes_data(self):
        unsafes_ids = list(report.pk for report in self.page)
        cnt = (self.page.number - 1) * self.paginator.per_page + 1

        columns = ['number']
        columns.extend(self.view['columns'])
        attributes = {}
        for r_id, a_name, a_value in ReportAttr.objects.filter(report_id__in=unsafes_ids).order_by('id')\
                .values_list('report_id', 'name', 'value'):
            if a_name not in attributes:
                columns.append(a_name)
                attributes[a_name] = {}
            attributes[a_name][r_id] = a_value

        verdicts_dict = dict(UNSAFE_VERDICTS)
        with_confirmed = 'hidden' not in self.view or 'confirmed_marks' not in self.view['hidden']

        values_data = []
        for report in self.page:
            values_row = []
            for col in columns:
                val = '-'
                href = None
                color = None
                if col in attributes:
                    val = attributes[col].get(report.pk, '-')
                elif col == 'number':
                    val = cnt
                    href = reverse('reports:unsafe', args=[report.trace_id])
                elif col == 'marks_number':
                    if with_confirmed:
                        val = '{0} ({1})'.format(report.cache.marks_confirmed, report.cache.marks_total)
                    else:
                        val = str(report.cache.marks_total)
                elif col == 'report_verdict':
                    val = verdicts_dict[report.cache.verdict]
                    color = UNSAFE_COLOR[report.cache.verdict]
                elif col == 'tags':
                    if len(report.cache.tags):
                        tags_values = []
                        for tag in sorted(report.cache.tags):
                            if report.cache.tags[tag] > 1:
                                tags_values.append('{0} ({1})'.format(tag, report.cache.tags[tag]))
                            else:
                                tags_values.append(tag)
                        val = ', '.join(tags_values)
                elif col == 'verifiers:cpu':
                    val = HumanizedValue(report.cpu_time, user=self.user).timedelta
                elif col == 'verifiers:wall':
                    val = HumanizedValue(report.wall_time, user=self.user).timedelta
                elif col == 'verifiers:memory':
                    val = HumanizedValue(report.memory, user=self.user).memory
                values_row.append({'value': val, 'color': color, 'href': href})
            values_data.append(values_row)
            cnt += 1

        return Header(columns, REP_MARK_TITLES).struct, values_data
示例#3
0
 def get_progress_ts(self, instance):
     progress = self.__calculate_progress(instance.total_ts,
                                          instance.solved_ts,
                                          instance.failed_ts)
     if instance.status == DECISION_STATUS[2][0]:
         progress = progress or _('Estimating progress')
     if not progress:
         return None
     value = {
         'progress': progress,
         'start': HumanizedValue(instance.start_ts, user=self._user).date,
         'finish': HumanizedValue(instance.finish_ts, user=self._user).date,
     }
     if instance.status == DECISION_STATUS[2][0]:
         value['expected_time'] = self.__get_expected_time(
             instance.expected_time_ts, instance.gag_text_ts)
     return value
示例#4
0
    def marks_data(self):
        cnt = (self.page.number - 1) * self.paginator.per_page + 1

        columns = ['checkbox', 'number']
        columns.extend(self.view['columns'])

        # We collecting attributes from separate request to ensure the order of attributes columns is right
        attr_columns, attributes = self.__get_attrs()
        columns.extend(attr_columns)

        values_data = []
        for mark_version in self.page:
            mark_id = mark_version.mark_id
            values_row = []
            for col in columns:
                val = '-'
                href = None
                color = None
                if col == 'checkbox':
                    values_row.append({'checkbox': mark_id})
                    continue
                elif col in attributes:
                    val = attributes[col].get(mark_id, '-')
                elif col == 'number':
                    val = cnt
                    href = reverse('marks:{}'.format(self.mark_type),
                                   args=[mark_id])
                elif col == 'num_of_links':
                    val = mark_version.num_of_links
                elif col == 'tags':
                    if mark_version.mark.cache_tags:
                        val = ', '.join(
                            x.split(' - ')[-1]
                            for x in mark_version.mark.cache_tags)
                elif col == 'author' and mark_version.author:
                    val = mark_version.author.get_full_name()
                    href = reverse('users:show-profile',
                                   args=[mark_version.author_id])
                elif col == 'change_date':
                    val = mark_version.change_date
                    if self.user.data_format == 'hum':
                        val = HumanizedValue.get_templated_text(
                            '{% load humanize %}{{ date|naturaltime }}',
                            date=val)
                elif col == 'source':
                    val = mark_version.mark.get_source_display()
                elif col == 'identifier':
                    val = str(mark_version.mark.identifier)
                else:
                    val, href, color = self.get_value(col, mark_version)

                values_row.append({'value': val, 'color': color, 'href': href})
            values_data.append(values_row)
            cnt += 1
        return columns, values_data
示例#5
0
 def get_progress_sj(self, instance):
     if instance.total_sj is None and instance.start_sj is None:
         # Seems like the decision doesn't have subjobs
         return None
     progress = self.__calculate_progress(instance.total_sj,
                                          instance.solved_sj,
                                          instance.failed_sj)
     if instance.status == DECISION_STATUS[2][0]:
         progress = progress or _('Estimating progress')
     if not progress:
         return None
     value = {
         'progress': progress,
         'start': HumanizedValue(instance.start_sj, user=self._user).date,
         'finish': HumanizedValue(instance.finish_sj, user=self._user).date,
     }
     if instance.status == DECISION_STATUS[2][0]:
         value['expected_time'] = self.__get_expected_time(
             instance.expected_time_sj, instance.gag_text_sj)
     return value
示例#6
0
    def __collect_decision_data(self):
        prodress_data = ProgressSerializerRO(
            instance=self._decisions_qs, many=True, context={'user': self.view.user}
        ).data
        for progress in prodress_data:
            if 'total_ts' in progress:
                self._values_data[progress['id']]['tasks:total_ts'] = cell_value(progress['total_ts'])
            if 'total_sj' in progress:
                self._values_data[progress['id']]['subjobs:total_sj'] = cell_value(progress['total_sj'])

            decision_progress = {'start_date': progress['start_date'], 'finish_date': progress['finish_date']}
            if 'progress_ts' in progress:
                decision_progress['tasks:progress_ts'] = progress['progress_ts']['progress']
                decision_progress['tasks:start_ts'] = progress['progress_ts']['start']
                decision_progress['tasks:finish_ts'] = progress['progress_ts']['finish']
                if 'expected_time' in progress['progress_ts']:
                    decision_progress['tasks:expected_time_ts'] = progress['progress_ts']['expected_time']
            if 'progress_sj' in progress:
                decision_progress['tasks:progress_sj'] = progress['progress_sj']['progress']
                decision_progress['tasks:start_sj'] = progress['progress_sj']['start']
                decision_progress['tasks:finish_sj'] = progress['progress_sj']['finish']
                if 'expected_time' in progress['progress_sj']:
                    decision_progress['tasks:expected_time_sj'] = progress['progress_sj']['expected_time']

            for column, value in decision_progress.items():
                self._values_data[progress['id']][column] = cell_value(value)

        for decision in self._decisions_qs:
            countable_data = {
                'tasks:total': decision.tasks_total,
                'tasks:cancelled': decision.tasks_cancelled,
                'tasks:error': decision.tasks_error,
                'tasks:finished': decision.tasks_finished,
                'tasks:processing': decision.tasks_processing,
                'tasks:pending': decision.tasks_pending,
                'tasks:solutions': decision.solutions
            }
            for column, value in countable_data.items():
                self._values_data[decision.id][column] = cell_value(value)

            self._values_data[decision.id]['priority'] = cell_value(decision.get_priority_display())
            if decision.finish_date is not None:
                solution_wall = HumanizedValue(
                    int((decision.finish_date - decision.start_date).total_seconds() * 1000), user=self.view.user
                ).timedelta
                self._values_data[decision.id]['solution_wall_time'] = cell_value(solution_wall)

            if decision.operator:
                self._values_data[decision.id]['operator'] = cell_value(
                    decision.operator.get_full_name(), url=reverse('users:show-profile', args=[decision.operator_id])
                )
示例#7
0
    def __get_info(self):
        resource_data = []

        total_resources = {'wall_time': 0, 'cpu_time': 0, 'memory': 0}
        for component in sorted(self._data):
            component_data = {
                'component':
                component,
                'wall_time':
                '-',
                'cpu_time':
                '-',
                'memory':
                '-',
                'instances':
                '{}/{}'.format(self._data[component]['finished'],
                               self._data[component]['total'])
            }
            if self._data[component]['finished'] and component in self._data:
                component_data['wall_time'] = HumanizedValue(
                    self._data[component]['wall_time'],
                    user=self.user).timedelta
                component_data['cpu_time'] = HumanizedValue(
                    self._data[component]['cpu_time'],
                    user=self.user).timedelta
                component_data['memory'] = HumanizedValue(
                    self._data[component]['memory'], user=self.user).memory

                total_resources['wall_time'] += self._data[component][
                    'wall_time']
                total_resources['cpu_time'] += self._data[component][
                    'cpu_time']
                total_resources['memory'] = max(
                    total_resources['memory'], self._data[component]['memory'])
            resource_data.append(component_data)

        if 'hidden' not in self.view or 'resource_total' not in self.view[
                'hidden']:
            if total_resources['wall_time'] or total_resources[
                    'cpu_time'] or total_resources['memory']:
                resource_data.append({
                    'component':
                    'total',
                    'instances':
                    '-',
                    'wall_time':
                    HumanizedValue(total_resources['wall_time'],
                                   user=self.user).timedelta,
                    'cpu_time':
                    HumanizedValue(total_resources['cpu_time'],
                                   user=self.user).timedelta,
                    'memory':
                    HumanizedValue(total_resources['memory'],
                                   user=self.user).memory
                })
        return resource_data
示例#8
0
 def __get_job_values_row(self, job):
     values_row = []
     for col in self._values_collector.columns:
         if col == 'identifier':
             value = cell_value(str(job.identifier))
         elif col == 'role':
             value = cell_value(self._job_roles[job.id])
         elif col == 'author':
             author_val = author_url = None
             if job.author:
                 author_val = job.author.get_full_name()
                 author_url = reverse('users:show-profile', args=[job.author_id])
             value = cell_value(author_val, url=author_url)
         elif col == 'creation_date':
             value = cell_value(HumanizedValue(job.creation_date, user=self.view.user).date)
         else:
             value = cell_value('')
         values_row.append(value)
     return values_row
示例#9
0
    def __collect_resources(self):
        total_resources = {}
        for cache_obj in DecisionCache.objects.filter(decision_id__in=self._decisions_ids).select_related('decision'):
            value = "{} {} {}".format(
                HumanizedValue(cache_obj.wall_time, user=self.view.user).timedelta,
                HumanizedValue(cache_obj.cpu_time, user=self.view.user).timedelta,
                HumanizedValue(cache_obj.memory, user=self.view.user).memory,
            )
            column = 'resource:{}'.format(self.slugify(cache_obj.component))
            self._values_data[cache_obj.decision_id][column] = cell_value(value)
            total_resources.setdefault(cache_obj.decision_id, [0, 0, 0])
            total_resources[cache_obj.decision_id][0] += cache_obj.wall_time
            total_resources[cache_obj.decision_id][1] += cache_obj.cpu_time
            total_resources[cache_obj.decision_id][2] = max(total_resources[cache_obj.decision_id][2], cache_obj.memory)

        for d_id in total_resources:
            value = "{} {} {}".format(
                HumanizedValue(total_resources[d_id][0], user=self.view.user).timedelta,
                HumanizedValue(total_resources[d_id][1], user=self.view.user).timedelta,
                HumanizedValue(total_resources[d_id][2], user=self.view.user).memory,
            )
            self._values_data[d_id]['resource:total'] = cell_value(value)
示例#10
0
 def get_finish_date(self, instance):
     return HumanizedValue(instance.finish_date, user=self._user).date
示例#11
0
 def get_start_date(self, instance):
     return HumanizedValue(instance.start_date, user=self._user).date
示例#12
0
 def __get_expected_time(self, db_value, default_text):
     return HumanizedValue(db_value * 1000 if db_value else None,
                           user=self._user,
                           default=default_text
                           or _('Estimating time')).timedelta