-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathregistry_metrics.py
More file actions
176 lines (168 loc) · 7.24 KB
/
registry_metrics.py
File metadata and controls
176 lines (168 loc) · 7.24 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import elasticsearch_metrics.imps.elastic6 as metrics
from osf.utils.workflows import RegistrationModerationTriggers, RegistrationModerationStates
from .metric_mixin import MetricMixin
class RegistriesModerationMetrics(MetricMixin, metrics.Metric):
registration_id = metrics.Keyword(index=True, doc_values=True, required=True)
provider_id = metrics.Keyword(index=True, doc_values=True, required=True)
trigger = metrics.Keyword(index=True, doc_values=True, required=True)
from_state = metrics.Keyword(index=True, doc_values=True, required=True)
to_state = metrics.Keyword(index=True, doc_values=True, required=True)
user_id = metrics.Keyword(index=True, doc_values=True, required=True)
comment = metrics.Keyword(index=True)
class Index:
settings = {
'number_of_shards': 1,
'number_of_replicas': 1,
'refresh_interval': '1s',
}
class Meta:
source = metrics.MetaField(enabled=True)
@classmethod
def record_transitions(cls, action):
return cls.record(
registration_id=action.target._id,
provider_id=action.target.provider._id,
from_state=action.from_state,
to_state=action.to_state,
trigger=action.trigger,
user_id=action.creator._id,
comment=action.comment,
)
@classmethod
def get_registries_info(cls) -> dict:
"""
Gets metrics info for each registry
expected output:
{
'doc_count_error_upper_bound': 0,
'sum_other_doc_count': 0,
'buckets': [{
'key': 'osf',
'doc_count': 6,
'rejected': {'doc_count': 0},
'submissions': {'doc_count': 3},
'not_embargoed_but_accepted': {'doc_count': 0},
'withdrawn': {'doc_count': 0},
'transitions_without_comments': {'doc_count': 1},
'embargoed': {'doc_count': 0},
'transitions_with_comments': {'doc_count': 5}
},
{
'key': 'provider2',
'doc_count': 4,
'rejected': {'doc_count': 1},
'submissions': {'doc_count': 1},
'not_embargoed_but_accepted': {'doc_count': 1},
'withdrawn': {'doc_count': 0},
'transitions_without_comments': {'doc_count': 0},
'embargoed': {'doc_count': 0},
'transitions_with_comments': {'doc_count': 4}
}]
}
:return: dict
"""
search = cls.search()
return search.update_from_dict({
'aggs': {
'providers': {
'terms': {
'field': 'provider_id'
},
'aggs': {
'transitions_without_comments': {
'missing': {
'field': 'comment'
}
},
'transitions_with_comments': {
'filter': {
'exists': {
'field': 'comment'
}
}
},
'submissions': {
'filter': {
'match': {
'trigger': {
'query': RegistrationModerationTriggers.SUBMIT.db_name
}
}
}
},
'accepted_with_embargo': {
'filter': {
'bool': {
'must': [
{
'match': {
'to_state': RegistrationModerationStates.EMBARGO.db_name
}
},
{
'match': {
'trigger': RegistrationModerationTriggers.SUBMIT.db_name
}
}
]
}
}
},
'accepted_without_embargo': {
'filter': {
'bool': {
'must': [
{
'match': {
'to_state': RegistrationModerationStates.ACCEPTED.db_name
}
},
{
'match': {
'trigger': RegistrationModerationTriggers.SUBMIT.db_name
}
}
]
}
}
},
'rejected': {
'filter': {
'bool': {
'must': [
{
'match': {
'to_state': RegistrationModerationStates.REJECTED.db_name
}
},
{
'match': {
'trigger': RegistrationModerationTriggers.REJECT_SUBMISSION.db_name
}
}
]
}
}
},
'withdrawn': {
'filter': {
'bool': {
'must': [
{
'match': {
'to_state': RegistrationModerationStates.WITHDRAWN.db_name
}
},
{
'match': {
'trigger': RegistrationModerationTriggers.ACCEPT_WITHDRAWAL.db_name
}
}
]
}
}
},
}
}
}
}).execute().aggregations['providers'].to_dict()