Esempio n. 1
0
    def handle(self, *args, **options):
        date = datetime.date.today()
        if options['yesterday']:
            date = date - datetime.timedelta(days=1)

        WorkMetrics.update_all_work_metrics()
        DailyWorkMetrics.update_daily_work_metrics(date)
Esempio n. 2
0
def update_yesterdays_metrics():
    """ Task to update daily metrics for yesterday. This will replace any existing task.
    """
    WorkMetrics.update_all_work_metrics()

    yesterday = date.today() - timedelta(days=1)
    DailyWorkMetrics.update_daily_work_metrics(yesterday)
Esempio n. 3
0
    def test_update(self):
        work = Work.objects.get(pk=1)
        metrics = WorkMetrics.create_or_update(work)

        metrics.n_languages = 99
        metrics.save()

        metrics = WorkMetrics.create_or_update(work)
        metrics.refresh_from_db()
        self.assertEqual(metrics.n_languages, 1)
Esempio n. 4
0
    def test_metrics(self):
        for work in Work.objects.all():
            WorkMetrics.create_or_update(work)

        date = datetime.date(2019, 2, 1)

        DailyWorkMetrics.create_or_update(date)

        dailies = DailyWorkMetrics.objects.filter(date=date).all()
        self.assertEqual(len(dailies), 2)
Esempio n. 5
0
def update_yesterdays_metrics():
    """ Task to update daily metrics for yesterday. This will replace any existing task.
    """
    try:
        WorkMetrics.update_all_work_metrics()

        yesterday = date.today() - timedelta(days=1)
        DailyWorkMetrics.update_daily_work_metrics(yesterday)
    except Exception as e:
        log.error(f"Error updating work metrics: {e}", exc_info=e)
        raise e
Esempio n. 6
0
    def test_metrics(self):
        for work in Work.objects.all():
            WorkMetrics.create_or_update(work)

        date = datetime.date(2019, 2, 1)

        DailyWorkMetrics.create_or_update(date)

        dailies = DailyWorkMetrics.objects.filter(date=date).all()
        # DailyWorkMetrics should have been created for two places:
        # - `za` (8 Works, pk 1 to 8 and 10 of work fixtures)
        # - `za-cpt` (1 Work, pk 9 of work fixtures)
        self.assertEqual(len(dailies), 2)
Esempio n. 7
0
    def get_context_data(self, **kwargs):
        context = super(WorkOverviewView, self).get_context_data(**kwargs)

        context['active_tasks'] = Task.objects\
            .filter(work=self.work)\
            .exclude(state='done')\
            .exclude(state='cancelled')\
            .order_by('-created_at')
        context['work_timeline'] = self.get_work_timeline()

        # ensure work metrics are up to date
        WorkMetrics.create_or_update(self.work)

        return context
Esempio n. 8
0
    def get_context_data(self, **kwargs):
        context = super(WorkOverviewView, self).get_context_data(**kwargs)
        work_tasks = Task.objects.filter(work=self.work)

        context['active_tasks'] = work_tasks.exclude(state=Task.DONE)\
            .exclude(state=Task.CANCELLED)\
            .order_by('-created_at')
        context['work_timeline'] = self.get_work_timeline(self.work)
        context['contributors'] = self.get_top_contributors()

        # ensure work metrics are up to date
        WorkMetrics.create_or_update(self.work)

        return context
Esempio n. 9
0
    def test_basics(self):
        work = Work.objects.get(pk=1)
        metrics = WorkMetrics.create_or_update(work)

        self.assertEqual(metrics.n_languages, 1)
        self.assertEqual(metrics.n_points_in_time, 1)
        self.assertEqual(metrics.n_expressions, 1)
        self.assertEqual(metrics.n_expected_expressions, 1)
Esempio n. 10
0
 def test_metrics_for_all_fixtures(self):
     for work in Work.objects.all():
         WorkMetrics.create_or_update(work)
Esempio n. 11
0
 def update_work_metrics(self):
     self.stdout.write(self.style.SUCCESS('Updating individual work metrics.'))
     for work in Work.objects.all():
         WorkMetrics.create_or_update(work)
     self.stdout.write(self.style.SUCCESS('Done'))