예제 #1
0
    def weektable_boundaries(self):
        ''' Return the boundaries to draw the week table

        return a dict_like {'morning': slot1,
                            'afternoon': slot2}
        '''
        week_table = self.context.getSettimana_tipo()
        boundaries = {}
        for key in ('inizio_m', 'inizio_p'):
            boundaries[key] = min(day_table[key] for day_table in week_table
                                  if day_table[key])
        for key in ('end_m', 'end_p'):
            boundaries[key] = max(day_table[key] for day_table in week_table
                                  if day_table[key])
        for key, value in boundaries.iteritems():
            boundaries[key] = hm2seconds(value)
        return {
            'morning': BaseSlot(
                boundaries['inizio_m'],
                boundaries['end_m'],
            ),
            'afternoon': BaseSlot(
                boundaries['inizio_p'],
                boundaries['end_p'],
            ),
        }
예제 #2
0
 def get_choosen_slot(self, data):
     ''' Get's the slot requested by the user
     '''
     tipology = data.get('tipology', '')
     tipology_duration = self.prenotazioni.get_tipology_duration(tipology)
     start = data.get('booking_date', '')
     end = start + timedelta(seconds=tipology_duration * 60)
     slot = BaseSlot(start, end)
     return slot
예제 #3
0
    def extend_availability(self, slots, gate_slots):
        ''' We add slots to the gate_slots list and we make unions
        when they overlap.
        '''
        for i in range(len(gate_slots)):
            for slot in slots:
                if gate_slots[i].overlaps(slot):
                    interval = gate_slots[i].union(slot)
                    gate_slots[i] = BaseSlot(interval.lower_value,
                                             interval.upper_value)

        return gate_slots + slots
예제 #4
0
 def get_day_intervals(self, day):
     ''' Return the time ranges of this day
     '''
     weekday = day.weekday()
     week_table = self.context.getSettimana_tipo()
     day_table = week_table[weekday]
     # Convert hours to DateTime
     inizio_m = hm2DT(day, day_table['inizio_m'])
     end_m = hm2DT(day, day_table['end_m'])
     inizio_p = hm2DT(day, day_table['inizio_p'])
     end_p = hm2DT(day, day_table['end_p'])
     # Get's the daily schedule
     day_start = inizio_m or inizio_p
     day_end = end_p or end_m
     break_start = end_m or end_p
     break_stop = inizio_p or end_m
     return {
         'morning': BaseSlot(inizio_m, end_m),
         'break': BaseSlot(break_start, break_stop),
         'afternoon': BaseSlot(inizio_p, end_p),
         'day': BaseSlot(day_start, day_end),
         'stormynight': BaseSlot(0, 86400),
     }
예제 #5
0
    def get_anonymous_slots(self, booking_date, period='day'):
        ''' This will return all the slots under the fake name
        anonymous_gate

        :param booking_date: a datetime object
        :param period: a string
        :return: a dictionary like:
        {'anonymous_gate': [slot2, slot3],
        }
        '''
        interval = self.get_day_intervals(booking_date)[period]
        slots_by_gate = {'anonymous_gate': []}
        if not interval or len(interval) == 0:
            return slots_by_gate
        start = interval.lower_value
        stop = interval.upper_value
        hours = set(3600 * i for i in range(24) if start <= i * 3600 <= stop)
        hours = sorted(hours.union(set((start, stop))))
        slots_number = len(hours) - 1
        slots = [BaseSlot(hours[i], hours[i + 1]) for i in range(slots_number)]
        slots_by_gate['anonymous_gate'] = slots
        return slots_by_gate
예제 #6
0
 def get_vacation_slot(self, data):
     ''' The requested vacation slot
     '''
     start_time = self.get_start_time(data)
     end_time = self.get_end_time(data)
     return BaseSlot(start_time, end_time)