Skip to content
Snippets Groups Projects
Commit 65eb5c3c authored by John Watkins's avatar John Watkins
Browse files

Finished recommendation system

parent a8e83611
Branches issueThirtyThree
No related tags found
2 merge requests!114LoggingService service class, new method to add a log to the "Logs" table when...,!91Issue thirty three
...@@ -40,7 +40,7 @@ public class RecommendationGenerator { ...@@ -40,7 +40,7 @@ public class RecommendationGenerator {
userStampBoardsRepo = usbr; userStampBoardsRepo = usbr;
} }
public List<Shops> getRecommendations(HttpSession session) throws Exception { public List<Shops> getRecommendations(HttpSession session, List<Shops> shopsToRecommend) throws Exception {
Long userId = 1L; Long userId = 1L;
List<Tags> tags = new ArrayList<Tags>(); List<Tags> tags = new ArrayList<Tags>();
...@@ -118,7 +118,7 @@ public class RecommendationGenerator { ...@@ -118,7 +118,7 @@ public class RecommendationGenerator {
//Calculate weights for each shop, later do this based off a list of passed in shops //Calculate weights for each shop, later do this based off a list of passed in shops
//Ignore shops that have been starred or where the user has a stamp //Ignore shops that have been starred or where the user has a stamp
List<HashMap<Shops, Double>> weightedShops = new ArrayList<>(); List<HashMap<Shops, Double>> weightedShops = new ArrayList<>();
for(Shops shop : shopsRepo.findAll()){ for(Shops shop : shopsToRecommend){
//If the shop isn't starred or purchased from //If the shop isn't starred or purchased from
if(!purchasedFromShops.contains(shop.getShopId()) && !favoriteShops.contains(shop.getShopId())){ if(!purchasedFromShops.contains(shop.getShopId()) && !favoriteShops.contains(shop.getShopId())){
double weight = 0; double weight = 0;
......
...@@ -10,6 +10,7 @@ import com.example.clientproject.data.tags.TagsRepo; ...@@ -10,6 +10,7 @@ import com.example.clientproject.data.tags.TagsRepo;
import com.example.clientproject.service.Utils.JWTUtils; import com.example.clientproject.service.Utils.JWTUtils;
import com.example.clientproject.service.searches.TagSearch; import com.example.clientproject.service.searches.TagSearch;
import com.example.clientproject.services.DashboardStampLoader; import com.example.clientproject.services.DashboardStampLoader;
import com.example.clientproject.services.RecommendationGenerator;
import com.example.clientproject.services.UserFavouriteDTO; import com.example.clientproject.services.UserFavouriteDTO;
import com.example.clientproject.services.UserFavouriteToggle; import com.example.clientproject.services.UserFavouriteToggle;
import com.example.clientproject.web.forms.UserFavouriteForm; import com.example.clientproject.web.forms.UserFavouriteForm;
...@@ -35,18 +36,21 @@ public class HomeController { ...@@ -35,18 +36,21 @@ public class HomeController {
private TagSearch tagsSearch; private TagSearch tagsSearch;
private TagsRepo tagsRepo; private TagsRepo tagsRepo;
private DashboardStampLoader stampLoader; private DashboardStampLoader stampLoader;
private RecommendationGenerator recommendationGenerator;
@Autowired @Autowired
public HomeController(ShopsRepo ashopsRepo, public HomeController(ShopsRepo ashopsRepo,
UserFavouriteToggle uft, TagSearch aTagsSearch, UserFavouriteToggle uft, TagSearch aTagsSearch,
TagsRepo aTagsRepo, JWTUtils jwt, TagsRepo aTagsRepo, JWTUtils jwt,
DashboardStampLoader aStampLoader) { DashboardStampLoader aStampLoader,
RecommendationGenerator rg) {
shopsRepo = ashopsRepo; shopsRepo = ashopsRepo;
toggleFavourite = uft; toggleFavourite = uft;
this.tagsSearch = aTagsSearch; this.tagsSearch = aTagsSearch;
this.tagsRepo = aTagsRepo; this.tagsRepo = aTagsRepo;
jwtUtils = jwt; jwtUtils = jwt;
stampLoader = aStampLoader; stampLoader = aStampLoader;
recommendationGenerator = rg;
} }
@GetMapping({"/", "dashboard"}) @GetMapping({"/", "dashboard"})
...@@ -90,12 +94,10 @@ public class HomeController { ...@@ -90,12 +94,10 @@ public class HomeController {
model.addAttribute("allTags", Tags); model.addAttribute("allTags", Tags);
model.addAttribute("favouriteShops", stampLoader.getData(userId).get("favourited")); model.addAttribute("favouriteShops", stampLoader.getData(userId).get("favourited"));
model.addAttribute("activeShops",stampLoader.getData(userId).get("purchased")); model.addAttribute("activeShops",stampLoader.getData(userId).get("purchased"));
model.addAttribute("loggedInUser", user.get()); model.addAttribute("loggedInUser", user.get());
model.addAttribute("normalShops", normalShops); model.addAttribute("normalShops", recommendationGenerator.getRecommendations(session, normalShops));
model.addAttribute("tags", new String[]{"Coffee", "Vegan", "Sustainable"}); model.addAttribute("tags", new String[]{"Coffee", "Vegan", "Sustainable"});
return "index"; return "index";
} }
......
package com.example.clientproject.web.restControllers;
import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.tags.Tags;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.exceptions.ForbiddenErrorException;
import com.example.clientproject.service.Utils.JWTUtils;
import com.example.clientproject.services.RecommendationGenerator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
@RestController
public class Recommendations {
public JWTUtils jwtUtils;
public RecommendationGenerator recommendationGenerator;
public Recommendations(JWTUtils jwt, RecommendationGenerator r){
jwtUtils = jwt;
recommendationGenerator = r;
}
@GetMapping("/recommend")
public String getRecommendationsForUser(HttpSession session){
try {
List<Shops> recommendations = recommendationGenerator.getRecommendations(session);
return recommendations.toString();
}catch (Exception e){
e.printStackTrace();
return "User Not Logged In";
}
}
}
src/main/resources/static/imgs/uploaded/43f67c70_c2cc_4dce_81c3_c018e6357751.jpg

6.35 KiB

src/main/resources/static/imgs/uploaded/b4fe6226_54a0_41ee_87b9_a6c3a33e49e4.png

6.8 KiB

src/main/resources/static/imgs/uploaded/bab8bd52_075f_4830_9640_399c4481cd40.png

6.8 KiB

src/main/resources/static/imgs/uploaded/c1c72053_761f_4a77_841e_e19f986c0bfe.png

6.8 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment