コード例 #1
0
def generate_control_chart(tickets: List[Issue],
                           chart_class: Type[IChart] = Chart) -> None:
    if not tickets:
        print('No data. Check that the JSON file was correctly populated ' +
              'when you ran the `fetch` command.')
        return

    completed_cycle_times: List[CycleTime] = list(
        sorted(
            (get_cycle_time(ticket) for ticket in tickets
             if ticket.completed is not None and ticket.started is not None),
            key=attrgetter("completed"),
        ))

    if not completed_cycle_times:
        print('Could not process cycle time, check that the statuses ' +
              'in config.yaml are correct.')
        return

    cycle_time_plot = CycleTimeScatterPlot(cycle_times=completed_cycle_times,
                                           data_source=ColumnDataSource)
    average_cycle_time_plot = AverageCycleTimePlot(
        cycle_times=completed_cycle_times, data_source=ColumnDataSource)
    rolling_cycle_time_plot = RollingAverageCycleTimePlot(
        cycle_times=completed_cycle_times, data_source=ColumnDataSource)
    cycle_time_deviation_plot = CycleTimeDeviationPlot(
        cycle_times=completed_cycle_times, data_source=ColumnDataSource)

    start_date, end_date = (
        completed_cycle_times[0].completed,
        completed_cycle_times[-1].completed,
    )

    chart = chart_class(
        x=Axis(
            label="Closed (date)",
            values=[
                d[0].date().isoformat() for d in Arrow.span_range(
                    "day",
                    Arrow(start_date.year, start_date.month, start_date.day),
                    Arrow(end_date.year, end_date.month, end_date.day),
                )
            ],
            size=1800,
        ),
        y=Axis(label="Cycle time (days)", values=None, size=900),
        label="Ticket",
        tooltips=[
            ("Ticket", "@label"),
            ("Closed (date)", "@x"),
            ("Cycle time (days)", "@y"),
        ],
    )
    cycle_time_plot.draw(chart)
    average_cycle_time_plot.draw(chart)
    rolling_cycle_time_plot.draw(chart)
    cycle_time_deviation_plot.draw(chart)

    chart.render()
コード例 #2
0
def generate_control_chart(tickets: List[Issue],
                           chart_class: Type[IChart] = Chart) -> None:
    if not tickets:
        return

    completed_cycle_times: List[CycleTime] = list(
        sorted(
            (get_cycle_time(ticket) for ticket in tickets
             if ticket.completed is not None and ticket.started is not None),
            key=attrgetter("completed"),
        ))
    cycle_time_plot = CycleTimeScatterPlot(cycle_times=completed_cycle_times,
                                           data_source=ColumnDataSource)
    average_cycle_time_plot = AverageCycleTimePlot(
        cycle_times=completed_cycle_times, data_source=ColumnDataSource)
    rolling_cycle_time_plot = RollingAverageCycleTimePlot(
        cycle_times=completed_cycle_times, data_source=ColumnDataSource)
    cycle_time_deviation_plot = CycleTimeDeviationPlot(
        cycle_times=completed_cycle_times, data_source=ColumnDataSource)

    start_date, end_date = (
        completed_cycle_times[0].completed,
        completed_cycle_times[-1].completed,
    )

    chart = chart_class(
        x=Axis(
            label="Closed (date)",
            values=[
                d[0].date().isoformat() for d in Arrow.span_range(
                    "day",
                    Arrow(start_date.year, start_date.month, start_date.day),
                    Arrow(end_date.year, end_date.month, end_date.day),
                )
            ],
            size=1800,
        ),
        y=Axis(label="Cycle time (days)", values=None, size=900),
        label="Ticket",
        tooltips=[
            ("Ticket", "@label"),
            ("Closed (date)", "@x"),
            ("Cycle time (days)", "@y"),
        ],
    )
    cycle_time_plot.draw(chart)
    average_cycle_time_plot.draw(chart)
    rolling_cycle_time_plot.draw(chart)
    cycle_time_deviation_plot.draw(chart)

    chart.render()
