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

Reversed the list

parent cd440123
Branches
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 {
userStampBoardsRepo = usbr;
}
public String getRecommendations(HttpSession session) throws Exception {
public List<Shops> getRecommendations(HttpSession session) throws Exception {
Long userId = 1L;
List<Tags> tags = new ArrayList<Tags>();
......@@ -50,7 +50,7 @@ public class RecommendationGenerator {
tags = user.get().getFavouriteTags();
userId = user.get().getUserId();
}else{
return "User not logged in";
throw new ForbiddenErrorException("User Not Logged In");
}
//Make the user weights list
......@@ -104,7 +104,6 @@ public class RecommendationGenerator {
List<Tags> shopTags = s.getShopTags();
//For each tag
for(Tags tag : shopTags){
System.out.println(tag.getTagName());
//Add 2*factor to tag relevancy or add the tag at 1 if not exists
String tagName = tag.getTagName().toLowerCase().strip();
if(tagWeights.containsKey(tagName)){
......@@ -138,11 +137,16 @@ public class RecommendationGenerator {
Collections.sort(weightedShops, new Comparator<HashMap<Shops, Double>>(){
public int compare(HashMap<Shops, Double> one, HashMap<Shops, Double> two) {
return one.entrySet().iterator().next().getValue().compareTo(two.entrySet().iterator().next().getValue());
return two.entrySet().iterator().next().getValue().compareTo(one.entrySet().iterator().next().getValue());
}
});
return weightedShops.toString();
//Only return the shop objects
List<Shops> recommendations = new ArrayList<>();
for(HashMap<Shops, Double> s: weightedShops){
recommendations.add(s.entrySet().iterator().next().getKey());
}
return recommendations;
}
}
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;
......@@ -28,11 +29,11 @@ public class Recommendations {
public String getRecommendationsForUser(HttpSession session){
try {
return recommendationGenerator.getRecommendations(session);
List<Shops> recommendations = recommendationGenerator.getRecommendations(session);
return recommendations.toString();
}catch (Exception e){
e.printStackTrace();
return "User Not Logged In";
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment