Exemple #1
0
    def _trends_render_with_graph(self, collection, num, num_days):
        """
        Render trend data with UTF8 graphs
        """

        row = "{component:<40} {jump:>7}   {graph:>" + str(num_days) + "}"
        txt = row.format(component="Component", jump="Jump", graph="Graph")
        out = txt + "\n"
        out += "-" * len(txt) + "\n"

        for comp in collection[:num]:
            counts = []
            for day in prev_days(num_days):
                counts.append(comp.history[day])

            minval = min(counts)
            maxval = max(counts)
            scale = ((maxval - minval) << 8) // (len(self.graph_symbols) - 1)
            scale = max(scale, 1)
            graph = ""

            for day in prev_days(num_days):
                graph += self.graph_symbols[(
                    (comp.history[day] - minval) << 8) // scale]

            out += row.format(component=comp.name,
                              jump=comp.jump,
                              a=comp.a,
                              b=comp.b,
                              graph=graph.replace(" ", "") + "\n\n")

        return out
Exemple #2
0
    def _trends_render_with_graph(self, collection, num, num_days):
        """
        Render trend data with UTF8 graphs
        """

        row = "{component:<40} {jump:>7}   {graph:>" + str(num_days) + "}"
        txt = row.format(component="Component", jump="Jump", graph="Graph")
        out = txt + "\n"
        out += "-" * len(txt) + "\n"

        for comp in collection[:num]:
            counts = []
            for day in prev_days(num_days):
                counts.append(comp.history[day])

            minval = min(counts)
            maxval = max(counts)
            scale = ((maxval - minval) << 8) // (len(self.graph_symbols) - 1)
            scale = max(scale, 1)
            graph = ""

            for day in prev_days(num_days):
                graph += self.graph_symbols[((comp.history[day] - minval)
                                             << 8) // scale]

            out += row.format(component=comp.name,
                              jump=comp.jump,
                              a=comp.a,
                              b=comp.b,
                              graph=graph.replace(" ", "") + "\n\n")

        return out
Exemple #3
0
    def make_up_history(self, report, over_days):
        """
        Make up history counts for report for `over_days` days.
        """

        total = 0

        daily = []
        weekly = []
        monthly = []

        self.db.session.delete(report.history_daily[0])
        self.db.session.delete(report.history_weekly[0])
        self.db.session.delete(report.history_monthly[0])

        opsysrelease = report.opsysreleases[0].opsysrelease

        for i, day in enumerate(prev_days(over_days)):
            d = ReportHistoryDaily(report=report,
                                   opsysrelease=opsysrelease,
                                   count=i,
                                   day=day)

            w = ReportHistoryWeekly(report=report,
                                    opsysrelease=opsysrelease,
                                    count=i,
                                    week=day)

            m = ReportHistoryMonthly(report=report,
                                     opsysrelease=opsysrelease,
                                     count=i,
                                     month=day)

            total += i
            daily.append(d)
            weekly.append(w)
            monthly.append(m)

        report.history_daily = daily
        report.history_weekly = weekly
        report.history_monthly = monthly
        report.first_occurrence = daily[0].day
        report.last_occurrence = daily[-1].day

        return total
Exemple #4
0
    def make_up_history(self, report, over_days):
        """
        Make up history counts for report for `over_days` days.
        """

        total = 0

        daily = []
        weekly = []
        monthly = []

        self.db.session.delete(report.history_daily[0])
        self.db.session.delete(report.history_weekly[0])
        self.db.session.delete(report.history_monthly[0])

        opsysrelease = report.opsysreleases[0].opsysrelease

        for i, day in enumerate(prev_days(over_days)):
            d = ReportHistoryDaily(report=report,
                                   opsysrelease=opsysrelease,
                                   count=i,
                                   day=day)

            w = ReportHistoryWeekly(report=report,
                                    opsysrelease=opsysrelease,
                                    count=i,
                                    week=day)

            m = ReportHistoryMonthly(report=report,
                                     opsysrelease=opsysrelease,
                                     count=i,
                                     month=day)

            total += i
            daily.append(d)
            weekly.append(w)
            monthly.append(m)

        report.history_daily = daily
        report.history_weekly = weekly
        report.history_monthly = monthly
        report.first_occurrence = daily[0].day
        report.last_occurrence = daily[-1].day

        return total
Exemple #5
0
    def trends(self, cmdline, db, opsys, release):
        """
        Get trends for crashing components
        """

        hist_table, hist_field = get_history_target(self.history_type)

        num_days = 7
        if cmdline.last:
            num_days = int(cmdline.last)

        last_date = datetime.date.today() - datetime.timedelta(days=num_days)

        comp_detail = []

        comps = get_report_count_by_component(db, opsys, release)
        comps = comps.filter(hist_field >= last_date)

        for (comp, count) in comps:
            if comp.name in self.comps_filter:
                continue

            report_ids = (db.session.query(
                Report.id).join(OpSysComponent).filter(
                    OpSysComponent.id == comp.id)).subquery()

            history = (db.session.query(
                hist_field,
                func.sum(hist_table.count).label("count")).filter(
                    hist_table.report_id.in_(report_ids)).filter(
                        hist_field >= last_date).filter(
                            hist_field < datetime.date.today()).group_by(
                                hist_field).order_by(hist_field).all())

            if len(history) < 2:
                continue

            hist_dict = collections.defaultdict(int)
            for key, value in history:
                hist_dict[key] = value

            # Compute linear regression
            xsum, ysum, xysum, xxsum, yysum = 0., 0., 0., 0., 0.
            for x, day in enumerate(prev_days(num_days)):
                y = hist_dict[day]
                xsum += x
                ysum += y
                xysum += x * y
                xxsum += x * x
                yysum += y * y

            # y = bx + a
            b = xysum - xsum * ysum // num_days
            b //= xxsum - xsum**2 // num_days

            a = ysum - b * xsum
            a //= num_days

            first_day = hist_dict[prev_days(num_days)[0]]
            last_day = hist_dict[prev_days(num_days)[-1]]

            Comp = collections.namedtuple("Component", "name jump a b history")
            comp_tuple = Comp(name=comp.name,
                              jump=last_day - first_day,
                              a=a,
                              b=b,
                              history=hist_dict)

            comp_detail.append(comp_tuple)

        trend_data = sorted(comp_detail, key=lambda x: x.b, reverse=True)

        if not trend_data:
            return ""

        # render trend data
        render_fn = self._trends_render
        if cmdline.graph:
            render_fn = self._trends_render_with_graph

        out = "Most destabilized components:\n\n"
        out += render_fn(trend_data, cmdline.count, num_days)
        out += "\n"

        out += "Most stabilized components:\n\n"
        trend_data.reverse()
        out += render_fn(trend_data, cmdline.count, num_days)
        out += "\n"

        return out
Exemple #6
0
    def trends(self, cmdline, db, opsys, release):
        """
        Get trends for crashing components
        """

        hist_table, hist_field = get_history_target(self.history_type)

        num_days = 7
        if cmdline.last:
            num_days = int(cmdline.last)

        last_date = datetime.date.today() - datetime.timedelta(days=num_days)

        comp_detail = []

        comps = get_report_count_by_component(db, opsys, release)
        comps = comps.filter(hist_field >= last_date)

        for (comp, count) in comps:
            if comp.name in self.comps_filter:
                continue

            report_ids = (db.session.query(Report.id)
                          .join(OpSysComponent)
                          .filter(OpSysComponent.id == comp.id)).subquery()

            history = (db.session.query(hist_field,
                                        func.sum(hist_table.count)
                                        .label("count"))
                       .filter(hist_table.report_id.in_(report_ids))
                       .filter(hist_field >= last_date)
                       .filter(hist_field < datetime.date.today())
                       .group_by(hist_field)
                       .order_by(hist_field).all())

            if len(history) < 2:
                continue

            hist_dict = collections.defaultdict(int)
            for key, value in history:
                hist_dict[key] = value

            # Compute linear regression
            xsum, ysum, xysum, xxsum, yysum = 0., 0., 0., 0., 0.
            for x, day in enumerate(prev_days(num_days)):
                y = hist_dict[day]
                xsum += x
                ysum += y
                xysum += x * y
                xxsum += x * x
                yysum += y * y

            # y = bx + a
            b = xysum - xsum * ysum // num_days
            b //= xxsum - xsum ** 2 // num_days

            a = ysum - b * xsum
            a //= num_days

            first_day = hist_dict[prev_days(num_days)[0]]
            last_day = hist_dict[prev_days(num_days)[-1]]

            Comp = collections.namedtuple("Component", "name jump a b history")
            comp_tuple = Comp(
                name=comp.name,
                jump=last_day - first_day,
                a=a,
                b=b,
                history=hist_dict)

            comp_detail.append(comp_tuple)

        trend_data = sorted(comp_detail, key=lambda x: x.b, reverse=True)

        if not trend_data:
            return ""

        # render trend data
        render_fn = self._trends_render
        if cmdline.graph:
            render_fn = self._trends_render_with_graph

        out = "Most destabilized components:\n\n"
        out += render_fn(trend_data, cmdline.count, num_days)
        out += "\n"

        out += "Most stabilized components:\n\n"
        trend_data.reverse()
        out += render_fn(trend_data, cmdline.count, num_days)
        out += "\n"

        return out