-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backend for volunteer history, added aggregation stats to frontend (#145
- Loading branch information
Showing
5 changed files
with
157 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,41 @@ | ||
import React, { Component } from 'react' | ||
import { Header, Icon, Table } from 'semantic-ui-react' | ||
import Axios from 'axios' | ||
import moment from 'moment' | ||
|
||
class VolunteerSubmissions extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
submissions: [ | ||
{ | ||
date: '06-10-19', | ||
name: 'Pablo Escobar', | ||
email: '[email protected]', | ||
type: 'Main', | ||
desc: 'Pizza', | ||
servings: 100, | ||
vegan: false, | ||
vegetarian: false, | ||
gluten_free: true | ||
} | ||
] | ||
submissions: [] | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
Axios.post('/api/volunteerHistory', {email: this.props.email}) | ||
.then(res => { | ||
let tempSubs = res.data.sub_info | ||
|
||
tempSubs.forEach(e => { | ||
e.sortDate = moment(e.date, 'MM-DD-YY') | ||
}) | ||
|
||
tempSubs.sort((older, newer) => { | ||
if(moment(older.sortDate).isBefore(moment(newer.sortDate))) { | ||
return 1 | ||
} else { | ||
return -1 | ||
} | ||
}) | ||
|
||
this.setState({ | ||
submissions: tempSubs | ||
}) | ||
}).catch(err => { | ||
console.log('Error retrieving volunteer history', err) | ||
}) | ||
} | ||
|
||
renderIcon = value => { | ||
if (value) { | ||
return <Icon color="green" name="checkmark" size="small" /> | ||
|
@@ -30,9 +45,89 @@ class VolunteerSubmissions extends Component { | |
} | ||
|
||
render() { | ||
let stats = { | ||
name: null, | ||
events: 0, | ||
categories: [], | ||
avg_servings: 0, | ||
vegan_pct: 0.0, | ||
vegetarian_pct: 0.0, | ||
gf_pct: 0.0, | ||
counts: {} | ||
} | ||
|
||
this.state.submissions.forEach(e => { | ||
if(!stats.name) { | ||
stats.name = e.name | ||
} | ||
stats.events++ | ||
stats.avg_servings += e.servings | ||
if(e.vegan) { | ||
stats.vegan_pct++ | ||
} | ||
if(e.vegetarian) { | ||
stats.vegetarian_pct++ | ||
} | ||
if(e.gluten_free) { | ||
stats.gf_pct++ | ||
} | ||
if(!stats.categories.includes(e.type)) { | ||
stats.categories.push(e.type) | ||
stats.counts[e.type] = 1 | ||
} else { | ||
stats.counts[e.type]++ | ||
} | ||
}) | ||
|
||
stats.avg_servings = stats.avg_servings / this.state.submissions.length | ||
stats.vegan_pct = 100 * (stats.vegan_pct / this.state.submissions.length) | ||
stats.vegetarian_pct = 100* (stats.vegetarian_pct / this.state.submissions.length) | ||
stats.gf_pct = 100 * (stats.gf_pct / this.state.submissions.length) | ||
|
||
stats.categories.sort((a, b) => { | ||
return stats.counts[b] - stats.counts[a] | ||
}) | ||
|
||
|
||
return ( | ||
<div> | ||
<Header as="h3">Pablo Escobar</Header> | ||
<Header as="h2">{stats.name}</Header> | ||
<div> | ||
<Header as="h3">Stats</Header> | ||
<Table celled textAlign={'center'} selectable> | ||
<Table.Header> | ||
<Table.Row> | ||
<Table.HeaderCell>Total Events</Table.HeaderCell> | ||
<Table.HeaderCell>Top 3 Categories</Table.HeaderCell> | ||
<Table.HeaderCell>Avgerage Servings</Table.HeaderCell> | ||
<Table.HeaderCell>% Vegan</Table.HeaderCell> | ||
<Table.HeaderCell>% Vegetarian</Table.HeaderCell> | ||
<Table.HeaderCell>% Gluten-Free</Table.HeaderCell> | ||
</Table.Row> | ||
</Table.Header> | ||
<Table.Body> | ||
{stats.events > 0 && | ||
<Table.Row> | ||
<Table.Cell>{stats.events}</Table.Cell> | ||
<Table.Cell> | ||
<ol> | ||
{stats.categories[0] && <li>{stats.categories[0]}</li>} | ||
{stats.categories[1] && <li>{stats.categories[1]}</li>} | ||
{stats.categories[2] && <li>{stats.categories[2]}</li>} | ||
</ol> | ||
</Table.Cell> | ||
<Table.Cell>{stats.avg_servings}</Table.Cell> | ||
<Table.Cell>{stats.vegan_pct}</Table.Cell> | ||
<Table.Cell>{stats.vegetarian_pct}</Table.Cell> | ||
<Table.Cell>{stats.gf_pct}</Table.Cell> | ||
</Table.Row> | ||
} | ||
</Table.Body> | ||
</Table> | ||
</div> | ||
<hr></hr> | ||
<div> | ||
<Header as="h3">Signup History</Header> | ||
<Table celled textAlign={'center'} selectable> | ||
<Table.Header> | ||
<Table.Row> | ||
|
@@ -68,6 +163,7 @@ class VolunteerSubmissions extends Component { | |
))} | ||
</Table.Body> | ||
</Table> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters