-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreccomendationEngine.py
More file actions
185 lines (134 loc) · 6.9 KB
/
Copy pathreccomendationEngine.py
File metadata and controls
185 lines (134 loc) · 6.9 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Colton Payne
import webbrowser
import PySimpleGUI as sg
import imageManager
import spotifyAPI
class ReccomendationEngine:
global imgArray
imgArray = []
global nameList
nameList = []
global typeList
typeList = []
global urlList
urlList = []
def __init__(self) -> None:
pass
def update_likes(cur, conn, a_id, isPodcast):
# Set the like score to 1000 if a song is liked- prevents the system from reccomending a song the user has already liked
update_string = 'UPDATE "Audio" SET "a_likeDislike" = -10000 WHERE a_id='
update_string = update_string + str(a_id)
cur.execute(update_string)
conn.commit()
# Add 30 points to the like score if a song or podcast of the same genre is liked
if(isPodcast):
update_string = 'Update "Podcast" SET "a_likeDislike" = "a_likeDislike" + 30 WHERE p_genre = (SELECT p_genre FROM "Podcast" where a_id = '
update_string = update_string + str(a_id)
update_string = update_string + ')'
else:
update_string = 'Update "Song" SET "a_likeDislike" = "a_likeDislike" + 30 WHERE s_genre = (SELECT s_genre FROM "Song" where a_id = '
update_string = update_string + str(a_id)
update_string = update_string + ')'
cur.execute(update_string)
conn.commit()
# Add 60 points to the like score if a song or podcast by the same creator is liked
# Fetch a list of a_id's by the artist who has made this piece of auido
update_string = 'SELECT s.a_id FROM "Audio" s, "CreatedBy" cb, "Creator" cr WHERE s.a_id= cb.a_id AND cb.c_id = cr.c_id AND c_name = (SELECT cr.c_name FROM "Creator" cr, "Audio" au, "CreatedBy" cB WHERE cr.c_id = cb.c_id AND cb.a_id = au.a_id AND AU.A_ID = '
update_string = update_string + str(a_id)
update_string = update_string + ')'
cur.execute(update_string)
audioList = cur.fetchall()
# Add 60 like points to the matching a_id's
for a in audioList:
new_update_string = 'Update "Audio" SET "a_likeDislike" = "a_likeDislike" + 60 WHERE a_id = '
new_update_string = new_update_string + str(a[0])
cur.execute(new_update_string)
conn.commit()
def update_dislikes(cur, conn, a_id, isPodcast):
# Set the like score to 1000 if a song is liked- prevents the system from reccomending a song the user has already liked
update_string = 'UPDATE "Audio" SET "a_likeDislike" = -10000 WHERE a_id='
update_string = update_string + str(a_id)
cur.execute(update_string)
conn.commit()
# Add 30 points to the like score if a song or podcast of the same genre is liked
if(isPodcast):
update_string = 'Update "Podcast" SET "a_likeDislike" = "a_likeDislike" - 30 WHERE p_genre = (SELECT p_genre FROM "Podcast" where a_id = '
update_string = update_string + str(a_id)
update_string = update_string + ')'
else:
update_string = 'Update "Song" SET "a_likeDislike" = "a_likeDislike" - 30 WHERE s_genre = (SELECT p_genre FROM "Podcast" where a_id = '
update_string = update_string + str(a_id)
update_string = update_string + ')'
cur.execute(update_string)
conn.commit()
# Add 60 points to the like score if a song or podcast by the same creator is liked
# Fetch a list of a_id's by the artist who has made this piece of auido
update_string = 'SELECT s.a_id FROM "Audio" s, "CreatedBy" cb, "Creator" cr WHERE s.a_id= cb.a_id AND cb.c_id = cr.c_id AND c_name = (SELECT cr.c_name FROM "Creator" cr, "Audio" au, "CreatedBy" cB WHERE cr.c_id = cb.c_id AND cb.a_id = au.a_id AND AU.A_ID = '
update_string = update_string + str(a_id)
update_string = update_string + ')'
cur.execute(update_string)
audioList = cur.fetchall()
# Add 60 like points to the matching a_id's
for a in audioList:
new_update_string = 'Update "Audio" SET "a_likeDislike" = "a_likeDislike" - 60 WHERE a_id = '
new_update_string = new_update_string + str(a[0])
cur.execute(new_update_string)
conn.commit()
print("Disliked")
def open_reccomendation_window(cur, conn):
# Create five images
cur.execute('SELECT a_name from "Audio" ORDER BY "a_likeDislike" desc limit 6')
for a in cur:
nameList.append(a[0])
cur.execute('SELECT a_rating from "Audio" ORDER BY "a_likeDislike" desc limit 6')
for a in cur:
typeList.append(a[0])
counter = 0
for a in typeList:
# Audio is a song
if(typeList[a] == 1):
# create image from song name
imgUrl = spotifyAPI.spotify.get_image(nameList[counter])
imageBox = imageManager.ImageManager.create_image(imgUrl, False)
imgArray.append(imageBox)
# get link to song
songUrl = spotifyAPI.spotify.get_Song(nameList[counter])
urlList.append(songUrl)
else:
# create image from podcast name
imgUrl = spotifyAPI.spotify.get_podcastImage(nameList[counter])
imageBox = imageManager.ImageManager.create_image(imgUrl, False)
imgArray.append(imageBox)
# get link to podcast
podcastUrl = spotifyAPI.spotify.get_podcastURL(nameList[counter])
urlList.append(podcastUrl)
counter = counter + 1
print(nameList)
# ------ Window Layout ------
layout = [
[imgArray[0], imgArray[1]],
[imgArray[2], imgArray[3]],
[imgArray[4], imgArray[5]]
]
# ------ Create Window ------
window = sg.Window('Reccomendations', layout,
ttk_theme='clam',
resizable=True)
# ------ Event Loop ------
while True:
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED:
break
if event == 0:
webbrowser.open(urlList[0])
if event == 1:
webbrowser.open(urlList[1])
if event == 2:
webbrowser.open(urlList[2])
if event == 3:
webbrowser.open(urlList[3])
if event == 4:
webbrowser.open(urlList[4])
if event == 5:
webbrowser.open(urlList[5])