import React from "react"; import useSWR from "swr"; import { DateTime } from "luxon"; import { BrowserRouter, Route, Switch, Link } from "react-router-dom"; import MainPage from "./MainPage"; import History from "./History"; import HistoryTable from "./HistoryTable"; import "./App.css"; const url = "https://ritcoviddashboard.com/api/v0/history"; function App() { const { data: data, error: error } = useSWR(url); const [timeDifference, setTimeDifference] = React.useState(1); if (error) return (

RIT Covid Dashboard

An error occurred

); if (!data) return (

RIT Covid Dashboard

Loading latest 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 = []; for (let i = 5; i < data.length; i++) { positiveCases.push({ date: data[i].last_updated, value: ( ((data[i].total_students - data[i - 5].total_students) * 100) / (data[i].tests_administered - data[i - 5].tests_administered) ).toFixed(1), }); } positiveCases = positiveCases.filter((o) => o.value > 0 && o.value <= 100); console.log(positiveCases); return (

RIT Covid Dashboard

Last Updated:{" "} {lastUpdate.toLocaleString({ weekday: "long", month: "long", day: "2-digit", hour: "2-digit", minute: "2-digit", })}

Prior Update:{" "} {priorUpdate.toLocaleString({ weekday: "long", month: "long", day: "2-digit", hour: "2-digit", minute: "2-digit", })}


{ return { value: d.total_students, date: d.last_updated }; })} /> { return { value: d.total_staff, date: d.last_updated }; })} /> { return { value: d.new_students, date: d.last_updated }; })} /> { return { value: d.new_staff, date: d.last_updated }; })} /> { return { value: d.quarantine_on_campus, date: d.last_updated }; })} /> { return { value: d.quarantine_off_campus, date: d.last_updated }; })} /> { return { value: d.isolation_on_campus, date: d.last_updated }; })} /> { return { value: d.isolation_off_campus, date: d.last_updated }; })} /> { return { value: d.tests_administered, date: d.last_updated }; })} /> { return { value: d.beds_available, date: d.last_updated }; })} />

By Galen Guyer. Source available on{" "} GitHub {" "} ( Report Issue )

); } export default App;