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.shellSort(lst, less)
    probarOrden(lst)
    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.shellSort (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)
Beispiel #3
0
def req2(lst, function, criteria, n):

    t1_start = process_time()
    result = lt.newList('ARRAY_LIST')
    nombres = lt.newList('ARRAY_LIST')
    votos = lt.newList('ARRAY_LIST')
    sh.shellSort(lst, function, criteria)
    #sel.selectionSort(lst, function, criteria)
    #ins.insertionSort(lst,function,criteria)

    for i in range(n + 1):
        lt.addLast(result, lt.getElement(lst, i))
    iterator = it.newIterator(result)
    while it.hasNext(iterator):
        element = it.next(iterator)
        lt.addLast(nombres, element['title'])
        lt.addLast(votos, element[criteria])
    final = lt.newList('ARRAY_LIST')
    for i in range(n + 1):
        lt.addLast(final, (lt.getElement(nombres, i), lt.getElement(votos, i)))
    lt.addLast(final, lt.getElement(final, 0))
    lt.removeFirst(final)
    lt.removeFirst(final)
    t1_stop = process_time()
    print('El tiempo fue de ', t1_stop - t1_start, ' segundos')
    return final
 def test_sort_menor_a_mayor(self):
     """
      Lista con elementos en orden aleatorio
     """
     print("sorting ....")
     sort.shellSort(self.lst_movies, self.grater)
     self.printList(self.lst_movies)
Beispiel #5
0
 def test_sort(self):
     """
      Lista con elementos en orden aleatorio
     """
     print("sorting ....")
     sort.shellSort(self.lst_books, self.less)
     self.printList(self.lst_books)
    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.shellSort(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)
    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.shellSort(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)
    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.shellSort(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)
