예제 #1
0
def mergeDictionnaries():
    '''Merge temporary dictionaries into one'''
    print("----Merging generated dictionaries----")
    files = []
    files = glob.glob(savePath + "*.txt")
    print("Nb files : " + str(len(files)))
    ArtistsMainDic = dict()
    ArtistsAllDic = dict()

    for file in files:
        filename = file.replace(".txt", "")
        dictTemp = LU.loadDictionary(filename, path="")

        if ("All" in file):
            ArtistsAllDic = {**ArtistsAllDic, **dictTemp}

        if ("Main" in file):
            ArtistsMainDic = {**ArtistsMainDic, **dictTemp}

    print("Artist dictionaries loaded. Merging...", end="")
    LU.saveDictionary(ArtistsAllDic, AllGenresDicName, savePath, enc="UTF-8")
    LU.saveDictionary(ArtistsMainDic, MainGenreDicName, savePath, enc="UTF-8")
    print("done.")
    print("Deleting temp files...")
    for file in files:
        if ("-" in file and "temp" in file):
            print("Deleting temp file " + file)
            os.remove(file)
    print("DONE.")
예제 #2
0
def expand(df_src, df_dst="completeWithCoordinates.csv", dic_file="locationDic"):
    df = pd.read_csv(df_src)
    if('Unnamed: 0' in df.columns):
        df = df.drop('Unnamed: 0', 1)
    dic = lu.loadDictionary(dic_file)
    dic["Palais-des-Congrès"] = (47.134881, 7.248004000000001)
    dic["Il_Caffè"] = (46.9382202, 7.787970900000001)
    dic["Festivalgelände"] = (47.4222173, 9.3395195)
    dic["Festivalgelände-am-Rotten"] = dic["Festivalgelände"]
    dic["Römerareal"] = (47.136266, 7.30622)
    addCoordinatesColumn(df, dic, replace = True, inplace=True)
    lu.saveDictionary(dic, dic_file)
    df.to_csv(df_dst, index=False)
예제 #3
0
	DataFrame = None
	SpotifyDic = None
	RADic = None
	WikiDic = None
	GenresDic = None
	
	#Getting the dataframe
	try:
		Dataframe = pd.read_csv(PATH_DF,index_col=0)
	except:
		print("Error occured during read of "+PATH_DF+". Maybe can't find the file.")
		sys.exit(0)
	
	#Getting the Spotify dictionary
	try:
		SpotifyDic = LU.loadDictionary(filename_spotify_dic,PATH_DIC,encoding)
	except:
		print("Can't find the dictionary of Spotify genres.")
		SpotifyDic = None
		
	#Getting the RA dictionary
	try:
		RADic = LU.loadDictionary(filename_ra_dic,PATH_DIC,encoding)
	except:
		print("Can't find the dictionary of RA genres.")
		RADic = None
		
	#Getting the Wikipedia dictionary
	try:
		WikiDic = LU.loadDictionary(filename_wiki_dic,PATH_DIC,encoding)
	except:
예제 #4
0
def ExportGenres(ClubDataFrame, init, end):

    ArtistsSet = set()
    ArtistDicoMain = dict()
    ArtistDicoAll = dict()

    filenameMain = "ArtistDicoMain-" + str(init) + "-" + str(end) + "-temp"
    filenameAll = "ArtistDicoAll-" + str(init) + "-" + str(end) + "-temp"

    #Loading artists dictionaries
    try:
        ArtistDicoMain = LU.loadDictionary(filenameMain,
                                           path=savePath,
                                           enc="UTF-8")
        ArtistDicoAll = LU.loadDictionary(filenameAll,
                                          path=savePath,
                                          enc="UTF-8")
        ArtistsSet = set(ArtistDicoMain.keys())
    except:
        print("Cannot find dictionnaries")

    ##Loading genre Dictionary
    try:
        print("Loading genre dictionnary : " + dictionaryPath + dictionary +
              ".txt")
        LU.loadDictionary(dictionary, dictionaryPath, enc="UTF-8")
    except:
        print("Cannot find genre dictionnary : " + dictionaryPath +
              dictionary + ".txt")

    ClubDataFrame["Genre"] = None
    ClubDataFrame["All Genres"] = None

    print("Retrieving genre for events[" + str(init) + "," + str(end) + "] :")

    i = 0
    for id, row in ClubDataFrame[init:end].iterrows():
        genres = []
        lineup = row["LineUp"]
        artists = SplitLineup(lineup)

        for artist in artists:
            mainGenre = None
            allGenres = None

            if (artist in ArtistsSet):
                mainGenre = ArtistDicoMain.get(artist)
                allGenres = ArtistDicoAll.get(artist)
            else:
                #Updating dictionnaries
                ArtistsSet.add(artist)
                allGenres = AE.getGenre(artist, ReturnAllGenres=True)
                mainGenre = AE.getMaxGenre(allGenres)
                ArtistDicoMain.update({artist: mainGenre})
                ArtistDicoAll.update({artist: allGenres})

            #Adding to LineUp genres
            genres.append(mainGenre)

        if (len(genres) == 0):
            print(artists)
        else:
            maxGenre = AE.getMaxGenre(genres)
            #updating dataframe
            ClubDataFrame = ClubDataFrame.set_value(id, "Genre", maxGenre)
            ClubDataFrame = ClubDataFrame.set_value(id, "All Genres",
                                                    str(genres))
            ClubDataFrame = ClubDataFrame.set_value(id, "LineUp", str(artists))

        i += 1
        if (i % 10 == 0):
            print(str(i))
        if (i % 50 == 0):
            LU.saveDictionary(ArtistDicoMain,
                              filenameMain,
                              path=savePath,
                              enc="UTF-8")
            LU.saveDictionary(ArtistDicoAll,
                              filenameAll,
                              path=savePath,
                              enc="UTF-8")

    print("Extraction finished. Saving dictionnaries..")
    LU.saveDictionary(ArtistDicoMain, filenameMain, path=savePath, enc="UTF-8")
    LU.saveDictionary(ArtistDicoAll, filenameAll, path=savePath, enc="UTF-8")
    print("Finished.")
    mergeDictionnaries()