def moviesPastDueDate(self, movieRepo): """ Get list of movies past due date """ rentalsPassedDueDate = List() constants = Constants() for rental in self.getRentalList(): if rental.getReturnedDate() is None and rental.getDueDate( ).isBeforeDate(self.__constants.currentDay()): rentalsPassedDueDate.append(rental) for i in range(0, len(rentalsPassedDueDate) - 1): for j in range(i + 1, len(rentalsPassedDueDate)): if constants.currentDay().daysUntilDate( rentalsPassedDueDate[i].getRentedDate( )) < constants.currentDay().daysUntilDate( rentalsPassedDueDate[j].getRentedDate()): aux = rentalsPassedDueDate[i] rentalsPassedDueDate[i] = rentalsPassedDueDate[j] rentalsPassedDueDate[j] = aux moviesPassedDueDateSorted = List() for rental in rentalsPassedDueDate: moviesPassedDueDateSorted.append( movieRepo.getMovieWithId(rental.getMovieId())) return moviesPassedDueDateSorted
def test_equals(self): list1 = [5, 4, 10, 50] self.assertEqual(list1, self.testList) list1 = List([5, 4, 10, 50]) self.assertEqual(list1, self.testList) list1 = {} self.assertNotEqual(list1, self.testList) list1 = [5, 4, 10] self.assertNotEqual(list1, self.testList) list1 = List([5, 4, 10, 51]) self.assertNotEqual(list1, self.testList)
def test_sort(self): sortList(self.testList, lambda a, b: True if a < b else False) self.assertEqual(self.testList, [4, 5, 10, 50]) testList = List() sortList(testList, lambda a, b: True if a < b else False) self.assertEqual(testList, []) testList = List([1, 2, 3]) sortList(testList, lambda a, b: True if a < b else False) self.assertEqual(testList, [1, 2, 3]) testList = List([1, -2, -3]) sortList(testList, lambda a, b: True if a < b else False) self.assertEqual(testList, [-3, -2, 1])
def moviesMostRentedByDays(self, movieRepo): """ Get list of movies most rented by days rented """ constants = Constants() rentals = self.getRentalList() movies = movieRepo.getList() moviesDictionary = {} for movie in movies: moviesDictionary[movie.getId()] = 0 for rental in rentals: if rental.getMovieId() in moviesDictionary: if rental.getReturnedDate() is None: daysToAdd = constants.currentDay().daysUntilDate( rental.getRentedDate()) else: daysToAdd = rental.getRentedDate().daysUntilDate( rental.getReturnedDate()) moviesDictionary[rental.getMovieId()] += daysToAdd sortedMovies = sorted(moviesDictionary.items(), key=operator.itemgetter(1)) sortedMovies.reverse() sortedMovieList = List() for movie in sortedMovies: sortedMovieList.append(movieRepo.getMovieWithId(movie[0])) return sortedMovieList
def mostActiveClients(self, clientRepo): """ Get list of most active clients by days rented """ constants = Constants() rentals = self.getRentalList() clients = clientRepo.getList() clientsDictionary = {} for client in clients: clientsDictionary[client.getId()] = 0 for rental in rentals: if rental.getClientId() in clientsDictionary: if rental.getReturnedDate() is None: daysToAdd = constants.currentDay().daysUntilDate( rental.getRentedDate()) else: daysToAdd = rental.getRentedDate().daysUntilDate( rental.getReturnedDate()) clientsDictionary[rental.getClientId()] += daysToAdd sortedClients = sorted(clientsDictionary.items(), key=operator.itemgetter(1)) sortedClients.reverse() sortedClientList = List() for client in sortedClients: sortedClientList.append(clientRepo.getClientWithId(client[0])) return sortedClientList
def __loadRepo(self): file = open(self.__fileName, "rb") try: readRepo = pickle.load(file) except EOFError: readRepo = List() for movie in readRepo: super().addMovieWithId(movie) file.close()
def __loadRepo(self): file = open(self.__fileName, "rb") try: readRepo = pickle.load(file) except EOFError: readRepo = List() for client in readRepo: super().addClientWithId(client) file.close()
def listOfMoviesWithGenre(self, movieGenreToFind): """ Get movies having genre """ movieListWithPartialGenreCorresponding = List() for movie in self.getMovieList(): if stringsPartiallyMatch(movie.getGenre(), movieGenreToFind): movieListWithPartialGenreCorresponding.append(movie) return movieListWithPartialGenreCorresponding
def listOfMoviesWithTitle(self, movieTitleToFind): """ Get movies having title """ movieListWithPartialTitleCorresponding = List() for movie in self.getMovieList(): if stringsPartiallyMatch(movie.getTitle(), movieTitleToFind): movieListWithPartialTitleCorresponding.append(movie) return movieListWithPartialTitleCorresponding
def __loadRepo(self): file = open(self.__fileName, "rb") try: readRepo = pickle.load(file) except EOFError: readRepo = List() for rental in readRepo: super().addRentalWithId(rental) file.close()
def moviesCurrentlyRented(self, movieRepo): """ Get list of movie currently rented """ moviesRentedNow = List() for rental in self.getRentalList(): if rental.getReturnedDate() is None: moviesRentedNow.append( movieRepo.getMovieWithId(rental.getMovieId())) return moviesRentedNow
def listOfMoviesWithDescription(self, movieDescriptionToFind): """ Get movies having description """ movieListWithPartialDescriptionCorresponding = List() for movie in self.getMovieList(): if stringsPartiallyMatch(movie.getDescription(), movieDescriptionToFind): movieListWithPartialDescriptionCorresponding.append(movie) return movieListWithPartialDescriptionCorresponding
def __clientHasPassedDueDateMovies(self, clientId): clientRentalList = List() for rental in self.getRentalList(): if rental.getClientId() == clientId: clientRentalList.append(rental) for rental in clientRentalList: if rental.getReturnedDate() is None and rental.getDueDate( ).isBeforeDate(self.__constants.currentDay()): return True return False
def __isMovieAvailable( self, movieId ): # TODO check if have to check if movie exist (probably handled in ui) movieRentalList = List() for rental in self.getRentalList(): if rental.getMovieId() == movieId: movieRentalList.append(rental) if len(movieRentalList) == 0: # movie never rented return True for rental in movieRentalList: if rental.getReturnedDate() is None: return False return True
def moviesMostRentedByTimesRented(self, movieRepo): """ Get list of movies most rented by times rented """ rentals = self.getRentalList() movies = movieRepo.getList() moviesDictionary = {} for movie in movies: moviesDictionary[movie.getId()] = 0 for rental in rentals: if rental.getMovieId() in moviesDictionary: moviesDictionary[rental.getMovieId()] += 1 sortedMovies = sorted(moviesDictionary.items(), key=operator.itemgetter(1)) sortedMovies.reverse() sortedMovieList = List() for movie in sortedMovies: sortedMovieList.append(movieRepo.getMovieWithId(movie[0])) return sortedMovieList
def test_contains(self): list = List() list.add("hola") list.add("adios") self.assertTrue(list.contains("adios"))
def setUp(self): self.testList = List([5, 4, 10, 50])
def test_filter(self): self.assertEqual(filterList(self.testList, lambda a: True if a % 2 == 0 else False), [4, 10, 50]) self.assertEqual(filterList(List([1, -2, -3]), lambda a: True if a % 2 == 0 else False), [-2])
def clean(self): self.__movieList = List()
def __init__(self) -> None: self.__movieList = List()
def __init__(self) -> None: self.__rentalList = List()
def cleanFile(self): file = open(self.__fileName, "wb") pickle.dump(List(), file) file.close()
def listOfClientsWithName(self, clientNameToFind): clientListWithPartialNameCorresponding = List() for client in self.getClientList(): if stringsPartiallyMatch(client.getName(), clientNameToFind): clientListWithPartialNameCorresponding.append(client) return clientListWithPartialNameCorresponding
def test_to_string(self): list = List() for i in range(0, 10): list.add(i) self.assertEquals(list.to_string(), "[0,1,2,3,4,5,6,7,8,9]")
def clean(self): self.__rentalList = List()
def test_is_tail(self): list = List() for i in range(0, 101): list.add(i) self.assertTrue(list.is_tail(list.get_node(100)))
def test_is_head(self): list = List() for i in range(0, 10): list.add(i) self.assertTrue(list.is_head(list.get_node(0)))
def test_get_node(self): list = List() list.add("hola") self.assertTrue(list.get_node("hola") != None)
def test_add(self): list = List() list.add("hola") self.assertTrue(list.get_head().get_elem() == "hola")
def test_remove(self): list = List() list.add("hola") list.add("adios") list.remove("hola") self.assertEquals(list.get_head().get_elem(), "adios")