Add wood shop dust sensor to Charts page

This commit is contained in:
Tanner Collin 2021-07-23 22:58:45 +00:00
parent f4d7060e5b
commit 393bf04180

View File

@ -9,14 +9,16 @@ import moment from 'moment-timezone';
let memberCountCache = false; let memberCountCache = false;
let signupCountCache = false; let signupCountCache = false;
let spaceActivityCache = false; let spaceActivityCache = false;
let dustLevelCache = false; let classroomDustLevelCache = false;
let woodshopDustLevelCache = false;
export function Charts(props) { export function Charts(props) {
const [memberCount, setMemberCount] = useState(memberCountCache); const [memberCount, setMemberCount] = useState(memberCountCache);
const [signupCount, setSignupCount] = useState(signupCountCache); const [signupCount, setSignupCount] = useState(signupCountCache);
const [spaceActivity, setSpaceActivity] = useState(spaceActivityCache); const [spaceActivity, setSpaceActivity] = useState(spaceActivityCache);
const [fullActivity, setFullActivity] = useState(false); const [fullActivity, setFullActivity] = useState(false);
const [dustLevel, setDustLevel] = useState(dustLevelCache); const [classroomDustLevel, setClassroomDustLevel] = useState(classroomDustLevelCache);
const [woodshopDustLevel, setWoodshopDustLevel] = useState(woodshopDustLevelCache);
useEffect(() => { useEffect(() => {
requester('/charts/membercount/', 'GET') requester('/charts/membercount/', 'GET')
@ -48,8 +50,17 @@ export function Charts(props) {
requester('https://ps-iot.dns.t0.vc/sensors/air/0/pm25/week', 'GET') requester('https://ps-iot.dns.t0.vc/sensors/air/0/pm25/week', 'GET')
.then(res => { .then(res => {
setDustLevel(res.result); setClassroomDustLevel(res.result);
dustLevelCache = 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 => { .catch(err => {
console.log(err); console.log(err);
@ -296,12 +307,13 @@ export function Charts(props) {
<Header size='medium'>Dust Level</Header> <Header size='medium'>Dust Level</Header>
<p>Averaged every 15 minutes for the past week.</p> <p>Averaged every 15 minutes for the past week. They are cheap sensors so don't trust the absolute value of the readings.</p>
<p> <p>
{dustLevel && {classroomDustLevel && woodshopDustLevel &&
<>
<ResponsiveContainer width='100%' height={300}> <ResponsiveContainer width='100%' height={300}>
<LineChart data={dustLevel}> <LineChart data={classroomDustLevel} syncId={1}>
<XAxis dataKey='time' tickFormatter={(t) => moment(t).format('ddd h:mm a')} minTickGap={10} /> <XAxis dataKey='time' tickFormatter={(t) => moment(t).format('ddd h:mm a')} minTickGap={10} />
<YAxis /> <YAxis />
<CartesianGrid strokeDasharray='3 3'/> <CartesianGrid strokeDasharray='3 3'/>
@ -319,11 +331,34 @@ export function Charts(props) {
/> />
</LineChart> </LineChart>
</ResponsiveContainer> </ResponsiveContainer>
<ResponsiveContainer width='100%' height={300}>
<LineChart data={woodshopDustLevel} syncId={1}>
<XAxis dataKey='time' tickFormatter={(t) => moment(t).format('ddd h:mm a')} minTickGap={10} />
<YAxis />
<CartesianGrid strokeDasharray='3 3'/>
<Tooltip formatter={v => v.toFixed(2) + ' μg/m³'} labelFormatter={t => 'Time: ' + moment(t).format('ddd h:mm a')} />
<Legend />
<Line
type='monotone'
dataKey='value'
name='Woodshop PM2.5'
stroke='#82ca9d'
strokeWidth={2}
dot={false}
animationDuration={1000}
/>
</LineChart>
</ResponsiveContainer>
</>
} }
</p> </p>
<p>Classroom PM2.5: Amount of PM2.5 particles measured from the classroom ceiling. Units are μg/.</p> <p>Classroom PM2.5: Amount of PM2.5 particles measured from the classroom ceiling. Units are μg/.</p>
<p>Woodshop PM2.5: Amount of PM2.5 particles measured from the woodshop ceiling. Units are μg/.</p>
</Container> </Container>
); );
}; };