def update_l10n_contributor_metrics(day=None): """Update the number of active contributors for each locale/product. An active contributor is defined as a user that created or reviewed a revision in the previous calendar month. """ if day is None: day = date.today() first_of_month = date(day.year, day.month, 1) if day.month == 1: previous_first_of_month = date(day.year - 1, 12, 1) else: previous_first_of_month = date(day.year, day.month - 1, 1) # Loop through all locales. for locale in settings.SUMO_LANGUAGES: # Loop through all enabled products, including None (really All). for product in [None] + list(Product.objects.filter(visible=True)): num = num_active_contributors( from_date=previous_first_of_month, to_date=first_of_month, locale=locale, product=product) WikiMetric.objects.create( code=L10N_ACTIVE_CONTRIBUTORS_CODE, locale=locale, product=product, date=previous_first_of_month, value=num)
def update_l10n_contributor_metrics(day=None): """Update the number of active contributors for each locale/product. An active contributor is defined as a user that created or reviewed a revision in the previous calendar month. """ if day is None: day = date.today() first_of_month = date(day.year, day.month, 1) if day.month == 1: previous_first_of_month = date(day.year - 1, 12, 1) else: previous_first_of_month = date(day.year, day.month - 1, 1) # Loop through all locales. for locale in settings.SUMO_LANGUAGES: # Loop through all enabled products, including None (really All). for product in [None] + list(Product.objects.filter(visible=True)): num = num_active_contributors(from_date=previous_first_of_month, to_date=first_of_month, locale=locale, product=product) WikiMetric.objects.create(code=L10N_ACTIVE_CONTRIBUTORS_CODE, locale=locale, product=product, date=previous_first_of_month, value=num)
def test_num_active_contributors(self): """Test the num_active_contributors util method.""" start_date = self.start_date eq_(3, num_active_contributors(from_date=start_date, locale="en-US")) eq_(4, num_active_contributors(from_date=start_date, locale="es")) eq_(6, num_active_contributors(from_date=start_date)) eq_(1, num_active_contributors(from_date=start_date, product=self.product)) eq_(1, num_active_contributors(from_date=start_date, locale="en-US", product=self.product)) eq_(0, num_active_contributors(from_date=start_date, locale="es", product=self.product))
def test_num_active_contributors(self): """Test the num_active_contributors util method.""" start_date = self.start_date eq_(3, num_active_contributors(from_date=start_date, locale='en-US')) eq_(4, num_active_contributors(from_date=start_date, locale='es')) eq_(6, num_active_contributors(from_date=start_date)) eq_(1, num_active_contributors(from_date=start_date, product=self.product)) eq_(1, num_active_contributors(from_date=start_date, locale='en-US', product=self.product)) eq_(0, num_active_contributors(from_date=start_date, locale='es', product=self.product))