-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·142 lines (122 loc) · 4.44 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#import numpy and pandas (for data) and NearestNeighbors (for neighbor calculations)
import numpy as np
import random
import pandas as pd
import matplotlib.pyplot as plt
import json
import pprint
import time
import sys
import os
import math
import warnings
#our modules
import helper
import prodplay
import spotify
import plot
import algos
import testing
from songdataset import SongDataset, SegmentDataset
#get important personal information from Spotify API
datasetpath = "data/deezer/deezer-std-all.csv"
segmentpath = "data/deezer/segments/cnt100.csv"
info = helper.loadConfig("config.json")
scores = testing.ARG_DISTANCES
sp, spo = spotify.Spotify(
info["auth"]["client_id"],
info["auth"]["client_secret"],
info["auth"]["redirect_uri"],
info["auth"]["username"],
info["auth"]["scope"]
)
songdata = SongDataset(
name="Deezer+Spotify",
cols=info["cols"]["deezer"] + info["cols"]["spotify"],
path=datasetpath, knn=True, verbose=True,
feat_index = 5, arousal = 4, valence = 3,
)
pointdata = SongDataset(
name="Deezer",
cols=info["cols"]["deezer"],
path=datasetpath, knn=True, verbose=True,
feat_index = 3, arousal = 4, valence = 3,
)
segmentdata = SegmentDataset(
name="Deezer+Segments",
cols=info["cols"]["deezer"] + info["cols"]["segments"],
path=segmentpath, knn=True, verbose=True,
feat_index = 5, arousal = 4, valence = 3,
)
print("N: {}".format(len(songdata)))
print("Sqrt(N): {}".format(np.sqrt(len(songdata))))
print("N2:", songdata.unique_size)
# 3135555 = Daft Punk - Digital Love (0.950468991,0.572575336)
# 3135561 = Daft Punk - Something About Us (-0.317973857,-0.399224044)
# 540954 = Rachael Yamagata - 1963 (1.070081923,1.018911652)
# 533164 = Patty Loveless - How Can I Help U ... (-1.636899729,-0.45914527)
user_orig = 533164
user_dest = 540954
n_songs_reqd = 12
orig_point = np.array([
pointdata.full_df.loc[user_orig]['valence'],
pointdata.full_df.loc[user_orig]['arousal']
])
dest_point = np.array([
pointdata.full_df.loc[user_dest]['valence'],
pointdata.full_df.loc[user_dest]['arousal']
])
point_diff = dest_point - orig_point
point_step = point_diff / (n_songs_reqd - 1)
# target = [orig_point]
# for i in range(1, (n_songs_reqd - 1)):
# target.append(orig_point + (i * point_step))
# target.append(dest_point)
# target = np.array(target)
testsuite = [
# {"name": "points only", "dataset": pointdata},
{"name": "with features", "dataset": songdata},
# {"name": "with segments", "dataset": segmentdata},
]
testpoints = []
testdir = helper.makeTestDir("main")
print("N Songs Reqd:", n_songs_reqd)
print("orig:", user_orig,
pointdata.full_df.loc[user_orig]['artist_name'], "\t",
pointdata.full_df.loc[user_orig]['track_name'], "\t",
"({},{})".format(
np.around(orig_point[0], decimals=2),
np.around(orig_point[1], decimals=2)
))
print("dest:", user_dest,
pointdata.full_df.loc[user_dest]['artist_name'], "\t",
pointdata.full_df.loc[user_dest]['track_name'], "\t",
"({},{})".format(
np.around(dest_point[0], decimals=2),
np.around(dest_point[1], decimals=2)
))
evals = {}
for obj in testsuite:
name = obj["name"]
data = obj["dataset"]
playlistDF = prodplay.makePlaylist(
data, user_orig, user_dest, n_songs_reqd, verbose = 1
)
testpoints.append(playlistDF[["valence", "arousal"]].to_numpy())
print()
print(playlistDF.to_string())
with warnings.catch_warnings():
warnings.simplefilter("ignore")
playlistDF.to_latex("{}/{}.tex".format(testdir, name))
evals[name] = testing.evaluate(playlistDF, segmentdata, verbose=1)
# # Generate Spotify Playlist.
# title = "Playlist {} {}".format(name, str(time.strftime("%Y-%m-%d-%H:%M")))
# spid = spotify.makePlaylist(sp, spo, title, playlistDF["id-spotify"], True)
# splink = "https://open.spotify.com/playlist/{}".format(spid)
# print("\nSpotify Playlist: {}".format(splink))
plot.playlist(testpoints,
# legend=["ideal", "points only", "with features", "segments"],
file = "{}/compare-graph.png".format(testdir),
title = "Playlist from {} to {}".format(user_orig, user_dest)
)
helper.jsonout(evals, "{}/evals.json".format(testdir))