Beispiel #9
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)
    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)
        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.shellSort (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_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.shellSort(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)
Beispiel #12
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.shellSort (self.lst, self.less)
     self.assertTrue(self.verifySorting(self.lst, self.less))
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.shellSort(lst, less)
    iterator = it.newIterator(lst)
    probarOrden(lst)
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.shellSort(lst, less)
    probarOrden(lst)
def lowAveMovies(lstmovies):
    t1 = process_time()
    lista = []
    ls.shellSort(lstmovies, lowMoviesAve)
    for i in range(1, 6):
        dato = lt.getElement(lstmovies, i)
        gg = (dato['original_title'] + ": " + dato['vote_average'])
        lista.append(gg)
    t2 = process_time()
    print("El tiempo de procesamiento es de: ", t2 - t1)
    return lista
def topCountMovies(lstmovies):
    t1 = process_time()
    lista = []
    ls.shellSort(lstmovies, topMovies)
    for i in range(1, 11):
        dato = lt.getElement(lstmovies, i)
        gg = (dato['original_title'] + ": " + dato['vote_count'])
        lista.append(gg)
    t2 = process_time()
    print("El tiempo de procesamiento es de: ", t2 - t1)
    return lista
Beispiel #17
0
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.shellSort(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
Beispiel #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.shellSort(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
Beispiel #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.shellSort(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
Beispiel #20
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")
def crear_ranking_peliculas(decision1,decision2,movies,cantidad_count=10,cantidad_average=10):
    tiempo1=process_time()
    peliculas_count=lt.newList("ARRAY_LIST")
    peliculas_average=lt.newList("ARRAY_LIST")
    if(decision1.lower() == "mas votadas"):
        for i in range(1,lt.size(movies)):
            elemento=lt.getElement(movies,i)
            datos={}
            datos["titulo"]=elemento["title"]
            datos["votos"]=int(elemento["vote_count"])
            lt.addLast(peliculas_count,datos)
        she.shellSort(peliculas_count,comparador_ascendente)

    elif(decision1.lower() == "menos votadas"):
        for i in range(1,lt.size(movies)+1):
            elemento=lt.getElement(movies,i)
            datos={}
            datos["titulo"]=elemento["title"]
            datos["votos"]=int(elemento["vote_count"])
            lt.addLast(peliculas_count,datos)
        she.shellSort(peliculas_count,comparador_descendente)

    if(decision2.lower() == "mejor calificadas"):
        for i in range(1,lt.size(movies)+1):
            elemento=lt.getElement(movies,i)
            datos2={}
            datos2["titulo"]=elemento["title"]
            datos2["promedio"]=float(elemento["vote_average"])
            lt.addLast(peliculas_average,datos2)
        she.shellSort(peliculas_average,comparador_ascendente_average)

    elif(decision2.lower() == "peor calificadas"):
        for i in range(1,lt.size(movies)+1):
            elemento=lt.getElement(movies,i)
            datos2={}
            datos2["titulo"]=elemento["title"]
            datos2["promedio"]=float(elemento["vote_average"])
            lt.addLast(peliculas_average,datos2)
        she.shellSort(peliculas_average,comparador_descendente_average)
    total_count=lt.newList("ARRAY_LIST")
    total_average=lt.newList("ARRAY_LIST")
    x=0
    x2=0
    for i in range(1,lt.size(peliculas_count)):
        elemento=lt.getElement(peliculas_count,i)
        x+=1
        lt.addLast(total_count,elemento)
        if(x == cantidad_count):
            break
    for i in range(1,lt.size(peliculas_average)):
        elemento=lt.getElement(peliculas_average,i)
        x2+=1
        lt.addLast(total_average,elemento)
        if(x2 == cantidad_average):
            break
    tiempo2=process_time()
    return (total_count,total_average,tiempo2-tiempo1)
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.shellSort(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) == book13
    assert slt.removeFirst(lst) == book9
    assert slt.removeFirst(lst) == book10
    assert slt.removeFirst(lst) != book14
Beispiel #23
0
    def test_oneElement (self):
        """
        Un elemento
        """
        self.lst = slt.newList(self.list_type)
        slt.addFirst (self.lst, self.book1)

        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.shellSort (self.lst, self.less)
        iterator = it.newIterator(self.lst)
        self.assertTrue(self.verifySorting(self.lst, self.less))
def Ranking_del_genero(lst, criteria, orden):
    lista = lt.newList('ARRAY_LIST')
    i = 0
    while i < lt.size(lst):
        valor = lt.getElement(lst, i)
        if criteria in valor["genres"]:
            lt.addFirst(lista, valor)
        i += 1
    a = 0
    b = 0
    c = 0
    d = 0
    lista2 = []
    lista3 = []
    if orden == "mayor":
        ls.shellSort(lista, topMovies)
        for i in range(1, 11):
            dato = lt.getElement(lista, i)
            a += int(dato["vote_count"])
            lista2.append(dato['original_title'] + ": " + dato['vote_count'])
            #print (dato['original_title'] + ": " + dato['vote_count'])
        promedio = a / 10
        count = "\nEl promedio del count es: " + str(promedio)
        ls.shellSort(lista, topMoviesAve)
        for i in range(1, 6):
            dato = lt.getElement(lista, i)
            b += float(dato["vote_average"])
            lista3.append(dato['original_title'] + ": " + dato['vote_average'])
            #print (dato['original_title'] + ": " + dato['vote_average'])
        promedio2 = b / 5
        average = "\nEl promedio del average es: " + str(promedio2)
    elif orden == "menor":
        ls.shellSort(lista, lowMovies)
        for i in range(1, 11):
            dato = lt.getElement(lista, i)
            c += int(dato["vote_count"])
            lista2.append(dato['original_title'] + ": " + dato['vote_count'])
            #print (dato['original_title'] + ": " + dato['vote_count'])
        promedio3 = c / 10
        count = "\nEl promedio del count es: " + str(promedio3)
        ls.shellSort(lista, lowMoviesAve)
        for i in range(1, 6):
            dato = lt.getElement(lista, i)
            d += float(dato["vote_average"])
            lista3.append(dato['original_title'] + ": " + dato['vote_average'])
            #print (dato['original_title'] + ": " + dato['vote_average'])
        promedio4 = d / 5
        average = "\nEl promedio del average es: " + str(promedio4)
    return "\nSus películas por count: \n" + str(
        lista2) + count + "\nSus películas por average: \n" + str(
            lista3) + average
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.shellSort(lst, less)
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        element = it.next(iterator)
        assert element == book1
Beispiel #26
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')
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 test_agregarYquitar():
    """
    Prueba que al hacer varios ordnamientos el orden debe mantenerse asi se cambien los elementos
    Se requiere tener la lista ordenada, luego desordenada y probar que genera excepcion
    """
    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)
    probarOrden(lst)  #Prueba que al inicio la lista esté en orden
    slt.addFirst(lst, slt.removeLast(lst))
    slt.addLast(lst, slt.removeFirst(lst))
    slt.addFirst(lst, slt.removeLast(lst))
    with pytest.raises(Exception):
        probarOrden(lst)
    sort.shellSort(lst, less)
    probarOrden(lst)
Beispiel #29
0
def orderElementsByCriteria(orderfunction, column, lista, compfunction,
                            elements):
    """
    Retorna una lista con cierta cantidad de elementos ordenados por el criterio
    """
    t1_start = process_time()  #tiempo inicial
    if orderfunction == 1:
        ins.insertionSort(lista, compfunction, column)
    elif orderfunction == 2:
        ss.selectionSort(lista, compfunction, column)
    elif orderfunction == 3:
        shell.shellSort(lista, compfunction, column)
        ins.insertionSort(lista, compfunction, column)
    iterator = it.newIterator(lista)
    ranking = []
    x = 1
    while it.hasNext(iterator) and x <= elements:
        element = it.next(iterator)
        ranking.append(element.get("original_title"))
        x += 1
    t1_stop = process_time()  #tiempo final
    print("Tiempo de ejecución ", t1_stop - t1_start, " segundos")

    return ranking
Beispiel #30
0
def rankingPeli(listaCalif, decision, numPel) -> list:

    if decision == 1:
        listaMasVotos = lt.newList("ARRAY_LIST")
        SSort.shellSort(listaCalif, greaterCount)

        for i in range(1, numPel + 1):
            ind = lt.getElement(listaCalif, i)
            lt.addLast(listaMasVotos, ind["title"])
        return listaMasVotos["elements"]

    elif decision == 2:

        listaMenosVotos = lt.newList("ARRAY_LIST")
        SSort.shellSort(listaCalif, lessCount)

        for i in range(1, numPel + 1):
            ind = lt.getElement(listaCalif, i)
            lt.addLast(listaMenosVotos, ind["title"])

        return listaMenosVotos["elements"]

    elif decision == 3:
        listaMejorAverage = lt.newList("ARRAY_LIST")
        SSort.shellSort(listaCalif, greaterVote)

        for i in range(1, numPel + 1):
            ind = lt.getElement(listaCalif, i)
            lt.addLast(listaMejorAverage, ind["title"])
        return listaMejorAverage["elements"]

    elif decision == 4:
        listaPeorAverage = lt.newList("ARRAY_LIST")
        SSort.shellSort(listaCalif, lessVote)

        for i in range(1, numPel + 1):
            ind = lt.getElement(listaCalif, i)
            lt.addLast(listaPeorAverage, ind["title"])
        return listaPeorAverage["elements"]