-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMetrics.java
246 lines (220 loc) · 8.72 KB
/
Metrics.java
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/
package sirius.biz.analytics.metrics;
import sirius.db.mixing.BaseEntity;
import javax.annotation.Nullable;
import java.time.LocalDate;
import java.util.List;
/**
* Provides a database independent API to store and retrieve metrics.
* <p>
* Metrics in this case are numerical values (integers) which are stored for an object in serveral time intervals.
* <p>
* Most metrics are most probably computed using a {@link DailyMetricComputer} or {@link MonthlyMetricComputer}.
* However this API can also be used outside of such computers.
*/
public interface Metrics {
/**
* Creates or updates a fact (timeless metric) for the given target object.
*
* @param targetType the type of the object for which the metric is stored
* @param targetId the id of the object for which the metric is stored
* @param name the name of the metric
* @param value the value to store
*/
void updateFact(String targetType, String targetId, String name, int value);
/**
* Creates or updates a fact (timeless metric) for the given target object.
*
* @param target the object for which the metric is stored
* @param name the name of the metric
* @param value the value to store
*/
void updateFact(BaseEntity<?> target, String name, int value);
/**
* Creates or updates a global fact (timeless metric).
*
* @param name the name of the metric
* @param value the value to store
*/
void updateGlobalFact(String name, int value);
/**
* Creates or updates a yearly metric for the given target object.
*
* @param targetType the type of the object for which the metric is stored
* @param targetId the id of the object for which the metric is stored
* @param name the name of the metric
* @param year the year of the metric
* @param value the value to store
*/
void updateYearlyMetric(String targetType, String targetId, String name, int year, int value);
/**
* Creates or updates a yearly metric for the given target object.
*
* @param target the object for which the metric is stored
* @param name the name of the metric
* @param year the year of the metric
* @param value the value to store
*/
void updateYearlyMetric(BaseEntity<?> target, String name, int year, int value);
/**
* Creates or updates a yearly metric for the given target object.
*
* @param target the object for which the metric is stored
* @param name the name of the metric
* @param date the date to determine the year of the metric
* @param value the value to store
*/
void updateYearlyMetric(BaseEntity<?> target, String name, LocalDate date, int value);
/**
* Creates or updates a global yearly metric.
*
* @param name the name of the metric
* @param year the year of the metric
* @param value the value to store
*/
void updateGlobalYearlyMetric(String name, int year, int value);
/**
* Creates or updates a global yearly metric.
*
* @param name the name of the metric
* @param date the date to determine the year of the metric
* @param value the value to store
*/
void updateGlobalYearlyMetric(String name, LocalDate date, int value);
/**
* Creates or updates a monthly metric for the given target object.
*
* @param targetType the type of the object for which the metric is stored
* @param targetId the id of the object for which the metric is stored
* @param name the name of the metric
* @param year the year of the metric
* @param month the month of the metric
* @param value the value to store
*/
void updateMonthlyMetric(String targetType, String targetId, String name, int year, int month, int value);
/**
* Creates or updates a monthly metric for the given target object.
*
* @param target the object for which the metric is stored
* @param name the name of the metric
* @param year the year of the metric
* @param month the month of the metric
* @param value the value to store
*/
void updateMonthlyMetric(BaseEntity<?> target, String name, int year, int month, int value);
/**
* Creates or updates a monthly metric for the given target object.
*
* @param target the object for which the metric is stored
* @param name the name of the metric
* @param date the date to determine the year and month of the metric
* @param value the value to store
*/
void updateMonthlyMetric(BaseEntity<?> target, String name, LocalDate date, int value);
/**
* Creates or updates a global monthly metric.
*
* @param name the name of the metric
* @param year the year of the metric
* @param month the month of the metric
* @param value the value to store
*/
void updateGlobalMonthlyMetric(String name, int year, int month, int value);
/**
* Creates or updates a global monthly metric.
*
* @param name the name of the metric
* @param date the date to determine the year and month of the metric
* @param value the value to store
*/
void updateGlobalMonthlyMetric(String name, LocalDate date, int value);
/**
* Creates or updates a daily metric for the given target object.
*
* @param targetType the type of the object for which the metric is stored
* @param targetId the id of the object for which the metric is stored
* @param name the name of the metric
* @param year the year of the metric
* @param month the month of the metric
* @param day the day of the metric
* @param value the value to store
*/
void updateDailyMetric(String targetType, String targetId, String name, int year, int month, int day, int value);
/**
* Creates or updates a daily metric for the given target object.
*
* @param target the object for which the metric is stored
* @param name the name of the metric
* @param year the year of the metric
* @param month the month of the metric
* @param day the day of the metric
* @param value the value to store
*/
void updateDailyMetric(BaseEntity<?> target, String name, int year, int month, int day, int value);
/**
* Creates or updates a daily metric for the given target object.
*
* @param target the object for which the metric is stored
* @param name the name of the metric
* @param date the date to determine the year, month and day of the metric
* @param value the value to store
*/
void updateDailyMetric(BaseEntity<?> target, String name, LocalDate date, int value);
/**
* Creates or updates a daily metric.
*
* @param name the name of the metric
* @param year the year of the metric
* @param month the month of the metric
* @param day the day of the metric
* @param value the value to store
*/
void updateGlobalDailyMetric(String name, int year, int month, int day, int value);
/**
* Creates or updates a daily metric.
*
* @param name the name of the metric
* @param date the date to determine the year, month and day of the metric
* @param value the value to store
*/
void updateGlobalDailyMetric(String name, LocalDate date, int value);
/**
* Creates a query against the metrics database.
*
* @return a query to be executed against the metrics database
*/
MetricQuery query();
/**
* Fetches the metric values of the last 12 months for the given entity.
*
* @param entity the entity to query metrics for
* @param metric the metric to query
* @return a list of metric values for the last 12 months.
*/
List<Integer> fetchMetricValuesForLast12Months(BaseEntity<?> entity, String metric);
/**
* Fetches the label for the given metric.
* <p>
* This is boilerplate for {@code NLS.get('Metric.'+name)}
*
* @param name the name of the metric to fetch the label for
* @return the label of the metric in the current language
*/
String fetchLabel(String name);
/**
* Fetches the description for the given metric.
* <p>
* This is boilerplate for {@code NLS.get('Metric.'+name+'.description')}
*
* @param name the name of the metric to fetch the description for
* @return the description of the metric in the current language or <tt>null</tt> if none is present
*/
@Nullable
String fetchDescription(String name);
}