UPDATE: Added recommended categories as well as streamer data
BUGFIX: Fixed wrong datatypes
This commit is contained in:
@@ -5,7 +5,8 @@ from utils.stream_utils import (
|
||||
user_stream,
|
||||
followed_live_streams,
|
||||
followed_streamers,
|
||||
stream_tags
|
||||
stream_tags,
|
||||
streamer_data
|
||||
)
|
||||
from utils.user_utils import get_user_id
|
||||
from blueprints.utils import login_required
|
||||
@@ -14,7 +15,8 @@ from utils.recommendation_utils import (
|
||||
recommendations_based_on_category,
|
||||
user_recommendation_category,
|
||||
followed_categories_recommendations,
|
||||
category_recommendations
|
||||
category_recommendations,
|
||||
user_category_recommendations
|
||||
)
|
||||
from utils.utils import most_popular_category
|
||||
from database.database import Database
|
||||
@@ -70,16 +72,9 @@ def get_recommended_categories() -> list | list[dict]:
|
||||
Queries DB to get a list of recommended categories for the user
|
||||
|
||||
"""
|
||||
username = session.get('username')
|
||||
user_id = get_user_id(username)
|
||||
|
||||
db = Database()
|
||||
categories = db.fetchall("""SELECT categories.category_id, categories.category_name, favourability
|
||||
FROM categories, user_preferences
|
||||
WHERE user_id = ? AND categories.category_id = user_preferences.category_id,
|
||||
ORDER BY favourability DESC""", (user_id,))
|
||||
|
||||
return jsonify({'categories': categories})
|
||||
user_id = session.get("user_id")
|
||||
categories = user_category_recommendations(user_id)
|
||||
return categories
|
||||
|
||||
|
||||
@stream_bp.route('/get_streamer_data/<string:streamer_username>')
|
||||
@@ -87,7 +82,11 @@ def get_streamer_data(streamer_username):
|
||||
"""
|
||||
Returns a given streamer's data
|
||||
"""
|
||||
return
|
||||
streamer_id = get_user_id(streamer_username)
|
||||
if not streamer_id:
|
||||
abort(404)
|
||||
data = streamer_data(streamer_id)
|
||||
return data
|
||||
|
||||
|
||||
@stream_bp.route('/streamer/<string:streamer_username>/status')
|
||||
|
||||
@@ -49,11 +49,3 @@ CREATE TABLE streams
|
||||
FOREIGN KEY (category_id) REFERENCES categories(category_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
|
||||
SELECT users.user_id, title, username, num_viewers, category_name
|
||||
FROM streams
|
||||
JOIN users ON users.user_id = streams.user_id
|
||||
JOIN categories ON streams.category_id = categories.category_id
|
||||
ORDER BY num_viewers DESC
|
||||
LIMIT 25;
|
||||
@@ -6,14 +6,14 @@ def user_recommendation_category(user_id: int) -> Optional[int]:
|
||||
Queries user_preferences database to find users favourite streaming category and returns the category
|
||||
"""
|
||||
with Database() as db:
|
||||
data = db.fetchone("""
|
||||
category = db.fetchone("""
|
||||
SELECT category_id
|
||||
FROM user_preferences
|
||||
WHERE user_id = ?
|
||||
ORDER BY favourability DESC
|
||||
LIMIT 1
|
||||
""", (user_id,))
|
||||
return data
|
||||
return category["category_id"] if category else None
|
||||
|
||||
def followed_categories_recommendations(user_id : int) -> Optional[List[dict]]:
|
||||
"""
|
||||
@@ -78,3 +78,18 @@ def category_recommendations() -> Optional[List[dict]]:
|
||||
LIMIT 5;
|
||||
""")
|
||||
return categories
|
||||
|
||||
def user_category_recommendations(user_id: int) -> Optional[List[dict]]:
|
||||
"""
|
||||
Queries user_preferences database to find users top 5 favourite streaming category and returns the category
|
||||
"""
|
||||
with Database() as db:
|
||||
categories = db.fetchall("""
|
||||
SELECT categories.category_id, categories.category_name
|
||||
FROM categories
|
||||
JOIN user_preferences ON categories.category_id = user_preferences.category_id
|
||||
WHERE user_id = ?
|
||||
ORDER BY favourability DESC
|
||||
LIMIT 5
|
||||
""", (user_id,))
|
||||
return categories
|
||||
@@ -45,7 +45,7 @@ def followed_streamers(user_id: int) -> Optional[List[dict]]:
|
||||
""", (user_id,))
|
||||
return followed_streamers
|
||||
|
||||
def streamer_most_recent_stream(user_id: int) -> dict:
|
||||
def streamer_most_recent_stream(user_id: int) -> Optional[dict]:
|
||||
"""
|
||||
Returns data of the most recent stream by a streamer
|
||||
"""
|
||||
@@ -57,6 +57,17 @@ def streamer_most_recent_stream(user_id: int) -> dict:
|
||||
""", (user_id, user_id))
|
||||
return most_recent_stream
|
||||
|
||||
def streamer_data(streamer_id: int) -> Optional[dict]:
|
||||
"""
|
||||
Returns information about the streamer
|
||||
"""
|
||||
with Database() as db:
|
||||
data = db.fetchone("""
|
||||
SELECT username, num_followering, isPartnered FROM users
|
||||
WHERE user_id = ?
|
||||
""", (streamer_id))
|
||||
return data
|
||||
|
||||
def user_stream(user_id: int, stream_id: int) -> dict:
|
||||
"""
|
||||
Returns data of a streamers selected stream
|
||||
|
||||
Reference in New Issue
Block a user