diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/edu/brown/cs/student/term/Main.java | 6 | ||||
-rw-r--r-- | src/main/java/edu/brown/cs/student/term/hub/SuspicionRanker.java | 13 | ||||
-rw-r--r-- | src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java (renamed from src/main/java/edu/brown/cs/student/term/ProfitCalculation.java) | 12 |
3 files changed, 16 insertions, 15 deletions
diff --git a/src/main/java/edu/brown/cs/student/term/Main.java b/src/main/java/edu/brown/cs/student/term/Main.java index 5ca40e8..3b0a258 100644 --- a/src/main/java/edu/brown/cs/student/term/Main.java +++ b/src/main/java/edu/brown/cs/student/term/Main.java @@ -2,8 +2,7 @@ package edu.brown.cs.student.term; import com.google.common.collect.ImmutableMap; import edu.brown.cs.student.term.hub.Holder; -import edu.brown.cs.student.term.hub.HubSearch; -import edu.brown.cs.student.term.hub.LinkMapper; +import edu.brown.cs.student.term.profit.ProfitCalculation; import edu.brown.cs.student.term.profit.StockHolding; import edu.brown.cs.student.term.hub.SuspicionRanker; import edu.brown.cs.student.term.repl.Command; @@ -27,6 +26,7 @@ import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -124,7 +124,7 @@ public final class Main { } /** - * Gets the list of holders with id, name, and suspicion rank + * Gets the list of holders with id, name, and suspicion rank. */ private static class SuspicionRankHandler implements Route { @Override diff --git a/src/main/java/edu/brown/cs/student/term/hub/SuspicionRanker.java b/src/main/java/edu/brown/cs/student/term/hub/SuspicionRanker.java index dd959f0..9f5f9c1 100644 --- a/src/main/java/edu/brown/cs/student/term/hub/SuspicionRanker.java +++ b/src/main/java/edu/brown/cs/student/term/hub/SuspicionRanker.java @@ -1,7 +1,7 @@ package edu.brown.cs.student.term.hub; import edu.brown.cs.student.term.DatabaseQuerier; -import edu.brown.cs.student.term.ProfitCalculation; +import edu.brown.cs.student.term.profit.ProfitCalculation; import java.time.Instant; import java.sql.Date; @@ -10,7 +10,8 @@ import java.util.*; public class SuspicionRanker { DatabaseQuerier querier; - public SuspicionRanker(DatabaseQuerier db){ + + public SuspicionRanker(DatabaseQuerier db) { this.querier = db; } @@ -21,7 +22,7 @@ public class SuspicionRanker { return maxEntry.getValue(); } - public List<Holder> getSuspicionScoreList(Instant start, Instant end){ + public List<Holder> getSuspicionScoreList(Instant start, Instant end) { List<Holder> suspicionList = new ArrayList<>(); try { LinkMapper lm = new LinkMapper(querier); @@ -29,8 +30,8 @@ public class SuspicionRanker { Map<Holder, Double> holderToHubScore = hub.runHubSearch(start, end); ProfitCalculation pc = new ProfitCalculation(DatabaseQuerier.getConn(), "", - new Date(start.toEpochMilli()), - new Date(end.toEpochMilli())); + new Date(start.toEpochMilli()), + new Date(end.toEpochMilli())); Map<Integer, Double> profitMap = pc.getProfitMap(); @@ -38,7 +39,7 @@ public class SuspicionRanker { double hubMax = getMaxOfMap(holderToHubScore); - for(Holder guy: holderToHubScore.keySet()){ + for (Holder guy : holderToHubScore.keySet()) { double normalizedProfitScore = profitMap.get(guy.getId()) / profitMax; double normalizedHubScore = holderToHubScore.get(guy) / hubMax; double suspicionScore = normalizedHubScore * 0.6 + normalizedProfitScore * 0.4; diff --git a/src/main/java/edu/brown/cs/student/term/ProfitCalculation.java b/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java index 88b4b04..85b2a9a 100644 --- a/src/main/java/edu/brown/cs/student/term/ProfitCalculation.java +++ b/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java @@ -1,8 +1,7 @@ -package edu.brown.cs.student.term; +package edu.brown.cs.student.term.profit; import edu.brown.cs.student.term.profit.StockHolding; -import org.eclipse.jetty.util.DecoratedObjectFactory; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -362,11 +361,12 @@ public class ProfitCalculation { while (rs.next()) { int id = rs.getInt("holder_id"); this.person = rs.getString("holder_name"); - //TODO: Temporary fix for the moneyinput divide by 0 error - if(moneyInput == 0){ - moneyInput = 1; + if (moneyInput == 0) { + profitMap.put(id, 0.0); + } else { + profitMap.put(id, this.calculateGains() / moneyInput); } - profitMap.put(id, this.calculateGains() / moneyInput); + } } catch (SQLException throwables) { System.out.println("ERROR: SQl error in profit calculation"); |