aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/edu/brown/cs/student/term/Main.java4
-rw-r--r--src/main/java/edu/brown/cs/student/term/hub/SuspicionRanker.java4
-rw-r--r--src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java26
-rw-r--r--src/test/java/edu/brown/cs/student/ProfitCalculationTest.java16
4 files changed, 40 insertions, 10 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 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<Holder> suspiciousHolders = ranker.getSuspicionScoreList(start, end);
System.err.println("LOG: Making map " + getClass());
Map<String, Object> 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<Holder, Double> 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");
}
diff --git a/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java b/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java
index 1291245..4ca1780 100644
--- a/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java
+++ b/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java
@@ -140,5 +140,21 @@ public class ProfitCalculationTest {
assertEquals(profitCalculation.getHoldingsList().get(0).getUnrealizedGain(), 0, .01);
}
+ @Test
+ public void optimizationTest() {
+ try {
+ db = new DatabaseQuerier("data/trades.sqlite3");
+ } catch (Exception e) {
+ System.out.println("DBQuerier Test, couldn't connect to db???");
+ }
+
+ ProfitCalculation profitCalculation = new ProfitCalculation(DatabaseQuerier.getConn(), "invalidTicker", new Date(1618223864000l),
+ new Date(1618483064000l));
+
+ long startTime = System.currentTimeMillis();
+ profitCalculation.getProfitMap();
+ System.out.println("DATA ENDPOINT " + ((System.currentTimeMillis() - startTime) / 1000) + "seconds");
+ }
+
} \ No newline at end of file