Exemplo n.º 1
0
 def test_sort_menor_a_mayor(self):
     """
      Lista con elementos en orden aleatorio
     """
     print("sorting ....")
     sort.insertionSort(self.lst_movies, self.greater)
     self.printList(self.lst_movies)
Exemplo n.º 2
0
    def test_repeatedElements_greater(self):
        """
           Con muchos elementos en la lista
        """
        self.lst = slt.newList(self.list_type)
        slt.addFirst(self.lst, self.movie5)
        slt.addFirst(self.lst, self.movie4)
        slt.addFirst(self.lst, self.movie6)
        slt.addFirst(self.lst, self.movie3)
        slt.addFirst(self.lst, self.movie1)
        slt.addFirst(self.lst, self.movie6)
        slt.addFirst(self.lst, self.movie2)
        slt.addFirst(self.lst, self.movie4)

        print(
            "Repeated elements:----------------------------------------------------"
        )
        iterator = it.newIterator(self.lst)
        while it.hasNext(iterator):
            element = it.next(iterator)
            result = "".join(
                str(key) + ": " + str(value) + ",  "
                for key, value in element.items())
            print(result)
        print("sorting ....")
        sort.insertionSort(self.lst, self.greater)
        iterator = it.newIterator(self.lst)
        while it.hasNext(iterator):
            element = it.next(iterator)
            result = "".join(
                str(key) + ": " + str(value) + ",  "
                for key, value in element.items())
            print(result)
Exemplo n.º 3
0
def orderElementsByCriteria(function,lst):
    """
    Retorna una lista con cierta cantidad de elementos ordenados por el criterio
    """
    t1_start = process_time() #tiempo inicial

    lst_count = lt.newList()
    lst_count['elements'] = [[],{}]
    print(lst_count)
    
    lst_average = lt.newList()
    lst_average['elements'] = [[],{}]

    for i in range(lt.size(lst)):
        lst_count['elements'][0].append(int(lst['elements'][i]['vote_count']))
        lst_count['elements'][1][lst['elements'][i]['vote_count']] = lst['elements'][i]['original_title']
        lst_average['elements'][0].append(float(lst['elements'][i]['vote_average']))
        lst_average['elements'][1][lst['elements'][i]['vote_average']] = lst['elements'][i]['original_title']
    
    if function == '1':
        lst_count['elements'][0] = sor1.insertionSort(lst_count['elements'][0])
        lst_average['elements'][0] = sor1.insertionSort(lst_average['elements'][0])
    elif function == '2':
        lst_count['elements'][0] = sor2.selectionSort(lst_count['elements'][0])
        lst_average['elements'][0] = sor2.selectionSort(lst_average['elements'][0])
    elif function == '3':
        lst_count['elements'][0] = sor3.shellSort(lst_count['elements'][0])
        lst_average['elements'][0] = sor3.shellSort(lst_average['elements'][0])
    
    t1_stop = process_time() #tiempo final
    print("Tiempo de ejecución ",t1_stop-t1_start," segundos")
    return (lst_count,lst_average)
Exemplo n.º 4
0
 def test_randomElements (self):
     """
      Lista con elementos en orden aleatorio
     """
     self.lst = slt.newList(self.list_type)
     slt.addFirst (self.lst, self.book5)
     slt.addFirst (self.lst, self.book6)
     slt.addFirst (self.lst, self.book3)
     slt.addFirst (self.lst, self.book10)
     slt.addFirst (self.lst, self.book1)
     slt.addFirst (self.lst, self.book2)
     slt.addFirst (self.lst, self.book8)
     slt.addFirst (self.lst, self.book4)
     slt.addFirst (self.lst, self.book7)
     slt.addFirst (self.lst, self.book9)
  
     print ("Random list:----------------------------------------------------")
     iterator = it.newIterator(self.lst)
     while  it.hasNext(iterator):
         element = it.next(iterator)
         #result = "".join(str(key) + ": " + str(value) + ",  " for key, value in element.items())
         #print (result)
     print ("Sorting ....")
     sort.insertionSort (self.lst, self.less)
     self.assertTrue(self.verifySorting(self.lst, self.less))
