def sortVideos(catalog, size, algorithm): sub_list = lt.subList(catalog['videos'], 0, size) if algorithm == 'Insertion sort': start_time = time.process_time() ins.sort(sub_list, cmpVideosbyViews) stop_time = time.process_time() elif algorithm == 'Selection sort': start_time = time.process_time() ses.sort(sub_list, cmpVideosbyViews) stop_time = time.process_time() elif algorithm == 'Shell sort': start_time = time.process_time() shs.sort(sub_list, cmpVideosbyViews) stop_time = time.process_time() elif algorithm == 'Merge sort': start_time = time.process_time() mrg.sort(sub_list, cmpVideosbyViews) stop_time = time.process_time() elif algorithm == 'Quick sort': start_time = time.process_time() qck.sort(sub_list, cmpVideosbyViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg
def sortVideos(catalog, size, sort_type, cmp): """ La Función sortVideos() la usamos en varios requerimientos por la necesidad de tener la información organizada. Por esto mismo, la función cuenta con cuatro parámetros en donde destacan "cmp" y "sort_type". Para cada caso particular, dejamos que según estos dos parámetros se invoque la función correspondiente de la librería sort y usando los algoritmos de merge sort y quick sort """ sub_list = lt.subList(catalog, 0, size) sub_list = sub_list.copy() start_time = time.process_time() if cmp == 'cmpVideosByViews': if sort_type == "ms": sorted_list = ms.sort(sub_list, cmpVideosByViews) elif sort_type == "qs": sorted_list = qs.sort(sub_list, cmpVideosByViews) if cmp == 'comparetitles': if sort_type == "ms": sorted_list = ms.sort(sub_list, comparetitles) elif sort_type == "qs": sorted_list = qs.sort(sub_list, comparetitles) if cmp == 'comparelikes': if sort_type == "ms": sorted_list = ms.sort(sub_list, comparelikes) elif sort_type == "qs": sorted_list = qs.sort(sub_list, comparelikes) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, sorted_list
def dataim(mini, k) -> float: t1 = t.perf_counter() qs.sort(mini, cmpVideosByViews) t2 = t.perf_counter() main = (t2 - t1) * 1000 return main
def sortVideos(lt, sorting): if sorting == 0: sa.sort(lt, cmpVideosByViews) elif sorting == 1: ins.sort(lt, cmpVideosByViews) elif sorting == 2: sel.sort(lt, cmpVideosByViews) elif sorting == 3: mer.sort(lt, cmpVideosByViews) else: qck.sort(lt, cmpVideosByViews)
def quickSortVideos(catalog, size): sub_list = lt.subList(catalog['videos'], 0, size) start_time = time.process_time() sorted_list = quick.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, sorted_list
def requerimiento4(catalog, size, tipodeorden, tagg, tipo): nueva = lt.newList(tipo) final = lt.newList(tipo) listaee = [] for i in range(0, lt.size(catalog['videos'])): ele = lt.getElement(catalog['videos'], i) if tagg in ele['tags']: lt.addLast(nueva, ele) sublista = nueva.copy() start_time = time.process_time() if (tipodeorden == "shell"): sorted_list = sa.sort(sublista, cmpVideosByLikes) elif (tipodeorden == "insertion"): sorted_list = si.sort(sublista, cmpVideosByLikes) elif (tipodeorden == "selection"): sorted_list = ss.sort(sublista, cmpVideosByLikes) elif (tipodeorden == "quick"): sorted_list = sq.sort(sublista, cmpVideosByLikes) elif (tipodeorden == "merge"): sorted_list = sm.sort(sublista, cmpVideosByLikes) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 for i in range(0, lt.size(sorted_list)): ete = lt.getElement(sorted_list, i) if not (ete['title'] in listaee): listaee.append(ete['title']) lt.addLast(final, ete) return elapsed_time_mseg, final
def secondReq(catalog, country): """ Completa el requerimiento #2 """ new_map = mp.newMap(50000, 50007, 'PROBING', 0.80, None) for videos in catalog["videos"]["table"]["elements"]: if videos["key"] != None: for video in lt.iterator(videos["value"]["videos"]): if str(video["country"]).lower() == str(country).lower(): value = { "title": video["title"], "channel": video["channel_title"], "count": "1" } key = video["title"] exists = mp.contains(new_map, key) if not exists: mp.put(new_map, key, value) else: new_value = mp.get(new_map, key) new_value["value"]["count"] = str( int(new_value["value"]["count"]) + 1) mp.put(new_map, key, new_value["value"]) new_list = lt.newList('ARRAY_LIST', cmpfunction=cmpVideosByTrendingdays) for element in new_map["table"]["elements"]: if element["key"] != None: lt.addLast(new_list, element["value"]) sorted_list = quick.sort(new_list, cmpVideosByTrendingdays) result = lt.firstElement(sorted_list) result["country"] = country return result
def sortVideos(catalog, size, tipo): sub_list = lt.subList(catalog['videos'], 0, size) sub_list = sub_list.copy() if tipo == 'selection': start_time = time.process_time() sorted_list = ss.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, sorted_list elif tipo == 'insertion': start_time = time.process_time() sorted_list = ins.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, sorted_list elif tipo == 'shell': start_time = time.process_time() sorted_list = sa.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, sorted_list elif tipo == 'quick': start_time = time.process_time() sorted_list = qs.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, sorted_list elif tipo == 'merge': start_time = time.process_time() sorted_list = ms.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, sorted_list
def TrendingVideoCategory(catalog, category): """ Busca la categoria dentro del map y retorna la lista con los videos de esa categoria. Despues compara los titulos de los videos y busca cual es que mas se repite. """ idEsta = mp.contains(catalog['videosCategory'], category) if idEsta: entry = mp.get(catalog['videosCategory'], category) videos = me.getValue(entry) videos = sa.sort(videos, cmpTitle) diasValGrande = 0 diasValPequenio = 0 videoGrande = None videoPequenio = None videoAnterior = None iterador = it.newIterator(videos) while it.hasNext(iterador): video = it.next(iterador) title = video['title'] if videoPequenio == None: videoPequenio = title elif title == videoPequenio: diasValPequenio += 1 else: if diasValGrande < diasValPequenio: diasValGrande = diasValPequenio videoGrande = videoAnterior diasValPequenio = 1 videoPequenio = title videoAnterior = video return videoGrande, diasValGrande
def sortVideos(catalog, size, tipo): try: sub_list = lt.subList(catalog["videos"], 1, size) sub_list = sub_list.copy() if tipo == "Insertion": start_time = time.process_time() sorted_list = ints.sort(sub_list, cmpVideosbyViews) stop_time = time.process_time() elif tipo == "Selection": start_time = time.process_time() sorted_list = sets.sort(sub_list, cmpVideosbyViews) stop_time = time.process_time() elif tipo == "Shell": start_time = time.process_time() sorted_list = shls.sort(sub_list, cmpVideosbyViews) stop_time = time.process_time() elif tipo == "Merge": start_time = time.process_time() sorted_list = mrgs.sort(sub_list, cmpVideosbyViews) stop_time = time.process_time() elif tipo == "Quick": start_time = time.process_time() sorted_list = qcks.sort(sub_list, cmpVideosbyViews) stop_time = time.process_time() Tiempo_total = (stop_time - start_time) * 1000 return Tiempo_total, sorted_list except IndexError: pass
def requerimiento3(catalog, categor, tipodeorden, tipo): nueva = lt.newList(tipo) listae = {} for i in range(0, lt.size(catalog['videos'])): ele = lt.getElement(catalog['videos'], i) if ele['category_id'] == categor and not (ele['title'] in listae.keys()): listae[ele['title']] = 1 ele['dias'] = 1 lt.addLast(nueva, ele) elif ele['category_id'] == categor and (ele['title'] in listae.keys()): listae[ele['title']] = listae[ele['title']] + 1 ele['dias'] = listae[ele['title']] lt.addLast(nueva, ele) sublista = nueva.copy() start_time = time.process_time() if (tipodeorden == "shell"): sorted_list = sa.sort(sublista, cmpVideosBytiempo) elif (tipodeorden == "insertion"): sorted_list = si.sort(sublista, cmpVideosBytiempo) elif (tipodeorden == "selection"): sorted_list = ss.sort(sublista, cmpVideosBytiempo) elif (tipodeorden == "quick"): sorted_list = sq.sort(sublista, cmpVideosBytiempo) elif (tipodeorden == "merge"): sorted_list = sm.sort(sublista, cmpVideosBytiempo) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return sorted_list
def quickSortVideos(catalog, size, parametro): sub_list = lt.subList(catalog, 1, size) sub_list = sub_list.copy() if parametro == 'trending_days': start_time = time.process_time() quickSortList = qui.sort(sub_list, cmpVideosByTrendingdays) stop_time = time.process_time() elif parametro == 'views': start_time = time.process_time() quickSortList = qui.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elif parametro == 'likes': start_time = time.process_time() quickSortList = qui.sort(sub_list, cmpVideosByLikes) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return (elapsed_time_mseg, quickSortList)
def sortVideos(value_list, cmp): ''' Esta funcion organiza los videos por la cantidad de likes que tiene el video y retorna la lista ordenada ''' if lt.isEmpty(value_list): newlist = 1 else: newlist = qs.sort(value_list, cmp) return newlist
def nCountryVideos(catalog, country, id): """ Crea una lista con la informacion de los videos por pais y categoria """ countryVideoList = lt.newList('ARRAY_LIST') iterador = it.newIterator(catalog['videos']) while it.hasNext(iterador): elemento = it.next(iterador) if compareCountryCategory(elemento,country, id) == 0: lt.addLast(countryVideoList,elemento) countryVideoList = sa.sort(countryVideoList, cmpVideosByViews) return countryVideoList
def requerimiento1(catalog, pais, categoria, cantidad): paises = lt.getElement(catalog['paisescat'], 1) pais = paises[pais][categoria] lista_ordenada = qck.sort(pais, cmpVideosByViews) lista_retornar = lt.newList('ARRAY_LIST') iterador = it.newIterator(lista_ordenada) i = 0 while (it.hasNext(iterador)) and i < cantidad: elemento = it.next(iterador) lt.addLast(lista_retornar, elemento) i += 1 return lista_retornar
def sortList(tad_lista, metodo, orden='vistas'): if orden == "vistas": funcion_comp = cmpVideosByViews if orden == "video_id": funcion_comp = cmpVideosByVideoID if orden == "likes": funcion_comp = cmpVideosByLikes ''' if orden == "criterio" funcion_comp = cmpVideosBy_criterio ''' #se puede hacer mas elegante haciendo un diccionario de funciones como valores y los nombres como llaves #tanto lo del criterio como lo de los metodos if metodo == "shell": shell.sort(tad_lista, funcion_comp) if metodo == "selection": selection.sort(tad_lista, funcion_comp) if metodo == "insertion": insertion.sort(tad_lista, funcion_comp) if metodo == "quick": quick.sort(tad_lista, funcion_comp) if metodo == "merge": merge.sort(tad_lista, funcion_comp)
def sortVideos(list_2, alg): start_time = time.process_time() if alg == 1: sorted_list = sa.sort(list_2, cmpVideosByViews) elif alg == 2: sorted_list = sel.sort(list_2, cmpVideosByViews) elif alg == 3: sorted_list = ins.sort(list_2, cmpVideosByViews) elif alg == 4: sorted_list = merg.sort(list_2, cmpVideosByViews) else: sorted_list = quick.sort(list_2, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return sorted_list
def quickSort(lista,numero): numero=int(numero) start_time = time.process_time() if numero==1: qs.sort(lista, cmpVideosByvViewsAscendant) stop_time = time.process_time() elif numero==2: qs.sort(lista,cmpVideosByViewsDescendant) stop_time = time.process_time() elif numero==3: qs.sort(lista,cmpVideosById) stop_time = time.process_time() else: qs.sort(lista,cmpVideosByLikes) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time)*1000 return lista
def sortVideos(catalog, size, sortType): sub_list = lt.subList(catalog['videos'], 0, size) start_time = time.process_time() if sortType == 1: sorted_list = ss.sort(sub_list, cmpVideosByViews) elif sortType == 2: sorted_list = ins.sort(sub_list, cmpVideosByViews) elif sortType == 3: sorted_list = sa.sort(sub_list, cmpVideosByViews) elif sortType == 4: sorted_list = mg.sort(sub_list, cmpVideosByViews) else: sorted_list = qs.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, sorted_list
def sortVideos(catalog, size, iterable_ord): start_time = time.process_time() sub_list = lt.subList(catalog['title'], 0, size) if iterable_ord == "quicksort": new_title = qs.sort(sub_list, cmpVideosByViews) elif iterable_ord == "mergesort": new_title = ms.sort(sub_list, cmpVideosByViews) elif iterable_ord == "selectionsort": new_title = ss.sort(sub_list, cmpVideosByViews) elif iterable_ord == "insertionsort": new_title = ins.sort(sub_list, cmpVideosByViews) elif iterable_ord == "shellsort": new_title = shs.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, new_title
def tipo_de_orden_model(numero, catalog, size): sub_list = lt.subList(catalog['video'], 0, size) sub_list = sub_list.copy() start_time = time.process_time() if numero == 2: sorted_list = sa.sort(sub_list, compareviews) elif numero == 1: sorted_list = isort.sort(sub_list, compareviews) elif numero == 3: sorted_list = ssort.sort(sub_list, compareviews) elif numero == 4: sorted_list = quick.sort(sub_list, compareviews) else: sorted_list = merge.sort(sub_list, compareviews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, sorted_list
def mejoresVideosPorViews(catalog, numeroDeElementos, algoritmo): sub_list = lt.subList(catalog['videos'], 1, numeroDeElementos) sub_list = sub_list.copy() start_time = time.process_time() if algoritmo == "shellsort": sorted_list = sa.sort(sub_list, cmpVideosByViews) elif algoritmo == "insertionsort": sorted_list = ins.sort(sub_list, cmpVideosByViews) elif algoritmo == "selectionsort": sorted_list = sele.sort(sub_list, cmpVideosByViews) elif algoritmo == "mergesort": sorted_list = merge.sort(sub_list, cmpVideosByViews) elif algoritmo == "quicksort": sorted_list = quick.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time -start_time)*1000 return elapsed_time_mseg, sorted_list
def sortVideos(catalog, size, sort_type): sub_list = lt.subList(catalog['videos'], 1, size) sub_list = sub_list.copy() start_time = time.process_time() if sort_type == "se": sorted_list = se.sort(sub_list, cmpVideosByViews) elif sort_type == "ins": sorted_list = ins.sort(sub_list, cmpVideosByViews) elif sort_type == "sa": sorted_list = sa.sort(sub_list, cmpVideosByViews) elif sort_type == "mg": sorted_list = mg.sort(sub_list, cmpVideosByViews) elif sort_type == "qk": sorted_list = qk.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, sorted_list
def sortVideos(catalog, size, tipo, cmpfunction): if size != "None": sub_list = lt.subList(catalog['videos'], 0, size) else: sub_list = catalog sub_list = sub_list.copy() if tipo == 1: sorted_list = se.selection_sort(sub_list, cmpfunction) elif tipo == 2: sorted_list = it.insertion_sort(sub_list, cmpfunction) elif tipo == 3: sorted_list = sa.shell_sort(sub_list, cmpfunction) elif tipo == 4: sorted_list = qu.sort(sub_list, cmpfunction) elif tipo == 5: sorted_list = me.mergesort(sub_list, cmpfunction) return sorted_list
def sortByHashTags(lista): """ Ordena valores de mayor a menor. En este caso, ordena strings de hashtags con sort 'quick' según la función compareHashtags(). Retorna: una tupla, donde [0] es el tiempo [ms] que tarda y [1] es la lista ordenada. """ size = lt.size(lista) sub_list = lt.subList(lista, 0, size) sub_list = sub_list.copy() t1 = time.process_time() sorted_list = qui.sort(sub_list, compareHashtags) t2 = time.process_time() tiempo_ms = (t2 - t1) * 1000 sub_list = None return (tiempo_ms, sorted_list)
def sort_type(catalog, size, type): sub_list = lt.subList(catalog['videos'], 0, size) sub_list = sub_list.copy() start_time = time.process_time() if type == "insertionsort": sorted_list = it.sort(sub_list, cmpVideosByViews) elif type == "selectionsort": sorted_list = sr.sort(sub_list, cmpVideosByViews) elif type == "mergesort": sorted_list = mt.sort(sub_list, cmpVideosByViews) elif type == "quicksort": sorted_list = qt.sort(sub_list, cmpVideosByViews) else: sorted_list = sa.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, sorted_list
def sortVideosbyViews(catalog, ordenamiento, size): """ Organiza todos los videos de una lista por número de views y retorna una nueva lista organizada """ sortedlist = lt.subList(catalog, 0, size) sortedlist = sortedlist.copy() start_time = time.process_time() if ordenamiento == 1: sublist = nsr.sort(sortedlist, cmpVideosByViews) elif ordenamiento == 2: sublist = stn.sort(sortedlist, cmpVideosByViews) elif ordenamiento == 3: sublist = shr.sort(sortedlist, cmpVideosByViews) elif ordenamiento == 4: sublist = qst.sort(sortedlist, cmpVideosByViews) elif ordenamiento == 5: sublist = mst.sort(sortedlist, cmpVideosByViews) return sublist
def inefficient_ordering(videos, size, algorithm='shell'): if (size > lt.size(videos)): size = lt.size(videos) temp_list = lt.subList(videos, 0, size) temp_list = temp_list.copy() start_time = time.process_time() if (algorithm == 'shell'): temp_list = sa.sort(temp_list, cmpVideosByViews) elif (algorithm == 'insertion'): temp_list = ie.sort(temp_list, cmpVideosByViews) elif (algorithm == 'selection'): temp_list = se.sort(temp_list, cmpVideosByViews) elif (algorithm == 'quick'): temp_list = qk.sort(temp_list, cmpVideosByViews) else: temp_list = mr.sort(temp_list, cmpVideosByViews) stop_time = time.process_time() elapsed_time_mseg = (stop_time - start_time) * 1000 return elapsed_time_mseg, temp_list
def sortVideos(catalog, size, tiposort): sorted_list = [] sub_list = lt.subList(catalog['videos'], 0, size) sub_list = sub_list.copy() start_time = time.process_time() if tiposort == 1: sorted_list = sa.sort(sub_list, cmpVideosByViews) elif tiposort == 2: sorted_list = insort.sort(sub_list, cmpVideosByViews) elif tiposort == 3: sorted_list = selsort.sort(sub_list, cmpVideosByViews) elif tiposort == 4: sorted_list = mrgsort.sort(sub_list, cmpVideosByViews) elif tiposort == 5: sorted_list = qsort.sort(sub_list, cmpVideosByViews) stop_time = time.process_time() msegtime = (stop_time - start_time) * 1000 return msegtime, sorted_list
def fourthReq(catalog, data_size, country, tag): """ Completa el requerimiento #4 """ info = catalog["videos"]["table"]["elements"] new_list = lt.newList() for videos in info: if videos["key"] != None: for video in lt.iterator(videos["value"]["videos"]): if (str(video["country"]).lower() == str(country).lower() ) and ((str(tag)).lower() in (str(video["tags"])).lower()): lt.addLast(new_list, video) sorted_list = quick.sort(new_list, cmpVideosByLikes) try: data_sublist = lt.subList(sorted_list, 1, data_size) data_sublist = data_sublist.copy() return data_sublist except: return sorted_list