From b5f996ec8dd845f3294f9f71421c084d8f74130f Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Sat, 16 Jan 2021 00:51:03 -0500 Subject: Add option to only show information from the current semester --- src/App.js | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'src/App.js') diff --git a/src/App.js b/src/App.js index 87e8010..4e45139 100644 --- a/src/App.js +++ b/src/App.js @@ -10,9 +10,10 @@ import "./App.css"; const url = "https://ritcoviddashboard.com/api/v0/history"; function App() { - const { data: data, error: error } = useSWR(url); + let { data: rawData, error: error } = useSWR(url); const [timeDifference, setTimeDifference] = React.useState(1); + const [showAllTime, setShowAllTime] = React.useState(true); if (error) return ( @@ -21,7 +22,7 @@ function App() {

An error occurred

); - if (!data) + if (!rawData) return (

RIT Covid Dashboard

@@ -29,9 +30,36 @@ function App() {
); + let data = rawData; + const local = DateTime.local().zoneName; + const semesterStart = DateTime.fromISO("2021-01-01"); + if (!showAllTime) { + data = rawData.filter((d) => { + let date = DateTime.fromSQL(d.last_updated, { zone: "UTC" }).setZone(local); + return date > semesterStart; + }); + const last = rawData[rawData.length - data.length - 1]; + data = data.map((d) => { + return { + alert_level: d.alert_level, + beds_available: d.beds_available, + isolation_off_campus: d.isolation_off_campus, + isolation_on_campus: d.isolation_on_campus, + last_updated: d.last_updated, + new_staff: d.new_staff, + new_students: d.new_students, + quarantine_off_campus: d.quarantine_off_campus, + quarantine_on_campus: d.quarantine_on_campus, + tests_administered: d.tests_administered - last.tests_administered, + total_staff: d.total_staff - last.total_staff, + total_students: d.total_students - last.total_students, + }; + }); + } + + console.log(data); const latest = data[data.length - 1]; const prior = data[data.length - (1 + timeDifference)]; - const local = DateTime.local().zoneName; const lastUpdate = DateTime.fromSQL(latest.last_updated, { zone: "UTC" }).setZone(local); const priorUpdate = DateTime.fromSQL(prior.last_updated, { zone: "UTC" }).setZone(local); let positiveCases = []; @@ -45,7 +73,6 @@ function App() { }); } positiveCases = positiveCases.filter((o) => o.value > 0 && o.value <= 100); - console.log(positiveCases); return (
@@ -72,17 +99,23 @@ function App() { minute: "2-digit", })} - +   +
- +