def get_result(self): result = json.loads(self.result) data = {"count": self.count} er = EnumResult() for it in result: data[er.get(it["result"])] = it["count"] return data
def get_result(self): result = json.loads(self.result) data = {"count": self.count} er = EnumResult() for it in result: data[er.get(it["result"])] = (it["count"] * 100) / self.count return data
def stat_tasks(self): for report in self.reports: data = Task.objects.filter( recipe__job__template__is_enable=True, recipe__job__template__in=report.jobs.all(), recipe__job__schedule__in=self.periods, )\ .values("result").annotate(dcount=Count("result")).order_by("result") er = EnumResult() for it in data: it["name"] = er.get(it["result"]) report.tasks = data
def call_broken_systems(self): self.brokensystems = {} brokensystems = {} tasks = Task.objects.filter(recipe__job__date__gt=timezone.now() - timedelta(days=settings.BROKEN_SYSTEM_DAYS)) \ .values("result", "recipe__system__hostname") \ .annotate(results=Count("result"), hosts=Count("recipe__system__hostname")) \ .order_by("recipe__system__hostname",) for it in tasks: brokensystems.setdefault(it["recipe__system__hostname"], {}) \ .setdefault(EnumResult.get(it["result"]), it["results"]) for key, it in brokensystems.items(): if not key: continue # system wasn't assigned count = 0 for k, res in it.items(): if k not in ('fail', 'warning'): continue count += res positive = 0 if it.get("pass"): positive += it.get("pass") if it.get("new"): positive += it.get("new") # 90 % tasks fail/warning in more than 30 tasks MIN_TASK = 30 FAIL_LIMIT = 0.9 if count > MIN_TASK and (positive == 0 or count / float(positive + count) > FAIL_LIMIT): # 90% tasks failed self.brokensystems[key] = (count, it.get("pass"), brokensystems[key]) self.brokensystems = OrderedDict(sorted( self.brokensystems.items()))
def get_network_stas(self, **kwargs): def get_lab(hostname, num): return ".".join(hostname.split(".")[-1 * num:]) # TODO - show only some last runs periods = TaskPeriodSchedule.objects.all().values( "title", "date_create", "id", "counter").order_by("title", "-date_create") ids = map(lambda x: x["id"], periods) tasks = Task.objects.filter(recipe__job__schedule_id__in=ids) \ .values("result", "recipe__system__hostname", "recipe__job__schedule__id") \ .annotate(results=Count("result"), hosts=Count("recipe__system__hostname"), label=Count("recipe__job__schedule")) \ .order_by("recipe__system__hostname", "recipe__job__schedule__id") data = {} labels = set() ER = EnumResult() for it in tasks: hostname = get_lab(it.get("recipe__system__hostname"), 4) schedule = it.get("recipe__job__schedule__id") result, count = ER.get(it.get("result")), it.get("hosts") labels.add(schedule) if hostname in data: if schedule not in data[hostname]: data[hostname].update({schedule: {result: count}}) data[hostname][schedule][result] = count else: data[hostname] = {schedule: {result: count}} for hostname, value in data.items(): for schedule in labels: if not value.get(schedule): data[hostname][schedule] = {} return {"labels": labels, "data": data}