Skip to content

Commit

Permalink
skipped df
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdlb committed Oct 23, 2022
1 parent 0db1a17 commit 0c38421
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 10 deletions.
3 changes: 2 additions & 1 deletion backend/src/model/decision_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def __init__(self):
self.all_skipped = []
self.all_non_skipped = []
self.next_song = None
Path(settings.APP_PATH)
Path(settings.APP_PATH, "", "")


def decision_maker(self):
while True:
Expand Down
6 changes: 3 additions & 3 deletions backend/src/spotify_api/skip_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def listen(self):
self.previous_song = self.interface.get_current_song()
self.update_end_time()
while True:
if time.time() < self.end_time:
if time.time() < self.end_time - 1:
if self.previous_song["id"] != self.current_song["id"]:
self.all_skipped.append(self.previous_song)
self.save_all_skipped()
Expand All @@ -55,12 +55,12 @@ def listen(self):
def save_all_non_skipped(self):
self.all_non_skipped = self.all_non_skipped[-50:]
pd.DataFrame(self.all_skipped).to_csv(Path(settings.DATA_PATH, "player_data",
"non_skipped.csv"))
"non_skipped.csv"), index=False)

def save_all_skipped(self):
self.all_skipped = self.all_skipped[-50:]
pd.DataFrame(self.all_skipped).to_csv(Path(settings.DATA_PATH, "player_data",
"skipped.csv"))
"skipped.csv"), index=False)

def update_end_time(self):
try:
Expand Down
3 changes: 0 additions & 3 deletions data/player_data/non_skipped.csv

This file was deleted.

