@@ -17,20 +17,25 @@ pub use crate::app::models::FilterType;
1717
1818#[ derive( Serialize , Deserialize , JsonSchema , Debug , Clone , Hash , PartialEq , Eq ) ]
1919pub struct DateRange {
20+ /// Start of the report range
2021 pub start : DateTime < Utc > ,
22+ /// End of the report range
2123 pub end : DateTime < Utc > ,
2224}
2325
2426impl DateRange {
27+ /// Return the immediately preceding range with the same duration
2528 pub fn prev ( & self ) -> Self {
2629 let duration = self . end - self . start ;
2730 Self { start : self . start - duration, end : self . start }
2831 }
2932
33+ /// Return whether the range ends after the current time
3034 pub fn ends_in_future ( & self ) -> bool {
3135 self . end > Utc :: now ( )
3236 }
3337
38+ /// Return the range duration
3439 pub fn duration ( & self ) -> chrono:: Duration {
3540 self . end - self . start
3641 }
@@ -45,9 +50,13 @@ impl Display for DateRange {
4550#[ derive( Debug , Serialize , Deserialize , JsonSchema , Clone , Copy , PartialEq , Eq , Hash ) ]
4651#[ serde( rename_all = "snake_case" ) ]
4752pub enum Metric {
53+ /// Total pageviews
4854 Views ,
55+ /// Distinct visitor groups
4956 UniqueVisitors ,
57+ /// Percentage of sessions with one pageview
5058 BounceRate ,
59+ /// Average time between pageviews in a session
5160 AvgTimeOnSite ,
5261}
5362
@@ -62,33 +71,62 @@ impl Display for Metric {
6271 }
6372}
6473
74+ impl Metric {
75+ /// Return all report metrics in dashboard order
76+ pub const fn all ( ) -> & ' static [ Self ] {
77+ & [ Self :: Views , Self :: UniqueVisitors , Self :: BounceRate , Self :: AvgTimeOnSite ]
78+ }
79+ }
80+
81+ /// Time bucket size for graph reports
6582#[ derive( Debug , Serialize , Deserialize , JsonSchema , Clone , Copy , PartialEq , Eq , Hash ) ]
6683#[ serde( rename_all = "snake_case" ) ]
6784pub enum GraphInterval {
85+ /// Hourly buckets
6886 Hour ,
87+ /// Daily buckets
6988 Day ,
7089}
7190
91+ /// Dimension selected for table reports and filters
7292#[ derive( Debug , Serialize , Deserialize , JsonSchema , Clone , Copy , Hash , Eq , PartialEq , PartialOrd , Ord ) ]
7393#[ serde( rename_all = "snake_case" ) ]
7494pub enum Dimension {
95+ /// Full tracked URL
7596 Url ,
97+ /// First URL in a session
7698 UrlEntry ,
99+ /// Last URL in a session
77100 UrlExit ,
101+ /// Tracked hostname
78102 Fqdn ,
103+ /// Tracked path
79104 Path ,
105+ /// Referrer domain
80106 Referrer ,
107+ /// Operating system family
81108 Platform ,
109+ /// Browser family
82110 Browser ,
111+ /// Device type
83112 Mobile ,
113+ /// GeoIP country
84114 Country ,
115+ /// GeoIP city
85116 City ,
117+ /// UTM source
86118 UtmSource ,
119+ /// UTM medium
87120 UtmMedium ,
121+ /// UTM campaign
88122 UtmCampaign ,
123+ /// UTM content
89124 UtmContent ,
125+ /// UTM term
90126 UtmTerm ,
127+ /// Screen width bucket
91128 ScreenWidth ,
129+ /// Screen orientation
92130 Orientation ,
93131}
94132
@@ -117,25 +155,63 @@ impl Display for Dimension {
117155 }
118156}
119157
158+ impl Dimension {
159+ /// Return all report dimensions in dashboard order
160+ pub const fn all ( ) -> & ' static [ Self ] {
161+ & [
162+ Self :: Platform ,
163+ Self :: Browser ,
164+ Self :: Url ,
165+ Self :: UrlEntry ,
166+ Self :: UrlExit ,
167+ Self :: Path ,
168+ Self :: Mobile ,
169+ Self :: Referrer ,
170+ Self :: City ,
171+ Self :: Country ,
172+ Self :: Fqdn ,
173+ Self :: UtmCampaign ,
174+ Self :: UtmContent ,
175+ Self :: UtmMedium ,
176+ Self :: UtmSource ,
177+ Self :: UtmTerm ,
178+ Self :: ScreenWidth ,
179+ Self :: Orientation ,
180+ ]
181+ }
182+ }
183+
184+ /// One point in a graph report
120185#[ derive( Serialize , Deserialize , JsonSchema , Debug , Clone ) ]
121186#[ serde( rename_all = "camelCase" ) ]
122187pub struct ReportGraphPoint {
188+ /// Start timestamp of the graph bucket
123189 pub bin_start : DateTime < Utc > ,
190+ /// Metric value for the graph bucket
124191 pub value : f64 ,
125192}
126193
194+ /// Graph report points ordered by bucket start
127195pub type ReportGraph = Vec < ReportGraphPoint > ;
196+
197+ /// Dimension table values mapped to their metric value
128198pub type ReportTable = BTreeMap < String , f64 > ;
129199
200+ /// Overall metric summary for a report range
130201#[ derive( Serialize , Deserialize , JsonSchema , Clone , Debug , Default ) ]
131202#[ serde( rename_all = "camelCase" ) ]
132203pub struct ReportStats {
204+ /// Total pageviews
133205 pub total_views : u64 ,
206+ /// Distinct visitor groups
134207 pub unique_visitors : u64 ,
208+ /// Bounce rate, when session metrics are available
135209 pub bounce_rate : Option < f64 > ,
210+ /// Average time on site, when session metrics are available
136211 pub avg_time_on_site : Option < f64 > ,
137212}
138213
214+ /// Filter applied to a dashboard report query
139215#[ derive( Serialize , Deserialize , JsonSchema , Debug , Clone , Hash , Eq , PartialEq , PartialOrd , Ord ) ]
140216#[ serde( rename_all = "camelCase" ) ]
141217pub struct DimensionFilter {
0 commit comments