mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 14:43:08 +02:00
Added tests, fixed some frontend_AI_connector.py, analytics.py kinda done
This commit is contained in:
parent
f20e6e483a
commit
2f117ea384
@ -111,6 +111,6 @@ if __name__ == "__main__":
|
||||
break
|
||||
|
||||
cache.init_app(app)
|
||||
app.run(host="0.0.0.0", port=8090, debug=True)
|
||||
app.run(host="0.0.0.0", port=8082, debug=True)
|
||||
|
||||
conn.close()
|
||||
|
||||
@ -6,7 +6,6 @@ import json
|
||||
from configparser import ConfigParser
|
||||
from datetime import datetime
|
||||
import requests
|
||||
from flask_caching import Cache
|
||||
|
||||
app = Flask(__name__)
|
||||
cache = Cache(config={'CACHE_TYPE': 'SimpleCache'})
|
||||
@ -20,7 +19,7 @@ def error_decorator(fun):
|
||||
try:
|
||||
fun(*args, **kwargs)
|
||||
except psycopg2.DatabaseError:
|
||||
return jsonify({"status": "Something... unexpected has occured :sweat_smile:"}), 500
|
||||
return jsonify({"status": "Something... unexpected has occurred :sweat_smile:"}), 500
|
||||
|
||||
return inner1
|
||||
|
||||
@ -34,7 +33,13 @@ def hello():
|
||||
# endpoint do wyciągania danych o userze
|
||||
@app.route("/api/v3/get/<string:username>", methods=["GET"])
|
||||
def access_user(username):
|
||||
return jsonify({"us": "er"}), 200
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("select * from users where username='{}';".format(username))
|
||||
res = cursor.fetchall()
|
||||
|
||||
cursor.close()
|
||||
|
||||
return jsonify(res[0]), 200
|
||||
|
||||
|
||||
# endpoint służący do zapisu danych nowo stworzonego użytkownika, podajemy mu
|
||||
@ -47,7 +52,7 @@ def add_user(oauth_ID, username):
|
||||
|
||||
if len(res):
|
||||
cursor.close()
|
||||
return jsonify({"status": "User already exists"}), 500
|
||||
return jsonify({"status": "User already exists"}), 409
|
||||
|
||||
cursor.execute("INSERT INTO users (username, oauth_ID) VALUES ('{}','{}');".format(
|
||||
username, oauth_ID
|
||||
@ -66,7 +71,7 @@ def get_recommendations(oauth_ID):
|
||||
cursor.execute("select movie_ID from ratings where oauth_ID='{}'", oauth_ID)
|
||||
res = cursor.fetchall()
|
||||
movies = [int(i) for i in res[0]]
|
||||
url = 'http://localhost:4200/api/v3/AI_recommendations'
|
||||
url = 'http://localhost:8081/api/v3/AI_recommendations'
|
||||
response = requests.post(url,
|
||||
json=movies,
|
||||
headers={'Content-Type': 'application/json'})
|
||||
@ -78,7 +83,7 @@ def get_movie(movie_ID):
|
||||
movie_info = movie_list.loc[movie_list['movie_id'] == movie_ID]
|
||||
if movie_info.empty:
|
||||
return jsonify({"status": "Movie with ID {} doesn't exist".format(movie_ID)}
|
||||
), 500
|
||||
), 404
|
||||
|
||||
cast = json.loads(movie_info["cast"][0].replace('\\"', '"'))
|
||||
crew = json.loads(movie_info["crew"][0].replace('\\"', '"'))
|
||||
@ -96,10 +101,10 @@ def rate_movie(uID, movie_ID, rating):
|
||||
movie_info = movie_list.loc[movie_list['movie_id'] == int(movie_ID)]
|
||||
if movie_info.empty:
|
||||
return jsonify({"status": "Movie with ID {} doesn't exist".format(movie_ID)}
|
||||
), 500
|
||||
), 404
|
||||
|
||||
if rating < 1 or rating > 5:
|
||||
return jsonify({"status": "Incorrect rating"}), 500
|
||||
return jsonify({"status": "Incorrect rating"}), 400
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("select * from users where oauth_ID='{}';".format(uID))
|
||||
@ -107,7 +112,7 @@ def rate_movie(uID, movie_ID, rating):
|
||||
|
||||
if not len(res):
|
||||
cursor.close()
|
||||
return jsonify({"status": "User doesn't exists"}), 500
|
||||
return jsonify({"status": "User doesn't exists"}), 404
|
||||
|
||||
cursor.execute("select * from ratings where oauth_ID='{}' AND movie_ID='{}';".format(uID, movie_ID))
|
||||
res = cursor.fetchall()
|
||||
|
||||
@ -6,4 +6,4 @@ password=root
|
||||
port=5432
|
||||
|
||||
[movie]
|
||||
csv_path=init_scripts/movies.csv
|
||||
csv_path=../../movie_recommendations/datasets/tmdb_5000_credits.csv
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
### GET request to example server
|
||||
GET http://127.0.0.1:5000/boop
|
||||
|
||||
###
|
||||
|
||||
GET http://127.0.0.1:8090/api/v3/ai/1111
|
||||
|
||||
###
|
||||
|
||||
POST http://127.0.0.1:4200/api/v3/AI_recommendations
|
||||
Content-Type: application/json
|
||||
|
||||
[
|
||||
49026,
|
||||
155,
|
||||
312113
|
||||
]
|
||||
|
||||
###
|
||||
@ -165,6 +165,6 @@ if __name__ == "__main__":
|
||||
break
|
||||
|
||||
cache.init_app(app)
|
||||
app.run(host="0.0.0.0", port=4200, debug=False)
|
||||
app.run(host="localhost", port=8081, debug=True)
|
||||
|
||||
conn.close()
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
###
|
||||
GET http://127.0.0.1:8090/get/boop
|
||||
###
|
||||
POST http://127.0.0.1:8090/api/v3/AI_recommendations
|
||||
POST http://127.0.0.1:8081/api/v3/AI_recommendations
|
||||
Content-Type: application/json
|
||||
|
||||
[
|
||||
@ -10,15 +8,23 @@ Content-Type: application/json
|
||||
312113
|
||||
]
|
||||
###
|
||||
POST http://127.0.0.1:8090/api/v3/add/1111/boop
|
||||
POST http://127.0.0.1:8090/api/v3/add/1234/blep
|
||||
###
|
||||
POST http://127.0.0.1:8090/api/v3/rate_movie/1111/155/4
|
||||
GET http://127.0.0.1:8090/api/v3/get/blep
|
||||
###
|
||||
GET http://localhost:8090/api/get_number_of_ratings
|
||||
POST http://127.0.0.1:8090/api/v3/add/6666/blop
|
||||
###
|
||||
GET http://localhost:8090/api/get_movie_ratings/155
|
||||
POST http://127.0.0.1:8090/api/v3/rate_movie/1234/155/4
|
||||
###
|
||||
GET http://localhost:8090/api/get_users_number
|
||||
POST http://127.0.0.1:8090/api/v3/rate_movie/6666/155/5
|
||||
###
|
||||
GET http://localhost:8090/api/get_movie_rating_avg/155
|
||||
POST http://127.0.0.1:8090/api/v3/rate_movie/1234/19995/5
|
||||
###
|
||||
GET http://localhost:8082/api/get_movie_ratings/155
|
||||
###
|
||||
GET http://localhost:8082/api/get_number_of_ratings
|
||||
###
|
||||
GET http://localhost:8082/api/get_users_number
|
||||
###
|
||||
GET http://localhost:8082/api/get_movie_rating_avg/155
|
||||
###
|
||||
|
||||
Loading…
Reference in New Issue
Block a user