self.assertEquals(result, expected)
+class NbOfHalfDaysInPeriodPerMonthTestCase2(SimpleTestCase):
+
+ def setUp(self):
+ self.date_from = datetime.date(2016,1,1)
+ self.date_to = datetime.date(2016,12,31)
+
+ def test_nbhalf_half_days(self):
+ expected = {
+ 1:{
+ 'wednesday_pm':4,
+ 'tuesday_am':4,
+ 'thursday_am':4,
+ 'monday_am':4,
+ 'tuesday_pm':4,
+ 'friday_am':4,
+ 'wednesday_am':4,
+ 'thursday_pm':4,
+ 'friday_pm':4,
+ 'monday_pm':4
+ },
+ 2:{
+ 'wednesday_pm':4,
+ 'tuesday_am':4,
+ 'thursday_am':4,
+ 'monday_am':5,
+ 'tuesday_pm':4,
+ 'friday_am':4,
+ 'wednesday_am':4,
+ 'thursday_pm':4,
+ 'friday_pm':4,
+ 'monday_pm':5
+ },
+ 3:{
+ 'wednesday_pm':5,
+ 'tuesday_am':5,
+ 'thursday_am':5,
+ 'monday_am':3,
+ 'tuesday_pm':5,
+ 'friday_am':4,
+ 'wednesday_am':5,
+ 'thursday_pm':5,
+ 'friday_pm':4,
+ 'monday_pm':3
+ },
+ 4:{
+ 'wednesday_pm':4,
+ 'tuesday_am':4,
+ 'thursday_am':4,
+ 'monday_am':4,
+ 'tuesday_pm':4,
+ 'friday_am':5,
+ 'wednesday_am':4,
+ 'thursday_pm':4,
+ 'friday_pm':5,
+ 'monday_pm':4
+ },
+ 5:{
+ 'wednesday_pm':4,
+ 'tuesday_am':5,
+ 'thursday_am':3,
+ 'monday_am':4,
+ 'tuesday_pm':5,
+ 'friday_am':4,
+ 'wednesday_am':4,
+ 'thursday_pm':3,
+ 'friday_pm':4,
+ 'monday_pm':4
+ },
+ 6:{
+ 'wednesday_pm':5,
+ 'tuesday_am':4,
+ 'thursday_am':5,
+ 'monday_am':4,
+ 'tuesday_pm':4,
+ 'friday_am':4,
+ 'wednesday_am':5,
+ 'thursday_pm':5,
+ 'friday_pm':4,
+ 'monday_pm':4
+ },
+ 7:{
+ 'wednesday_pm':4,
+ 'tuesday_am':4,
+ 'thursday_am':3,
+ 'monday_am':4,
+ 'tuesday_pm':4,
+ 'friday_am':5,
+ 'wednesday_am':4,
+ 'thursday_pm':3,
+ 'friday_pm':5,
+ 'monday_pm':4
+ },
+ 8:{
+ 'wednesday_pm':5,
+ 'tuesday_am':5,
+ 'thursday_am':4,
+ 'monday_am':4,
+ 'tuesday_pm':5,
+ 'friday_am':4,
+ 'wednesday_am':5,
+ 'thursday_pm':4,
+ 'friday_pm':4,
+ 'monday_pm':4
+ },
+ 9:{
+ 'wednesday_pm':4,
+ 'tuesday_am':4,
+ 'thursday_am':5,
+ 'monday_am':4,
+ 'tuesday_pm':4,
+ 'friday_am':5,
+ 'wednesday_am':4,
+ 'thursday_pm':5,
+ 'friday_pm':5,
+ 'monday_pm':4
+ },
+ 10:{
+ 'wednesday_pm':4,
+ 'tuesday_am':4,
+ 'thursday_am':4,
+ 'monday_am':5,
+ 'tuesday_pm':4,
+ 'friday_am':4,
+ 'wednesday_am':4,
+ 'thursday_pm':4,
+ 'friday_pm':4,
+ 'monday_pm':5
+ },
+ 11:{
+ 'wednesday_pm':5,
+ 'tuesday_am':4,
+ 'thursday_am':4,
+ 'monday_am':4,
+ 'tuesday_pm':4,
+ 'friday_am':3,
+ 'wednesday_am':5,
+ 'thursday_pm':4,
+ 'friday_pm':3,
+ 'monday_pm':4
+ },
+ 12:{
+ 'wednesday_pm':4,
+ 'tuesday_am':4,
+ 'thursday_am':5,
+ 'monday_am':4,
+ 'tuesday_pm':4,
+ 'friday_am':5,
+ 'wednesday_am':4,
+ 'thursday_pm':5,
+ 'friday_pm':5,
+ 'monday_pm':4
+ }
+ }
+ result = get_nb_half_days_by_period_per_month(self.date_from, self.date_to)
+ self.assertEquals(result, expected)
+
+
+class NbOfLeaveDaysPerMonthTestCase2(SimpleTestCase):
+
+ def setUp(self):
+ self.date_from = datetime.date(2016,1,1)
+ self.date_to = datetime.date(2016,1,31)
+ self.external_id = 106
+
+ def test_nb_leave_days(self):
+ expected = {}
+ result = get_leave_days_per_month(self.date_from, self.date_to, self.external_id)
+ self.assertEquals(result, expected)
+
+
class NbOfLeaveDaysPerMonthTestCase(SimpleTestCase):
def setUp(self):
from organization.network.api import *
from collections import defaultdict, OrderedDict
from pprint import pprint
+from workalendar.europe import France
def get_nb_half_days_by_period(date_from, date_to):
def get_nb_half_days_by_period_per_month(date_from, date_to):
day_list = pd.date_range(date_from, date_to).tolist()
-
+ cal = France()
+ holidays = cal.holidays(date_from.year)
+ holidays_date = [h[0] for h in holidays]
md_dict = {}
for i in range(1,13):
md_dict[i] = {
# for each day of the period
for day in day_list :
- if day.dayofweek == 0:
- md_dict[day.month]['monday_am'] += 1
- md_dict[day.month]['monday_pm'] += 1
- if day.dayofweek == 1:
- md_dict[day.month]['tuesday_am'] += 1
- md_dict[day.month]['tuesday_pm'] += 1
- if day.dayofweek == 2:
- md_dict[day.month]['wednesday_am'] += 1
- md_dict[day.month]['wednesday_pm'] += 1
- if day.dayofweek == 3:
- md_dict[day.month]['thursday_am'] += 1
- md_dict[day.month]['thursday_pm'] += 1
- if day.dayofweek == 4:
- md_dict[day.month]['friday_am'] += 1
- md_dict[day.month]['friday_pm'] += 1
+ if not day.date() in holidays_date:
+ if day.dayofweek == 0:
+ md_dict[day.month]['monday_am'] += 1
+ md_dict[day.month]['monday_pm'] += 1
+ if day.dayofweek == 1:
+ md_dict[day.month]['tuesday_am'] += 1
+ md_dict[day.month]['tuesday_pm'] += 1
+ if day.dayofweek == 2:
+ md_dict[day.month]['wednesday_am'] += 1
+ md_dict[day.month]['wednesday_pm'] += 1
+ if day.dayofweek == 3:
+ md_dict[day.month]['thursday_am'] += 1
+ md_dict[day.month]['thursday_pm'] += 1
+ if day.dayofweek == 4:
+ md_dict[day.month]['friday_am'] += 1
+ md_dict[day.month]['friday_pm'] += 1
return md_dict