Exemplo n.º 5
0
def test_orderedElementss():
    """
    Lista ordenada normalmente, deberia ser igual a como se ingresan los libros
    """
    lst = slt.newList(list_type)
    slt.addFirst(lst, book10)
    slt.addFirst(lst, book9)
    slt.addFirst(lst, book8)
    slt.addFirst(lst, book7)
    slt.addFirst(lst, book6)
    slt.addFirst(lst, book5)
    slt.addFirst(lst, book4)
    slt.addFirst(lst, book3)
    slt.addFirst(lst, book2)
    slt.addFirst(lst, book1)

    print("Inverted list:----------------------------------------------------")
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        element = it.next(iterator)
        result = "".join(str(key) + ": " + str(value) +
                         ",  " for key, value in element.items())
        print(result)
    print("sorting ....")
    sort.insertionSort(lst, less)
    probarOrden(lst)
Exemplo n.º 6
0
    def test_invertedElements (self):
        """
        Lista ordenada inversamente
        """
        self.lst = slt.newList(self.list_type)
        slt.addFirst (self.lst, self.book1)
        slt.addFirst (self.lst, self.book2)
        slt.addFirst (self.lst, self.book3)
        slt.addFirst (self.lst, self.book4)
        slt.addFirst (self.lst, self.book5)
        slt.addFirst (self.lst, self.book6)
        slt.addFirst (self.lst, self.book7)
        slt.addFirst (self.lst, self.book8)
        slt.addFirst (self.lst, self.book9)
        slt.addFirst (self.lst, self.book10)

        print ("Inverted list:----------------------------------------------------")
        iterator = it.newIterator(self.lst)
        count=0
        while  it.hasNext(iterator):
            element = it.next(iterator)
            count+=1
            result = "".join(str(key) + ": " + str(value) + ",  " for key, value in element.items())
            print (result)
        print ("sorting ....")
        sort.insertionSort (self.lst, self.less)
        print( "result insertion sort: ")
        print (self.lst )
        self.assertTrue(self.verifySorting(self.lst, self.less))
Exemplo n.º 7
0
    def test_repeatedElements (self):
        """
           Con muchos elementos en la lista
        """
        self.lst = slt.newList(self.list_type)
        slt.addFirst (self.lst, self.book5)
        slt.addFirst (self.lst, self.book6)
        slt.addFirst (self.lst, self.book14)
        slt.addFirst (self.lst, self.book3)
        slt.addFirst (self.lst, self.book13)
        slt.addFirst (self.lst, self.book10)
        slt.addFirst (self.lst, self.book1)
        slt.addFirst (self.lst, self.book12)
        slt.addFirst (self.lst, self.book2)
        slt.addFirst (self.lst, self.book8)
        slt.addFirst (self.lst, self.book4)
        slt.addFirst (self.lst, self.book11)
        slt.addFirst (self.lst, self.book7)
        slt.addFirst (self.lst, self.book9)

        print ("Repeated elements:----------------------------------------------------")
        iterator = it.newIterator(self.lst)
        while  it.hasNext(iterator):
            element = it.next(iterator)
            result = "".join(str(key) + ": " + str(value) + ",  " for key, value in element.items())
            print (result)
        print ("sorting ....")
        sort.insertionSort (self.lst, self.less)
        self.assertTrue(self.verifySorting(self.lst, self.less))
Exemplo n.º 8
0
def test_randomElements():
    """
    Lista con elementos en orden aleatorio, prueba que se ordene correctamente cuando no hay orden alguno
    """
    lst = slt.newList(list_type)
    slt.addFirst(lst, book5)
    slt.addFirst(lst, book6)
    slt.addFirst(lst, book3)
    slt.addFirst(lst, book10)
    slt.addFirst(lst, book1)
    slt.addFirst(lst, book2)
    slt.addFirst(lst, book8)
    slt.addFirst(lst, book4)
    slt.addFirst(lst, book7)
    slt.addFirst(lst, book9)

    print("Random list:----------------------------------------------------")
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        element = it.next(iterator)
        result = "".join(str(key) + ": " + str(value) +
                         ",  " for key, value in element.items())
        print(result)
    print("sorting ....")
    sort.insertionSort(lst, less)
    probarOrden(lst)
