コード例 #1
0
    def __len__(self):
        '''
        Returns the length of the current list of activities.
        :return: integer - length of the current list of activities
        '''

        self.__list[:] = sort(self.__list, key=lambda x: str(x))

        return len(self.__list)
コード例 #2
0
    def __iter__(self):
        '''
        Returns an iterator object for the repository.
        :return: iter(list) - iterator object
        '''

        self.__list[:] = sort(self.__list, key=lambda x: str(x))

        return iter(self.__list)
コード例 #3
0
    def __len__(self):
        '''
        Returns the length of the current list of people.
        :return: integer - length of the current list of people
        '''

        self.__list[:] = sort(self.__list, key=lambda x: x.id)

        return len(self.__list)
コード例 #4
0
    def activities_for_person_by_date(self, id):
        '''
        Returns a list of activities performed by the person with the indicated ID by date.
        :param id: positive integer - person's ID
        :return: list of Activity as specified
        :exception NABException: if one of the parameters is not valid
        '''

        funct = lambda x: x.person.id == id
        L = filter(funct, self.__activityRepo)
        return sort(L, key=lambda x: x.date)
コード例 #5
0
    def add(self, activity):
        '''
        Adds an activity to the current list of activities.
        :param activity: Activity - activity to be added
        :return: activity is added to the current list of activities
        :exception NABException: if one of the parameters is not valid
        '''

        if type(activity) is not Activity:
            raise NABException("The given activity is not valid.")

        self.__list.append(activity)
        self.__list[:] = sort(self.__list, key=lambda x: str(x))
コード例 #6
0
    def add(self, person):
        '''
        Adds a person to the current list of people, if his ID does not already exist.
        :param person: Person - person to be added
        :return: person is added to the current list of people
        :exception NABException: if one of the parameters is not valid or a person with that ID already exists
        '''

        if type(person) is not Person:
            raise NABException("The given person is not valid.")

        if self.find(person.id) != -1:
            raise NABException("There's already a person with that ID.")

        self.__list.append(person)
        self.__list[:] = sort(self.__list, key=lambda x: x.id)
コード例 #7
0
    def activities_in_interval_alphabetically(self, date1, date2):
        '''
        Returns a list of activities performed in the indicated interval alphabetically by description.
        :param date1: string - start date in a valid format
        :param date1: string - end date in a valid format
        :return: list of Activity as specified
        :exception NABException: if one of the parameters is not valid
        '''

        if date1 > date2:
            raise NABException("End date must be after the start date.")

        if not ActivityValidator.valid_date(date1) or not ActivityValidator.valid_date(date2):
            raise NABException("At least one of the dates is invalid.")

        funct = lambda x: date1 <= x.date and x.date <= date2
        L = filter(funct, self.__activityRepo)
        return sort(L, key=lambda x: x.description)
コード例 #8
0
    def people_with_activities_in_interval(self, date1, date2):
        '''
        Returns a list of people who perform activities in the indicated interval.
        :param date1: string - start date in a valid format
        :param date1: string - end date in a valid format
        :return: list of Person as specified
        :exception NABException: if one of the parameters is not valid
        '''

        if date1 > date2:
            raise NABException("End date must be after the start date.")

        if not ActivityValidator.valid_date(date1) or not ActivityValidator.valid_date(date2):
            raise NABException("At least one of the dates is invalid.")

        funct = lambda x: len([a for a in self.__activityRepo if a.person == x and date1 <= a.date and a.date <= date2]) != 0
        L = filter(funct, self.__personRepo)
        return sort(L, key=lambda x: x.id)