class TestCalendarWesternWeekWithHolidays(BaseCalendarTest):
    @classmethod
    def setup_class(cls):
        print('\n\nTesting regular week, Mo-Fr, WITH holidays, 2010-2013')
        warnings.filterwarnings('ignore', module='business_calendar')

    def __init__(self):
        BaseCalendarTest.__init__(self)
        self.holidays = [parse(x) for x in global_holidays.split('\n')]
        self.cal = Calendar(holidays=self.holidays)
        self.cal.warn_on_holiday_exhaustion = False
        rr = rruleset()
        rr.rrule(rrule(DAILY,
                       byweekday=(MO,TU,WE,TH,FR),
                       dtstart=datetime.datetime(2010,1,1)))
        for h in self.holidays:
            rr.exdate(h)
        self.rr = rr
        self.dates = rr.between(datetime.datetime(2010,1,1),
                                datetime.datetime(2013,12,31),
                                inc=True)

    def test_workdaycount_with_non_workday_dates(self):
        print('test_workdaycount_with_non_workday_dates')
        """ Jan 1st is a holiday, Jan 30th and 31st fall on a weekend """
        daycount = 20;
        for date2 in ['Jan 30, 2010','Jan 31, 2010','Feb 1, 2010']:
            count = len(list(self.cal.range('2010-01-01', date2)));
            assert count == daycount
        for date2 in ['Jan 29, 2010','Jan 30, 2010','Jan 31, 2010']:
            count = self.cal.workdaycount('Dec 31, 2009', date2);
            assert count == daycount+1
        for date2 in ['Jan 29, 2010','Jan 30, 2010','Jan 31, 2010']:
            count = self.cal.busdaycount('Dec 31, 2009', date2);
            assert count == daycount
class TestCalendarWesternWeek(BaseCalendarTest):
    @classmethod
    def setup_class(cls):
        print('\n\nTesting regular week, Mo-Fr, no holidays, 2010-2013')

    def __init__(self):
        BaseCalendarTest.__init__(self)
        self.cal = Calendar()
        rr = rruleset()
        rr.rrule(
            rrule(DAILY,
                  byweekday=(MO, TU, WE, TH, FR),
                  dtstart=datetime.datetime(2010, 1, 1)))
        self.rr = rr
        self.dates = rr.between(datetime.datetime(2010, 1, 1),
                                datetime.datetime(2013, 12, 31),
                                inc=True)

    def test_workdaycount_with_non_workday_dates(self):
        print('test_workdaycount_with_non_workday_dates')
        """ Jan 30th and 31st fall on a weekend """
        daycount = 21
        for date2 in ['Jan 30, 2010', 'Jan 31, 2010', 'Feb 1, 2010']:
            count = len(list(self.cal.range('2010-01-01', date2)))
            assert count == daycount
        for date2 in ['Jan 29, 2010', 'Jan 30, 2010', 'Jan 31, 2010']:
            count = self.cal.workdaycount('Dec 31, 2009', date2)
            assert count == daycount
class TestCalendarWesternWeek(BaseCalendarTest):
    @classmethod
    def setup_class(cls):
        print('\n\nTesting regular week, Mo-Fr, no holidays, 2010-2013')

    def __init__(self):
        BaseCalendarTest.__init__(self)
        self.cal = Calendar()
        rr = rruleset()
        rr.rrule(rrule(DAILY,
                       byweekday=(MO,TU,WE,TH,FR),
                       dtstart=datetime.datetime(2010,1,1)))
        self.rr = rr
        self.dates = rr.between(datetime.datetime(2010,1,1),
                                datetime.datetime(2013,12,31),
                                inc=True)

    def test_workdaycount_with_non_workday_dates(self):
        print('test_workdaycount_with_non_workday_dates')
        """ Jan 30th and 31st fall on a weekend """
        daycount = 21;
        for date2 in ['Jan 30, 2010','Jan 31, 2010','Feb 1, 2010']:
            count = len(list(self.cal.range('2010-01-01', date2)));
            assert count == daycount
        for date2 in ['Jan 29, 2010','Jan 30, 2010','Jan 31, 2010']:
            count = self.cal.workdaycount('Dec 31, 2009', date2);
            assert count == daycount
예제 #4
0
                           activityInfo["activity"]] = {
                               "caseName": caseName,
                               "activityAppearIndex": activityAppearIndex,
                               "activity": activityInfo["activity"]
                           }

caseActivityStartTimeDict = {}
caseActivityEndTimeDict = {}
cal = Calendar()
for caseName, activityTimeList in caseActivityTimeDict.items():
    startTime = activityTimeList[0]
    endTime = activityTimeList[-1]
    caseActivityStartTimeDict[caseName] = []
    caseActivityEndTimeDict[caseName] = []
    for activityTime in activityTimeList:
        startWorkday = cal.workdaycount(startTime.date(), activityTime.date())
        endWorkday = cal.workdaycount(activityTime.date(), endTime.date())
        caseActivityStartTimeDict[caseName].append(startWorkday)
        caseActivityEndTimeDict[caseName].append(endWorkday)
#print(caseActivityStartTimeDict["d0c4a4241daa1d89"])
#print(caseActivityEndTimeDict["d0c4a4241daa1d89"])

sortedTimeStampAndIdList = sorted(timeStampAndIdDict)
#print(sortedTimeStampAndIdList[0:10])
#print(sortedTimeStampAndIdList[-10:])
subSequenceList = []
subSequenceTimeList = []
for timeStampKey in sortedTimeStampAndIdList:
    timeStampAndIdInfo = timeStampAndIdDict[timeStampKey]
    caseName = timeStampAndIdInfo["caseName"]
    activityAppearIndex = timeStampAndIdInfo["activityAppearIndex"]