Exemplo n.º 9
0
def test_invertedElements():
    """
    Lista ordenada inversamente, sale correcta si el orden final es el inverso a la forma en la cual se
    agregan
    """
    lst = slt.newList(list_type)
    slt.addFirst(lst, book1)
    slt.addFirst(lst, book2)
    slt.addFirst(lst, book3)
    slt.addFirst(lst, book4)
    slt.addFirst(lst, book5)
    slt.addFirst(lst, book6)
    slt.addFirst(lst, book7)
    slt.addFirst(lst, book8)
    slt.addFirst(lst, book9)
    slt.addFirst(lst, book10)

    print("Inverted list:----------------------------------------------------")
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        element = it.next(iterator)
        result = "".join(str(key) + ": " + str(value) +
                         ",  " for key, value in element.items())
        print(result)
    print("sorting ....")
    sort.insertionSort(lst, less)
    iterator = it.newIterator(lst)
    probarOrden(lst)
Exemplo n.º 10
0
    def test_invertedElements_greater(self):
        """
        Lista ordenada inversamente
        """
        self.lst = slt.newList(self.list_type)
        slt.addFirst(self.lst, self.movie1)
        slt.addFirst(self.lst, self.movie2)
        slt.addFirst(self.lst, self.movie3)
        slt.addFirst(self.lst, self.movie4)
        slt.addFirst(self.lst, self.movie5)
        slt.addFirst(self.lst, self.movie6)

        print(
            "Inverted list:----------------------------------------------------"
        )
        iterator = it.newIterator(self.lst)
        while it.hasNext(iterator):
            element = it.next(iterator)
            result = "".join(
                str(key) + ": " + str(value) + ",  "
                for key, value in element.items())
            print(result)
        print("sorting ....")
        sort.insertionSort(self.lst, self.greater)
        iterator = it.newIterator(self.lst)
        while it.hasNext(iterator):
            element = it.next(iterator)
            result = "".join(
                str(key) + ": " + str(value) + ",  "
                for key, value in element.items())
            print(result)
Exemplo n.º 11
0
 def test_sort(self):
     """
      Lista con elementos en orden aleatorio
     """
     print("sorting ....")
     sort.insertionSort(self.lst_books, self.less)
     self.printList(self.lst_books)
Exemplo n.º 12
0
    def test_randomElements(self):
        """
         Lista con elementos en orden aleatorio
        """
        self.lst = slt.newList(self.list_type)
        slt.addFirst(self.lst, self.movie5)
        slt.addFirst(self.lst, self.movie6)
        slt.addFirst(self.lst, self.movie3)
        slt.addFirst(self.lst, self.movie4)
        slt.addFirst(self.lst, self.movie1)
        slt.addFirst(self.lst, self.movie2)

        print(
            "Random list:----------------------------------------------------")
        iterator = it.newIterator(self.lst)
        while it.hasNext(iterator):
            element = it.next(iterator)
            result = "".join(
                str(key) + ": " + str(value) + ",  "
                for key, value in element.items())
            print(result)
        print("sorting ....")
        sort.insertionSort(self.lst, self.less)
        iterator = it.newIterator(self.lst)
        while it.hasNext(iterator):
            element = it.next(iterator)
            result = "".join(
                str(key) + ": " + str(value) + ",  "
                for key, value in element.items())
            print(result)
Exemplo n.º 13
0
    def test_oneElement_greater(self):
        """
        Un elemento
        """
        self.lst = slt.newList(self.list_type)
        slt.addFirst(self.lst, self.movie1)

        print(
            "one element:----------------------------------------------------")
        iterator = it.newIterator(self.lst)
        while it.hasNext(iterator):
            element = it.next(iterator)
            result = "".join(
                str(key) + ": " + str(value) + ",  "
                for key, value in element.items())
            print(result)
        print("sorting ....")
        sort.insertionSort(self.lst, self.greater)
        iterator = it.newIterator(self.lst)
        while it.hasNext(iterator):
            element = it.next(iterator)
            result = "".join(
                str(key) + ": " + str(value) + ",  "
                for key, value in element.items())
            print(result)
