public void CountPropertyOk() { clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); Int32 count = 9744; AllFilmGenres.Count = count; Assert.AreEqual(AllFilmGenres.Count, count); }
public void GetAllFilmsByGenreMethodOk() { clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); Int32 numberofFilmsByGenre = 1830; Int32 genreId = 1; AllFilmGenres.GetAllFilmsByGenre(genreId); Assert.AreEqual(AllFilmGenres.AllFilmsByGenre.Count, numberofFilmsByGenre); }
public void ThisFilmGenrePropertyOk() { clsFilmGenreCollection FilmGenres = new clsFilmGenreCollection(); clsFilmGenre aFilmGenre = new clsFilmGenre(); aFilmGenre.FilmId = 45517; aFilmGenre.GenreId = 3; FilmGenres.ThisFilmGenre = aFilmGenre; Assert.AreEqual(FilmGenres.ThisFilmGenre, aFilmGenre); }
public void AddMethodOk() { clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); clsFilmGenre TestItem = new clsFilmGenre(); TestItem.FilmId = 1; TestItem.GenreId = 5; AllFilmGenres.ThisFilmGenre = TestItem; AllFilmGenres.Add(); AllFilmGenres.ThisFilmGenre.Find(TestItem.FilmId, TestItem.GenreId); Assert.AreEqual(AllFilmGenres.ThisFilmGenre, TestItem); }
public void CountMatchesList() { clsFilmGenreCollection FilmGenres = new clsFilmGenreCollection(); List <clsFilmGenre> testList = new List <clsFilmGenre>(); clsFilmGenre testItem = new clsFilmGenre(); testItem.FilmId = 1; testItem.GenreId = 1; testList.Add(testItem); FilmGenres.AllFilmGenres = testList; Assert.AreEqual(FilmGenres.Count, testList.Count); }
public void AllFilmsByGenrePropertyOk() { clsFilmGenreCollection FilmGenres = new clsFilmGenreCollection(); List <clsFilmGenre> testList = new List <clsFilmGenre>(); clsFilmGenre testItem = new clsFilmGenre(); testItem.FilmId = 1; testItem.GenreId = 1; testList.Add(testItem); FilmGenres.AllFilmsByGenre = testList; Assert.AreEqual(FilmGenres.AllFilmsByGenre, testList); }
public void DeleteMethodOk() { clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); clsFilmGenre TestItem = new clsFilmGenre(); TestItem.FilmId = 1; TestItem.GenreId = 5; AllFilmGenres.ThisFilmGenre = TestItem; AllFilmGenres.Add(); AllFilmGenres.Delete(); Boolean found = AllFilmGenres.ThisFilmGenre.Find(TestItem.FilmId, TestItem.GenreId); Assert.IsFalse(found); }
public void DeleteByFilmIdMethodOk() { bool found; clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); clsFilmCollection AllFilms = new clsFilmCollection(); AllFilms.ThisFilm.Title = "test"; Int32 primaryKey = AllFilms.Add(); Int32 genreId = 1; AllFilmGenres.ThisFilmGenre.FilmId = primaryKey; AllFilmGenres.ThisFilmGenre.GenreId = genreId; AllFilmGenres.Add(); AllFilmGenres.DeleteByFilmId(); found = AllFilmGenres.ThisFilmGenre.Find(primaryKey, genreId); Assert.IsFalse(found); }
public void InstanceOk() { clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); Assert.IsNotNull(AllFilmGenres); }
void GenerateRecommendations(int genreId) { //create a new instance of the MLContext class MLContext mlContext = new MLContext(); (IDataView trainingDataView, IDataView testDataView) = LoadData(mlContext); ITransformer model = BuildAndTrainModel(mlContext, trainingDataView); //create an instance of the class which represents the IDataView/ DataViewRow schema DataViewSchema modelSchema; //find the saved model var path = Server.MapPath(@"~/Model.zip"); //load the saved model ITransformer trainedModel = mlContext.Model.Load(path, out modelSchema); //create a prediction engine for film recommendations var predictionEngine = mlContext.Model.CreatePredictionEngine <clsFilmRating, MovieRatingPrediction>(trainedModel); var tempUserId = Session["UserId"]; Single userId; Boolean signedIn = false; //check if user is signed in if (tempUserId == null) { userId = 1; } else { userId = Convert.ToSingle(tempUserId); signedIn = true; } //get all films from the database clsFilmGenreCollection AllFilms = new clsFilmGenreCollection(); AllFilms.GetAllFilmsByGenre(genreId); List <clsFilmPrediction> AllPredictions = new List <clsFilmPrediction>(); clsFilmPrediction aFilmPrediction = new clsFilmPrediction(); foreach (clsFilmGenre aFilm in AllFilms.AllFilmsByGenre) { var potentialRecommendation = new clsFilmRating { UserId = userId, FilmId = aFilm.FilmId }; var movieRatingPrediction = predictionEngine.Predict(potentialRecommendation); //if a rating is high enough, add it to film predictions if (Math.Round(movieRatingPrediction.Score, 1) > 4.4) { aFilmPrediction = new clsFilmPrediction(); aFilmPrediction.FilmId = aFilm.FilmId; aFilmPrediction.Score = movieRatingPrediction.Score; AllPredictions.Add(aFilmPrediction); } } //sort them by score AllPredictions.Sort(); //get the ten best recommendations var topTenPredictions = AllPredictions.Take(10); clsFilmRecommendationCollection FilmRecommendations = new clsFilmRecommendationCollection(); clsFilmRecommendation aRecommendationToAdd = new clsFilmRecommendation(); clsMostRecommendedFilmsCollection AllMostRecommendedFilms = new clsMostRecommendedFilmsCollection(); clsMostRecommendedFilms aMostRecommendedFilm = new clsMostRecommendedFilms(); foreach (clsFilmPrediction aTopTenPrediction in topTenPredictions) { if (signedIn) { //save the recommendations for future use aRecommendationToAdd = new clsFilmRecommendation(); aRecommendationToAdd.FilmId = aTopTenPrediction.FilmId; aRecommendationToAdd.UserId = Convert.ToInt32(userId); FilmRecommendations.ThisFilmRecommendation = aRecommendationToAdd; FilmRecommendations.Add(); } aMostRecommendedFilm = new clsMostRecommendedFilms(); AllMostRecommendedFilms.ThisMostRecommendedFilm.FilmId = aTopTenPrediction.FilmId; if (AllMostRecommendedFilms.ThisMostRecommendedFilm.Find(aTopTenPrediction.FilmId) == true) { AllMostRecommendedFilms.IncreaseTimesRecommended(); } else { AllMostRecommendedFilms.Add(); } //get imdb information for film pnlRecommendations.Controls.Add(anImdbApi.GetImdbInformation(aTopTenPrediction.FilmId)); } pnlRecommendations.Visible = true; //save the model for later use mlContext.Model.Save(trainedModel, modelSchema, path); }
protected void btnActionFilm_Click(object sender, EventArgs e) { string originalTitle = ""; editFilm = Convert.ToBoolean(Session["EditFilm"]); if (editFilm) { originalTitle = Session["Title"].ToString(); } string newTitle = txtFilmTitle.Text; string tempImdbId = txtImdbId.Text; Int32 imdbId = 0; bool imdbIdOk = false; clsFilm aFilm = new clsFilm(); var filmTitleCheck = aFilm.Valid(newTitle); if (filmTitleCheck.Count != 0) { foreach (string error in filmTitleCheck) { Label lblError = new Label(); lblError.Text = "- " + error; pnlActionFilmErrorBody.Controls.Add(lblError); pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />")); } } clsLinkCollection AllLinks = new clsLinkCollection(); var imdbIdCheck = AllLinks.ThisLink.Valid(tempImdbId); if (imdbIdCheck.Count != 0) { foreach (string error in imdbIdCheck) { Label lblError = new Label(); lblError.Text = "- " + error; pnlActionFilmErrorBody.Controls.Add(lblError); pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />")); imdbIdOk = false; } pnlActionFilmError.Visible = true; } else { imdbId = Convert.ToInt32(tempImdbId); bool ImdbIdAlreadyExists = AllLinks.ImdbIdAlreadyExistsCheck(imdbId); if (ImdbIdAlreadyExists) { //if (!editFilm) //adding a new film //{ Label lblError = new Label(); lblError.Text = "- IMDBId already assigned to another film"; pnlActionFilmErrorBody.Controls.Add(lblError); pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />")); pnlActionFilmError.Visible = true; imdbIdOk = false; //} Int32 originalImdbId = Convert.ToInt32(Session["originalIMDBId"]); if (originalImdbId == imdbId) { imdbIdOk = true; } else { imdbIdOk = false; } //else //if we're editing a film //{ // Int32 originalImdbId = Convert.ToInt32(Session["originalIMDBId"]); // if (originalImdbId != imdbId) // { // Label lblError = new Label(); // lblError.Text = "- IMDBId already assigned to another film"; // pnlActionFilmErrorBody.Controls.Add(lblError); // pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />")); // imdbIdOk = false; // } // else // { // imdbIdOk = true; // } //} } else { imdbIdOk = true; } } newTitle = newTitle.TrimEnd(); string yearReleased = " " + "(" + ddlYear.SelectedValue + ")"; string titleAndYearReleased = newTitle + yearReleased; bool filmAlreadyExists = false; clsFilmCollection AllFilms = new clsFilmCollection(); if (AllFilms.FilmAlreadyExistsCheck(titleAndYearReleased)) { if (!editFilm) { Label lblError = new Label(); lblError.Text = "Film already exists"; pnlActionFilmErrorBody.Controls.Add(lblError); filmAlreadyExists = true; } else //if we ARE editing a film { if (newTitle != originalTitle) { Label lblError = new Label(); lblError.Text = "Film already exists"; pnlActionFilmErrorBody.Controls.Add(lblError); filmAlreadyExists = true; } else { filmAlreadyExists = false; } } } else { filmAlreadyExists = false; } if (!editFilm && !filmAlreadyExists && imdbIdOk) { AllFilms = new clsFilmCollection(); AllFilms.ThisFilm.Title = titleAndYearReleased; Int32 filmId = AllFilms.Add(); AllLinks.ThisLink.FilmId = filmId; AllLinks.ThisLink.ImdbId = imdbId; AllLinks.Add(); clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); foreach (ListItem item in chkbxlstGenres.Items) { if (item.Selected) { AllFilmGenres.ThisFilmGenre.FilmId = filmId; AllFilmGenres.ThisFilmGenre.GenreId = Convert.ToInt32(item.Value); AllFilmGenres.Add(); AllFilmGenres = new clsFilmGenreCollection(); } } LoadData(); pnlActionFilm.Visible = false; } if (editFilm) { AllFilms = new clsFilmCollection(); AllFilms.ThisFilm.FilmId = Convert.ToInt32(Session["FilmId"]); newTitle = titleAndYearReleased; if (newTitle == originalTitle) { AllFilms.ThisFilm.Title = originalTitle; } else { AllFilms.ThisFilm.Title = newTitle; } AllFilms.Update(); clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); AllFilmGenres.ThisFilmGenre.FilmId = filmId; AllFilmGenres.DeleteByFilmId(); foreach (ListItem item in chkbxlstGenres.Items) { if (item.Selected) { AllFilmGenres.ThisFilmGenre.FilmId = filmId; AllFilmGenres.ThisFilmGenre.GenreId = Convert.ToInt32(item.Value); AllFilmGenres.Add(); AllFilmGenres = new clsFilmGenreCollection(); } } LoadData(); pnlActionFilm.Visible = false; } }