/// <summary> /// Watch the requested movie /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <HttpResponseMessage> WatchMovie(HttpRequestMessage request) { try { // get the user message var requestData = await request.Content.ReadAsStringAsync(); var machineLearningRequest = JsonConvert.DeserializeObject <MachineLearningMessage>(requestData); // get all the lines on disk var lines = _machineLearningFileHandler.GetMovieLinesFromDisk(); // returns the movie var movie = _machineLearningHelper.GetMovie(lines, machineLearningRequest.RequestedMovieID); //save the fact they watched this movie _machineLearningFileHandler.StoreUserResult(movie, machineLearningRequest.UserID); //Return data to requesting user var linesToReturn = new Movie[] { movie }; machineLearningRequest.Results = linesToReturn; var jsonString = JsonConvert.SerializeObject(machineLearningRequest); return(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(jsonString) }); } catch (Exception ex) { LoggerHelper.Log("An Exception occurred: " + ex.Message + "\n" + ex.StackTrace); return(new HttpResponseMessage() { StatusCode = HttpStatusCode.InternalServerError }); } }
public void MachineLearningHandler_CanInit() { var machineLearningFileHandler = new MachineLearningFileHandler(); //This doesn't work var lines = machineLearningFileHandler.GetMovieLinesFromDisk(); var movieParser = new MovieParser(); var movies = movieParser.ParseMovies(lines); KMeansHelper kmeansHelper = new KMeansHelper(); var clusteredMoviesResults = kmeansHelper.kmeans(movies, 10000); }