1
1
package cmd
2
2
3
3
import (
4
- "fmt"
4
+ // "fmt"
5
5
"os"
6
6
"sort"
7
7
"strconv"
@@ -13,6 +13,9 @@ import (
13
13
"github.com/rai-project/model"
14
14
"github.com/spf13/cobra"
15
15
upper "upper.io/db.v3"
16
+ "github.com/rai-project/auth/provider"
17
+ "github.com/pkg/errors"
18
+ "github.com/rai-project/client"
16
19
)
17
20
18
21
var numResults int
@@ -48,14 +51,14 @@ var rankingCmd = &cobra.Command{
48
51
}
49
52
defer db .Close ()
50
53
51
- col , err := model .NewFa2017Ece408JobCollection (db )
54
+ col , err := model .NewSp2018Ece408JobCollection (db )
52
55
if err != nil {
53
56
return err
54
57
}
55
58
defer col .Close ()
56
59
57
60
// Get submissions
58
- var jobs model.Fa2017Ece408Jobs
61
+ var jobs model.Sp2018Ece408Jobs
59
62
// cond := upper.Or(
60
63
// upper.Cond{
61
64
// "model": "ece408-high",
@@ -70,17 +73,16 @@ var rankingCmd = &cobra.Command{
70
73
condInferencesExist := upper.Cond {"inferences.0 $exists" : "true" }
71
74
cond := upper .And (
72
75
condInferencesExist ,
73
- upper.Cond {"is_submission" : true },
76
+ upper.Cond {
77
+ "is_submission" : true ,
78
+ "inferences.correctness" : 0.8451 ,},
74
79
)
75
80
76
81
err = col .Find (cond , 0 , 0 , & jobs )
77
82
if err != nil {
78
83
return err
79
84
}
80
85
81
- // keep only jobs with correct inferences
82
- jobs = model .FilterCorrectInferences (jobs )
83
-
84
86
// keep only jobs with non-zero runtimes
85
87
jobs = model .FilterNonZeroTimes (jobs )
86
88
@@ -96,20 +98,51 @@ var rankingCmd = &cobra.Command{
96
98
}
97
99
numResults = min (numResults , maxResults )
98
100
numResults = min (numResults , len (jobs ))
99
- jobs = jobs [0 :numResults ]
101
+ // jobs = jobs[0:numResults]
100
102
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
+ }
108
112
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
109
124
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
+
111
134
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
+ }
113
146
}
114
147
115
148
table .Render ()
0 commit comments