def addActor(catalog, movie): """ Esta función adiciona una pelicula por su actor en el map """ actors = catalog['actor'] actor_names = [ movie["actor1_name"], movie["actor2_name"], movie["actor3_name"], movie["actor4_name"], movie["actor5_name"] ] movie_avg = movie['vote_average'] director_name = movie["director_name"] title = movie["title"] for actor_name1 in actor_names: actor_name = actor_name1.lower() if actor_name != "none": existActor = mp.contains(actors, actor_name) if existActor: entry = mp.get(actors, actor_name) actor = me.getValue(entry) else: actor = newActor(actor_name) mp.put(actors, actor_name, actor) lt.addLast(actor['movies'], title) actor_avg = actor['vote_average'] if (actor_avg == 0.0): actor['vote_average'] = float(movie_avg) else: actor['vote_average'] = actor_avg + float(movie_avg) actor_dir = actor["directors"] existDir = mp.contains(actor_dir, director_name) if existDir: entry = mp.get(actor_dir, director_name) times = (me.getValue(entry) + 1) me.setValue(entry, times) if times > actor["most_times"]: actor["most_times"] = times actor["most_feat"] = director_name else: if director_name != "none": times1 = 1 mp.put(actor_dir, director_name, times1) if times1 > actor["most_times"]: actor["most_times"] = times1 actor["most_feat"] = director_name
def addAnchoQueue(catalog, point, ancho): if mp.contains(catalog["anchos_landing"], point): cola = me.getValue(mp.get(catalog["anchos_landing"], point)) pq.insert(cola, ancho) else: cola = pq.newMinPQ(cmpfunction_minPQ) pq.insert(cola, ancho) mp.put(catalog["anchos_landing"], point, cola)
def addCable(catalog, connection): if not mp.contains(catalog['cables'], connection['cable_id']): filteredcable = dict( filter( lambda elem: elem[0] != 'origin' and elem[0] != 'destination', connection.items())) mp.put(catalog['cables'], connection['cable_id'], filteredcable) filteredcable.clear()
def search_genres(catalog, genres): for index in range(len(genres)): genres[index] = genres[index].capitalize() existgenre = mp.contains(catalog['genres'], genres[index]) if not existgenre: print('Un género no se encuentra. Intente de nuevo.') return None return genres
def getVideosByCountry(catalog, country): existe = mp.contains(catalog['countries'], country) if exist: entry = lt.get(catalog['countries'], country) country1 = me.getValue(entry) else: country1 = "No existe dicho Pais" return country1
def getCategoryById(catalog, categoryId): categoryExists = mp.contains(catalog["categories"], categoryId) if categoryExists: entry = mp.get(catalog["categories"], categoryId) category = me.getValue(entry) else: category = None return category
def addIdCastingMovie(catalog, authorname, movie): authors = catalog['id_casting'] existauthor = mp.contains(authors, authorname) if existauthor: return "Hay dos peliculas con mismo id, compruebe sus datos." else: author = movie mp.put(authors, authorname, author)
def getCategoryIdByName(catalog, categoryName): categoryExists = mp.contains(catalog['category_ids'], categoryName) if categoryExists: entry = mp.get(catalog["category_ids"], categoryName) categoryId = me.getValue(entry) else: categoryId = None return categoryId
def AddBike(bikes, EachBikeID, trip): BikesHash = bikes["BikesIDs"] ExistBike = m.contains(BikesHash, EachBikeID) if ExistBike: entry = m.get(BikesHash, EachBikeID) ThatBike = me.getValue(entry) #print (ThatBike) HashFechas = ThatBike['Fechas'] ExistDate = m.contains( HashFechas, str((datetime.datetime.strptime((trip["starttime"][:19]), '%Y-%m-%d %H:%M:%S')).date())) if ExistDate: entryDate = m.get( HashFechas, str((datetime.datetime.strptime((trip["starttime"][:19]), '%Y-%m-%d %H:%M:%S')).date())) DichaFecha = me.getValue(entryDate) UpdateTimes(DichaFecha, trip) #print (DichaFecha) else: GivenDate = NewDate(trip) m.put( ThatBike["Fechas"], str((datetime.datetime.strptime((trip["starttime"][:19]), '%Y-%m-%d %H:%M:%S')).date()), GivenDate) else: ThatBike = NewBike(EachBikeID) m.put(BikesHash, EachBikeID, ThatBike) entry = m.get(BikesHash, EachBikeID) ThatBike = me.getValue(entry) ThatBike["Fechas"] = m.newMap(71, maptype='PROBING', loadfactor=0.5, comparefunction=compareIds) GivenDate = NewDate(trip) m.put( ThatBike["Fechas"], str((datetime.datetime.strptime((trip["starttime"][:19]), '%Y-%m-%d %H:%M:%S')).date()), GivenDate)
def addInterconnection(analyzer,connection): if not mp.contains(analyzer['interconnections'], connection['origin']): lista=lt.newList('ARRAY_LIST') lt.addLast(lista,1) lt.addLast(lista,connection['cable_id']) mp.put(analyzer['interconnections'],connection['origin'],lista) elif mp.contains(analyzer['interconnections'], connection['origin']): entry=mp.get(analyzer['interconnections'],connection['origin']) lista=me.getValue(entry) esta=False for i in lt.iterator(lista): if i==connection['cable_id']: esta=True if not esta: numero=lt.removeFirst(lista) numero+=1 lt.addFirst(lista,numero)
def obtener_videos_categoria(catalog, categoria): posvideo = mp.contains(catalog['categorias'], categoria) if posvideo: pais = mp.get(catalog['categorias'], categoria) return me.getValue(pais) return None
def addCompany(analyzer, company_name, taxiid, trip): exist_company = m.contains(analyzer['mapcompany'], company_name) if exist_company: entry = m.get(analyzer['mapcompany'], company_name) entry = me.getValue(entry) entry["Cantidad de servicios: "] += 1 if not m.contains(analyzer["taxids"], taxiid): entry["taxis: "] += 1 m.remove(analyzer["taxids"], taxiid) else: company = Newcompany(company_name) m.put(analyzer['mapcompany'], company_name, company) entry = m.get(analyzer['mapcompany'], company_name) entry = me.getValue(entry) if not m.contains(analyzer["taxids"], taxiid): entry["taxis: "] += 1 m.remove(analyzer["taxids"], taxiid)
def getVideosbyCatLikes(catalog,category): vid_cat=getCat(catalog,category) if vid_cat != 0: exist = mp.contains(catalog['video_category'], vid_cat) if exist: entry = mp.get(catalog['video_category'],vid_cat) li = me.getValue(entry) return li
def addEvent(catalog, event): ccs = ['energy', 'tempo', 'liveness', 'acousticness'] lt.addFirst(catalog['events'], event) artist = event['artist_id'] track = event['track_id'] updateTempoIndex(catalog['tempo_req4'], event, 'tempo') if mp.contains(catalog['uni_tracks'], track) == False: a = {'tempo': event['tempo'], 'hashtags': lt.newList(), 't_vader': 0} mp.put(catalog['uni_tracks'], track, a) catalog['uni_artists'][artist] = 1 y = 0 while y < len(ccs): main = ccs[y] main_val = event[main] mini = catalog['sup_inf'][main] mini_val = event[mini] if not main in catalog: catalog[main] = om.newMap() if (om.contains(catalog[main], main_val)) == False: om.put(catalog[main], main_val, om.newMap()) a = om.get(catalog[main], main_val) a = me.getValue(a) if (om.contains(a, mini_val)) == False: a = om.get(catalog[main], main_val) a = me.getValue(a) om.put(a, mini_val, lt.newList()) alpha = om.get(catalog[main], main_val) alpha = me.getValue(alpha) alpha = om.get(alpha, mini_val) alpha = me.getValue(alpha) lt.addFirst(alpha, event) y += 1 #para crear arbol de fechas-------------------------- mapa_track = mp.get(catalog['track'], event['track_id']) info = {} list_track = me.getValue(mapa_track)['lstevents'] for i in lt.iterator(list_track): if event['user_id'] == i['user_id'] and event['created_at'] == i[ 'created_at']: hashtag = mp.get(catalog['hashtag_vader'], i['hashtag']) if hashtag != None: h = hashtag['key'] vader = hashtag['value'] event['hashtag'] = h event['vader'] = vader addTimeStamp(catalog['time_stamps'], event)
def addConnectionToLandingMapVer3(data, mapa): name = data['name'].split(', ')[-1] entry = mp.get(mapa, name) if mp.contains(mapa, name): value = me.getValue(entry) else: value = newDataEntry() lt.addLast(value['cables'], data) mp.put(mapa, name, value)
def tendencias(mapp, videoid, video): existvideo = mp.contains(mapp, str(videoid)) if existvideo: pareja = mp.get(mapp, videoid) trending = me.getValue(pareja) trending["tendencias"] += 1 else: trending = {'videoid': videoid, 'tendencias': 1, 'video': video} mp.put(mapp, videoid, trending)
def addConnectionToMap(analyzer): iterator0 = it.newIterator(analyzer['connections']) while it.hasNext(iterator0): station = it.next(iterator0) if not mp.contains(analyzer['connections_map'], station['origin']): value = createVertexOrigin(station) mp.put(analyzer['connections_map'], station['origin'], value) if not mp.contains(analyzer['connections_map'], station['destination']): value = createVertexDestination(station) mp.put(analyzer['connections_map'], station['destination'], value) return analyzer
def addStationF(citibike, trip): if m.contains(citibike["StationF"], trip['end station id']) == True: n = m.get(citibike["StationF"], trip['end station id']) lt.addLast(en.getValue(n), 2020 - int(trip['birth year'])) else: N = lt.newList("ARRAY_LIST") lt.addLast(N, 2020 - int(trip['birth year'])) m.put(citibike["StationF"], trip['end station id'], N)
def addDirectorActor(actor, directorName): directors = actor['directores'] existDirector = mp.contains(directors, directorName) if existDirector: entry = mp.get(directors, directorName) contador = me.getValue(entry) me.setValue(entry,contador+1) else: mp.put(directors, directorName, 1)
def getCat(catalog,category): exist = mp.contains(catalog['categories'], category) if exist: cati=mp.get(catalog['categories'],category) cat_id= me.getValue(cati) else: cat_id=0 return cat_id
def addCategoryIdVideo(catalog, categoryId, video): catego = catalog['categoryIds'] if mp.contains(catego, categoryId): g = mp.get(catego, categoryId) category = me.getValue(g) else: category = newCategory(categoryId) mp.put(catego, categoryId, category) lt.addLast(category['videos'], video)
def addCountryVideo(catalog, countryName, video): countries = catalog['countries'] if mp.contains(countries, countryName): g = mp.get(countries, countryName) country = me.getValue(g) else: country = newCountry(countryName) mp.put(countries, countryName, country) lt.addLast(country['videos'], video)
def addConnectionToLandingMapVer4(connection, mapa): cable_name = connection['cable_name'] entry = mp.get(mapa, cable_name) if mp.contains(mapa, cable_name): value = me.getValue(entry) else: value = newDataEntry2() lt.addLast(value['landing_points'], connection) mp.put(mapa, cable_name, value)
def newHashtagReference(catalog, tid, hashtag): hashtags = catalog['hashtagReference'] if mp.contains(hashtags, tid): l = mp.get(hashtags, tid)["value"] l.append(hashtag) mp.put(hashtags, tid, l) else: l = [hashtag] mp.put(hashtags, tid, l)
def addTagVideo(catalog, tagName, video): tags = catalog['tags'] if mp.contains(tags, tagName): entry = mp.get(tags, tagName) tag = me.getValue(entry) else: tag = newTag(tagName) mp.put(tags, tagName, tag) lt.addLast(tag['videos'], video)
def getStation(citibike, idStation): """ Args:\n citibike: El archivo en total; idStation el vertice <end station id>-<start station id> """ if m.contains(citibike['name_IDstations'], idStation): keyValue = m.get(citibike['name_IDstations'], idStation) return (keyValue['key'], keyValue['value']) return None, None
def getStation(analyzer, idStation): """ Args:\n citibike: El archivo en total; idStation el vertice <end station id>-<start station id> """ if m.contains(analyzer['EstacionesXid'], idStation): keyValue = m.get(citibike['EstacionesXid'], idStation) return (keyValue['key'], keyValue['value']) return None, None
def addUsertrack(analyzer, data): exists = mp.contains(analyzer['contextContent'], data['track_id']) if exists: entry = mp.get(analyzer['contextContent'], data['track_id']) newL = me.getValue(entry) else: newL = lt.newList() lt.addLast(newL, data['hashtag']) mp.put(analyzer['contextContent'], data['track_id'], newL)
def add_info_cable(catalog: dict, cable_name: str, cable_id: str, cable_length: str, cable_rfs: str, owners: str, capacityTBPS: str) -> None: cables = catalog["cables"] exist = mp.contains(cables, cable_id) if (not exist): cable = crear_cable(cable_name, cable_id, cable_length, cable_rfs, owners, capacityTBPS) mp.put(cables, cable_id, cable)
def addLandingPoint(analyzer, datalandingpoint): map = analyzer['landingpoints'] landingpoint = datalandingpoint['landing_point_id'] existlandingpoint = mp.contains(map, landingpoint) if not existlandingpoint: entry = {'data': datalandingpoint, 'points' : lt.newList()} mp.put(map, landingpoint, entry)