Add more reports

This commit is contained in:
Aaron Lindsay 2017-01-10 20:31:13 -05:00
parent 9ed692aa10
commit 007e122a4a
2 changed files with 80 additions and 6 deletions

View File

@ -19,6 +19,9 @@ module.exports = React.createClass({
if (reportId == "suggestion-veto-ratio") {
this.props.fetchReport("suggestions");
this.props.fetchReport("vetoed-suggestions");
} else if (reportId == "suggestor-veto-ratio") {
this.props.fetchReport("suggestors");
this.props.fetchReport("vetoed-suggestors");
} else {
this.props.fetchReport(reportId);
}
@ -41,6 +44,13 @@ module.exports = React.createClass({
title="Suggestion Veto Ratio"
numerator={this.props.reports['vetoed-suggestions'].Data}
denominator={this.props.reports['suggestions'].Data}/>);
} else if (this.state.selectedReportId == "suggestor-veto-ratio" &&
this.props.reports.hasOwnProperty("suggestors") &&
this.props.reports.hasOwnProperty("vetoed-suggestors")) {
chart=(<RatioBarChart
title="Suggestor Veto Ratio"
numerator={this.props.reports['vetoed-suggestors'].Data}
denominator={this.props.reports['suggestors'].Data}/>);
}
return (
@ -51,10 +61,14 @@ module.exports = React.createClass({
id="lunch-report-selection-dropdown"
onSelect={this.selectReport}>
<MenuItem eventKey="suggestions">Suggestion Frequency</MenuItem>
<MenuItem eventKey="non-vetoed-suggestions">Non-Vetoed Suggestions</MenuItem>
<MenuItem eventKey="winning-suggestions">Winning Suggestions</MenuItem>
<MenuItem eventKey="vetoed-suggestions">Vetoed Suggestions</MenuItem>
<MenuItem eventKey="suggestion-veto-ratio">Veto Ratio</MenuItem>
<MenuItem eventKey="suggestion-veto-ratio">Suggestion Veto Ratio</MenuItem>
<MenuItem eventKey="attendees">Attendee Frequency</MenuItem>
<MenuItem eventKey="suggestors">Suggestor Frequency</MenuItem>
<MenuItem eventKey="winning-suggestors">Winning Suggestors</MenuItem>
<MenuItem eventKey="vetoed-suggestors">Vetoed Suggestors</MenuItem>
<MenuItem eventKey="suggestor-veto-ratio">Suggestor Veto Ratio</MenuItem>
</DropdownButton>
</ButtonGroup>

View File

@ -80,7 +80,7 @@ func GetVetoedSuggestions(groupid int64) (*[]*Suggestion, error) {
return &suggestions, nil
}
func GetNonVetoedSuggestions(groupid int64) (*[]*Suggestion, error) {
func GetWinningSuggestions(groupid int64) (*[]*Suggestion, error) {
var suggestions []*Suggestion
_, err := DB.Select(&suggestions, "SELECT suggestions.* FROM suggestions LEFT OUTER JOIN suggestions AS s2 ON suggestions.SuggestionId=s2.VetoingId WHERE s2.SuggestionId IS NULL AND suggestions.GroupId=?;", groupid)
@ -102,6 +102,39 @@ func GetAllAttendees(groupid int64) (*[]*Attendee, error) {
return &attendees, nil
}
func GetAllSuggestors(groupid int64) (*[]*Attendee, error) {
var suggestors []*Attendee
_, err := DB.Select(&suggestors, "SELECT attendees.* FROM attendees INNER JOIN suggestions ON suggestions.AttendeeId==attendees.AttendeeId WHERE suggestions.GroupId=?", groupid)
if err != nil {
return nil, err
}
return &suggestors, nil
}
func GetVetoedSuggestors(groupid int64) (*[]*Attendee, error) {
var suggestors []*Attendee
_, err := DB.Select(&suggestors, "SELECT attendees.* FROM attendees INNER JOIN (SELECT suggestions.* FROM suggestions INNER JOIN suggestions AS s2 WHERE suggestions.GroupId=? AND s2.GroupId=? AND suggestions.Date=s2.Date AND s2.VetoingId=suggestions.SuggestionId) a ON a.AttendeeId==attendees.AttendeeId", groupid, groupid)
if err != nil {
return nil, err
}
return &suggestors, nil
}
func GetWinningSuggestors(groupid int64) (*[]*Attendee, error) {
var suggestors []*Attendee
_, err := DB.Select(&suggestors, "SELECT attendees.* FROM attendees INNER JOIN (SELECT suggestions.* FROM suggestions LEFT OUTER JOIN suggestions AS s2 ON suggestions.SuggestionId=s2.VetoingId WHERE s2.SuggestionId IS NULL AND suggestions.GroupId=?) a ON a.AttendeeId==attendees.AttendeeId", groupid)
if err != nil {
return nil, err
}
return &suggestors, nil
}
func ReportHandler(w http.ResponseWriter, r *http.Request) {
user, err := GetUserFromSession(r)
if err != nil {
@ -116,9 +149,9 @@ func ReportHandler(w http.ResponseWriter, r *http.Request) {
reportid := query.Get("id")
report.ReportId = reportid
if reportid == "non-vetoed-suggestions" {
report.Title = "Non-Vetoed Suggestions"
suggestions, err := GetNonVetoedSuggestions(user.GroupId)
if reportid == "winning-suggestions" {
report.Title = "Winning Suggestions"
suggestions, err := GetWinningSuggestions(user.GroupId)
if err != nil {
WriteError(w, 999 /*Internal Error*/)
log.Print(err)
@ -152,6 +185,33 @@ func ReportHandler(w http.ResponseWriter, r *http.Request) {
return
}
report.FromSummedAttendeeList(attendees)
} else if reportid == "winning-suggestors" {
report.Title = "Winning Suggestors"
attendees, err := GetWinningSuggestors(user.GroupId)
if err != nil {
WriteError(w, 999 /*Internal Error*/)
log.Print(err)
return
}
report.FromSummedAttendeeList(attendees)
} else if reportid == "vetoed-suggestors" {
report.Title = "Vetoed Suggestors"
attendees, err := GetVetoedSuggestors(user.GroupId)
if err != nil {
WriteError(w, 999 /*Internal Error*/)
log.Print(err)
return
}
report.FromSummedAttendeeList(attendees)
} else if reportid == "suggestors" {
report.Title = "Suggestor Frequency"
attendees, err := GetAllSuggestors(user.GroupId)
if err != nil {
WriteError(w, 999 /*Internal Error*/)
log.Print(err)
return
}
report.FromSummedAttendeeList(attendees)
} else {
WriteError(w, 3 /*Invalid Request*/)
return