Example #1
0
    def setUp(self):
        QueueDatabaseTest.setUp(self)
        # registration for all the editors below
        self.r = r = 20150101000000
        # exactly 30 days after registration
        self.m = m = 20150131000000
        self.r_plus_30 = format_pretty_date(d(self.m))

        self.create_test_cohort(
            editor_count=5,
            revisions_per_editor=8,
            revision_timestamps=[
                # this one will make 5 edits within 30 days of self.r_plus_30
                [r + 1, r + 2, r + 3, r + 4, r + 5, m + 6, m + 7, m + 8],
                # this one will make 3 edits within 30 days of self.r_plus_30
                [r + 1, r + 2, r + 3, m + 4, m + 5, m + 6, m + 7, m + 8],
                # this one will make 8 edits within 30 days of self.r_plus_30
                [r + 1, r + 2, r + 3, r + 4, r + 5, r + 6, r + 7, r + 8],
                # this one will make 0 edits within 30 days of self.r_plus_30
                [m + 1, m + 2, m + 3, m + 4, m + 5, m + 6, m + 7, m + 8],
                # this one will make the 5th edit right on self.r_plus_30
                [r + 1, r + 2, r + 3, r + 4, m + 0, m + 6, m + 7, m + 8],
            ],
            user_registrations=r,
            revision_lengths=10
        )
Example #2
0
 def normalize_datetime_slices(self, results_by_user, submetrics):
     """
     Starting from a sparse set of timeseries results, fill in default values
     for the specified list of sub-metrics.  Also make sure the chronological
     first timeseries slice is >= self.start_date.
     If self.timeseries is NONE, this is a simple identity function.
     
     Parameters
         results_by_user : dictionary of submetrics dictionaries by user
         submetrics      : list of tuples of the form (label, index, default)
     
     Returns
         the results, filled in with default values
     """
     if self.timeseries.data == TimeseriesChoices.NONE:
         return results_by_user
     
     slice_delta = self.get_delta_from_choice()
     timeseries_slices = OrderedDict()
     start_slice_key = format_pretty_date(self.start_date.data)
     timeseries_slices[start_slice_key] = None
     
     first_slice = self.get_first_slice()
     first_slice_key = format_pretty_date(first_slice)
     slice_to_default = first_slice
     while slice_to_default < self.end_date.data:
         date_key = format_pretty_date(slice_to_default)
         timeseries_slices[date_key] = None
         slice_to_default += slice_delta
     
     for user_id, user_submetrics in results_by_user.iteritems():
         for label, i, default in submetrics:
             if not label or not user_submetrics or label not in user_submetrics:
                 continue
             defaults = timeseries_slices.copy()
             defaults.update(user_submetrics[label])
             for k, v in defaults.iteritems():
                 if not v:
                     defaults[k] = default
             
             if start_slice_key != first_slice_key:
                 # coerce the first datetime slice to be self.start_date
                 defaults[start_slice_key] = defaults.pop(first_slice_key)
             
             user_submetrics[label] = defaults
     
     return results_by_user
Example #3
0
 def get_date_from_tuple(self, row_tuple, start_index, stop_index):
     """
     Suppose you have a tuple like this:
     ([data], [data], ... , year, month, day, [data], [data])
     Then this function will parse out the year, month, day, and hour
     into a date string.  Anything beyond year, month, day is optional.
     """
     date_pieces = row_tuple[start_index:stop_index]
     year, month, day, hour = 1970, 1, 1, 0
     
     if len(date_pieces) > 0:
         year = date_pieces[0]
     if len(date_pieces) > 1:
         month = date_pieces[1]
     if len(date_pieces) > 2:
         day = date_pieces[2]
     if len(date_pieces) > 3:
         hour = date_pieces[3]
     
     return format_pretty_date(datetime(year, month, day, hour))
 def test_parse_pretty_date(self):
     date = datetime.datetime(2012, 2, 3, 4, 5)
     assert_equal(date, parse_pretty_date(format_pretty_date(date)))
 def test_parse_pretty_date(self):
     date = datetime(2012, 2, 3, 4, 5)
     assert_equal(date, parse_pretty_date(format_pretty_date(date)))