Skip to content

Commit

Permalink
Modified backend and frontend to work more refined
Browse files Browse the repository at this point in the history
  • Loading branch information
kamatmihir2002 committed Nov 1, 2024
1 parent efed7a8 commit f7993ce
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 37 deletions.
22 changes: 22 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Prerequisites

To install dependencies for the backend, run:

pip install -r requirements.txt

For the frontend, navigate to ```./src/frontend``` and run:

npm install

# How to run

To start the backend, cd to ./src/backend and run:

python3 app.py ../../data/movies.csv

To start the frontend, navigate to ./src/frontend and then run:

npm start

The frontend and backend will be available at localhost 3000 and 5000 respectively.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<a href='https://coveralls.io/github/SoftwareEngg2024/CineScout?branch=ver_i'><img src='https://coveralls.io/repos/github/SoftwareEngg2024/CineScout/badge.svg?branch=ver_i' alt='Coverage Status' /></a>
<a href="https://github.com/SoftwareEngg2024/CineScout/blob/ver_i/LICENSE.md"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-green"></a>
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>

</p>

<!-- [![DOI](https://sandbox.zenodo.org/badge/720190225.svg)](https://sandbox.zenodo.org/doi/10.5072/zenodo.3401) [![Code Coverage](https://github.com/MadhurDixit13/MovieRecommender/actions/workflows/codecov.yml/badge.svg)](https://github.com/MadhurDixit13/MovieRecommender/actions/workflows/codecov.yml) [![codecov](https://codecov.io/gh/MadhurDixit13/MovieRecommender/graph/badge.svg?token=9NGWAJ7BST)]
(https://codecov.io/gh/MadhurDixit13/MovieRecommender) -->
[![GitHub release](https://img.shields.io/github/release/git-ankit/MovieRecommender.svg)](https://github.com/SoftwareEngg2024/CineScout/releases) [![black](https://img.shields.io/badge/StyleChecker-black-purple.svg)](https://pypi.org/project/black/)

## Bug? 🐛
Raise an issue on this repository, we would love to look at it ❤️
## Bug
Raise an issue on this repository, we would love to look at it!

## License 📃
This project is under MIT License.
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy>=1.18.5,<=1.20.3
pandas>=1.0.4,<=1.2.4
Flask>=1.1.2,<=2.1
Flask-Cors>=3.0.9,<=3.1
autopep8>=1.5.4,<=1.6
requests>=2.22.0,<=2.25.0
Flask
flask-cors
flask-sqlalchemy
flask-login
requests
pytest
13 changes: 8 additions & 5 deletions src/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import LoginManager, UserMixin, login_user, logout_user, login_required, current_user
import json
import random
import csv
import sys, string
from datetime import datetime
Expand All @@ -27,9 +28,9 @@ def find_in_list(title, listp):
cond = True
T2 = title.split("(")[0].strip().lower().translate(str.maketrans('','',string.punctuation))
T2_list = T2.split()
print(T2_list)
print(T1_list)
for i in range(len(T2_list)):
# print(T2_list)
# print(T1_list)
for i in range(min(len(T1_list), len(T2_list))):
cond = cond and (T2_list[i] in T1_list[i])

if cond:
Expand Down Expand Up @@ -176,7 +177,7 @@ def register():
username = request.form.get('username')
password = request.form.get('password')
if (len(User.query.filter_by(username = username).all()) == 0):
user = User(username=username)
user = User(username=username, newuser=1)
user.set_password(password)
db.session.add(user)
db.session.commit()
Expand Down Expand Up @@ -223,6 +224,7 @@ def raw_getmovielist():
db.session.add(rec)
db.session.commit()
recmovies = [t[1][0] for t in recommended_movies]
random.shuffle(recmovies)
return {"movie_list" : recmovies}

# get recommended movie list based on history
Expand All @@ -244,7 +246,8 @@ def watchmovie():
"""
if (current_user.newuser):
User.query.filter_by(id=current_user.id).update({"newuser" : 0})

db.session.commit()

moviename_other= json.loads(request.data)["movie_title"]
moviename = translate_local(moviename_other)
Recommendation.query.filter_by(user_id = current_user.id)\
Expand Down
8 changes: 6 additions & 2 deletions src/frontend/src/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const Login = ({ onLogin, movieListGet, movieListSet}) => {
formData.append('password', password);
fetch("http://localhost:5000/login", {
method : "post",
body : formData
// credentials : 'include'
body : formData,
// credentials : "include"

})
.then((response) => response.json())
.then((resp) => {
Expand All @@ -36,6 +37,9 @@ const Login = ({ onLogin, movieListGet, movieListSet}) => {
console.log("c")
var error_string = resp["errstring"]
}
else if (resp["redirect_url_key"] == "LOGIN") {
console.log("c")
}

})
}
Expand Down
10 changes: 0 additions & 10 deletions src/frontend/src/pages/.func.js

This file was deleted.

5 changes: 3 additions & 2 deletions src/frontend/src/pages/Preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import './Preferences.css';
import { getmovielist, setmovielist } from './.func';

const Preferences = ({movieListGet, movieListSet}) => {
const availableGenres = [28, 35, 18, 27, 10749, 878]; // TMDB genre IDs
Expand All @@ -25,10 +24,12 @@ const Preferences = ({movieListGet, movieListSet}) => {
genreList = genreList.concat(genreNames[i])
}
}
console.log(genreList)
fetch("http://localhost:5000/registeruserprefs", {
method: 'post',
credentials : 'include',
body : JSON.stringify({genre_list : genreList}),
credentials : 'include'

}).then((response) => response.json())
.then((resp) => {
movieListSet(resp["movie_list"])
Expand Down
1 change: 0 additions & 1 deletion src/frontend/src/pages/Recommendations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import React, { useEffect, useState } from 'react';
import MovieCard from '../components/MovieCard';
import './Recommendations.css';
import { getmovielist } from './.func';

const Recommendations = ({ language, movieListGet, movieListSet}) => {
const [recommendedMovies, setRecommendedMovies] = useState([]);
Expand Down
12 changes: 6 additions & 6 deletions src/test_core_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_core_algo_genre_consistency_two():
for movie in list_movies:
watched_genres.update(get_genres_for_movie(movie[0]))

for movie, processed_movie in result:
for movie, processed_movie in result[0:200]:
recommended_genres = get_genres_for_movie(movie[0])
assert all(genre in recommended_genres for genre in watched_genres) # At least one genre must match

Expand All @@ -127,7 +127,7 @@ def test_core_algo_genre_consistency_three():
for movie in list_movies:
watched_genres.update(get_genres_for_movie(movie[0]))

for movie, processed_movie in result:
for movie, processed_movie in result[0:200]:
recommended_genres = get_genres_for_movie(movie[0])
assert all(genre in recommended_genres for genre in watched_genres) # At least one genre must match

Expand All @@ -139,7 +139,7 @@ def test_core_algo_genre_consistency_five():
for movie in list_movies:
watched_genres.update(get_genres_for_movie(movie[0]))

for movie, processed_movie in result:
for movie, processed_movie in result[0:200]:
recommended_genres = get_genres_for_movie(movie[0])
assert all(genre in recommended_genres for genre in watched_genres) # At least one genre must match

Expand All @@ -151,7 +151,7 @@ def test_core_algo_genre_consistency_single():
for movie in list_movies:
watched_genres.update(get_genres_for_movie(movie[0]))

for movie, processed_movie in result:
for movie, processed_movie in result[0:200]:
recommended_genres = get_genres_for_movie(movie[0])
assert all(genre in recommended_genres for genre in watched_genres) # At least one genre must match

Expand All @@ -165,7 +165,7 @@ def test_surprise_me_horror():
for movie in watched_list:
watched_genres.update(get_genres_for_movie(movie))

for movie, processed_movie in result:
for movie, processed_movie in result[0:200]:
recommended_genres = get_genres_for_movie(movie)
assert any(genre in recommended_genres for genre in watched_genres)

Expand All @@ -179,7 +179,7 @@ def test_surprise_me_comedy():
for movie in watched_list:
watched_genres.update(get_genres_for_movie(movie))

for movie, processed_movie in result:
for movie, processed_movie in result[0:200]:
recommended_genres = get_genres_for_movie(movie)
assert any(genre in recommended_genres for genre in watched_genres)

Expand Down
7 changes: 5 additions & 2 deletions test/test_api_core_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def test_apicall_recommend_movie_newuser():
# get recommendations without having watched
code, res, resp = formdata_apicall2("getmovielist", get, req_body, pcookies=user_cookies)
assert code == 200 and "movie_list" in dict(res).keys()



def test_apicall_update_user_history():

# register and login user
Expand Down Expand Up @@ -115,6 +116,7 @@ def test_recommend_based_on_watched_history():
code, res, resp = formdata_apicall2("/getmovielist", get, "", pcookies=user_cookies)
assert code == 200 and "movie_list" in dict(res).keys()


def test_recommend_search():
user = {'username' : "newuser5", "password" : "new_password5"}
code, res = formdata_apicall("register", post, user)
Expand All @@ -130,6 +132,7 @@ def test_recommend_search():

assert code == 200 and "movie_list" in dict(res).keys()


def test_recommend_sort():
user = {'username' : "newuser6", "password" : "new_password5"}
code, res = formdata_apicall("register", post, user)
Expand Down Expand Up @@ -168,7 +171,7 @@ def test_recommend_searchyear():
# user searches movie
req_body = json.dumps({"year" : "1998"})

code, res, resp = formdata_apicall2("searchyear", get, "descending", pcookies=user_cookies)
code, res, resp = formdata_apicall2("searchyear", get, req_body, pcookies=user_cookies)

assert code == 200 and "movie_list" in dict(res).keys()

0 comments on commit f7993ce

Please sign in to comment.