mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-20 03:34:26 +01:00
Basic poprawki
This commit is contained in:
parent
782f1c806b
commit
fb86be5af8
@ -1,5 +1,5 @@
|
|||||||
from User import User
|
from User import User
|
||||||
from Ranting import Ranting
|
from Rating import Rating
|
||||||
|
|
||||||
users = [
|
users = [
|
||||||
User(1, "Lola"),
|
User(1, "Lola"),
|
||||||
@ -8,17 +8,17 @@ users = [
|
|||||||
User(4, "Betty")
|
User(4, "Betty")
|
||||||
]
|
]
|
||||||
|
|
||||||
rantings = [
|
ratings = [
|
||||||
Ranting(1, 1, 1, 5, "15-06-2024 15:04:32"),
|
Rating(1, 1, 1, 5, "15-06-2024 15:04:32"),
|
||||||
Ranting(2, 1, 2, 6, "15-06-2024 15:04:36"),
|
Rating(2, 1, 2, 6, "15-06-2024 15:04:36"),
|
||||||
Ranting(3, 2, 1, 7, "15-06-2024 15:04:40"),
|
Rating(3, 2, 1, 7, "15-06-2024 15:04:40"),
|
||||||
Ranting(4, 2, 2, 8, "15-06-2024 15:04:44"),
|
Rating(4, 2, 2, 8, "15-06-2024 15:04:44"),
|
||||||
Ranting(5, 2, 3, 9, "15-06-2024 15:04:48"),
|
Rating(5, 2, 3, 9, "15-06-2024 15:04:48"),
|
||||||
Ranting(6, 3, 1, 10, "15-06-2024 15:04:52"),
|
Rating(6, 3, 1, 10, "15-06-2024 15:04:52"),
|
||||||
Ranting(7, 3, 2, 6, "15-06-2024 15:04:56"),
|
Rating(7, 3, 2, 6, "15-06-2024 15:04:56"),
|
||||||
Ranting(8, 3, 3, 5, "15-06-2024 15:05:00"),
|
Rating(8, 3, 3, 5, "15-06-2024 15:05:00"),
|
||||||
Ranting(9, 4, 1, 4, "15-06-2024 15:05:04"),
|
Rating(9, 4, 1, 4, "15-06-2024 15:05:04"),
|
||||||
Ranting(10, 4, 2, 3, "15-06-2024 15:05:08"),
|
Rating(10, 4, 2, 3, "15-06-2024 15:05:08"),
|
||||||
Ranting(11, 4, 3, 2, "15-06-2024 15:05:12"),
|
Rating(11, 4, 3, 2, "15-06-2024 15:05:12"),
|
||||||
Ranting(12, 4, 4, 1, "15-06-2024 15:05:16")
|
Rating(12, 4, 4, 1, "15-06-2024 15:05:16")
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,33 +0,0 @@
|
|||||||
from User import User
|
|
||||||
from Ranting import Ranting
|
|
||||||
from MockUps import users,rantings
|
|
||||||
|
|
||||||
|
|
||||||
def get_rantings():
|
|
||||||
return rantings
|
|
||||||
|
|
||||||
|
|
||||||
def get_number_of_ratings():
|
|
||||||
return get_rantings().__len__()
|
|
||||||
|
|
||||||
|
|
||||||
def get_rantings_in_time(begin_time, end_time):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def get_rantings_of_movie(movie_id):
|
|
||||||
results = []
|
|
||||||
for ranting in rantings:
|
|
||||||
if ranting.movie_id == movie_id:
|
|
||||||
results.append(ranting)
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
def get_rantings_of_movie_numbers(movie_id):
|
|
||||||
return get_rantings_of_movie(movie_id).__len__()
|
|
||||||
|
|
||||||
|
|
||||||
def get_rantings_of_movie_in_time(movie_id, begin_time, end_time):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
class Ranting:
|
class Rating:
|
||||||
def __init__(self, id, movie_id, user_id, ranting, time):
|
def __init__(self, id, movie_id, user_id, ranting, time):
|
||||||
self.id=id
|
self.id=id
|
||||||
self.movie_id=movie_id
|
self.movie_id=movie_id
|
||||||
33
analitics/RatingsAnalytics.py
Normal file
33
analitics/RatingsAnalytics.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from User import User
|
||||||
|
from Rating import Rating
|
||||||
|
from MockUps import users, ratings
|
||||||
|
|
||||||
|
|
||||||
|
def get_ratings():
|
||||||
|
return ratings
|
||||||
|
|
||||||
|
|
||||||
|
def get_number_of_ratings():
|
||||||
|
return len(get_ratings())
|
||||||
|
|
||||||
|
|
||||||
|
def get_ratings_in_time(begin_time, end_time):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def get_ratings_of_movie(movie_id):
|
||||||
|
results = []
|
||||||
|
for ranting in ratings:
|
||||||
|
if ranting.movie_id == movie_id:
|
||||||
|
results.append(ranting)
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def get_ratings_of_movie_numbers(movie_id):
|
||||||
|
return len(get_ratings_of_movie(movie_id))
|
||||||
|
|
||||||
|
|
||||||
|
def get_ratings_of_movie_in_time(movie_id, begin_time, end_time):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -1,7 +1,4 @@
|
|||||||
|
|
||||||
class User:
|
class User:
|
||||||
def __init__(self,id,name):
|
def __init__(self, user_id, name):
|
||||||
self.id=id
|
self.id = user_id
|
||||||
self.name=name
|
self.name = name
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
from User import User
|
|
||||||
from Ranting import Ranting
|
|
||||||
from MockUps import users,rantings
|
|
||||||
|
|
||||||
|
|
||||||
def get_number_of_users():
|
|
||||||
return users.__len__()
|
|
||||||
|
|
||||||
|
|
||||||
def get_user_rantings(user_id):
|
|
||||||
results=[]
|
|
||||||
for ranting in rantings:
|
|
||||||
if ranting.user_id==user_id:
|
|
||||||
results.append(ranting)
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
def get_user_rantings_number(user_id):
|
|
||||||
return get_user_rantings(user_id).__len__()
|
|
||||||
|
|
||||||
|
|
||||||
def get_user_rantings_in_time(user_id, begin, end):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
25
analitics/UserAnalytics.py
Normal file
25
analitics/UserAnalytics.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
from User import User
|
||||||
|
from Rating import Rating
|
||||||
|
from MockUps import users, ratings
|
||||||
|
|
||||||
|
|
||||||
|
def get_number_of_users():
|
||||||
|
return len(users)
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_ratings(user_id):
|
||||||
|
results = []
|
||||||
|
for rating in ratings:
|
||||||
|
if rating.user_id == user_id:
|
||||||
|
results.append(rating)
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_ratings_number(user_id):
|
||||||
|
return len(get_user_ratings(user_id))
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_ratings_in_time(user_id, begin, end):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -1,2 +1,51 @@
|
|||||||
|
from flask import Flask, request, jsonify
|
||||||
|
from flask_caching import Cache
|
||||||
|
import psycopg2
|
||||||
|
import pandas
|
||||||
|
import json
|
||||||
|
from configparser import ConfigParser
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
cache = Cache(config={'CACHE_TYPE': 'SimpleCache'})
|
||||||
|
db_connector = None
|
||||||
|
conn = None
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/get_number_of_ratings")
|
||||||
|
@cache.cached(timeout=1000)
|
||||||
|
def get_number_of_ratings():
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("select count(*) as num_of_ratings from ratings")
|
||||||
|
res = cursor.fetchall()
|
||||||
|
|
||||||
|
return len(res['num_of_ratings'])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
config = ConfigParser()
|
||||||
|
config.read("init_scripts/constants.ini")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
conn = psycopg2.connect(
|
||||||
|
host=config["postgres"]["host"],
|
||||||
|
database=config["postgres"]["database"],
|
||||||
|
user=config["postgres"]["user"],
|
||||||
|
password=config["postgres"]["password"],
|
||||||
|
port=int(config["postgres"]["port"])
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
print("Trying to connect with database")
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
cache.init_app(app)
|
||||||
|
app.run(host="0.0.0.0", port=8090, debug=True)
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|||||||
@ -1,14 +1,13 @@
|
|||||||
import hashlib
|
|
||||||
import json
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
from sklearn.feature_extraction.text import CountVectorizer
|
from sklearn.feature_extraction.text import CountVectorizer
|
||||||
from sklearn.metrics.pairwise import cosine_similarity
|
from sklearn.metrics.pairwise import cosine_similarity
|
||||||
|
|
||||||
from flask import Flask, request, jsonify
|
from flask import Flask, request, jsonify
|
||||||
from flask_caching import Cache
|
from flask_caching import Cache
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
@ -147,7 +146,6 @@ def make_cache_key():
|
|||||||
def AI_recommendations():
|
def AI_recommendations():
|
||||||
ids = request.get_json()
|
ids = request.get_json()
|
||||||
recommendations = recommender.get_recommendations(ids)
|
recommendations = recommender.get_recommendations(ids)
|
||||||
recommendations[0] = datetime.now()
|
|
||||||
return jsonify(recommendations)
|
return jsonify(recommendations)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user