def test_auto_instantiations(self): """Test that we can create a StatsAggregator from projects or querysets.""" aggregator = KilowattStatsAggregator.from_project(Project.factories.base.create(impact_power=12.0)) self.assertEqual(aggregator.kilowatts, 12.0) project1, project2 = Project.factories.base.create_batch(2, impact_power=20.0) aggregator = KilowattStatsAggregator.from_project_queryset(Project.objects.filter(id__in=[project1.pk, project2.pk])) self.assertEqual(aggregator.kilowatts, 40.0)
def test_auto_instantiations(self): """Test that we can create a StatsAggregator from projects or querysets.""" aggregator = KilowattStatsAggregator.from_project( Project.factories.base.create(impact_power=12.0)) self.assertEqual(aggregator.kilowatts, 12.0) project1, project2 = Project.factories.base.create_batch( 2, impact_power=20.0) aggregator = KilowattStatsAggregator.from_project_queryset( Project.objects.filter(id__in=[project1.pk, project2.pk])) self.assertEqual(aggregator.kilowatts, 40.0)
def statistics(self): """ Return a revolv.project.stats.KilowattStatsAggregator for this project. Having this as a property is usefule in templates where we need to display statistics about the project (e.g. lbs carbon saved, $ saved, etc). """ return KilowattStatsAggregator.from_project(self)
def test_aggregator_works(self): """Test that none of the StatsAggregator functions error.""" aggregator = KilowattStatsAggregator(12) self.assert_stat_okay(aggregator.pounds_carbon_saved_per_month) self.assert_stat_okay(aggregator.acres_of_trees_saved_per_year) self.assert_stat_okay(aggregator.dollars_saved_per_month) self.assert_stat_okay(aggregator.automobile_miles_per_month) self.assert_stat_okay(aggregator.kilowatt_hours_per_month)
def statistics(self, queryset=None): """ Return a revolv.project.stats.KilowattStatsAggregator to aggregate statistics about the impact of the given queryset of projects. """ if queryset is None: queryset = super(ProjectManager, self).get_queryset() return KilowattStatsAggregator.from_project_queryset(queryset)