diff --git a/webclient/src/Charts.js b/webclient/src/Charts.js index b39fa69..91aa5e8 100644 --- a/webclient/src/Charts.js +++ b/webclient/src/Charts.js @@ -4,16 +4,19 @@ import { Button, Container, Checkbox, Dimmer, Divider, Dropdown, Form, Grid, Hea import { BarChart, Bar, LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, ReferenceLine } from 'recharts'; import { apiUrl, statusColor, BasicTable, staticUrl, requester } from './utils.js'; import { NotFound } from './Misc.js'; +import moment from 'moment-timezone'; let memberCountCache = false; let signupCountCache = false; let spaceActivityCache = false; +let dustLevelCache = false; export function Charts(props) { const [memberCount, setMemberCount] = useState(memberCountCache); const [signupCount, setSignupCount] = useState(signupCountCache); const [spaceActivity, setSpaceActivity] = useState(spaceActivityCache); const [fullActivity, setFullActivity] = useState(false); + const [dustLevel, setDustLevel] = useState(dustLevelCache); useEffect(() => { requester('/charts/membercount/', 'GET') @@ -42,6 +45,15 @@ export function Charts(props) { .catch(err => { console.log(err); }); + + requester('https://ps-iot.dns.t0.vc/sensors/air/0/pm25/week', 'GET') + .then(res => { + setDustLevel(res.result); + dustLevelCache = res.result; + }) + .catch(err => { + console.log(err); + }); }, []); return ( @@ -281,6 +293,37 @@ export function Charts(props) {

Retained Count: number of those signups who are still a member currently.

+ +
Dust Level
+ +

Averaged every 15 minutes for the past week.

+ +

+ {dustLevel && + + + moment(t).format('ddd h:mm a')} minTickGap={10} /> + + + v.toFixed(2) + ' μg/m³'} labelFormatter={t => 'Time: ' + moment(t).format('ddd h:mm a')} /> + + + + + + } +

+ +

Classroom PM2.5: Amount of PM2.5 particles measured from the classroom ceiling. Units are μg/m³.

+ ); }; diff --git a/webclient/src/utils.js b/webclient/src/utils.js index 5585257..81201d0 100644 --- a/webclient/src/utils.js +++ b/webclient/src/utils.js @@ -32,6 +32,7 @@ export const BasicTable = (props) => ( export const requester = (route, method, token, data) => { let options = {headers: {}}; + let url = ''; if (token) { options.headers.Authorization = 'Token ' + token; @@ -65,7 +66,13 @@ export const requester = (route, method, token, data) => { return error; } - return fetch(apiUrl + route, options) + if (route.startsWith('http')) { + url = route; + } else { + url = apiUrl + route; + } + + return fetch(url, options) .then(response => { if (!response.ok) { throw customError(response);