Exemplo n.º 14
0
    def test_orderedElements(self):
        """
        Lista ordenada
        """
        self.lst = slt.newList(self.list_type)
        slt.addFirst(self.lst, self.book10)
        slt.addFirst(self.lst, self.book9)
        slt.addFirst(self.lst, self.book8)
        slt.addFirst(self.lst, self.book7)
        slt.addFirst(self.lst, self.book6)
        slt.addFirst(self.lst, self.book5)
        slt.addFirst(self.lst, self.book4)
        slt.addFirst(self.lst, self.book3)
        slt.addFirst(self.lst, self.book2)
        slt.addFirst(self.lst, self.book1)

        print(
            "ordered list:----------------------------------------------------"
        )
        iterator = it.newIterator(self.lst)
        while it.hasNext(iterator):
            element = it.next(iterator)
            result = "".join(
                str(key) + ": " + str(value) + ",  "
                for key, value in element.items())
            print(result)
        print("sorting ....")
        sort.insertionSort(self.lst, self.less)
        iterator = it.newIterator(self.lst)
        while it.hasNext(iterator):
            element = it.next(iterator)
            result = "".join(
                str(key) + ": " + str(value) + ",  "
                for key, value in element.items())
            print(result)
def test_sort():
    """
    Lista con elementos en orden aleatorio
    """
    setUp()
    print("sorting ....")
    sort.insertionSort(lst_books, less)
    print("hola")
def conocer_un_actor(lista, lista2, nombre_actor):
    if lista['size'] == 0:
        print("La lista esta vacía")
        return 0
    else:
        autor = {'Nombre': nombre_actor, "Peliculas": None, "Directores": None}
        peliculas = lt.newList("ARRAY_LIST")
        Directores = lt.newList("ARRAY_LIST", cmpfunction=cmp1)
        conteo = 0
        sumatoria = 0
        iterador = it.newIterator(lista)
        while it.hasNext(iterador):
            elemento = it.next(iterador)
            encontre = False
            i = 1
            while i <= 5 and not encontre:
                actor = elemento["actor" + str(i) + "_name"]
                if actor.lower() == nombre_actor.lower():
                    encontre = True
                i += 1
            if encontre == True:
                id1 = elemento["id"]
                director = elemento["director_name"]
                iterador2 = it.newIterator(lista2)
                encontro2 = False
                while it.hasNext(iterador2) and not encontro2:
                    elemento2 = it.next(iterador2)
                    id2 = elemento2["id"]
                    if id1 == id2:
                        encontro2 = True
                        lt.addLast(peliculas, elemento2)
                        conteo += 1
                        sumatoria += float(elemento2["vote_average"])
                        iterador4 = it.newIterator(Directores)
                        encontro3 = False
                        while it.hasNext(iterador4) and not encontro3:
                            elemento4 = it.next(iterador4)
                            if director == elemento4["nombre"]:
                                encontro3 = True
                        if encontro3 == False:
                            lt.addLast(Directores, {
                                "nombre": director,
                                "conteo": 0
                            })
                        iterador3 = it.newIterator(Directores)
                        while it.hasNext(iterador3):
                            elemento3 = it.next(iterador3)
                            if director == elemento3["nombre"]:
                                elemento3["conteo"] += 1

        sort.insertionSort(Directores, greater_director)
        mas = lt.getElement(Directores, 1)
        autor["Peliculas"] = peliculas
        autor["Directores"] = Directores
        promedio = sumatoria / conteo

    return autor, mas, conteo, promedio
def test_loading_CSV_y_ordenamiento_inv():
    """
    Prueba que se pueda leer el archivo y que despues de relizar el sort, el orden este correcto
    """
    setUp()
    sort.insertionSort(lst_movies,greater)
    while not (lt.isEmpty(lst_movies)):
        x = int(lt.removeLast(lst_movies)['id'])
        if not (lt.isEmpty(lst_movies)):
            y = int(lt.lastElement(lst_movies)['id'])
        else:
            break
        assert x < y
Exemplo n.º 18
0
def test_loading_CSV_y_ordenamiento():
    """
    Prueba que se pueda leer el archivo y que despues de relizar el sort, el orden este correcto
    """
    setUp()
    sort.insertionSort(lst_books, less)
    while not (lt.isEmpty(lst_books)):
        x = int(lt.removeLast(lst_books)['goodreads_book_id'])
        if not (lt.isEmpty(lst_books)):
            y = int(lt.lastElement(lst_books)['goodreads_book_id'])
        else:
            break
        assert x > y
