Skip to content

Commit 9ff4ef1

Browse files
committed
Cleaned up structs for Sp2018Ece408. Implemented ranking for Sp2018Ece408 including listing rank for each team and highlighting the current users team.
1 parent 7ccb653 commit 9ff4ef1

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

cmd/ranking.go

+50-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cmd
22

33
import (
4-
"fmt"
4+
//"fmt"
55
"os"
66
"sort"
77
"strconv"
@@ -13,6 +13,9 @@ import (
1313
"github.com/rai-project/model"
1414
"github.com/spf13/cobra"
1515
upper "upper.io/db.v3"
16+
"github.com/rai-project/auth/provider"
17+
"github.com/pkg/errors"
18+
"github.com/rai-project/client"
1619
)
1720

1821
var numResults int
@@ -48,14 +51,14 @@ var rankingCmd = &cobra.Command{
4851
}
4952
defer db.Close()
5053

51-
col, err := model.NewFa2017Ece408JobCollection(db)
54+
col, err := model.NewSp2018Ece408JobCollection(db)
5255
if err != nil {
5356
return err
5457
}
5558
defer col.Close()
5659

5760
// Get submissions
58-
var jobs model.Fa2017Ece408Jobs
61+
var jobs model.Sp2018Ece408Jobs
5962
// cond := upper.Or(
6063
// upper.Cond{
6164
// "model": "ece408-high",
@@ -70,17 +73,16 @@ var rankingCmd = &cobra.Command{
7073
condInferencesExist := upper.Cond{"inferences.0 $exists": "true"}
7174
cond := upper.And(
7275
condInferencesExist,
73-
upper.Cond{"is_submission": true},
76+
upper.Cond{
77+
"is_submission": true,
78+
"inferences.correctness": 0.8451,},
7479
)
7580

7681
err = col.Find(cond, 0, 0, &jobs)
7782
if err != nil {
7883
return err
7984
}
8085

81-
// keep only jobs with correct inferences
82-
jobs = model.FilterCorrectInferences(jobs)
83-
8486
// keep only jobs with non-zero runtimes
8587
jobs = model.FilterNonZeroTimes(jobs)
8688

@@ -96,20 +98,51 @@ var rankingCmd = &cobra.Command{
9698
}
9799
numResults = min(numResults, maxResults)
98100
numResults = min(numResults, len(jobs))
99-
jobs = jobs[0:numResults]
101+
//jobs = jobs[0:numResults]
100102

101-
// Anonymize
102-
// for i, j := range jobs {
103-
// jobs[i] = j.Anonymize()
104-
// }
105-
for _, j := range jobs {
106-
fmt.Println(j)
107-
}
103+
//for _, j := range jobs {
104+
// fmt.Println(j)
105+
//}
106+
107+
// Get current user details
108+
prof, err := provider.New()
109+
if err != nil {
110+
return err
111+
}
108112

113+
ok, err := prof.Verify()
114+
if err != nil {
115+
return err
116+
}
117+
if !ok {
118+
return errors.Errorf("cannot authenticate using the credentials in %v", prof.Options().ProfilePath)
119+
}
120+
121+
tname, err := client.ReturnTeamName(prof.Info().Username)
122+
123+
// Create table of ranking
109124
table := tablewriter.NewWriter(os.Stdout)
110-
table.SetHeader([]string{"Anonymized Team", "Team's Fastest Conv (ms)"})
125+
table.SetHeader([]string{"You","Rank", "Anonymized Team", "Fastest Conv (ms)"})
126+
127+
var x int64
128+
var currentRank int64
129+
var currentMinOpRunTime float64
130+
x=1
131+
currentRank = 1
132+
currentMinOpRunTime = 0
133+
111134
for _, j := range jobs {
112-
table.Append([]string{j.Teamname, strconv.FormatFloat(float64(j.MinOpRuntime())/float64(time.Millisecond), 'f', -1, 64)})
135+
if currentMinOpRunTime != float64(j.MinOpRuntime())/float64(time.Millisecond) {
136+
currentMinOpRunTime = float64(j.MinOpRuntime()) / float64(time.Millisecond)
137+
currentRank = x
138+
}
139+
140+
if tname == j.Teamname {
141+
table.Append([]string{tname + " -->", strconv.FormatInt(currentRank, 10), j.Anonymize().Teamname, strconv.FormatFloat(currentMinOpRunTime, 'f', 3, 64)})
142+
} else {
143+
table.Append([]string{"", strconv.FormatInt(currentRank, 10), j.Anonymize().Teamname, strconv.FormatFloat(currentMinOpRunTime, 'f', 3, 64)})
144+
x++
145+
}
113146
}
114147

115148
table.Render()

cmd/submitted.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ var submittedCmd = &cobra.Command{
4242
}
4343
defer db.Close()
4444

45-
col, err := model.NewFa2017Ece408JobCollection(db)
45+
col, err := model.NewSp2018Ece408JobCollection(db)
4646
if err != nil {
4747
return err
4848
}
4949
defer col.Close()
5050

51-
var jobs model.Fa2017Ece408Jobs
51+
var jobs model.Sp2018Ece408Jobs
5252

5353
condInferencesExist := upper.Cond{"inferences.0 $exists": "true"}
5454
cond := upper.And(

0 commit comments

Comments
 (0)