コード例 #3
0
    def index(self, request, extra_context=None):
        """
        Add some extra index context such as a dataset to graph.
        """
        today = Arrow.fromdatetime(now())
        last_year = today.replace(months=-11)

        site_dataset = OrderedDict()

        sites = []

        if request.user.is_superuser:
            sites = Site.objects.annotate(video_count=Count('camera__video'))
        else:
            sites = Site.objects.annotate(
                video_count=Count('camera__video')).filter(id__lte=2).exclude(
                    pk=17)

        gf = GraphForm(request.GET)

        startd = last_year
        endd = today

        if gf.is_valid():
            startd = Arrow.fromdate(gf.cleaned_data['start_date'])
            endd = Arrow.fromdate(gf.cleaned_data['end_date'])

        difference = (endd - startd).days

        period = 'month'

        if difference < 31:
            period = 'day'
        elif difference < (30 * 6):
            period = 'week'
        else:
            period = 'month'

        # For every site, aggregate the average number of returning penguins
        # across the entire month. These calculations are the average over
        # the median number of penguins observed each day.

        site_dataset['Total Penguins'] = []
        for site in sites:
            site_dataset[site.name] = []
            for start, end in Arrow.span_range(period, startd, endd):
                average = site.penguincount_set.filter(
                    date__gte=start.date(), date__lte=end.date()).aggregate(
                        penguins=Avg('total_penguins'))
                site_dataset[site.name].append({
                    'date':
                    start.date(),
                    'value':
                    "%0.2f" % average['penguins'] if
                    (average['penguins'] > 0) else 0.0
                })
                for item in site_dataset['Total Penguins']:
                    if item['date'] == start.date():
                        item['value'] = "%0.2f" % (
                            float(item['value']) +
                            (average['penguins'] if
                             (average['penguins'] > 0) else 0.0))
                        break
                else:
                    site_dataset['Total Penguins'].append({
                        'date':
                        start.date(),
                        'value':
                        "%0.2f" % average['penguins'] if
                        (average['penguins'] > 0) else 0.0
                    })

        context = {
            'sites': sites,
            'site_dataset': site_dataset,
            'title': _("Penguin island sites"),
            'gform': gf,
        }
        context.update(extra_context or {})
        return super(PenguinSite, self).index(request, context)
コード例 #4
0
 def total_on_each(self, starts_on: Arrow, ends_on: Arrow):
     for i, v in enumerate(
             list(Arrow.span_range('year', starts_on, ends_on)), 1):
         yield (self.loan * self.interest) * i, v[-1]
コード例 #5
0
 def total_on(self, end_date: Arrow):
     total_years = len(
         list(Arrow.span_range('year', self.starts_on, end_date))) - 1
     self._total_loan = (self.loan * self.interest) * total_years
     return self._total_loan
コード例 #6
0
def generate_control_chart(
    tickets: List[Issue], chart_class: Type[IChart] = Chart
) -> None:
    """Generate the ticket control chart with the provided list of tickets.

    :param tickets: The list of tickets to generate your control chart from.
    :param chart_class: The chart class to output into, defaults to Chart.
    :raises NoTicketsProvided: If len(tickets) == 0.
    :raises ChartError: On any error attempting to generate a chart.
    """
    if not tickets:
        raise NoTicketsProvided

    completed_cycle_times: List[CycleTime] = list(
        sorted(
            (
                get_cycle_time(ticket)
                for ticket in tickets
                if ticket.completed is not None and ticket.started is not None
            ),
            key=attrgetter("completed"),
        )
    )

    if not completed_cycle_times:
        raise ChartError(
            "Could not process cycle time. Check your config.yaml statuses."
        )

    cycle_time_plot = CycleTimeScatterPlot(
        cycle_times=completed_cycle_times, data_source=ColumnDataSource
    )
    average_cycle_time_plot = AverageCycleTimePlot(
        cycle_times=completed_cycle_times, data_source=ColumnDataSource
    )
    rolling_cycle_time_plot = RollingAverageCycleTimePlot(
        cycle_times=completed_cycle_times, data_source=ColumnDataSource
    )
    cycle_time_deviation_plot = CycleTimeDeviationPlot(
        cycle_times=completed_cycle_times, data_source=ColumnDataSource
    )

    start_date, end_date = (
        completed_cycle_times[0].completed,
        completed_cycle_times[-1].completed,
    )

    chart = chart_class(
        x=Axis(
            label="Closed (date)",
            values=[
                d[0].date().isoformat()
                for d in Arrow.span_range(
                    "day",
                    Arrow(start_date.year, start_date.month, start_date.day),
                    Arrow(end_date.year, end_date.month, end_date.day),
                )
            ],
            size=1800,
        ),
        y=Axis(label="Cycle time (days)", values=None, size=900),
        label="Ticket",
        tooltips=[
            ("Ticket", "@label"),
            ("Closed (date)", "@x"),
            ("Cycle time (days)", "@y"),
        ],
    )
    cycle_time_plot.draw(chart)
    average_cycle_time_plot.draw(chart)
    rolling_cycle_time_plot.draw(chart)
    cycle_time_deviation_plot.draw(chart)

    chart.render()