Skip to content
Snippets Groups Projects
Commit c7625a5d authored by Carlos Vega's avatar Carlos Vega
Browse files

removed import, added docs

parent 8a852c7a
No related branches found
No related tags found
1 merge request!171Feature/daily availability
...@@ -4,7 +4,7 @@ from datetime import timedelta ...@@ -4,7 +4,7 @@ from datetime import timedelta
import logging import logging
import pandas as pd import pandas as pd
from web.utils import timeit, get_today_midnight_date from web.utils import get_today_midnight_date
from web.models.holiday import Holiday from web.models.holiday import Holiday
from web.models.availability import Availability from web.models.availability import Availability
from web.models.appointment import Appointment from web.models.appointment import Appointment
...@@ -49,20 +49,34 @@ class OfficeAvailability(object): ...@@ -49,20 +49,34 @@ class OfficeAvailability(object):
self.availability = pd.Series(index=self.range, data=0) # initialize range at 0 self.availability = pd.Series(index=self.range, data=0) # initialize range at 0
def _get_duration(self): def _get_duration(self):
'''
Private method. Returns the differ
'''
return self.availability.index[-1] - self.availability.index[0] return self.availability.index[-1] - self.availability.index[0]
def add_availability(self, range, only_working_hours=False): def add_availability(self, range, only_working_hours=False):
'''
Receives a pandas date_range `pd.date_range` object.
Sets the availability to one for the specific interval of the provided range.
'''
if only_working_hours: if only_working_hours:
range = range.to_series().between_time(self.office_start, self.office_end) range = range.to_series().between_time(self.office_start, self.office_end)
self.availability[range] = 1 self.availability[range] = 1
def remove_availability(self, range, only_working_hours=False): def remove_availability(self, range, only_working_hours=False):
'''
Receives a pandas date_range `pd.date_range` object.
Sets the availability to zero for the specific interval of the provided range.
'''
if only_working_hours: if only_working_hours:
range = range.to_series().between_time(self.office_start, self.office_end) range = range.to_series().between_time(self.office_start, self.office_end)
self.availability[range] = 0 self.availability[range] = 0
def consider_this(self, appointment_availability_or_holiday, only_working_hours=False): def consider_this(self, appointment_availability_or_holiday, only_working_hours=False):
''' '''
:appointment_availability_or_holiday can be an object from the following classes: Availability, Holiday, Appointment, AppointmentTypeLink.
:only_working_hours if true, only consider the defined working hours
Availability repeat every week. Availability repeat every week.
Availability always refers to a moment in which the worker should be working. Never the opposite. Availability always refers to a moment in which the worker should be working. Never the opposite.
...@@ -107,7 +121,7 @@ class OfficeAvailability(object): ...@@ -107,7 +121,7 @@ class OfficeAvailability(object):
portion = self.availability[pd.date_range(start=start, end=end, freq=self.minimum_slot)] #select the specific range portion = self.availability[pd.date_range(start=start, end=end, freq=self.minimum_slot)] #select the specific range
set_to = 0 set_to = 0
else: else:
logger.error('Expected Holiday or Availability objects.') logger.error('Expected Availability, Holiday, Appointment or AppointmentTypeLink objects.')
raise TypeError raise TypeError
if only_working_hours: if only_working_hours:
...@@ -141,15 +155,17 @@ class OfficeAvailability(object): ...@@ -141,15 +155,17 @@ class OfficeAvailability(object):
return availability.mean() * 100 #better to isolate the operation in case we change it later return availability.mean() * 100 #better to isolate the operation in case we change it later
def is_availabile(self, only_working_hours=False): def is_available(self, only_working_hours=False):
''' '''
Returns True if on the selected period is available at least 50% of the time Returns True if on the selected period is available at least 50% of the time
Otherwise returns False Otherwise returns False
''' '''
return self.get_availability_percentage(only_working_hours=only_working_hours) > 50.0 return self.get_availability_percentage(only_working_hours=only_working_hours) > 50.0
@timeit
def plot_availability(self): def plot_availability(self):
'''
Plot availability chart.
'''
fig = plt.figure() #create new figure. This should ensure thread safe method fig = plt.figure() #create new figure. This should ensure thread safe method
ax=fig.gca() #get current axes ax=fig.gca() #get current axes
matplotlib.rcParams['hatch.linewidth'] = 1 matplotlib.rcParams['hatch.linewidth'] = 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment