Merge commit 'fb23a16'
This commit is contained in:
commit
fc31eb97d4
@ -5,9 +5,11 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import com.camillepradel.movierecommender.model.Genre;
|
||||
import com.camillepradel.movierecommender.model.Movie;
|
||||
@ -28,7 +30,7 @@ import java.util.logging.Logger;
|
||||
import org.neo4j.driver.v1.Record;
|
||||
import org.neo4j.driver.v1.Session;
|
||||
import org.neo4j.driver.v1.StatementResult;
|
||||
|
||||
import com.camillepradel.movierecommender.model.Rating;
|
||||
|
||||
@Controller
|
||||
public class MainController {
|
||||
@ -63,7 +65,7 @@ public class MainController {
|
||||
int id=0;
|
||||
|
||||
StatementResult result = null;
|
||||
try {
|
||||
try {
|
||||
if (userId != null && userId >=0 ){
|
||||
|
||||
result = Neo4jConnector.getInstance().getConnection().run( "MATCH (me:User { id: "+userId+" })-[:RATED]->(movie:Movie) -[:CATEGORIZED_AS]->(g:Genre) RETURN movie.title as movies, collect(g.name) as genre;" );
|
||||
@ -142,4 +144,77 @@ public class MainController {
|
||||
}
|
||||
return listMovies;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/movieratings", method = RequestMethod.GET)
|
||||
public ModelAndView showMoviesRattings(
|
||||
@RequestParam(value = "user_id", required = true) Integer userId) {
|
||||
System.out.println("GET /movieratings for user " + userId);
|
||||
|
||||
// TODO: write query to retrieve all movies from DB
|
||||
List<Movie> allMovies = new LinkedList<Movie>();
|
||||
Genre genre0 = new Genre(0, "genre0");
|
||||
Genre genre1 = new Genre(1, "genre1");
|
||||
Genre genre2 = new Genre(2, "genre2");
|
||||
allMovies.add(new Movie(0, "Titre 0", Arrays.asList(new Genre[] {genre0, genre1})));
|
||||
allMovies.add(new Movie(1, "Titre 1", Arrays.asList(new Genre[] {genre0, genre2})));
|
||||
allMovies.add(new Movie(2, "Titre 2", Arrays.asList(new Genre[] {genre1})));
|
||||
allMovies.add(new Movie(3, "Titre 3", Arrays.asList(new Genre[] {genre0, genre1, genre2})));
|
||||
|
||||
// TODO: write query to retrieve all ratings from the specified user
|
||||
List<Rating> ratings = new LinkedList<Rating>();
|
||||
ratings.add(new Rating(new Movie(0, "Titre 0", Arrays.asList(new Genre[] {genre0, genre1})), userId, 3));
|
||||
ratings.add(new Rating(new Movie(2, "Titre 2", Arrays.asList(new Genre[] {genre1})), userId, 4));
|
||||
|
||||
ModelAndView mv = new ModelAndView("movieratings");
|
||||
mv.addObject("userId", userId);
|
||||
mv.addObject("allMovies", allMovies);
|
||||
mv.addObject("ratings", ratings);
|
||||
|
||||
return mv;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/movieratings", method = RequestMethod.POST)
|
||||
public String saveOrUpdateRating(@ModelAttribute("rating") Rating rating) {
|
||||
System.out.println("POST /movieratings for user " + rating.getUserId()
|
||||
+ ", movie " + rating.getMovie().getId()
|
||||
+ ", score " + rating.getScore());
|
||||
|
||||
// TODO: add query which
|
||||
// - add rating between specified user and movie if it doesn't exist
|
||||
// - update it if it does exist
|
||||
|
||||
return "redirect:/movieratings?user_id=" + rating.getUserId();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/recommendations", method = RequestMethod.GET)
|
||||
public ModelAndView ProcessRecommendations(
|
||||
@RequestParam(value = "user_id", required = true) Integer userId,
|
||||
@RequestParam(value = "processing_mode", required = false, defaultValue = "0") Integer processingMode){
|
||||
System.out.println("GET /movieratings for user " + userId);
|
||||
|
||||
// TODO: process recommendations for specified user exploiting other users ratings
|
||||
// use different methods depending on processingMode parameter
|
||||
Genre genre0 = new Genre(0, "genre0");
|
||||
Genre genre1 = new Genre(1, "genre1");
|
||||
Genre genre2 = new Genre(2, "genre2");
|
||||
List<Rating> recommendations = new LinkedList<Rating>();
|
||||
String titlePrefix;
|
||||
if (processingMode.equals(0))
|
||||
titlePrefix = "0_";
|
||||
else if (processingMode.equals(1))
|
||||
titlePrefix = "1_";
|
||||
else if (processingMode.equals(2))
|
||||
titlePrefix = "2_";
|
||||
else
|
||||
titlePrefix = "default_";
|
||||
recommendations.add(new Rating(new Movie(0, titlePrefix + "Titre 0", Arrays.asList(new Genre[] {genre0, genre1})), userId, 5));
|
||||
recommendations.add(new Rating(new Movie(1, titlePrefix + "Titre 1", Arrays.asList(new Genre[] {genre0, genre2})), userId, 5));
|
||||
recommendations.add(new Rating(new Movie(2, titlePrefix + "Titre 2", Arrays.asList(new Genre[] {genre1})), userId, 4));
|
||||
recommendations.add(new Rating(new Movie(3, titlePrefix + "Titre 3", Arrays.asList(new Genre[] {genre0, genre1, genre2})), userId, 3));
|
||||
|
||||
ModelAndView mv = new ModelAndView("recommendations");
|
||||
mv.addObject("recommendations", recommendations);
|
||||
|
||||
return mv;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class Movie {
|
||||
this.genres = genres;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,67 @@
|
||||
package com.camillepradel.movierecommender.model;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Rating {
|
||||
|
||||
private Movie movie;
|
||||
private int userId;
|
||||
private int score;
|
||||
|
||||
public Rating() {
|
||||
this.movie = null;
|
||||
this.userId = 0;
|
||||
this.score = 0;
|
||||
}
|
||||
|
||||
public Rating(Movie movie, int userId, int score) {
|
||||
this.movie = movie;
|
||||
this.userId = userId;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public Rating(Movie movie, int userId) {
|
||||
this.movie = movie;
|
||||
this.userId = userId;
|
||||
this.score = 0;
|
||||
}
|
||||
|
||||
public Movie getMovie() {
|
||||
return this.movie;
|
||||
}
|
||||
|
||||
public void setMovie(Movie movie) {
|
||||
this.movie = movie;
|
||||
}
|
||||
|
||||
// pseudo getter and setter for movie id
|
||||
// (in order to automatically serialize Rating object on form submission)
|
||||
|
||||
public int getMovieId() {
|
||||
return this.movie.getId();
|
||||
}
|
||||
|
||||
public void setMovieId(int movieId) {
|
||||
// TODO: get movie with id movieId from database
|
||||
String title = "Titre";
|
||||
Genre genre0 = new Genre(0, "genre0");
|
||||
Genre genre1 = new Genre(1, "genre1");
|
||||
this.movie = new Movie(movieId, title, Arrays.asList(new Genre[] {genre0, genre1}));
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return this.score;
|
||||
}
|
||||
|
||||
public void setScore(int score) {
|
||||
this.score = score;
|
||||
}
|
||||
}
|
57
src/main/webapp/WEB-INF/views/movieratings.jsp
Normal file
57
src/main/webapp/WEB-INF/views/movieratings.jsp
Normal file
@ -0,0 +1,57 @@
|
||||
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
||||
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Films</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>
|
||||
Vos films notés
|
||||
</h1>
|
||||
<ul>
|
||||
<c:forEach items="${ratings}" var="rating">
|
||||
<li>
|
||||
${rating.getMovie().id} - ${rating.score}
|
||||
</li>
|
||||
</c:forEach>
|
||||
</ul>
|
||||
|
||||
<h1>
|
||||
Ajouter une note
|
||||
</h1>
|
||||
<ul>
|
||||
<c:forEach items="${allMovies}" var="movie">
|
||||
<!-- get movie rating if any -->
|
||||
<c:set var="score" value="0" />
|
||||
<c:forEach items="${ratings}" var="rating">
|
||||
<c:if test="${rating.getMovie().id eq movie.id}">
|
||||
<c:set var="score" value="${rating.score}" />
|
||||
</c:if>
|
||||
</c:forEach>
|
||||
|
||||
<li>
|
||||
${movie.title} - ${score} (user id: ${userId}, movie id: ${movie.id})
|
||||
<form method="post" action="/MovieRecommender/movieratings">
|
||||
<input type="number" name="userId" value="${userId}" hidden="hidden">
|
||||
<input type="number" name="movieId" value="${movie.id}" hidden="hidden">
|
||||
<input type="radio" name="score" onclick="this.form.submit();" value="1" <c:if test="${score eq 1}">checked</c:if>>
|
||||
<input type="radio" name="score" onclick="this.form.submit();" value="2" <c:if test="${score eq 2}">checked</c:if>>
|
||||
<input type="radio" name="score" onclick="this.form.submit();" value="3" <c:if test="${score eq 3}">checked</c:if>>
|
||||
<input type="radio" name="score" onclick="this.form.submit();" value="4" <c:if test="${score eq 4}">checked</c:if>>
|
||||
<input type="radio" name="score" onclick="this.form.submit();" value="5" <c:if test="${score eq 5}">checked</c:if>>
|
||||
</form>
|
||||
<ul>
|
||||
<c:forEach items="${movie.genres}" var="genre">
|
||||
<li>
|
||||
${genre.name}
|
||||
</li>
|
||||
</c:forEach>
|
||||
</ul>
|
||||
</li>
|
||||
</c:forEach>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
23
src/main/webapp/WEB-INF/views/recommendations.jsp
Normal file
23
src/main/webapp/WEB-INF/views/recommendations.jsp
Normal file
@ -0,0 +1,23 @@
|
||||
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
||||
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Recommandations</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>
|
||||
Vos recommandations
|
||||
</h1>
|
||||
<ul>
|
||||
<c:forEach items="${recommendations}" var="recommendation">
|
||||
<li>
|
||||
${recommendation.getMovie().title}
|
||||
</li>
|
||||
</c:forEach>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user