|
16 | 16 |
|
17 | 17 | package com.duckduckgo.app.attributed.metrics.api
|
18 | 18 |
|
19 |
| -// owns storing events, providing stats and emitting metrics |
20 |
| -// owns collection and monitoring windows (6mo monitoring) |
21 |
| -// owns new user / returning user logic |
22 |
| -// owns adding common params to all metrics (e.g. origin, removing default params) |
| 19 | +/** |
| 20 | + * Client for collecting and emitting attributed metrics. |
| 21 | + */ |
23 | 22 | interface AttributedMetricClient {
|
24 |
| - // will store an event in the data base, keep the counter per day |
| 23 | + /** |
| 24 | + * Stores an event occurrence for later analysis. |
| 25 | + * Does nothing if the client is not active. |
| 26 | + * |
| 27 | + * @param eventName Name of the event to collect |
| 28 | + */ |
25 | 29 | fun collectEvent(eventName: String)
|
26 | 30 |
|
27 |
| - // return events stored in the last days, and precalculated stats |
| 31 | + /** |
| 32 | + * Calculates statistics for a specific event over a time period. |
| 33 | + * Returns zero stats if the client is not active. |
| 34 | + * |
| 35 | + * @param eventName Name of the event to analyze |
| 36 | + * @param days Number of days to look back |
| 37 | + * @return Statistics about the event's occurrences |
| 38 | + */ |
28 | 39 | suspend fun getEventStats(
|
29 | 40 | eventName: String,
|
30 | 41 | days: Int,
|
31 | 42 | ): EventStats
|
32 | 43 |
|
33 |
| - // if in monitoring window will emit the metric |
34 |
| - // this part owns adding common params to all metrics (e.g. origin, removing default params) |
| 44 | + /** |
| 45 | + * Emits a metric with its parameters if the client is active. |
| 46 | + * Does nothing if the client is not active. |
| 47 | + * |
| 48 | + * @param metric The metric to emit |
| 49 | + */ |
35 | 50 | fun emitMetric(metric: AttributedMetric)
|
36 | 51 | }
|
37 | 52 |
|
38 |
| -// stats about events collected |
| 53 | +/** |
| 54 | + * Statistics about collected events over a time period. |
| 55 | + * |
| 56 | + * @property daysWithEvents Number of days that had at least one event |
| 57 | + * @property rollingAverage Average number of events per day over the period |
| 58 | + * @property totalEvents Total number of events in the period |
| 59 | + */ |
39 | 60 | data class EventStats(
|
40 |
| - // number of days with at least one event |
41 | 61 | val daysWithEvents: Int,
|
42 |
| - // rolling average of events based on days timeframe |
43 | 62 | val rollingAverage: Double,
|
44 |
| - // total number of events in the timeframe |
45 | 63 | val totalEvents: Int,
|
46 | 64 | )
|
47 | 65 |
|
48 |
| -// interface for each metric |
| 66 | +/** |
| 67 | + * Interface for defining an attributed metric. |
| 68 | + * Each metric implementation should provide its name and parameters. |
| 69 | + */ |
49 | 70 | interface AttributedMetric {
|
50 |
| - // Metric owns the pixel name value |
| 71 | + /** |
| 72 | + * @return The name used to identify this metric |
| 73 | + */ |
51 | 74 | fun getPixelName(): String
|
52 | 75 |
|
53 |
| - // Metric owns adding metric specific parameters |
| 76 | + /** |
| 77 | + * @return Parameters to be included with this metric |
| 78 | + */ |
54 | 79 | suspend fun getMetricParameters(): Map<String, String>
|
55 | 80 | }
|
0 commit comments