Example #1
0
    def get(request):
        """
        Pass graph data to frontend.
        """
        timeline = InstallationStatistics.timeline()

        students, courses, instances = InstallationStatistics.data_per_period()

        instances_count, courses_count, students_count = InstallationStatistics.overall_counts(
        )

        first_datetime_of_update_data, last_datetime_of_update_data = get_data_created_datetime_scope(
        )

        context = {
            'timeline': json.dumps(timeline),
            'students': json.dumps(students),
            'courses': json.dumps(courses),
            'instances': json.dumps(instances),
            'instances_count': instances_count,
            'courses_count': courses_count,
            'students_count': students_count,
            'first_datetime_of_update_data': first_datetime_of_update_data,
            'last_datetime_of_update_data': last_datetime_of_update_data
        }

        return render(request, 'charts/graphs.html', context)
Example #2
0
    def test_data_per_period(self):
        """
        Verify that data_per_period method annotates by day with trunc and then sums statistics amounts.
        """
        result = InstallationStatistics.data_per_period()

        self.assertEqual(
            ([10, 10, 10, 5, 10], [2, 2, 2, 1, 2], [2, 2, 2, 1, 2]), result
        )