diff --git a/smash/web/officeAvailability.py b/smash/web/officeAvailability.py index c4cf72f4c2a4d0ab27e86ba92c32458eb1f4be73..297ec4214045049b55cfd64565d3dcbc63995d53 100644 --- a/smash/web/officeAvailability.py +++ b/smash/web/officeAvailability.py @@ -4,7 +4,7 @@ from datetime import timedelta import logging 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.availability import Availability from web.models.appointment import Appointment @@ -49,20 +49,34 @@ class OfficeAvailability(object): self.availability = pd.Series(index=self.range, data=0) # initialize range at 0 def _get_duration(self): + ''' + Private method. Returns the differ + ''' return self.availability.index[-1] - self.availability.index[0] 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: range = range.to_series().between_time(self.office_start, self.office_end) self.availability[range] = 1 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: range = range.to_series().between_time(self.office_start, self.office_end) self.availability[range] = 0 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 always refers to a moment in which the worker should be working. Never the opposite. @@ -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 set_to = 0 else: - logger.error('Expected Holiday or Availability objects.') + logger.error('Expected Availability, Holiday, Appointment or AppointmentTypeLink objects.') raise TypeError if only_working_hours: @@ -141,15 +155,17 @@ class OfficeAvailability(object): 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 Otherwise returns False ''' return self.get_availability_percentage(only_working_hours=only_working_hours) > 50.0 - @timeit def plot_availability(self): + ''' + Plot availability chart. + ''' fig = plt.figure() #create new figure. This should ensure thread safe method ax=fig.gca() #get current axes matplotlib.rcParams['hatch.linewidth'] = 1