From 43d42b0b88927a552c09bc32145f7e7ef2222652 Mon Sep 17 00:00:00 2001 From: clarkohw Date: Mon, 19 Apr 2021 18:49:44 -0400 Subject: exclude only sell people --- src/main/java/edu/brown/cs/student/term/Main.java | 4 ++++ .../brown/cs/student/term/hub/SuspicionRanker.java | 4 ---- .../cs/student/term/profit/ProfitCalculation.java | 26 +++++++++++++++++----- 3 files changed, 24 insertions(+), 10 deletions(-) (limited to 'src/main/java') 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 df95ec0..6a20de3 100644 --- a/src/main/java/edu/brown/cs/student/term/Main.java +++ b/src/main/java/edu/brown/cs/student/term/Main.java @@ -151,6 +151,7 @@ public final class Main { public Object handle(Request request, Response response) throws Exception { //String str = request.body(); //xmlLinks = new JSONObject(str); //this is all the filedAt times and xml files + long startTime = System.currentTimeMillis(); try { System.err.println("LOG: Call to /data from frontend"); DatabaseQuerier db = SetupCommand.getDq(); @@ -166,6 +167,9 @@ public final class Main { List suspiciousHolders = ranker.getSuspicionScoreList(start, end); System.err.println("LOG: Making map " + getClass()); Map variables = ImmutableMap.of("holders", suspiciousHolders); + + System.out.println("DATA ENDPOINT " + ((System.currentTimeMillis() - startTime) / 1000) + "seconds"); + return GSON.toJson(variables); } catch (Exception e) { System.out.println("Error retrieving the suspicion ranks for GUI"); 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..c77eb9f 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 @@ -52,7 +52,6 @@ public class SuspicionRanker { HubSearch hub = new HubSearch(lm); Map holderToHubScore = hub.runHubSearch(start, end); - /* ProfitCalculation pc = new ProfitCalculation(DatabaseQuerier.getConn(), "", new Date(start.toEpochMilli()), @@ -68,7 +67,6 @@ 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(profitMax <= 0) { profitMax = Math.abs(getMinOfMap(profitMap)); } @@ -76,11 +74,9 @@ public class SuspicionRanker { /*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); diff --git a/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java b/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java index 0ef87c3..ab76003 100644 --- a/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java +++ b/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java @@ -83,10 +83,10 @@ public class ProfitCalculation { private String validateTicker(String ticker) { //this is cleaning some improperly formatted tickers ticker = ticker.replaceAll("[^a-zA-Z0-9]", "").toUpperCase(); - if(ticker.contains("[0-9]") || - ticker.length() > 5 || - ticker.length() < 2 || - ticker.contains("NONE")) { + if (ticker.contains("[0-9]") || + ticker.length() > 5 || + ticker.length() < 2 || + ticker.contains("NONE")) { return ""; } @@ -109,7 +109,7 @@ public class ProfitCalculation { while (rs.next()) { String ticker = rs.getString("stock_name"); ticker = validateTicker(ticker); - if(ticker.equals("")){ + if (ticker.equals("")) { continue; } int shares = rs.getInt("number_of_shares"); @@ -284,11 +284,14 @@ public class ProfitCalculation { } public double calculateGains() { + if (!tablesFilled) { organizeOrders(); getRealizedGains(); tablesFilled = true; } + + double realizedGains = 0; for (double value : realizedGainsMap.values()) { @@ -383,13 +386,22 @@ public class ProfitCalculation { } try { PreparedStatement prep; + long START = System.currentTimeMillis(); prep = - conn.prepareStatement("SELECT * from trades group by holder_name;"); + conn.prepareStatement( + "SELECT * From trades GROUP BY holder_name having max(is_buy) = 1;"); ResultSet rs = prep.executeQuery(); + + long QUERY = System.currentTimeMillis(); + System.out.println((QUERY - START) + " query time"); + while (rs.next()) { int id = rs.getInt("holder_id"); this.person = rs.getString("holder_name"); resetClass(); + + + double gain = this.calculateGains(); if (moneyInput == 0) { profitMap.put(id, 0.0); @@ -398,6 +410,8 @@ public class ProfitCalculation { } } + + } catch (SQLException throwables) { System.out.println("ERROR: SQl error in profit calculation"); } -- cgit v1.2.3-70-g09d2