diff --git a/js/components/LunchStats.js b/js/components/LunchStats.js index 503e337..ff920b4 100644 --- a/js/components/LunchStats.js +++ b/js/components/LunchStats.js @@ -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=(); } return ( @@ -51,10 +61,14 @@ module.exports = React.createClass({ id="lunch-report-selection-dropdown" onSelect={this.selectReport}> Suggestion Frequency - Non-Vetoed Suggestions + Winning Suggestions Vetoed Suggestions - Veto Ratio + Suggestion Veto Ratio Attendee Frequency + Suggestor Frequency + Winning Suggestors + Vetoed Suggestors + Suggestor Veto Ratio diff --git a/reports.go b/reports.go index 7f2dda9..db6a019 100644 --- a/reports.go +++ b/reports.go @@ -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