8 changes: 5 additions & 3 deletions data/player_data/skipped.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
,danceability,energy,key,loudness,mode,speechiness,acousticness,instrumentalness,liveness,valence,tempo,type,id,uri,track_href,analysis_url,duration_ms,time_signature,skip_state,date_saved,skip_probability
0,0.702,0.823,11,-3.329,1,0.473,0.198,0.0,0.163,0.323,160.995,audio_features,7zlvNFYfOu0aK1kxDAHnu6,spotify:track:7zlvNFYfOu0aK1kxDAHnu6,https://api.spotify.com/v1/tracks/7zlvNFYfOu0aK1kxDAHnu6,https://api.spotify.com/v1/audio-analysis/7zlvNFYfOu0aK1kxDAHnu6,58280,4,SKIPPEP,2022-10-23 11:46:33.359512,0.0
1,0.466,0.576,2,-10.491,1,0.408,0.126,0.000334,0.175,0.832,180.084,audio_features,2IoSF6KSDcw5V9eVSxgsm0,spotify:track:2IoSF6KSDcw5V9eVSxgsm0,https://api.spotify.com/v1/tracks/2IoSF6KSDcw5V9eVSxgsm0,https://api.spotify.com/v1/audio-analysis/2IoSF6KSDcw5V9eVSxgsm0,55147,4,,,
danceability,energy,key,loudness,mode,speechiness,acousticness,instrumentalness,liveness,valence,tempo,type,id,uri,track_href,analysis_url,duration_ms,time_signature,skip_state,date_saved,skip_probability
0.625,0.726,1,-2.144,1,0.031,0.335,0.0,0.273,0.559,119.994,audio_features,4ClnJdCaf6PLeLgStqb1e9,spotify:track:4ClnJdCaf6PLeLgStqb1e9,https://api.spotify.com/v1/tracks/4ClnJdCaf6PLeLgStqb1e9,https://api.spotify.com/v1/audio-analysis/4ClnJdCaf6PLeLgStqb1e9,138800,4,SKIPPEP,2022-10-23 12:11:13.989002,0.0
0.502,0.972,10,-3.96,0,0.0793,6.78e-05,0.000702,0.0627,0.729,138.019,audio_features,3twNvmDtFQtAd5gMKedhLD,spotify:track:3twNvmDtFQtAd5gMKedhLD,https://api.spotify.com/v1/tracks/3twNvmDtFQtAd5gMKedhLD,https://api.spotify.com/v1/audio-analysis/3twNvmDtFQtAd5gMKedhLD,197280,4,SKIPPEP,2022-10-23 12:11:57.420438,0.0
0.518,0.436,4,-14.134,1,0.0349,0.0157,0.000621,0.079,0.27,80.88,audio_features,6mcxQ1Y3uQRU0IHsvdNLH1,spotify:track:6mcxQ1Y3uQRU0IHsvdNLH1,https://api.spotify.com/v1/tracks/6mcxQ1Y3uQRU0IHsvdNLH1,https://api.spotify.com/v1/audio-analysis/6mcxQ1Y3uQRU0IHsvdNLH1,236973,4,SKIPPEP,2022-10-23 12:12:02.145146,0.0
0.688,0.835,8,-4.162,1,0.0911,0.0583,2.87e-06,0.0795,0.88,84.858,audio_features,6ndmKwWqMozN2tcZqzCX4K,spotify:track:6ndmKwWqMozN2tcZqzCX4K,https://api.spotify.com/v1/tracks/6ndmKwWqMozN2tcZqzCX4K,https://api.spotify.com/v1/audio-analysis/6ndmKwWqMozN2tcZqzCX4K,230493,4,,,
178 changes: 178 additions & 0 deletions notebooks/skiptify_generate_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,184 @@
"print('Done querying')\n",
"data_file.close()\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Unnamed: 0</th>\n",
" <th>danceability</th>\n",
" <th>energy</th>\n",
" <th>key</th>\n",
" <th>loudness</th>\n",
" <th>mode</th>\n",
" <th>speechiness</th>\n",
" <th>acousticness</th>\n",
" <th>instrumentalness</th>\n",
" <th>liveness</th>\n",
" <th>...</th>\n",
" <th>type</th>\n",
" <th>id</th>\n",
" <th>uri</th>\n",
" <th>track_href</th>\n",
" <th>analysis_url</th>\n",
" <th>duration_ms</th>\n",
" <th>time_signature</th>\n",
" <th>skip_state</th>\n",
" <th>date_saved</th>\n",
" <th>skip_probability</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>0.744</td>\n",
" <td>0.578</td>\n",
" <td>8</td>\n",
" <td>-10.574</td>\n",
" <td>0</td>\n",
" <td>0.0286</td>\n",
" <td>0.31900</td>\n",
" <td>0.133</td>\n",
" <td>0.104</td>\n",
" <td>...</td>\n",
" <td>audio_features</td>\n",
" <td>2rXC8O7kaYw7FjStybL2rz</td>\n",
" <td>spotify:track:2rXC8O7kaYw7FjStybL2rz</td>\n",
" <td>https://api.spotify.com/v1/tracks/2rXC8O7kaYw7...</td>\n",
" <td>https://api.spotify.com/v1/audio-analysis/2rXC...</td>\n",
" <td>202158</td>\n",
" <td>4</td>\n",
" <td>SKIPPEP</td>\n",
" <td>2022-10-23 12:03:19.042178</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>0.378</td>\n",
" <td>0.122</td>\n",
" <td>2</td>\n",
" <td>-19.785</td>\n",
" <td>1</td>\n",
" <td>0.0360</td>\n",
" <td>0.00697</td>\n",
" <td>0.958</td>\n",
" <td>0.125</td>\n",
" <td>...</td>\n",
" <td>audio_features</td>\n",
" <td>0ttF21hZCPw2merE3GsHcP</td>\n",
" <td>spotify:track:0ttF21hZCPw2merE3GsHcP</td>\n",
" <td>https://api.spotify.com/v1/tracks/0ttF21hZCPw2...</td>\n",
" <td>https://api.spotify.com/v1/audio-analysis/0ttF...</td>\n",
" <td>29827</td>\n",
" <td>4</td>\n",
" <td>SKIPPEP</td>\n",
" <td>2022-10-23 12:03:51.343571</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2</td>\n",
" <td>0.740</td>\n",
" <td>0.266</td>\n",
" <td>1</td>\n",
" <td>-17.222</td>\n",
" <td>1</td>\n",
" <td>0.9470</td>\n",
" <td>0.98600</td>\n",
" <td>0.000</td>\n",
" <td>0.508</td>\n",
" <td>...</td>\n",
" <td>audio_features</td>\n",
" <td>0EgkVzDidmq4MP57jZFeik</td>\n",
" <td>spotify:track:0EgkVzDidmq4MP57jZFeik</td>\n",
" <td>https://api.spotify.com/v1/tracks/0EgkVzDidmq4...</td>\n",
" <td>https://api.spotify.com/v1/audio-analysis/0Egk...</td>\n",
" <td>22747</td>\n",
" <td>3</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>3 rows × 22 columns</p>\n",
"</div>"
],
"text/plain": [
" Unnamed: 0 danceability energy key loudness mode speechiness \\\n",
"0 0 0.744 0.578 8 -10.574 0 0.0286 \n",
"1 1 0.378 0.122 2 -19.785 1 0.0360 \n",
"2 2 0.740 0.266 1 -17.222 1 0.9470 \n",
"\n",
" acousticness instrumentalness liveness ... type \\\n",
"0 0.31900 0.133 0.104 ... audio_features \n",
"1 0.00697 0.958 0.125 ... audio_features \n",
"2 0.98600 0.000 0.508 ... audio_features \n",
"\n",
" id uri \\\n",
"0 2rXC8O7kaYw7FjStybL2rz spotify:track:2rXC8O7kaYw7FjStybL2rz \n",
"1 0ttF21hZCPw2merE3GsHcP spotify:track:0ttF21hZCPw2merE3GsHcP \n",
"2 0EgkVzDidmq4MP57jZFeik spotify:track:0EgkVzDidmq4MP57jZFeik \n",
"\n",
" track_href \\\n",
"0 https://api.spotify.com/v1/tracks/2rXC8O7kaYw7... \n",
"1 https://api.spotify.com/v1/tracks/0ttF21hZCPw2... \n",
"2 https://api.spotify.com/v1/tracks/0EgkVzDidmq4... \n",
"\n",
" analysis_url duration_ms \\\n",
"0 https://api.spotify.com/v1/audio-analysis/2rXC... 202158 \n",
"1 https://api.spotify.com/v1/audio-analysis/0ttF... 29827 \n",
"2 https://api.spotify.com/v1/audio-analysis/0Egk... 22747 \n",
"\n",
" time_signature skip_state date_saved skip_probability \n",
"0 4 SKIPPEP 2022-10-23 12:03:19.042178 0.0 \n",
"1 4 SKIPPEP 2022-10-23 12:03:51.343571 0.0 \n",
"2 3 NaN NaN NaN \n",
"\n",
"[3 rows x 22 columns]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd \n",
"pd.read_csv(\"../data/player_data/skipped.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit 0c38421

Please sign in to comment.