class RecommendationEngine: def __init__(self): self.manager = CourseManagement() self.moviemanager = MovieManagement() def WhatsHot(self): pass #TODO: Send query to MMS to retrieve list of "hottest" movies. # Criteria can be highest number of views and highest ratings (TBD) def LoadRecommendations(self, user: User): Courses = user.courses tags = [] faculty = [] typ = [] cids = [] for i, j in Courses: temp = self.manager.getCourseinfo(str(j)) Movies = self.moviemanager.getCourseMovieID(str(j)) if (len(Movies) != 0): tags.append(Movies[0][1]) tags.append(Movies[0][2]) tags.append(Movies[0][3]) if (len(temp) != 0): cids.append(temp[0][0]) faculty.append(temp[0][1]) typ.append(temp[0][2]) faculty = list(set(faculty)) if (len(faculty) != 0): typ = list(set(typ)) courseIDs = [] Rtags = [] Movierecommend = [] for i in typ: tem = (self.manager.getRecommendedCourses(i)) for j in range(len(tem)): if ((tem[j][0] in cids) == False): courseIDs.append(tem[j][0]) for i in courseIDs: recommend = self.moviemanager.getCourseMovieID(i) if (len(recommend) != 0): Rtags.append(recommend[0][1]) Rtags.append(recommend[0][2]) Rtags.append(recommend[0][3]) for k in range(len(recommend)): if ((Rtags[k] in tags) == True): Movierecommend.append(recommend[0][0]) if (len(Movierecommend) == 0): Movierecommend = recommend else: #reccommend randomly pass
def __init__(self, user: User): self.user = user #self.r_engine = RecommendationEngine() #self.r_engine.WhatsHot() #self.r_engine.LoadRecommendations(self.user.id) self.movie_manager = MovieManagement( ) #manager used to communicate with movies table in database
class HomeController: def __init__(self, user: User): self.user = user #self.r_engine = RecommendationEngine() #self.r_engine.WhatsHot() #self.r_engine.LoadRecommendations(self.user.id) self.movie_manager = MovieManagement( ) #manager used to communicate with movies table in database #loads the movie widget def loadMovieWidget(self): self.movieLayout = MovieWidget() return self.movieLayout # self.movieLoad = threading.Thread(target=self.loadMovie, args=(main,)) # self.movieLoad.start() # self.movieLoad.join() #loads movie (no longer in use) def loadMovie(self, main): self.movie_widget = MovieWidget() main.vbox.addWidget(self.movie_widget) main.example_movie.hide() #talks to manager to get list of recommended movies def getRecommended(self): byteImages = self.movie_manager.getThumbNailsURL() if (isinstance(byteImages, int) == False): url = [] images = [] movieIDs = [] titles = [] for i in byteImages: movieIDs.append(i[2]) images.append(i[0]) url.append(i[1]) titles.append(i[3]) else: images = [] url = [] movieIDs = [] titles = [] return images, url, movieIDs, titles #talks to manager to get list of hot movies def getHot(self): byteImages = self.movie_manager.getThumbNails() images = [] for i in byteImages: images.append(i[0]) return images
class MovieController: def __init__(self, url): self.url = url self.manager = MovieManagement() self.incrementViews() def incrementViews(self): self.manager.incrementViewsByURL(self.url) def submitComment(self, movieID, comment, user): return self.manager.submitComment(movieID, comment, user) def getComments(self, movieID): return self.manager.getComments(movieID) def LikeMovie(self, movieID, userID): return self.manager.addLike(movieID, userID) def removieLike(self, movieID, userID): return self.manager.deleteLike(movieID, userID) def getLikeStatus(self, movieID, userID): return self.manager.getLikeStatus(movieID, userID) def isMovieForUser(self, movieID, userID): return self.manager.isMovieForUser(movieID, userID) def openStatsLayout(self, views, desc, likes): stats = statisticsLayout(views, desc, likes) return stats
class MovieController: def __init__(self,url): self.url = url self.manager =MovieManagement() self.incrementViews() def incrementViews (self): self.manager.incrementViewsByURL(self.url) def submitComment(self, movieID, comment, user): return self.manager.submitComment(movieID, comment, user) def getComments(self, movieID): return self.manager.getComments(movieID)
def __init__(self, user: User): self.user = user self.course_manager = CourseManagement() self.movie_manager = MovieManagement() self.movies_in_progress = [] self.statistics = None #statistics about movies and courses (only for professor)
class MovieInputController: def __init__(self): self.movie_manager = MovieManagement() #manager to allow communication with movie management model #talks to movie manager to add movie to database and to youtube #transforms first thumbnail to base64, then checks if movie is already uploaded by user, then tries uploading to youtube, if sucessfull then it uploads relevant data to database #params: string moviename, int courseID, string description, int userID, string url (path to movie), string thumbnail (path to thumbnail) #returns 0 for database errors, 1 if sucessfull, 2 if movie already exists, 3 if error with youtube api, 4 if movie can't be found def addMovie(self, moviename, courseID, description, userID, url, thumbnail, tag1, tag2, tag3, style): try: with open(thumbnail, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) image_file.close() except: return 4 #cant read file try: exists = self.movie_manager.CheckForMovieUser(moviename, userID) except: return 0 #Database error try: videoid = uploadToYoutube(url, moviename, description, thumbnail) # videoid = 999 except: return 3 #youtube error if(exists == 0): result = self.movie_manager.addMovie(moviename, courseID, description, userID, "https://youtu.be/" + videoid['id'], encoded_string, tag1, tag2, tag3, style) # result = self.movie_manager.addMovie(moviename, courseID, description, userID, "test", encoded_string, tag1, tag2, tag3, style) print(result) if(result == 1): return 1 #sucessfully added course to database else: print("failed to add Movie") return 0 #database error else: #TODO: ADD code here that removes the youtube video from youtube since the database failed to insert it return 2 #movie already exists with user
def __init__(self, user: User, courseID): super().__init__() self.list_widget = QListWidget() self.user = user self.courseID = courseID self.controller = CourseMovieController(self.user) # self.list_widget.setFlow(QListView.LeftToRight) self.list_widget.setIconSize(QSize(190, 190)) self.list_widget.hasAutoScroll() self.list_widget.setAutoFillBackground(False) self.items_title = self.user.courses self.Manager = MovieManagement() self.error = QLabel() self.movies = self.controller.getCMovies(self.courseID) self.titles = [] self.thumbnails = [] self.urls = [] self.movieIDs = [] if (len(self.movies) != 0): for i, j, k, w in self.movies: self.titles.append(i) self.thumbnails.append(j) self.urls.append(k) self.movieIDs.append(w) self.setImages(self.thumbnails, self.urls, self.titles, self.movieIDs) else: self.error.setText("Course Has No Movies") self.back = QPushButton("Back") self.back.clicked.connect(lambda: self.BACK()) self.vbox = QVBoxLayout() self.vbox.addWidget(self.list_widget) self.vbox.addWidget(self.error) self.vbox.addWidget(self.back) if (isinstance(self.user, Professor) == True): self.add_movie = QPushButton("Add Movie") self.add_movie.clicked.connect( lambda: self.new_movie_request.emit(self.courseID)) self.vbox.addWidget(self.add_movie) self.setLayout(self.vbox) self.list_widget.itemPressed.connect(lambda: self.MovieIsClicked())
def __init__(self,user: User): self.user = user self.course_manager = CourseManagement() self.movie_manager = MovieManagement() self.movies_in_progress = [] self. statistics = None #statistics about movies and courses (only for professor) #TODO: load unfinished movies watched by user from MovieManagement #TODO: load courses for user from CourseManagement #TODO: load statitiscs if professor is signed in
def __init__(self, user: User): self.manager = MovieManagement()
class CourseMovieController: def __init__(self, user: User): self.manager = MovieManagement() def getCMovies(self, CID): return self.manager.getCourseMovies(CID)
def __init__(self): self.movie_manager = MovieManagement() #manager to allow communication with movie management model
def __init__(self): self.course_manager = CourseManagement( ) #manager that allows communication with course table in database self.movie_manager = MovieManagement()
def __init__(self): self.manager = CourseManagement() self.moviemanager = MovieManagement()
def __init__(self,url): self.url = url self.manager =MovieManagement() self.incrementViews()