Ejemplo 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())
Ejemplo n.º 2
0
 def test_2013(self):
     holidays_gen = USFederalHolidays()
     self.assertEqual(
         list(holidays_gen(date(2013, 1, 1), end=date(2013, 12, 31))), [
             date(2013, 1, 1),
             date(2013, 1, 21),
             date(2013, 2, 18),
             date(2013, 5, 27),
             date(2013, 7, 4),
             date(2013, 9, 2),
             date(2013, 10, 14),
             date(2013, 11, 11),
             date(2013, 11, 28),
             date(2013, 12, 25)
         ])
Ejemplo n.º 3
0
 def test_2014(self):
     holidays_gen = USFederalHolidays()
     self.assertEqual(
         list(holidays_gen(date(2014, 1, 1), end=date(2014, 12, 31))), [
             date(2014, 1, 1),
             date(2014, 1, 20),
             date(2014, 2, 17),
             date(2014, 5, 26),
             date(2014, 7, 4),
             date(2014, 9, 1),
             date(2014, 10, 13),
             date(2014, 11, 11),
             date(2014, 11, 27),
             date(2014, 12, 25)
         ])
Ejemplo n.º 4
0
 def test_2016(self):
     holidays_gen = USFederalHolidays()
     self.assertEqual(
         list(holidays_gen(date(2016, 1, 1), end=date(2016, 12, 31))), [
             date(2016, 1, 1),
             date(2016, 1, 18),
             date(2016, 2, 15),
             date(2016, 5, 30),
             date(2016, 7, 4),
             date(2016, 9, 5),
             date(2016, 10, 10),
             date(2016, 11, 11),
             date(2016, 11, 24),
             date(2016, 12, 25),
             date(2016, 12, 26)
         ])
Ejemplo n.º 5
0
 def test_2015(self):
     holidays_gen = USFederalHolidays()
     self.assertEqual(
         list(holidays_gen(date(2015, 1, 1), end=date(2015, 12, 31))), [
             date(2015, 1, 1),
             date(2015, 1, 19),
             date(2015, 2, 16),
             date(2015, 5, 25),
             date(2015, 7, 3),
             date(2015, 7, 4),
             date(2015, 9, 7),
             date(2015, 10, 12),
             date(2015, 11, 11),
             date(2015, 11, 26),
             date(2015, 12, 25)
         ])
Ejemplo n.º 6
0
 def test_2017(self):
     holidays_gen = USFederalHolidays()
     self.assertEqual(
         list(holidays_gen(date(2017, 1, 1), end=date(2017, 12, 31))), [
             date(2017, 1, 1),
             date(2017, 1, 2),
             date(2017, 1, 16),
             date(2017, 2, 20),
             date(2017, 5, 29),
             date(2017, 7, 4),
             date(2017, 9, 4),
             date(2017, 10, 9),
             date(2017, 11, 10),
             date(2017, 11, 11),
             date(2017, 11, 23),
             date(2017, 12, 25)
         ])
Ejemplo n.º 7
0
def dataGen(data):
    if 'FLAG_BusinessHour' not in data.columns:
        bt = businesstime.BusinessTime(business_hours = (datetime.time(9), datetime.time(18)),\
                                                   weekends=(5, 6), holidays=USFederalHolidays())
        dates, isBD = [],[]
        for row in data.itertuples(index=True, name='Pandas'):
            dates.append(getattr(row, "date"))
        for row in dates:
            boo = bt.isduringbusinesshours(datetime.datetime.strptime(row, '%Y-%m-%d %H:%M:%S'))
            isBD.append(1) if boo else isBD.append(0)
        data.insert(0, "FLAG_BusinessHour", isBD, True)
        data['GRAD_CO2'] = np.clip(np.gradient(data['CO2'].rolling(window=windowSize).mean()),-10,10)
        data['GRAD_HR'] = np.clip(np.gradient(data['HumidityRatio'].rolling(window=windowSize).mean()),-10,10)
        data['HRCO2'] = data['HumidityRatio']*data['CO2']
        data['GRAD_HRCO2'] = np.clip(np.gradient(data['HRCO2'].rolling(window=windowSize).mean()),-10,10)
        data['index'] = data.index
        data.drop("Occupancy", axis=1, inplace=True)
    return data
Ejemplo n.º 8
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)
Ejemplo n.º 9
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))
Ejemplo n.º 10
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
Ejemplo n.º 11
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: