Skip to content

Commit 16566e5

Browse files
committed
Always record ranking, add ranking command
1 parent 47e4043 commit 16566e5

File tree

2 files changed

+107
-1
lines changed

2 files changed

+107
-1
lines changed

cmd/ranking.go

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
"sort"
6+
"strconv"
7+
"time"
8+
9+
"github.com/olekukonko/tablewriter"
10+
"github.com/rai-project/config"
11+
"github.com/rai-project/database/mongodb"
12+
"github.com/rai-project/model"
13+
"github.com/spf13/cobra"
14+
upper "upper.io/db.v3"
15+
)
16+
17+
var numResults int
18+
19+
const (
20+
maxResults = 100
21+
)
22+
23+
func min(a, b int) int {
24+
if a < b {
25+
return a
26+
}
27+
return b
28+
}
29+
30+
func max(a, b int) int {
31+
if a > b {
32+
return a
33+
}
34+
return b
35+
}
36+
37+
// rankingCmd represents the ranking command
38+
var rankingCmd = &cobra.Command{
39+
Use: "ranking",
40+
Short: "View anonymous rankings.",
41+
Long: `View anonymized convolution performance. Only the fastest result for each team is reported.`,
42+
RunE: func(cmd *cobra.Command, args []string) error {
43+
44+
db, err := mongodb.NewDatabase(config.App.Name)
45+
if err != nil {
46+
return err
47+
}
48+
defer db.Close()
49+
50+
col, err := model.NewFa2017Ece408RankingCollection(db)
51+
if err != nil {
52+
return err
53+
}
54+
defer col.Close()
55+
56+
// Get submissions
57+
var rankings model.Fa2017Ece408Rankings
58+
cond := upper.Or(
59+
upper.Cond{
60+
"model": "ece408-high",
61+
"correctness": 0.8562,
62+
},
63+
upper.Cond{
64+
"model": "ece408-low",
65+
"correctness": 0.629,
66+
},
67+
)
68+
err = col.Find(cond, 0, maxResults, &rankings)
69+
if err != nil {
70+
return err
71+
}
72+
73+
// Sort by fastest
74+
sort.Sort(model.ByOpRuntime(rankings))
75+
76+
// Keep first instance of every team
77+
rankings = model.KeepFirstTeam(rankings) // Keep fastest entry for each team
78+
79+
// show only numResults
80+
if numResults < 0 {
81+
numResults = maxResults
82+
}
83+
numResults = min(numResults, maxResults)
84+
numResults = min(numResults, len(rankings))
85+
rankings = rankings[0:numResults]
86+
87+
// Anonymize
88+
for i, r := range rankings {
89+
rankings[i] = r.Anonymize()
90+
}
91+
92+
table := tablewriter.NewWriter(os.Stdout)
93+
table.SetHeader([]string{"Anonymized Team", "Team's Fastest Conv (ms)"})
94+
for _, r := range rankings {
95+
table.Append([]string{r.Teamname, strconv.FormatInt(int64(r.OpRuntime/time.Millisecond), 10)})
96+
}
97+
98+
table.Render()
99+
return nil
100+
},
101+
}
102+
103+
func init() {
104+
rankingCmd.Flags().IntVarP(&numResults, "num-results", "n", 10, "Number of results to show (<"+strconv.Itoa(maxResults)+")")
105+
RootCmd.AddCommand(rankingCmd)
106+
}

cmd/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var RootCmd = &cobra.Command{
7777
if err := client.Wait(); err != nil {
7878
return err
7979
}
80-
if err := client.RecordIfSubmission(); err != nil {
80+
if err := client.RecordRanking(); err != nil {
8181
return err
8282
}
8383
return nil

0 commit comments

Comments
 (0)