processed data bucket functional

This commit is contained in:
Evan Lanham
2022-03-12 10:32:02 -07:00
parent 71be3caac0
commit 79412b8afc
8 changed files with 134 additions and 204 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

+18 -90
View File
@@ -1,6 +1,6 @@
import React from "react";
import { useLocalDb } from "../DbContext";
import "./InputPage.css"
import "./InputPage.css";
// import { Button, Intent, Spinner } from "@blueprintjs/core";
import FormRenderer from "@data-driven-forms/react-form-renderer/form-renderer";
import componentTypes from "@data-driven-forms/react-form-renderer/component-types";
@@ -8,21 +8,7 @@ import componentMapper from "@data-driven-forms/blueprint-component-mapper/compo
import FormTemplate from "@data-driven-forms/blueprint-component-mapper/form-template";
import { Formik, FastField, Form } from "formik";
import InputNumberField from "../components/InputNumberField.jsx";
import {
TextField,
Button,
Grid,
FormRow,
Divider,
Checkbox,
Radio,
FormControlLabel,
FormControl,
FormLabel,
RadioGroup,
IconButton,
InputAdornment,
} from "@material-ui/core";
import { TextField, Button, Grid, FormRow, Divider, Checkbox, Radio, FormControlLabel, FormControl, FormLabel, RadioGroup, IconButton, InputAdornment } from "@material-ui/core";
import { AddCircleOutline, RemoveCircleOutline } from "@material-ui/icons";
const InputPage = () => {
@@ -51,7 +37,7 @@ const InputPage = () => {
climb_level: "",
alliance: "",
defence: "0",
disabled: false
disabled: false,
}}
validateOnChange="false"
onSubmit={(values, { setSubmitting, resetForm }) => {
@@ -74,18 +60,10 @@ const InputPage = () => {
// resetForm(); //Hah tobad
setSubmitting(false);
}, 400);
}}>
{({
values,
setValues,
errors,
touched,
handleChange,
handleBlur,
handleSubmit,
isSubmitting,
}) => (
<Form >
}}
>
{({ values, setValues, errors, touched, handleChange, handleBlur, handleSubmit, isSubmitting }) => (
<Form>
<Grid container direction="row" justifyContent="center" alignItems="flex-end" spacing={3}>
<Grid item>
<FastField type="input" as={TextField} name="team_number" label="Team #" />
@@ -97,18 +75,8 @@ const InputPage = () => {
<FormControl component="fieldset">
<FormLabel component="legend">Alliance</FormLabel>
<RadioGroup aria-label="Alliance" name="alliance" row>
<FormControlLabel
control={
<FastField as={Radio} type="radio" name="alliance" value="red" style={{ fontSize: 50 }} />
}
label="Red"
/>
<FormControlLabel
control={
<FastField as={Radio} type="radio" name="alliance" value="blue" />
}
label="Blue"
/>
<FormControlLabel control={<FastField as={Radio} type="radio" name="alliance" value="red" style={{ fontSize: 50 }} />} label="Red" />
<FormControlLabel control={<FastField as={Radio} type="radio" name="alliance" value="blue" />} label="Blue" />
</RadioGroup>
</FormControl>
</Grid>
@@ -142,36 +110,11 @@ const InputPage = () => {
<FormControl component="fieldset">
<FormLabel component="legend">Climbing</FormLabel>
<RadioGroup aria-label="Climbing" name="climb_level" row>
<FormControlLabel
control={
<FastField as={Radio} type="radio" name="climb_level" value="0" />
}
label="None"
/>
<FormControlLabel
control={
<FastField as={Radio} type="radio" name="climb_level" value="1" />
}
label="Low"
/>
<FormControlLabel
control={
<FastField as={Radio} type="radio" name="climb_level" value="2" />
}
label="Mid"
/>
<FormControlLabel
control={
<FastField as={Radio} type="radio" name="climb_level" value="3" />
}
label="High"
/>
<FormControlLabel
control={
<FastField as={Radio} type="radio" name="climb_level" value="4" />
}
label="Traversal"
/>
<FormControlLabel control={<FastField as={Radio} type="radio" name="climb_level" value="0" />} label="None" />
<FormControlLabel control={<FastField as={Radio} type="radio" name="climb_level" value="1" />} label="Low" />
<FormControlLabel control={<FastField as={Radio} type="radio" name="climb_level" value="2" />} label="Mid" />
<FormControlLabel control={<FastField as={Radio} type="radio" name="climb_level" value="3" />} label="High" />
<FormControlLabel control={<FastField as={Radio} type="radio" name="climb_level" value="4" />} label="Traversal" />
</RadioGroup>
</FormControl>
</Grid>
@@ -205,30 +148,15 @@ const InputPage = () => {
<FormControl component="fieldset">
<FormLabel component="legend">Defense</FormLabel>
<RadioGroup aria-label="Defense" name="defence" row>
<FormControlLabel
control={<FastField as={Radio} type="radio" name="defence" value="0" />}
label="None"
/>
<FormControlLabel control={<FastField as={Radio} type="radio" name="defence" value="0" />} label="None" />
{/* <Divider orientation="vertical" flexItem middle /> */}
<FormControlLabel
control={<FastField as={Radio} type="radio" name="defence" value="1" />}
label="Poor"
/>
<FormControlLabel
control={<FastField as={Radio} type="radio" name="defence" value="2" />}
label="Good"
/> <FormControlLabel
control={<FastField as={Radio} type="radio" name="defence" value="3" />}
label="Exceptional"
/>
<FormControlLabel control={<FastField as={Radio} type="radio" name="defence" value="1" />} label="Poor" />
<FormControlLabel control={<FastField as={Radio} type="radio" name="defence" value="2" />} label="Good" /> <FormControlLabel control={<FastField as={Radio} type="radio" name="defence" value="3" />} label="Exceptional" />
</RadioGroup>
</FormControl>
</Grid>
<Grid item>
<FormControlLabel
control={<FastField as={Checkbox} type="checkbox" name="disabled" />}
label="Disabled"
/>
<FormControlLabel control={<FastField as={Checkbox} type="checkbox" name="disabled" />} label="Disabled" />
</Grid>
</Grid>
<div />
+2 -1
View File
@@ -3,10 +3,11 @@
margin-left: auto;
margin-right: auto;
width: 100%;
height: 100%;
text-align: center;
margin: auto;
}
.welcome img {
max-width: 100%;
max-width: 50%
}
+10 -9
View File
@@ -1,13 +1,14 @@
import React from 'react'
import React from "react";
import "./WelcomePage.css";
import "../App.css";
const WelcomePage = () => {
return (
<div className="welcome">
<h1>Welcome to Ridgebotics Scouting Web Application 2022</h1>
<img src="/WelcomePageImage.webp" />
</div>
)
}
return (
<div className="welcome">
<h1>Welcome to Ridgebotics Scouting Web Application 2022</h1>
{/* <img src="/WelcomePageImage.webp" /> */}
<img src="/picgoeshard.jpg" />
</div>
);
};
export default WelcomePage
export default WelcomePage;
+103 -102
View File
@@ -1,109 +1,110 @@
export class ProcessedDataBucket {
constructor() {
this.teamData = {};
this.matchData = {};
this.updateData = (db) => {
//reset data
this.teamData = {};
this.matchData = {};
console.log(db);
constructor() {
this.teamData = {};
this.matchData = {};
this.updateData = (db) => {
db.allDocs({
include_docs: true,
})
.then((result) => {
//reset data
this.teamData = {};
this.matchData = {};
db.allDocs({
include_docs: true,
})
.then((result) => {
console.log(result);
result.rows.forEach((dbentry) => {
let doc = dbentry.doc;
console.log(doc);
// console.log(result);
result.rows.forEach((dbentry) => {
let doc = dbentry.doc;
// console.log(doc);
// //if there's no processed data on a team yet, create a default data entry
// if (typeof this.teamData[doc.team_number] === "undefined") {
// this.teamData[doc.team_number] = {
// team_number: doc.team_number,
// games_played: 0,
// data_sets: {
// upper_hub_auto: [],
// lower_hub_auto: [],
// upper_hub: [],
// lower_hub: [],
// match_points: []
// },
// climbs_none: 0,
// climbs_low: 0,
// climbs_mid: 0,
// climbs_high: 0,
// climbs_transverse: 0,
// points_average: 0,
// num_disables: 0,
// num_flips: 0,
// fouls: 0,
// fouls_tech: 0,
// red_cards: 0,
// yellow_cards: 0
// };
// }
//if there's no processed data on a team yet, create a default data entry
if (typeof this.teamData[doc.team_number] === "undefined") {
this.teamData[doc.team_number] = {
team_number: doc.team_number,
games_played: 0,
data_sets: {
upper_hub_auto: [],
lower_hub_auto: [],
upper_hub_teleop: [],
lower_hub_teleop: [],
match_points: [],
},
climbs_none: 0,
climbs_low: 0,
climbs_mid: 0,
climbs_high: 0,
climbs_transverse: 0,
points_average: 0,
num_disables: 0,
num_flips: 0,
fouls: 0,
fouls_tech: 0,
red_cards: 0,
yellow_cards: 0,
};
}
// //add this game's data to the respective team data:
// let thisTeamData = this.teamData[doc.team_number];
// thisTeamData.games_played++;
//add this game's data to the respective team data:
let thisTeamData = this.teamData[doc.team_number];
thisTeamData.games_played++;
// let match_points
// = parseInt(doc.taxi_auto)
// + parseInt(doc.upper_hub_auto) * 4
// + parseInt(doc.lower_hub_auto) * 2
// + parseInt(doc.upper_hub_teleop) * 2
// + parseInt(doc.lower_hub_teleop) * 1
// + (parseInt(doc.climb_level) == 0 ? 4 : 0)
// + (parseInt(doc.climb_level) == 1 ? 6 : 0)
// + (parseInt(doc.climb_level) == 2 ? 10 : 0)
// + (parseInt(doc.climb_level) == 3 ? 15 : 0)
// ;
let match_points =
(parseInt(doc.taxi_auto) ? 2 : 0) +
parseInt(doc.upper_hub_auto) * 4 +
parseInt(doc.lower_hub_auto) * 2 +
parseInt(doc.upper_hub_teleop) * 2 +
parseInt(doc.lower_hub_teleop) * 1 +
(parseInt(doc.climb_level) == 0 ? 4 : 0) +
(parseInt(doc.climb_level) == 1 ? 6 : 0) +
(parseInt(doc.climb_level) == 2 ? 10 : 0) +
(parseInt(doc.climb_level) == 3 ? 15 : 0);
//data sets
thisTeamData.data_sets.upper_hub_auto.push(parseInt(doc.upper_hub_auto));
thisTeamData.data_sets.lower_hub_auto.push(parseInt(doc.lower_hub_auto));
thisTeamData.data_sets.upper_hub_teleop.push(parseInt(doc.upper_hub_teleop));
thisTeamData.data_sets.lower_hub_teleop.push(parseInt(doc.lower_hub_teleop));
thisTeamData.data_sets.match_points.push(match_points);
// //data sets
// thisTeamData.data_sets.upper_hub_auto.push(parseInt(doc.upper_hub_auto));
// thisTeamData.data_sets.lower_hub_auto.push(parseInt(doc.lower_hub_auto));
// thisTeamData.data_sets.upper_hub.push(parseInt(doc.upper_hub));
// thisTeamData.data_sets.lower_hub.push(parseInt(doc.lower_hub));
// thisTeamData.data_sets.match_points.push(match_points);
//climb data
switch (parseInt(doc.climb_level)) {
case 0:
thisTeamData.climbs_none++;
break;
case 1:
thisTeamData.climbs_low++;
break;
case 2:
thisTeamData.climbs_mid++;
break;
case 3:
thisTeamData.climbs_high++;
break;
case 4:
thisTeamData.climbs_transverse++;
break;
default:
console.error("Invalid Climb Level (how did this even happen lol?): " + doc.climb_level);
break;
}
// //climb data
// switch (parseInt(doc.climb_level)) {
// case 0:
// thisTeamData.climbs_none++;
// break;
// case 1:
// thisTeamData.climbs_low++;
// break;
// case 2:
// thisTeamData.climbs_mid++;
// break;
// case 3:
// thisTeamData.climbs_high++;
// break;
// case 4:
// thisTeamData.climbs_transverse++;
// break;
// default:
// console.error('Invalid Climb Level (how did this even happen lol?): ' + doc.climb_level);
// break;
// }
// //misc data
// thisTeamData.num_disables += doc.disabled ? 1 : 0;
// thisTeamData.num_flips += doc.flipped ? 1 : 0;
// thisTeamData.fouls += parseInt(doc.fouls);
// thisTeamData.fouls_tech += parseInt(doc.fouls_tech);
// thisTeamData.red_cards += parseInt(doc.red_cards);
// thisTeamData.yellow_cards += parseInt(doc.yellow_cards);
// console.log(thisTeamData);
});
})
.catch((err) => {
console.log("Error while processing data!");
console.error(err);
});
};
}
}
//misc data
thisTeamData.num_disables += doc.disabled ? 1 : 0;
thisTeamData.num_flips += doc.flipped ? 1 : 0;
thisTeamData.fouls += parseInt(doc.fouls);
thisTeamData.fouls_tech += parseInt(doc.fouls_tech);
thisTeamData.red_cards += parseInt(doc.red_cards);
thisTeamData.yellow_cards += parseInt(doc.yellow_cards);
//sum of all points in the match points data set for this team
let total_points = thisTeamData.data_sets.match_points.reduce(function (accum, current) {
return accum + current;
}, 0);
thisTeamData.points_average = total_points / thisTeamData.games_played;
});
console.log(this.teamData);
})
.catch((err) => {
console.log("Error while processing data!");
console.error(err);
});
};
}
}
@@ -10,7 +10,7 @@ const Toolbar = props => {
<header className="toolbar">
<nav className="toolbar_navigation">
<DrawerButton click={props.drawerClickHandler} />
<div className = "toolbar_logo"><Link to="/">Ridgebotics Scouting ;)</Link></div>
<div className = "toolbar_logo"><Link to="/">Ridgebotics Scouting &lt;3</Link></div>
<div className = "toolbar_spacer" />
<div className = "toolbar_items">
<PagesList />