Beispiel #1
0
    def __init__(self, person, date, time, description):
        '''
        Constructor for the class Activity.
        :param person: Person - person who does the activity
        :param date: string - day, month and year of the activity in the format "yyyy.mm.dd"
        :param time: string - hour and minute of the activity in the format "hh:mm"
        :param description: string - description of the activity
        :exception NABException: if one of the parameters is not valid
        '''

        # Checks if parameters are valid.

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

        if not ActivityValidator.valid_date(date):
            raise NABException("The given date is not in a valid format.")

        if not ActivityValidator.valid_time(time):
            raise NABException("The given time is not in a valid format.")

        if not isinstance(description, str):
            raise NABException("The given description is not a string.")

        # Constructs object.

        self.__person = person
        self.__date = date
        self.__time = time
        self.__description = description
    def search_activities_with_date(self):
        '''
        Read a date and prints the activities taking place on that date.
        '''

        system("clear")

        print(
            "# You have chosen to search activities which take place on a certain date."
        )

        if self.__activitiesCtrl.number_of_activities() == 0:
            raise NABException("The list of activities is empty.")

        date = input("Type the date in format {0}: ".format(
            ActivityValidator.dateFormat()))

        try:
            system("clear")

            foundActivities = self.__activitiesCtrl.find_activities_by_date(
                date)

            print("# The following activities have been found: ")
            print(foundActivities, end='')

        except NABException as err:
            print(err)
    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)
    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)
Beispiel #5
0
    def time(self, newTime):
        '''
        Sets a new time of the current activity.
        :param newTime: string - new time of the current activity of format "hh:mm"
        :return: the time of the current activity is set to newTime
        :exception NABException: if one of the parameters is not valid
        '''

        if not ActivityValidator.valid_time(newTime):
            raise NABException("The given time is not in a valid format.")

        self.__time = newTime
Beispiel #6
0
    def date(self, newDate):
        '''
        Sets a new date of the current activity.
        :param newDate: string - new date of the current activity of format "dd:mm:yyyy"
        :return: the date of the current activity is set to newDate
        :exception NABException: if one of the parameters is not valid
        '''

        if not ActivityValidator.valid_date(newDate):
            raise NABException("The given date is not in a valid format.")

        self.__date = newDate
    def add_activity(self):
        '''
        Reads information about an activity and adds it to the NAB.
        '''

        system("clear")

        print("# You have chosen to add a new activity.")

        print(
            "ID must be the one of a person already existing in the list of people."
        )
        id = Console.read_positive_integer(
            "Type the ID of the person who performs the activity: ")
        print("Date must be one between {0} and {1}.".format(
            ActivityValidator.minDate(), ActivityValidator.maxDate()))
        date = input("Type the date of the activity in format {0}: ".format(
            ActivityValidator.dateFormat()))
        print("Time must be one between {0} and {1}.".format(
            ActivityValidator.minTime(), ActivityValidator.maxTime()))
        time = input("Type the time of the activity in format {0}: ".format(
            ActivityValidator.timeFormat()))
        description = input("Type the description of the activity: ")

        try:
            system("clear")

            person = self.__peopleCtrl.find_person_by_id(id)
            self.__activitiesCtrl.add_activity(
                Activity(person, date, time, description))
            self.__undoRedoCtrl.do_activities()
            print("Activity has been successfully added.")
        except NABException as err:
            print(err)
    def find_by_date(self, date):
        '''
        Returns an ActivityRepository which contains only activities performed on the indicated date.
        :param date: string - day, month and year of the activity in the format "yyyy.mm.dd"
        :return: ActivityRepository - activities performed on the indicated date
        :exception NABException: if one of the parameters is not valid
        '''

        if not ActivityValidator.valid_date(date):
            raise NABException("The given date is not in a valid format.")

        foundActivities = ActivityRepository()

        for activity in self.__list:
            if activity.date == date:
                foundActivities.add(activity)

        return foundActivities
    def find_by_time(self, time):
        '''
        Returns an ActivityRepository which contains only activities performed on the indicated time.
        :param time: string - hour and minute of the activity in the format "hh:mm"
        :return: ActivityRepository - activities performed on the indicated time
        :exception NABException: if one of the parameters is not valid
        '''

        if not ActivityValidator.valid_time(time):
            raise NABException("The given time is not in a valid format.")

        foundActivities = ActivityRepository()

        for activity in self.__list:
            if activity.time == time:
                foundActivities.add(activity)

        return foundActivities
