mirror of
https://github.com/Team4388/scouting-2021.git
synced 2026-06-09 00:38:01 -06:00
started processing of database docs
This commit is contained in:
@@ -6,7 +6,6 @@ import './App.css';
|
||||
// const Cushion = require('cushiondb-client');
|
||||
|
||||
//Pages
|
||||
import LoginPage from './Pages/LoginPage'
|
||||
import NotFoundPage from './Pages/NotFoundPage'
|
||||
import DashboardPage from './Pages/DashboardPage/DashboardPage';
|
||||
import InputPage from './Pages/InputPage';
|
||||
@@ -19,7 +18,6 @@ function App() {
|
||||
<Navigation />
|
||||
<Switch>
|
||||
<Route exact path="/" component={DashboardPage} />
|
||||
<Route exact path="/Login" component={LoginPage} />
|
||||
<Route exact path="/Dashboard" component={DashboardPage} />
|
||||
<Route exact path="/Input" component={InputPage} />
|
||||
<Route exact path="/404" component={NotFoundPage} />
|
||||
|
||||
@@ -15,13 +15,14 @@ export function useRemoteDb() {
|
||||
export function DbProvider({ children }) {
|
||||
const [localdb, setLocaldb] = useState(new PouchDB('kcmt2021'));
|
||||
//used in development server
|
||||
const [remotedb, setRemotedb] = useState(new PouchDB('http://192.168.7.190:5984/kcmt2021', {
|
||||
const [remotedb, setRemotedb] = useState(new PouchDB('http://192.168.1.5:5984/kcmt2021', {
|
||||
skip_setup: true,
|
||||
auth: {
|
||||
username: '2021',
|
||||
password: 'Ridgebotics'
|
||||
}
|
||||
}));
|
||||
console.log(remotedb);
|
||||
// const [remotedb, setRemotedb] = useState(new PouchDB(window.location.protocol + "//" + window.location.hostname + ":5984/kcmt2021", {skip_setup: true}))
|
||||
|
||||
//Login to the Remote Database
|
||||
|
||||
@@ -4,30 +4,72 @@ import { Bar } from 'react-chartjs-2'
|
||||
|
||||
const DashboardPage = () => {
|
||||
const localdb = useLocalDb();
|
||||
let team_data = {};
|
||||
let processed_data = {};
|
||||
localdb.allDocs({
|
||||
include_docs: true
|
||||
}).then((result) => {
|
||||
console.log(result);
|
||||
result.rows.forEach((doc) => {
|
||||
result.rows.forEach((dbentry) => {
|
||||
let doc = dbentry.doc;
|
||||
console.log(doc);
|
||||
if (typeof(processed_data[doc.team_name]) === 'undefined'){
|
||||
processed_data[doc.team_name] = {
|
||||
team_name: doc.team_name,
|
||||
alliance: doc.alliance,
|
||||
games_played: 0,
|
||||
num_climbs: 0,
|
||||
climb_average: 0,
|
||||
num_disables: 0,
|
||||
disables_average: 0,
|
||||
num_flips: 0,
|
||||
flips_average: 0,
|
||||
fouls: 0,
|
||||
fouls_average: 0,
|
||||
fouls_tech: 0,
|
||||
fouls_tech_average: 0,
|
||||
inner_port: 0,
|
||||
inner_port_average: 0,
|
||||
lower_port: 0,
|
||||
lower_port_average: 0,
|
||||
outer_port: 0,
|
||||
outer_port_average: 0
|
||||
}
|
||||
}
|
||||
let team_data = processed_data[doc.team_name];
|
||||
console.log(team_data);
|
||||
let new_team_data = {
|
||||
...team_data,
|
||||
games_played: team_data.games_played + 1,
|
||||
num_climbs: team_data.num_climbs + (doc.climb == true ? 1 : 0),
|
||||
num_disables: team_data.num_disables + (doc.disabled == true ? 1 : 0),
|
||||
num_flips: team_data.num_flips + (doc.flipped_over == true ? 1 : 0),
|
||||
fouls: team_data.fouls + parseInt(doc.fouls),
|
||||
fouls_tech: team_data.fouls_tech + parseInt(doc.fouls_tech),
|
||||
inner_port: team_data.inner_port + parseInt(doc.inner_port),
|
||||
outer_port: team_data.outer_port + parseInt(doc.outer_port),
|
||||
lower_port: team_data.lower_port + parseInt(doc.lower_port)
|
||||
}
|
||||
console.log(new_team_data);
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.log("Error Fetching Docs from Database!");
|
||||
console.log(err);
|
||||
})
|
||||
let datasets = [{
|
||||
data: []
|
||||
}];
|
||||
//https://react-charts.js.org/examples/column
|
||||
return (
|
||||
<div>
|
||||
<Bar
|
||||
{/* <Bar
|
||||
data={{
|
||||
labels: ['4388', '1619'],
|
||||
datasets: [
|
||||
|
||||
{1, 0}
|
||||
]
|
||||
}}
|
||||
// height
|
||||
/>
|
||||
/> */}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -195,34 +195,6 @@ const InputPage = () => {
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
<button onClick={() => {
|
||||
localdb.put({
|
||||
//creates a uuid for pouchdb to index documents, doing it this way will make the db sort them by date when viewed
|
||||
_id: "4388:" + new Date().toISOString(),
|
||||
inner_port: 0,
|
||||
outer_port: 0,
|
||||
lower_port: 0,
|
||||
control_panel: 0,
|
||||
disabled: false,
|
||||
assisted_climb: false,
|
||||
climb: false,
|
||||
leveling_climb: false,
|
||||
trench_run: false,
|
||||
yellow_card: false,
|
||||
red_card: false,
|
||||
flipped_over: false,
|
||||
center_climb: false
|
||||
}).then((result) => {
|
||||
console.log("Input Saved Successfully!");
|
||||
console.log(result);
|
||||
}).catch((err) => {
|
||||
console.log("Failed To Save Input!");
|
||||
console.log(err);
|
||||
})
|
||||
localdb.allDocs().then(console.log);
|
||||
}}>
|
||||
Test Save Button
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import React from 'react';
|
||||
import { useRemoteDb } from '../DbContext';
|
||||
|
||||
const LoginPage = () => {
|
||||
const remotedb = useRemoteDb();
|
||||
return (
|
||||
// <div className = "form_inner">
|
||||
// <form>
|
||||
// <h2>Login</h2>
|
||||
// <div className="form_group">
|
||||
// <label htmlFor="name">Name: </label>
|
||||
// <input type="text" name="name" id="name"/>
|
||||
// </div>
|
||||
// <div className="form_group">
|
||||
// <label htmlFor="password">Password: </label>
|
||||
// <input type="text" name="password" id="password"/>
|
||||
// </div>
|
||||
// <input type="submit" value="LOGIN" />
|
||||
// </form>
|
||||
// </div>
|
||||
<div>
|
||||
<button onClick={() => {
|
||||
console.log(remotedb);
|
||||
// remotedb.logIn('2021', 'Ridgebotics').then(function () {
|
||||
// console.log("CouchDb Login Successful!");
|
||||
// }).catch(function (err) {
|
||||
// console.log("Unable to login to CouchDb!");
|
||||
// console.log(err);
|
||||
// });
|
||||
}}>
|
||||
Sign In 2021
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default LoginPage
|
||||
@@ -6,7 +6,6 @@ const PagesList = props => {
|
||||
<ul>
|
||||
<li><Link onClick={props.click} to="/Dashboard">Dashboard</Link></li>
|
||||
<li><Link onClick={props.click} to="/Input">Input</Link></li>
|
||||
<li><Link onClick={props.click} to="/Login">Login</Link></li>
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user