Exemplo n.º 19
0
def test_loading_CSV_y_ordenamiento():
    """
    Prueba que se pueda leer el archivo y que despues de relizar el sort, el orden este correcto
    """
    setUp()
    sort.insertionSort(lst_movies, less)
    while not (lt.isEmpty(lst_movies)):
        x = float(lt.removeLast(lst_movies)['vote_average'])
        if not (lt.isEmpty(lst_movies)):
            y = float(lt.removeLast(lst_movies)['vote_average'])
        else:
            break
        print(x, y)
        assert x > y or x == y
def test_greater():
    lst = lstmovies
    print(
        "Ordenando lista por de manera descendente:----------------------------------------------------"
    )
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        element = it.next(iterator)
        result = "".join(
            str(key) + ": " + str(value) + ",  "
            for key, value in element.items())
        print(result)
    print("sorting ....")
    sort.insertionSort(lst, greater)
Exemplo n.º 21
0
def RankingPeliculas(lst, num_peliculas, mejor_peor,
                     criterio):  #Ranking de peliculas

    lista_nueva = []
    if criterio.lower() == "count":
        t1_start = process_time()
        if mejor_peor.lower() == "peor":
            insertionSort(lst, less_count)
        else:
            insertionSort(lst, greater_count)
        for peliculas in lst["elements"]:
            if len(lista_nueva) < num_peliculas:
                lista_nueva.append(
                    (peliculas["original_title"], peliculas["vote_count"]))
        t1_stop = process_time()
        print("Tiempo de ejecución ", t1_stop - t1_start, " segundos")
    else:
        t1_start = process_time()
        if mejor_peor.lower() == "peor":
            insertionSort(lst, less_average)
        else:
            insertionSort(lst, greater_average)
        for peliculas in lst["elements"]:
            if len(lista_nueva) < num_peliculas:
                lista_nueva.append(
                    (peliculas["original_title"], peliculas["vote_average"]))
        t1_stop = process_time()
        print("Tiempo de ejecución ", t1_stop - t1_start, " segundos")
    return lista_nueva
Exemplo n.º 22
0
def sort(option, elements, function):
    if option == 1:
        print("sorting by selection sort....")
        t1_start = process_time()  #tiempo inicial
        selsort.selectionSort(elements, function)
    if option == 2:
        print("sorting by insertion sort....")
        t1_start = process_time()  #tiempo inicial
        inssort.insertionSort(elements, function)
    if option == 3:
        print("sorting by shell sort....")
        t1_start = process_time()  #tiempo inicial
        shellsort.shellSort(elements, function)
    t1_stop = process_time()  #tiempo final
    print("Tiempo de ejecución ", t1_stop - t1_start, " segundos")
Exemplo n.º 23
0
def test_ManyElements():
    """
    Con muchos elementos en la lista, en donde identificadores se repiten
    Deben aparecer consecutivos aquellos con id igual
    """
    lst = slt.newList(list_type)
    slt.addFirst(lst, book5)
    slt.addFirst(lst, book6)
    slt.addFirst(lst, book14)
    slt.addFirst(lst, book3)
    slt.addFirst(lst, book13)
    slt.addFirst(lst, book10)
    slt.addFirst(lst, book1)
    slt.addFirst(lst, book12)
    slt.addFirst(lst, book2)
    slt.addFirst(lst, book8)
    slt.addFirst(lst, book4)
    slt.addFirst(lst, book11)
    slt.addFirst(lst, book7)
    slt.addFirst(lst, book9)

    print(
        "Repeated elements:----------------------------------------------------"
    )
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        element = it.next(iterator)
        result = "".join(
            str(key) + ": " + str(value) + ",  "
            for key, value in element.items())
        print(result)
    print("sorting ....")
    sort.insertionSort(lst, less)
    assert slt.removeFirst(lst) == book1
    assert slt.removeFirst(lst) == book2
    assert slt.removeFirst(lst) == book3
    assert slt.removeFirst(lst) == book4
    assert slt.removeFirst(lst) == book5
    assert slt.removeFirst(lst) == book6
    assert slt.removeFirst(lst) == book7
    assert slt.removeFirst(lst) == book11
    assert slt.removeFirst(lst) == book8
    assert slt.removeFirst(lst) == book12
    assert slt.removeFirst(lst) == book9
    assert slt.removeFirst(lst) == book13
    assert slt.removeFirst(lst) == book10
    assert slt.removeFirst(lst) == book14
