-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathmodels.go
More file actions
128 lines (108 loc) 路 2.45 KB
/
Copy pathmodels.go
File metadata and controls
128 lines (108 loc) 路 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package model
import (
"database/sql"
"database/sql/driver"
"errors"
)
// User of the application; can be Requester or Workers
type User struct {
ID int
Login string // GitHub account username
Username string // Real name, as returned by GitHub
AvatarURL string
Role Role
}
// Experiment groups a certain amount of FilePairs
type Experiment struct {
ID int
Name string
Description string
}
// Assignment tracks the answer of a worker to a given FilePair of an Experiment
type Assignment struct {
ID int
UserID int
PairID int
ExperimentID int
Answer sql.NullString
Duration int
}
// AnswerStr returns the string value, using "" if it's not set
func (a *Assignment) AnswerStr() string {
if a.Answer.Valid {
return a.Answer.String
}
return ""
}
// FilePair represents the pairs of files to annotate
type FilePair struct {
ID int
Score float64
ExperimentID int
Left File
Right File
}
// File contains the info of a File
type File struct {
BlobID string
RepositoryID string
CommitHash string
Path string
Content string
UAST []byte
Hash string
}
// Feature represents one name-value feature of file
type Feature struct {
Name string
Weight float64
}
// Role represents the position of a app User
type Role string
// String returns the string value of the Role
func (r Role) String() string {
return string(r)
}
// Value returns the string value of the Role
func (r Role) Value() (driver.Value, error) {
if isValidRole(r) {
return string(r), nil
}
return "", errors.New("invalid Role")
}
// Scan sets the Role with the passed string
func (r *Role) Scan(value interface{}) error {
var role string
switch v := value.(type) {
case []byte:
role = string(v)
case string:
role = v
}
if role != "" && isValidRole(Role(role)) {
*r = Role(role)
return nil
}
return errors.New("can't scan a valid Role")
}
func isValidRole(r Role) bool {
for _, role := range []Role{Worker, Requester} {
if r == role {
return true
}
}
return false
}
const (
// Requester is the role of a user that can review assignments, users, stats of experiments...
Requester Role = "requester"
// Worker is the role of a user that can answer assignments
Worker Role = "worker"
)
// Answers lists the accepted answers
var Answers = map[string]string{
"yes": "yes",
"maybe": "maybe",
"no": "no",
"skip": "skip",
}