Skip to content

Backend

Jtrep10 edited this page Oct 31, 2024 · 11 revisions

Backend Code: Files and Function Descriptions

login_user()

Generates a JWT token valid for one hour for a user based off the username and password sent via the front-end.

create_user()

Retrieves username and password from data request and stores them in the User object.

get_user_id()

Intercepts the request and extracts, decodes, and returns the decoded user ID token.

test_decoding()

Returns the userID in a JSON format for testing.

landing_page()

Renders the Landing page.

search_page()

Renders the Search page.

get_watchlist()

Retrieves and returns the Watchlist table for the current user.

add_to_watchlist()

Creates a new entry in the Watchlist table for the selected film.

delete_from_watchlist()

Deletes Watchlist entry for the current user and current film.

predict()

Returns movie recommendations and checks whether or not they are already in the Watchlist.

search()

Handles movie search requests.

feedback()

Handles user feedback submission.

send_mail()

Handles user feedback submission and mails the results.

success()

Renders the success page.

create_colored_tags(genres)

An utility function that creates colored, genre-specific tags. Input: A list of movie genres titled "genres" Output: A string of colored tags for those genres.

beautify_feedback_data(data)

An utility function to beautify the json containing recommended movies. Input: JSON containing recommended movies titled "data" Output: Beautified data dictionary containing movies grouped by watchlist category

create_movie_genres(movie_genre_df)

Utility function for creating a dictionary for movie-genres mapping Input: Data frame of movies.csv titled movie_genre_df Output: Dictionary of movies-genres mapping

send_email_to_user(recipient_email, categorized_data)

Utility function to send movie recommendations to user over email Input :

  • email of recipient_email titled "recipient_email".
  • Dictionary of movies grouped by watchlist category titled "categorized_data". Output: Sends email for valid email, otherwise raises exception in the server logs

starts_with(word)

Function to check movie prefix Input : Initial prefix titled "word" Output : List of movies beginning with that prefix

anywhere(word, visited_words)

Function to check visited words Input :

  • Word to check titled "word"
  • Visited words titled "visited_words"; Output : List of words that have not been visited

results(word)

Function to assist with rendering the results Input: Word to check titled "word" Output: A list of all titles that start with "word" results_top_ten(word) Function to get top 10 results Input : A word/initial character(s) titled "word" Output : A list of ten titles that start with "word"

recommend_for_new_user(user_rating)

Generates a list of recommended movie titles for a new user based on their ratings using Item-Item Collaborative Filtering (CF). This means that a user is recommended movies similar to ones they have previously enjoyed. Input: A list of dictionaries with the movie title and the user's rating titled "user_rating" Output: A tuple of lists representing the title, genre, and imdb_id of the recommended movies.

Class User(db.Model)

Stores the id, username, and password of users in a database

Class Watchlist(db.Model)

Stores the watchlist of each user in a database. The user is identified by the userID column, while the film is identified by the imdbID column.

Clone this wiki locally