Exemplo n.º 24
0
def iSort (lst:list, orden:str)->list: 
    
    input ("Vamos a proceder a ordenar ascendentemente usando el metodo Insertion Sort, esto puede tomar algunos segundos o minutos. Clic para continuar")
    listaOrdenada = []
    listaOrdenada=InsSort.insertionSort (lst, orden)
  
   
    return listaOrdenada
Exemplo n.º 25
0
def iSort (lst:list, criterio:str, orden:str)->list: 
    t1_start = process_time() #tiempo inicial
    input ("Vamos a proceder a ordenar usando el metodo Insertion Sort, esto puede tomar algunos segundos o minutos. Clic para continuar")
    listaOrdenada = []
    listaOrdenada=InsSort.insertionSort (lst,criterio, orden)
    t1_stop = process_time() #tiempo final
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    print("Tiempo de ejecución de metodo InsertionSort ",t1_stop-t1_start," segundos")
    input ("Dar clic para continuar...")
    return listaOrdenada
Exemplo n.º 26
0
def orderElementsByCriteria(function, column, lst, elements):
    """
    Retorna una lista con cierta cantidad de elementos ordenados por el criterio
    """
    if lst['size'] == 0:
        print("La lista esta vacía")
        return 0
    else:

        t1_start = process_time()  #tiempo inicial
        lista = lt.newList()
        if column == "vote_count" and function.lower() == "acendente":
            sort.insertionSort(lst, less)
            iterador = it.newIterator(lst)
            counter = 1
            while it.hasNext(iterador) and counter <= int(elements):
                element = it.next(iterador)
                lt.addLast(lista, element)

                counter += 1
            hola = lt.subList(lst, 1, int(elements))
        elif column == "vote_count" and function.lower() == "decendente":
            sort.insertionSort(lst, greater1)
            iterador = it.newIterator(lst)
            counter = 1
            while it.hasNext(iterador) and counter <= int(elements):
                element = it.next(iterador)
                lt.addLast(lista, element)
                counter += 1

        elif column == "vote_average" and function.lower() == "acendente":
            sort.insertionSort(lst, less2)
            iterador = it.newIterator(lst)
            counter = 1
            while it.hasNext(iterador) and counter <= int(elements):
                element = it.next(iterador)
                lt.addLast(lista, element)
                counter += 1

        elif column == "vote_average" and function.lower() == "decendente":
            sort.insertionSort(lst, greater2)
            iterador = it.newIterator(lst)
            counter = 1
            while it.hasNext(iterador) and counter <= int(elements):
                element = it.next(iterador)
                lt.addLast(lista, element["vote_average"])
                counter += 1

        t1_stop = process_time()  #tiempo final
        print("Tiempo de ejecución ", t1_stop - t1_start, " segundos")
    print(lt.size(hola))
    return hola
Exemplo n.º 27
0
def test_oneElement():
    """
    Se prueba el ordenamiento de un elemento, solo deberia haber un elemento en la lista
    """
    lst = slt.newList(list_type)
    slt.addFirst(lst, book1)

    print("one element:----------------------------------------------------")
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        element = it.next(iterator)
        result = "".join(str(key) + ": " + str(value) +
                         ",  " for key, value in element.items())
        print(result)
    print("sorting ....")
    sort.insertionSort(lst, less)
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        element = it.next(iterator)
        assert element == book1
