Exemplo n.º 1
0
    def setUp(self):
        """
        Tests mostly based around January 2014, where two holidays, New Years Day
        and MLK day, fall on the 1st and 20th, respectively.

            January 2014
        Su Mo Tu We Th Fr Sa
                  1  2  3  4
         5  6  7  8  9 10 11
        12 13 14 15 16 17 18
        19 20 21 22 23 24 25
        26 27 28 29 30 31
        """
        self.bt = BusinessTime(holidays=USFederalHolidays())
Exemplo n.º 2
0
    def test_businesstime_holidays_date_desc(self):
        """
        Test for https://github.com/seatgeek/businesstime/issues/25
        """
        bt_cal = BusinessTime(holidays=USFederalHolidays())

        non_holiday = datetime(2018, 5, 31, 12, 0)
        memorial_day_2017 = datetime(2017, 5, 29, 12, 0)
        memorial_day_2018 = datetime(2018, 5, 28, 12, 0)

        # Note that we test the later memorial day first, internally populating
        # the holidays cache starting with memorial day 2018. We then verify
        # that memorial day 2017 is properly classified as a holiday.
        is_memorial_day_2018_holiday = bt_cal.isholiday(memorial_day_2018)
        is_memorial_day_2017_holiday = bt_cal.isholiday(memorial_day_2017)
        is_non_holiday_holiday = bt_cal.isholiday(non_holiday)

        self.assertTrue(is_memorial_day_2017_holiday)
        self.assertTrue(is_memorial_day_2018_holiday)
        self.assertFalse(is_non_holiday_holiday)
Exemplo n.º 3
0
    def test_lots_of_holidays(self):
        """
        Test for https://github.com/seatgeek/businesstime/issues/25
        """
        bt_cal = BusinessTime(holidays=USFederalHolidays())

        non_holiday = datetime(2018, 5, 31, 12, 0)
        non_holiday2 = datetime(2018, 2, 3, 12, 0)
        non_holiday3 = datetime(2018, 6, 4, 12, 0)
        non_holiday4 = datetime(2018, 11, 21, 12, 0)

        memorial_day = datetime(2018, 5, 28, 12, 0)
        new_year_day = datetime(2018, 1, 1, 12, 0)
        labor_day = datetime(2018, 9, 3, 12, 0)
        christmas = datetime(2018, 12, 25, 12, 0)

        self.assertFalse(bt_cal.isholiday(non_holiday))
        self.assertTrue(bt_cal.isholiday(memorial_day))
        self.assertTrue(bt_cal.isholiday(new_year_day))
        self.assertFalse(bt_cal.isholiday(non_holiday2))
        self.assertFalse(bt_cal.isholiday(non_holiday4))
        self.assertTrue(bt_cal.isholiday(labor_day))
        self.assertFalse(bt_cal.isholiday(non_holiday3))
        self.assertTrue(bt_cal.isholiday(christmas))
Exemplo n.º 4
0
import datetime
import pytz
from businesstime import BusinessTime
from businesstime.holidays.usa import USFederalHolidays

# Number of business days we have to fix a security vulnerability.
SLA_DAYS = 90

# Days before SLA_DAYS we'll nag someone to attend to the vulnerability.
NAG_DAYS = [45, 22, 11, 5, 3, 2, 1]

# The timezone we base all "business day aware" date calculations on.
BUSINESS_TIMEZONE = 'US/Eastern'

_businesstime = BusinessTime(holidays=USFederalHolidays())


def businesstimedelta(a, b):
    '''
    Calculate the timedelta between two timezone-aware datetimes.

    Note that due to the fact that the businesstime package doesn't currently
    accept timezone-aware datetimes, we need to convert them to
    timezone-naive ones first.

    For future reference, this issue has been filed at:

        https://github.com/seatgeek/businesstime/issues/18
    '''

    # https://stackoverflow.com/a/5452709
Exemplo n.º 5
0
 def test_no_holidays(self):
     bt = BusinessTime()
     self.assertFalse(bt.isholiday(date(2014, 1, 1)))
Exemplo n.º 6
0
 def test_holidays_specified_as_list(self):
     bd = BusinessTime(holidays=[date(2014, 1, 1)])
     self.assertTrue(bd.isholiday(date(2014, 1, 1)))
     self.assertFalse(bd.isholiday(date(2014, 1, 2)))
Exemplo n.º 7
0
from common.admins import ADMINS
from common.git_hub_api import submit_graphql_search_query

ISSUE_CATEGORIES = {
    'question': {'question', 'getting started'},
    'support': {'support', 'non-library'},
    'bug': {'bug', 'docs', 'security'},
    'twilio_enhancement': {'twilio enhancement', 'sendgrid enhancement'},
    'community_enhancement': {'community enhancement'},
}
ISSUE_STATUSES = {'duplicate', 'invalid'}

DATE_TIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ'

BUSINESS_TIME = BusinessTime(holidays=USFederalHolidays())


class Issue:
    def __init__(self, issue_json: Dict, end_date: str):
        try:
            self.issue_json = issue_json
            self.end_date = end_date
            self.author = get_author(issue_json)
            self.type = issue_json['__typename']
            self.created_at = issue_json['createdAt']
            self.url = issue_json['url']
            self.reaction_count = issue_json.get('reactions',
                                                 {}).get('totalCount')

            if 'timelineItems' in issue_json:
Exemplo n.º 8
0
        datetime.date(2015, 12, 31),
        # 2016-2017 Christmas company holidays
        datetime.date(2016, 12, 23),
        datetime.date(2016, 12, 28),
        datetime.date(2016, 12, 29),
        datetime.date(2016, 12, 30),
    ]


GERRIT_CHANGES_URL = 'http://gerrit.beaker-project.org/changes/?q=project:beaker&o=ALL_REVISIONS&o=MESSAGES&o=DETAILED_ACCOUNTS&n=500'
NON_HUMAN_REVIEWERS = ['patchbot', 'jenkins']
POSTED_SINCE = datetime.datetime.utcnow() - datetime.timedelta(days=365)

tzoffset = datetime.timedelta(hours=10)  # our business hours are in UTC+10
business_time = BusinessTime(business_hours=(datetime.time(6),
                                             datetime.time(18)),
                             holidays=RedHatBrisbaneHolidays())


def parse_gerrit_timestamp(timestamp):
    # "2015-09-08 04:39:30.493000000"
    return datetime.datetime.strptime(timestamp[:19], '%Y-%m-%d %H:%M:%S')


# compute centred exponential weighted mean and variance for each point except the edge-most ones
# http://tdunning.blogspot.com.au/2011/03/exponential-weighted-averages-with.html
# http://nfs-uxsup.csx.cam.ac.uk/~fanf2/hermes/doc/antiforgery/stats.pdf
def ewm_var(timestamps, values):
    assert len(timestamps) == len(values)
    alpha = 8  # smoothing factor
    averages = []