import React, { useState, useEffect } from 'react'; import { Statistic, Button, Container, Header } from 'semantic-ui-react'; import { BarChart, Bar, LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, ReferenceLine } from 'recharts'; import { requester } from './utils.js'; import moment from 'moment-timezone'; let memberCountCache = false; let signupCountCache = false; let spaceActivityCache = false; let classroomDustLevelCache = false; let woodshopDustLevelCache = 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 [classroomDustLevel, setClassroomDustLevel] = useState(classroomDustLevelCache); const [woodshopDustLevel, setWoodshopDustLevel] = useState(woodshopDustLevelCache); useEffect(() => { requester('/charts/membercount/', 'GET') .then(res => { setMemberCount(res); memberCountCache = res; }) .catch(err => { console.log(err); }); requester('/charts/signupcount/', 'GET') .then(res => { setSignupCount(res); signupCountCache = res; }) .catch(err => { console.log(err); }); requester('/charts/spaceactivity/', 'GET') .then(res => { setSpaceActivity(res); spaceActivityCache = res; }) .catch(err => { console.log(err); }); requester('https://ps-iot.dns.t0.vc/sensors/air/0/pm25/week', 'GET') .then(res => { setClassroomDustLevel(res.result); classroomDustLevelCache = res.result; }) .catch(err => { console.log(err); }); requester('https://ps-iot.dns.t0.vc/sensors/air/1/pm25/week', 'GET') .then(res => { setWoodshopDustLevel(res.result); woodshopDustLevelCache = res.result; }) .catch(err => { console.log(err); }); }, []); return (
Charts
{memberCount && signupCount && <>

The total member count is {memberCount.slice().reverse()[0].member_count} members, compared to {memberCount.slice().reverse()[30].member_count} members 30 days ago.

The green member count is {memberCount.slice().reverse()[0].green_count} members, compared to {memberCount.slice().reverse()[30].green_count} members 30 days ago.

The older than six months member count is {memberCount.slice().reverse()[0].six_month_plus_count} members, compared to {memberCount.slice().reverse()[30].six_month_plus_count} members 30 days ago.

The vetted member count is {memberCount.slice().reverse()[0].vetted_count} members, compared to {memberCount.slice().reverse()[30].vetted_count} members 30 days ago.

There were {signupCount.slice().reverse()[0].signup_count} signups so far this month, and {signupCount.slice().reverse()[1].signup_count} signups last month.

}
Member Counts

Daily since March 2nd, 2020.

Total Members

{memberCount && }

Six Month+ Members

{memberCount && }

Vetted Members

{memberCount && }

PayPal Subscribers

{memberCount && }

Member Count: number of active paying members on Spaceport.

Green Count: number of Prepaid and Current members.

Six Months+: number of active memberships older than six months.

Vetted Count: number of active vetted members.

PayPal Subscriber Count: number of members with a PayPal subscription.

Space Activity
{fullActivity ?

Daily since March 7th, 2020, updates hourly.

:

Last four weeks, updates hourly. {' '}

}

{spaceActivity && moment(t).format('YYYY-MM-DD ddd')} /> }

Cards Scans: number of individual members who have scanned to enter the space.

Signup Count

Monthly for the last sixteen months, updates daily.

{signupCount && }

Signup Count: number of brand new account registrations that month.

Later Vetted Count: number of those signups who eventually got vetted (at a later date).

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

Protodust Level

Averaged every 15 minutes for the past week. They are cheap sensors so don't trust the absolute value of the readings.

{classroomDustLevel && woodshopDustLevel && <> moment(t).format('ddd h:mm a')} minTickGap={10} /> v.toFixed(2) + ' μg/m³'} labelFormatter={t => 'Time: ' + moment(t).format('ddd h:mm a')} /> 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³.

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

); };