Exemplo n.º 28
0
def order_movies(function, lst_d, req_elements, algorithm, column):
    """
    Retorna una lista con cierta cantidad de elementos ordenados por el criterio
    """
    if len(lst_d) == 0:
        print('Las listas están vacías')
    else:
        t1_start = process_time()  # tiempo inicial
        # Sort movies.
        if algorithm == 'selection':
            if function == 'less':
                selection.selectionSort(lst_d, less_count) if column == 'vote_count' \
                    else selection.selectionSort(lst_d, less_average)
            elif function == 'greater':
                selection.selectionSort(lst_d, greater_count) if column == 'vote_count' \
                    else selection.selectionSort(lst_d, greater_average)
        elif algorithm == 'shell':
            if function == 'less':
                shell.shellSort(lst_d, less_count) if column == 'vote_count' \
                    else shell.shellSort(lst_d, less_average)
            elif function == 'greater':
                shell.shellSort(lst_d, greater_count) if column == 'vote_count' \
                    else shell.shellSort(lst_d, greater_average)
        elif algorithm == 'insertion':
            if function == 'less':
                insertion.insertionSort(lst_d, less_count) if column == 'vote_count' \
                    else insertion.insertionSort(lst_d, less_average)
            elif function == 'greater':
                insertion.insertionSort(lst_d, greater_count) if column == 'vote_count' \
                    else insertion.insertionSort(lst_d, greater_average)
        t1_stop = process_time()  # tiempo final
        print(req_elements, 'best' if function == 'greater' else 'worst',
              'count:' if column == 'vote_count' else 'average:')
        show_movies(lt.subList(lst_d, 0, int(req_elements)), None)
        print('Tiempo de ejecución ', t1_stop - t1_start, ' segundos')
Exemplo n.º 29
0
def rankingPeliculas(function, lst, criteria, elements):
    """
    Retorna el ranking de películas con base en los parámetros
     Args:
        function
            Función de ordenamiento que se va a usar
        column:: str
            Columna que se usa para realiza el ordenamiento (vote_average o vote_count)   
        lst
            Lista encadenada o arreglo     
        criteria:: str
            Critero para ordenar (less o greater)
        elements:: int
            Cantidad de elementos para el ranking
    Return:
        counter :: int
            la cantidad de veces ue aparece un elemento con el criterio definido
    """
    t1_start = process_time()  #tiempo inicial
    if function == "selectionsort":
        selectionsort.selectionSort(lst, criteria)
    if function == "insertionsort":
        insertionsort.insertionSort(lst, criteria)
    if function == "mergesort":
        mergesort.mergesort(lst, criteria)
    if function == "quicksort":
        quicksort.quickSort(lst, criteria)
    if function == "shellsort":
        shellsort.shellSort(lst, criteria)
    i = 0
    ordenado = []
    while i < elements:
        i += 1
        pelicula = lt.getElement(lst, i)
        ordenado.append(pelicula)
    t1_stop = process_time()  #tiempo final
    print("Tiempo de ejecución ", t1_stop - t1_start, " segundos")
    return ordenado
def ranking_genero(lista, genero, tipo_votacion, orden, num_peliculas):

    if lista['size'] == 0:
        print("La lista esta vacía")
        return 0
    else:
        lista_final = lt.newList("ARRAY_LIST")
        peliculas, tamaño, promedio = conocer_genero(lista, genero)
        iterador = it.newIterator(peliculas)
        if tipo_votacion == "vote_count" and orden.lower() == "peores":
            sort.insertionSort(peliculas, less)
            lista_final = lt.subList(peliculas, 1, int(num_peliculas))
            iterador = it.newIterator(lista_final)
            counter = 0
            while it.hasNext(iterador):
                element = it.next(iterador)
                counter += float(element["vote_count"])

        elif tipo_votacion == "vote_count" and orden.lower() == "mejores":
            sort.insertionSort(peliculas, greater1)
            lista_final = lt.PsubList(peliculas, 1, int(num_peliculas))
            iterador = it.newIterator(lista_final)
            counter = 0
            while it.hasNext(iterador):
                element = it.next(iterador)
                counter += float(element["vote_count"])

        elif tipo_votacion == "vote_average" and orden.lower() == "peores":
            sort.insertionSort(peliculas, less2)
            lista_final = lt.subList(peliculas, 1, int(num_peliculas))
            iterador = it.newIterator(lista_final)
            counter = 0
            while it.hasNext(iterador):
                element = it.next(iterador)
                counter += float(element["vote_average"])

        elif tipo_votacion == "vote_average" and orden.lower() == "mejores":
            sort.insertionSort(peliculas, greater2)
            lista_final = lt.subList(peliculas, 1, int(num_peliculas))
            iterador = it.newIterator(lista_final)
            counter = 0
            while it.hasNext(iterador):
                element = it.next(iterador)
                counter += float(element["vote_count"])

    promedio = counter / lt.size(lista_final)
    return lista_final, promedio