def test_gt_positive(self):
        # Arrange
        delta = dateutil.relativedelta(years=2)
        threshold = dateutil.relativedelta(years=1, months=6)
        expected = True

        # Act
        actual = delta > threshold

        # Assert
        self.assertEqual(expected, actual)
    def test_le_negative(self):
        # Arrange
        delta = dateutil.relativedelta(years=2)
        threshold = dateutil.relativedelta(years=1, months=6)
        expected = False

        # Act
        actual = delta <= threshold

        # Assert
        self.assertEqual(expected, actual)
    def test_ge_negative(self):
        # Arrange
        delta = dateutil.relativedelta(years=2)
        threshold = dateutil.relativedelta(years=2, seconds=1)
        expected = False

        # Act
        actual = delta >= threshold

        # Assert
        self.assertEqual(expected, actual)
    def test_total_seconds(self):
        # Arrange
        delta = dateutil.relativedelta(hours=10, minutes=10, seconds=1)
        expected = 36601

        # Act
        actual = delta.total_seconds()

        # Assert
        self.assertEqual(expected, actual)
    def test_total_minutes(self):
        # Arrange
        delta = dateutil.relativedelta(hours=10)
        expected = 600

        # Act
        actual = delta.total_minutes()

        # Assert
        self.assertEqual(expected, actual)
    def test_total_hours(self):
        # Arrange
        delta = dateutil.relativedelta(years=1, months=6)
        expected = 13080

        # Act
        actual = delta.total_hours()

        # Assert
        self.assertEqual(expected, actual)
Beispiel #7
0
def parse_datetime_delta(datetime_delta):
    """Parse specification of datetime delta of the form nynmndnHnMnS

    Parameters
    ----------
    datetime_delta : str
        A string of the form nynmndnHnMnS. All components of the
        specification are optional. Note that the component specifiers are
        case-sensitive.

    Returns
    -------
    relativedelta : lib.dateutil.relativedelta
        An instance of lib.dateutil.relativedelta representing the datetime
        delta specified in the argument to this function. A value of zero is
        set for each component that is not specfied in the argument.
    """
    delta = dateutil.relativedelta()

    match = re.search('(\d+)y', datetime_delta)
    if match:
        delta.years = int(match.group(1))

    match = re.search('(\d+)m', datetime_delta)
    if match:
        delta.months = int(match.group(1))

    match = re.search('(\d+)d', datetime_delta)
    if match:
        delta.days = int(match.group(1))

    match = re.search('(\d+)H', datetime_delta)
    if match:
        delta.hours = int(match.group(1))

    match = re.search('(\d+)M', datetime_delta)
    if match:
        delta.minutes = int(match.group(1))

    match = re.search('(\d+)S', datetime_delta)
    if match:
        delta.seconds = int(match.group(1))

    return delta
Beispiel #8
0
def parse_datetime_delta(datetime_delta):
    """Parse specification of datetime delta of the form nynmndnHnMnS

    Parameters
    ----------
    datetime_delta : str
        A string of the form nynmndnHnMnS. All components of the
        specification are optional. Note that the component specifiers are
        case-sensitive.

    Returns
    -------
    relativedelta : lib.dateutil.relativedelta
        An instance of lib.dateutil.relativedelta representing the datetime
        delta specified in the argument to this function. A value of zero is
        set for each component that is not specfied in the argument.
    """
    delta = dateutil.relativedelta()

    match = re.search('(\d+)y', datetime_delta)
    if match:
        delta.years = int(match.group(1))

    match = re.search('(\d+)m', datetime_delta)
    if match:
        delta.months = int(match.group(1))

    match = re.search('(\d+)d', datetime_delta)
    if match:
        delta.days = int(match.group(1))

    match = re.search('(\d+)H', datetime_delta)
    if match:
        delta.hours = int(match.group(1))

    match = re.search('(\d+)M', datetime_delta)
    if match:
        delta.minutes = int(match.group(1))

    match = re.search('(\d+)S', datetime_delta)
    if match:
        delta.seconds = int(match.group(1))

    return delta
Beispiel #9
0
def run(project_id, repo_path, cursor, **options):
    bresult = False
    rresult = 'dormant'
    last_commit_date = getLastCommitDate(project_id)
    if last_commit_date is not None:
        today = options.get('today', datetime.today().date())
        if isinstance(today, str):
            today = datetime.strptime(today, '%Y-%m-%d')
        last_commit_date_formatted = tuple(
            map(int, last_commit_date.split("-")))
        delta = dateutil.relativedelta(today,
                                       datetime(*last_commit_date_formatted))
        threshold = utilities.parse_datetime_delta(options['threshold'])
        bresult = delta <= threshold
        if bresult:
            rresult = 'active'
    print("----- METRIC: STATE -----")
    print('state: ', rresult, ",", bresult)
    return bresult, rresult
Beispiel #10
0
def run(project_id, repo_path, cursor, **options):
    bresult = False
    rresult = 'dormant'

    cursor.execute(QUERY.format(project_id))
    result = cursor.fetchone()
    last_commit_date = result[0]

    if last_commit_date is not None:
        # Compute the delta between the last commit in the database and today.
        # Note: today may be the date the GHTorrent dump was published by
        #       ghtorrent.org
        today = options.get('today', datetime.today().date())
        if isinstance(today, str):
            today = datetime.strptime(today, '%Y-%m-%d')
        delta = dateutil.relativedelta(today, last_commit_date)
        threshold = utilities.parse_datetime_delta(options['threshold'])
        bresult = delta <= threshold
        if bresult:
            rresult = 'active'

    return bresult, rresult
Beispiel #11
0
def run(project_id, repo_path, cursor, **options):
    bresult = False
    rresult = 'dormant'

    cursor.execute(QUERY.format(project_id))
    result = cursor.fetchone()
    last_commit_date = result[0]

    if last_commit_date is not None:
        # Compute the delta between the last commit in the database and today.
        # Note: today may be the date the GHTorrent dump was published by
        #       ghtorrent.org
        today = options.get('today', datetime.today().date())
        if isinstance(today, str):
            today = datetime.strptime(today, '%Y-%m-%d')
        delta = dateutil.relativedelta(today, last_commit_date)
        threshold = utilities.parse_datetime_delta(options['threshold'])
        bresult = delta <= threshold
        if bresult:
            rresult = 'active'

    return bresult, rresult