aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/edu/brown/cs/student/term/hub
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/edu/brown/cs/student/term/hub')
-rw-r--r--src/main/java/edu/brown/cs/student/term/hub/LinkMapper.java32
-rw-r--r--src/main/java/edu/brown/cs/student/term/hub/SuspicionRanker.java32
2 files changed, 48 insertions, 16 deletions
diff --git a/src/main/java/edu/brown/cs/student/term/hub/LinkMapper.java b/src/main/java/edu/brown/cs/student/term/hub/LinkMapper.java
index 31e2625..e749aff 100644
--- a/src/main/java/edu/brown/cs/student/term/hub/LinkMapper.java
+++ b/src/main/java/edu/brown/cs/student/term/hub/LinkMapper.java
@@ -11,8 +11,9 @@ public class LinkMapper {
//TODO: Review what we actually need in here
//not strictly necessary but may be nice to maintain
- private List<List<Trade>> allTrades = new ArrayList<>();
+ //private List<List<Trade>> allTrades = new ArrayList<>();
private Map<Holder, Set<Holder>> followerToLeaders = new HashMap<>();
+ private static Map<Integer, Set<Trade>> holderIDToTrades = new HashMap<>();
private DatabaseQuerier databaseQuerier;
public LinkMapper(DatabaseQuerier db){
@@ -55,6 +56,25 @@ public class LinkMapper {
return followerToLeaders;
}
+ public static List<String> getCommonTrades(int leaderID, int followerID){
+ Set<Trade> leaderTrades = new HashSet<>(holderIDToTrades.get(leaderID));
+ Set<Trade> followerTrades = new HashSet<>(holderIDToTrades.get(followerID));
+
+ leaderTrades.retainAll(followerTrades);
+ //TODO: Could retain WAY more info in here!
+ List<String> commonTrades = new ArrayList<>();
+ for(Trade leaderTrade: leaderTrades){
+ String buyType = "";
+ if(leaderTrade.isBuy()){
+ buyType = "Buy";
+ } else{
+ buyType = "Sell";
+ }
+ commonTrades.add(buyType + ": " + leaderTrade.getStock());
+ }
+ return commonTrades;
+ }
+
/**
* Converts a single trade list into entries in the follower to leader map
* @param tradeList - a list of trades for a single stock (either buy or sell)
@@ -64,7 +84,15 @@ public class LinkMapper {
//gets in order list of people
for (Trade trade : tradeList) {
- holderList.add(trade.getHolder());
+ Holder currentHolder = trade.getHolder();
+ holderList.add(currentHolder);
+ if(!holderIDToTrades.containsKey(currentHolder.getId())){
+ Set<Trade> tradeSet = new HashSet<>();
+ tradeSet.add(trade);
+ holderIDToTrades.put(currentHolder.getId(), tradeSet);
+ } else {
+ holderIDToTrades.get(currentHolder.getId()).add(trade);
+ }
}
//Set<Holder> followers = new HashSet<>(holderList);
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 3283f5c..d37910e 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
@@ -16,8 +16,9 @@ public class SuspicionRanker {
}
private <K, V extends Comparable<V>> V getMaxOfMap(Map<K, V> map) {
- Map.Entry<K, V> maxEntry = Collections.max(map.entrySet(), Map.Entry.comparingByValue());
- return maxEntry.getValue();
+ //Map.Entry<K, V> maxEntry = Collections.max(map.entrySet(), Map.Entry.comparingByValue());
+ Collection<V> values = map.values();
+ return Collections.max(map.values());
}
private <K, V extends Comparable<V>> V getMinOfMap(Map<K, V> map) {
@@ -52,13 +53,12 @@ public class SuspicionRanker {
HubSearch hub = new HubSearch(lm);
Map<Holder, Double> holderToHubScore = hub.runHubSearch(start, end);
- /*
-
ProfitCalculation pc = new ProfitCalculation(DatabaseQuerier.getConn(), "",
new Date(start.toEpochMilli()),
new Date(end.toEpochMilli()));
Map<Integer, Double> profitMap = pc.getProfitMap();
+ System.out.println(profitMap);
//if the maps are empty, we abort because we have entirely incomplete data
if(profitMap.isEmpty() || holderToHubScore.isEmpty()){
@@ -66,30 +66,34 @@ public class SuspicionRanker {
}
double profitMax = getMaxOfMap(profitMap);
- /*if all of our values are negative, we need to flip sides so that the
- * biggest loser doesn't end up being the most suspicious person*/
- /*
+
+ //if all of our values are negative, we need to flip sides so that the
+ //biggest loser doesn't end up being the most suspicious person*/
if(profitMax <= 0) {
profitMax = Math.abs(getMinOfMap(profitMap));
}
- /*if both the min we found and max we found are 0, then we have
- the special case where all the values are 0, in which case we
- need to avoid dividing by 0*/
- /*
+
+ //if both the min we found and max we found are 0, then we have
+ //the special case where all the values are 0, in which case we
+ //need to avoid dividing by 0
+
if(profitMax == 0){
profitMax = 1;
}
- */
double hubMax = getMaxOfMap(holderToHubScore);
for (Holder guy : holderToHubScore.keySet()) {
- //double normalizedProfitScore = profitMap.get(guy.getId()) / profitMax;
+ double normalizedProfitScore = 0;
+ if (profitMap.containsKey(guy.getId())) {
+ normalizedProfitScore = profitMap.get(guy.getId()) / profitMax;
+ }
double normalizedHubScore = holderToHubScore.get(guy) / hubMax;
- double suspicionScore = normalizedHubScore; //* 0.6 + normalizedProfitScore * 0.4;
+ double suspicionScore = normalizedHubScore * 0.6 + normalizedProfitScore * 0.4;
+
guy.setSuspicionScore(suspicionScore);
orderedSuspicion.add(guy);
}