<commit_before>

__author__ = "<NAME>"
__date__ = "July 27th, 2012"
__license__ = "GPL (version 2 or later)"

from dateutil.parser import parse as date_parse
import user_metric as um


LAST_EDIT = -1
REGISTRATION = 0

class TimeToThreshold(um.UserMetric):
    """
        Produces an integer value representing the number of minutes taken to reach a threshold.

            `https://meta.wikimedia.org/wiki/Research:Metrics//time_to_threshold`

        usage e.g.: ::

            >>> import classes.Metrics as m
            >>> m.TimeToThreshold(m.TimeToThreshold.EDIT_COUNT_THRESHOLD, first_edit=1, threshold_edit=2).process(123456)
            500
    """

    def __init__(self,
                 threshold_type_class,
                 **kwargs):

        um.UserMetric.__init__(self, **kwargs)
        self._threshold_obj_ = threshold_type_class(**kwargs)

    @staticmethod
    def header(): return ['user_id', 'minutes_diff']

    def process(self, user_handle, is_id=True):
        """ Wrapper for specific threshold objects """
        self._results =  self._threshold_obj_.process(user_handle, self, is_id=is_id)
        return self

    class EditCountThreshold():
        """
            Nested Class. Objects of this class are to be created by the constructor of TimeToThreshold.  The class has one method,
            process(), which computes the time, in minutes, taken between making N edits and M edits for a user.  N < M.
        """

        def __init__(self, **kwargs):
            """
                Object constructor.  There are two required parameters:

                    - Parameters:
                        - **first_edit** - Integer.  The numeric value of the first edit from which to measure the threshold.
                        - **threshold_edit** - Integer.  The numeric value of the threshold edit from which to measure the threshold
            """

            try:
                self._first_edit_ = kwargs['first_edit']
                self._threshold_edit_ = kwargs['threshold_edit']

            except Exception:
                raise um.UserMetric.UserMetricError(str(self.__class__()) + ': Invalid init params.')

        def process(self, user_handle, threshold_obj, is_id=True, **kwargs):
            """
                First determine if the user has made an adequate number of edits.  If so, compute the number of minutes that passed
                between the Nth and Mth edit.

                    - Parameters:
                        - **first_edit** - Integer.  The numeric value of the first edit from which to measure the threshold.
                        - **threshold_edit** - Integer.  The numeric value of the threshold edit from which to measure the threshold
            """

            minutes_to_threshold = list()
<commit_msg>MOD: update documentation<commit_after>

__author__ = "<NAME>"
__date__ = "July 27th, 2012"
__license__ = "GPL (version 2 or later)"

from dateutil.parser import parse as date_parse
import user_metric as um


LAST_EDIT = -1
REGISTRATION = 0

class TimeToThreshold(um.UserMetric):
    """
        Produces an integer value representing the number of minutes taken to reach a threshold.

            `https://meta.wikimedia.org/wiki/Research:Metrics//time_to_threshold`

        As a UserMetric type this class utilizes the process() function attribute to produce an internal list of metrics by
        user handle (typically ID but user names may also be specified). The execution of process() produces a nested list that
        stores in each element:

            * User ID
            * Time difference in minutes between events

        Below is an example of how we can generate the time taken to reach the first edit and the last edit from registration : ::

            >>> import src.metrics.time_to_threshold as t
            >>> t.TimeToThreshold(t.TimeToThreshold.EditCountThreshold, first_edit=0, threshold_edit=1).process([13234584]).__iter__().next()
            [13234584, 3318]
            >>> t.TimeToThreshold(t.TimeToThreshold.EditCountThreshold, first_edit=0, threshold_edit=-1).process([13234584]).__iter__().next()
            [13234584, 18906]

        If the termination event never occurs the number of minutes returned is -1.
    """

    def __init__(self,
                 threshold_type_class,
                 **kwargs):

        um.UserMetric.__init__(self, **kwargs)
        self._threshold_obj_ = threshold_type_class(**kwargs)

    @staticmethod
    def header(): return ['user_id', 'minutes_diff']

    def process(self, user_handle, is_id=True):
        """ Wrapper for specific threshold objects """
        self._results =  self._threshold_obj_.process(user_handle, self, is_id=is_id)
        return self

    class EditCountThreshold():
        """
            Nested Class. Objects of this class are to be created by the constructor of TimeToThreshold.  The class has one method,
            process(), which computes the time, in minutes, taken between making N edits and M edits for a user.  N < M.
        """

        def __init__(self, **kwargs):
            """
                Object constructor.  There are two required parameters:

                    - Parameters:
                        - **first_edit** - Integer.  The numeric value of the first edit from which to measure the threshold.
                        - **threshold_edit** - Integer.  The numeric value of the threshold edit from which to measure the threshold
            """

            try:
                self._first_edit_ = kwargs['first_edit']
                self._threshold_edit_ = kwargs['threshold_edit']

            except Exception:
                raise um.UserMetric.UserMetricError(str(self.__class__()) + ': Invalid init params.')

        def process(self, user_handle, threshold_obj, is_id=True, **kwargs):
            """
                First determine if the user has made an adequate number of edits.  If so, compute the number of minutes that passed
                between the Nth and Mth edit.

                    - Parameters:
                        - **user_handle** - List(int).  List of user ids.
                        - **first_edit** - Integer.  The numeric value of the first edit from which to measure the threshold.
                        - **threshold_edit** - Integer.  The numeric value of the threshold edit from which to measure the threshold
            """

            minutes_to_threshold = list()

{'fraction_non_alphanumeric': 0.08295929422689986, 'fraction_numerical': 0.011608110199659495, 'mean_word_length': 2.1816838995568686, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 20, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5695020', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1584, 'n_words': 587}