Ejemplo n.º 1
0
    def top_30procent_customers_most_movies(self):

        rented = self.__repoRented.get_all()

        clients_with_movies = []

        rented_list = {}

        for i in rented:
            if i.get_rented_cid() not in rented_list:
                rented_list[i.get_rented_cid()] = 0
            else:
                rented_list[i.get_rented_cid()] += 1

        sortate = sorted(rented_list.items(),
                         key=lambda x: (x[1], x[0]),
                         reverse=True)

        for i in sortate:
            customer = Customer(i[0], None, None, None)
            customer_found = self.__repoCustomer.search(customer)
            clients_with_movies.append(customer_found)

        count = int((len(clients_with_movies * 3) / 10))

        return clients_with_movies[:count]
Ejemplo n.º 2
0
    def search_customer_by_name(self, name):

        self.list = []

        customer = Customer(None, name, None, None)

        self.list = self.__repoCustomer.get_all_customers_same_name(customer)

        return self.list
Ejemplo n.º 3
0
    def all_customrs_with_more_movies(self):

        rented = self.__repoRented.get_all()

        clients_with_movies = []

        rented_list = {}

        for i in rented:
            if i.get_rented_cid() not in rented_list:
                rented_list[i.get_rented_cid()] = 0
            else:
                rented_list[i.get_rented_cid()] += 1

        #sortate = sorted(rented_list.items(), key = lambda x:(x[1], x[0]), reverse = True)

        #listaValues = list(rented_list.values())
        #listaKeys = list(rented_list.keys())

        #print(listaValues)
        #print(listaKeys)
        '''
        bingo sort
        '''
        dictlist = []

        for key, value in rented_list.items():
            temp = [key, value]
            dictlist.append(temp)

        #print(dictlist)

        bingoSort(dictlist, keye2=keye2)
        '''
        sortate = True
        
        while sortate == True:# best case = O(n) cand toate elementele sunt sortate
            sortate = False # worst case = O(n^2) cand elementele sunt in ordine crescatoare
            for i in range(0, len(listaValues)-1):# nr cazuri totale = n(n-1)
                if listaValues[i] < listaValues[i+1]:# caz mediu = caiet ( O(n^2) )
                    sortate = True
                    listaKeys[i], listaKeys[i+1] = listaKeys[i+1], listaKeys[i]
                    listaValues[i], listaValues[i+1] = listaValues[i+1], listaValues[i]
        '''
        for i in dictlist:
            customer = Customer(i[0], None, None, None)
            customer_found = self.__repoCustomer.search(customer)
            clients_with_movies.append(customer_found)

        return clients_with_movies
Ejemplo n.º 4
0
    def all_customers_with_moviesV2(self, rented, len_rented,
                                    clients_with_movies):

        if len_rented == 0:
            print(clients_with_movies)
            return clients_with_movies
        else:
            customer = Customer(rented[len_rented - 1].get_rented_cid(), None,
                                None, None)
            customer_found = self.__repoCustomer.search(customer)
            if customer_found not in clients_with_movies:

                clients_with_movies.append(customer_found)
            return self.all_customers_with_moviesV2(rented, len_rented - 1,
                                                    clients_with_movies)
Ejemplo n.º 5
0
    def all_customers_with_movies(self):

        rented = self.__repoRented.get_all()

        clients_with_movies = []

        for i in rented:
            customer = Customer(i.get_rented_cid(), None, None, None)
            customer_found = self.__repoCustomer.search(customer)
            if customer_found not in clients_with_movies:
                clients_with_movies.append(customer_found)

        clients_with_movies.sort(key=lambda x: x.get_name(), reverse=False)

        return clients_with_movies
Ejemplo n.º 6
0
    def add_rental(self, mid, cid, start_date, return_date):

        rental = Rental(mid, cid, start_date, return_date)

        customer = Customer(cid, None, None, None)

        movie = Movie(mid, None, None, None)

        self.__repoCustomer.search(customer)
        movie_found = self.__repoMovie.search(movie)
        if movie_found.get_status() == "rented":
            raise RepoError("film deja inchiriat!\n")

        else:
            self.__validRented.validate_rental(rental)
            self.__repoRented.add(rental)
Ejemplo n.º 7
0
    def all_customrs_with_more_moviesV2(self):

        rented = self.__repoRented.get_all()  # O(n)

        clients_with_movies = []  # O(1)

        rented_list = {}  # O(1)

        for i in rented:  # O(n) / Theta(n)
            if i.get_rented_cid() not in rented_list:
                rented_list[i.get_rented_cid()] = 0
            else:
                rented_list[i.get_rented_cid()] += 1

        #sortate = sorted(rented_list.items(), key = lambda x:(x[1], x[0]), reverse = True)

        listaValues = list(rented_list.values())
        listaKeys = list(rented_list.keys())

        #print(listaValues)
        #print(listaKeys)

        sortate = True

        while sortate == True:  # best case = O(n) cand toate elementele sunt sortate
            sortate = False  # worst case = O(n^2) cand elementele sunt in ordine crescatoare
            for i in range(0,
                           len(listaValues) - 1):  # nr cazuri totale = n(n-1)
                if listaValues[i] < listaValues[
                        i + 1]:  # caz mediu = caiet ( O(n^2) )
                    sortate = True
                    listaKeys[i], listaKeys[i + 1] = listaKeys[i +
                                                               1], listaKeys[i]
                    listaValues[i], listaValues[i + 1] = listaValues[
                        i + 1], listaValues[i]

        for i in listaKeys:  # O(n)
            customer = Customer(i, None, None, None)
            customer_found = self.__repoCustomer.search(customer)
            clients_with_movies.append(customer_found)

        return clients_with_movies
Ejemplo n.º 8
0
 def remove_customer(self, cid):
     customer = Customer(cid, None, None, None)
     #TEMA LAAAB MODIFICA
     customer_selected = self.__repoCustomer.search(customer)
     self.__repoCustomer.delete(customer_selected)
Ejemplo n.º 9
0
 def modify_customer_by_adress(self, cid, newAdress):
     customer = Customer(cid, None, None, None)
     valid = Customer(cid, "Alex", 1, newAdress)
     self.__validCustomer.validate_customer(valid)
     self.__repoCustomer.modify_adress(customer, newAdress)
Ejemplo n.º 10
0
 def modify_customer_by_cnp(self, cid, newCNP):
     customer = Customer(cid, None, None, None)
     valid = Customer(cid, "Alex", newCNP, "1")
     self.__validCustomer.validate_customer(valid)
     self.__repoCustomer.modify_cnp(customer, newCNP)
Ejemplo n.º 11
0
    def modify_customer_by_name(self, cid, newName):

        customer = Customer(cid, None, None, None)
        valid = Customer(cid, newName, 1, "1")
        self.__validCustomer.validate_customer(valid)
        self.__repoCustomer.modify_name(customer, newName)
Ejemplo n.º 12
0
    def add_customer(self, cid, name, cnp, adress):

        customer = Customer(cid, name, cnp, adress)

        self.__validCustomer.validate_customer(customer)
        self.__repoCustomer.add(customer)