From 8e7c77b5bff25762dbd874ac6999ad7f493ba41d Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Fri, 16 Apr 2021 12:43:17 -0400 Subject: Have a little bug with backend. Going to skip over it for now. --- frontend/src/DateInput.js | 35 +++++++++++++++++++ frontend/src/SECAPIData.js | 85 ++++++++++------------------------------------ 2 files changed, 53 insertions(+), 67 deletions(-) create mode 100644 frontend/src/DateInput.js (limited to 'frontend/src') diff --git a/frontend/src/DateInput.js b/frontend/src/DateInput.js new file mode 100644 index 0000000..b5962f0 --- /dev/null +++ b/frontend/src/DateInput.js @@ -0,0 +1,35 @@ +// React import +import { useEffect, useState, useRef } from "react"; + +/** + * Componenet for checkins. Has a toggle to show more info. + * @param {Object} props The props of the component. + * @returns {import('react').HtmlHTMLAttributes} A list element holding a checkin's info. + */ +function DateInput(props) { + const startInput = useRef(); + const endInput = useRef(); + + const toValue = date => date.toISOString().slice(0, 10); + + useEffect(() => setInitDates(), []); + + const setInitDates = () => { + startInput.current.value = toValue(new Date()); + + // Two weeks away -> from stack overflow, + const fortnightAway = toValue(new Date(Date.now() - 12096e5)); + endInput.current.value = fortnightAway; + } + + return ( + <> + + props.setStart(e.target.value)}/> + + props.setEnd(e.target.value)}/> + + ); +} + +export default DateInput; \ No newline at end of file diff --git a/frontend/src/SECAPIData.js b/frontend/src/SECAPIData.js index a209ff2..d14ee1f 100644 --- a/frontend/src/SECAPIData.js +++ b/frontend/src/SECAPIData.js @@ -1,89 +1,40 @@ import React, {useState, useEffect} from 'react'; import Button from './Button'; -import HubList from './HubList' +import HubList from './HubList'; +import DateInput from './DateInput'; function SECAPIData() { + const [displayData, setDisplayData] = useState({}); + const [startDate, setStartDate] = useState(""); + const [endDate, setEndDate] = useState(""); - const [dataToBackend, setDataToBackend] = useState([]); - const [displayData, setDisplayData] = useState(""); + const toEpochMilli = date => Date.parse(date); - const requestData = () => { - // End early in debug to avoid too many requests. - if (dataToBackend.length !== 0) { - sendToBackend(); - return; - } - - console.log("Makig request..."); - - let date = new Date() - let today = date.toISOString().slice(0, 10); - - let pastDate = new Date(); - pastDate.setDate(date.getDate() - 14); - let past = pastDate.toISOString().slice(0, 10); - - fetch("https://api.sec-api.io?token=4d6ff81353d665c975d443e30020879b1ea882bc96a00cd8774a95bddd838fe5", { + const getLinks = () => { + fetch("http://localhost:4567/susrank", { method: "POST", - body: JSON.stringify({ - "query": { "query_string": { "query": "formType:4 AND filedAt:{"+ past +" TO "+ today +"} AND formType:(NOT \"N-4\") AND formType:(NOT \"4/A\")" } }, - "from": "0", - "size": "1000", - "sort": [{ "filedAt": { "order": "desc" } }] - }), - headers: { - "Content-Type": "application/json" - }, - credentials: "same-origin" - }) - .then(res => res.json()) - .then(data => { - let list = []; - data.filings.forEach(filing => { - if (filing.ticker === "") { - // TODO: why are there repitions of urls. - list.push({ - timestamp: filing.filedAt, - url: filing.documentFormatFiles[1].documentUrl - }); - } - }) - setDataToBackend(list); - }) - .catch(error => { - console.log(error); - }); - } - - const sendToBackend = () => { - console.log(dataToBackend); - - fetch("http://localhost:4567/data", { - method: "POST", - body: JSON.stringify({ - "data" : dataToBackend - }), + body: JSON.stringify( + { + "start" : toEpochMilli(startDate), + "end" : toEpochMilli(endDate) + }), headers: { "Content-Type": "application/json", }, credentials: "same-origin" }) - - .then(response => response.json().then(data => setDisplayData(data))) - .catch(function (error) { - console.log(error); - }); + .then(res => res.json()) + .then(data => setDisplayData(data)) + .catch(err => console.log(err)); } - - // This hook is autocalled once the setDataToBackend takes effect. - useEffect(() => sendToBackend(), [dataToBackend]); return (

SECAPIData

- + +
); -- cgit v1.2.3-70-g09d2 From ccacfbf0a288f6aa69c10ec17d96151cfba77c70 Mon Sep 17 00:00:00 2001 From: Julia McCauley Date: Fri, 16 Apr 2021 14:01:46 -0400 Subject: fixed error with empty hub map in suspicion rank --- data/empty.sqlite3 | 0 frontend/src/SECAPIData.js | 2 +- src/main/java/edu/brown/cs/student/term/Main.java | 2 +- src/main/java/edu/brown/cs/student/term/hub/SuspicionRanker.java | 6 ++++++ 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 data/empty.sqlite3 (limited to 'frontend/src') diff --git a/data/empty.sqlite3 b/data/empty.sqlite3 new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/SECAPIData.js b/frontend/src/SECAPIData.js index d14ee1f..8d0611f 100644 --- a/frontend/src/SECAPIData.js +++ b/frontend/src/SECAPIData.js @@ -13,7 +13,7 @@ function SECAPIData() { const toEpochMilli = date => Date.parse(date); const getLinks = () => { - fetch("http://localhost:4567/susrank", { + fetch("http://localhost:4567/data", { method: "POST", body: JSON.stringify( { 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 4b910f7..5c7497f 100644 --- a/src/main/java/edu/brown/cs/student/term/Main.java +++ b/src/main/java/edu/brown/cs/student/term/Main.java @@ -162,7 +162,7 @@ public final class Main { Map variables = ImmutableMap.of("holders", suspiciousHolders); return GSON.toJson(variables); } catch (Exception e) { - System.out.println("DBQuerier Test, couldn't connect to db???"); + System.out.println("Error retrieving the suspicion ranks for GUI"); return "Error"; } } 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 564ba28..2b567c2 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 @@ -31,6 +31,7 @@ public class SuspicionRanker { LinkMapper lm = new LinkMapper(querier); HubSearch hub = new HubSearch(lm); Map holderToHubScore = hub.runHubSearch(start, end); + System.out.println(holderToHubScore); ProfitCalculation pc = new ProfitCalculation(DatabaseQuerier.getConn(), "", new Date(start.toEpochMilli()), @@ -38,6 +39,11 @@ public class SuspicionRanker { Map profitMap = pc.getProfitMap(); + //if the maps are empty, we abort because we have entirely incomplete data + if(profitMap.isEmpty() || holderToHubScore.isEmpty()){ + return new ArrayList<>(); + } + 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*/ -- cgit v1.2.3-70-g09d2