Beispiel #10
0
    initListPers(persRepo)
if settings[0]["file_type"] == "text_file":
    persRepo = PersonTextFileRepo()
if settings[0]["file_type"] == "binary_file":
    persRepo = PersonBinaryRepo()

if settings[1]["file_type"] == "memory":
    actRepo = ActivityRepository()
    initListActs(actRepo)
if settings[1]["file_type"] == "text_file":
    actRepo = ActivityTextFileRepo()
if settings[1]["file_type"] == "binary_file":
    actRepo = ActivityBinaryRepo()

dayRepo = DayRepository()
#initListGen(persRepo)
#initListGenAct(persRepo, actRepo)
actPers = ActivitiesOfPerson(persRepo, actRepo)
dayController = DayController(dayRepo, actRepo)
persValidator = PersonValidator(persRepo)
actValidator = ActivityValidator(actRepo, persRepo)
undoController = UndoController()
actPersController = ActivitiesOfPersonController(actPers)
persController = PersonController(persRepo, persValidator, actPersController,
                                  undoController)
actController = ActivityController(actRepo, actValidator, undoController)
assign = UI(persController, actController, dayController, actPersController,
            undoController)

assign.run()
Beispiel #11
0
 def test_valid_date(self):
     self.assertFalse(ActivityValidator.valid_date([]))
     self.assertFalse(ActivityValidator.valid_date(424))
     self.assertTrue(ActivityValidator.valid_date("2014.05.10"))
     self.assertFalse(ActivityValidator.valid_date("10.05.2014"))
     self.assertFalse(ActivityValidator.valid_date("10.5.2014"))
     self.assertFalse(ActivityValidator.valid_date("2014:05.10"))
     self.assertTrue(ActivityValidator.valid_date("2014.02.24"))
     self.assertTrue(ActivityValidator.valid_date("2999.01.30"))
     self.assertFalse(ActivityValidator.valid_date("2015.13.01"))
     self.assertFalse(ActivityValidator.valid_date("1900.02.29"))
     self.assertTrue(ActivityValidator.valid_date("2000.02.29"))
     self.assertTrue(ActivityValidator.valid_date("2004.02.29"))
     self.assertFalse(ActivityValidator.valid_date("2014..02.29"))
     self.assertFalse(ActivityValidator.valid_date("2014.29"))
     self.assertFalse(
         ActivityValidator.valid_date("29.3.02...32..3232.2004"))
     self.assertFalse(ActivityValidator.valid_date("Banana"))
Beispiel #12
0
 def test_valid_time(self):
     self.assertFalse(ActivityValidator.valid_time([]))
     self.assertFalse(ActivityValidator.valid_time(424))
     self.assertTrue(ActivityValidator.valid_time("12:12"))
     self.assertFalse(ActivityValidator.valid_time("12:::12"))
     self.assertTrue(ActivityValidator.valid_time("00:00"))
     self.assertFalse(ActivityValidator.valid_time("0:0"))
     self.assertFalse(ActivityValidator.valid_time("51:12"))
     self.assertFalse(ActivityValidator.valid_time("banana"))
     self.assertFalse(ActivityValidator.valid_time("24.12.2015"))
     self.assertFalse(ActivityValidator.valid_time("23.59"))
     self.assertTrue(ActivityValidator.valid_time("23:59"))