pub struct AdminReport {
pub report_type: String,
pub data: Value,
pub prev_data: Option<Value>,
pub start_date: Option<String>,
pub end_date: Option<String>,
pub prev_start_date: Option<String>,
pub prev_end_date: Option<String>,
pub average: Option<f64>,
pub higher_is_better: Option<bool>,
}Expand description
Raw report payload, distilled from /admin/reports/{id}.json. Only the
fields dsc analytics actually reads are deserialised — Discourse
emits a lot more (axis labels, chart modes, descriptions) that we don’t
care about.
data and prev_data are kept as raw serde_json::Value because
Discourse uses two different shapes:
- Flat counter reports (
signups,topics,posts,likes,flags,new_contributors):data: [{x: date, y: number}, ...]. - Stacked-chart reports (
trust_level_growth):data: [{req: "tl1_reached", label: "...", data: [{x, y}, ...]}, ...].
current_total() walks both shapes and returns the right sum.
Fields§
§report_type: String§data: Value§prev_data: Option<Value>§start_date: Option<String>§end_date: Option<String>§prev_start_date: Option<String>§prev_end_date: Option<String>§average: Option<f64>Some reports (e.g. time_to_first_response) emit an average
scalar that is more meaningful than summing the daily points.
Discourse occasionally emits this as false when no average is
computable; we coerce that to None.
higher_is_better: Option<bool>Whether higher-is-better — Discourse marks this on each report, and
we use it to set the default desirable direction when our spec
doesn’t already pin one.
Implementations§
Source§impl AdminReport
impl AdminReport
Sourcepub fn current_total(&self) -> f64
pub fn current_total(&self) -> f64
Total for the current window.
Walks the data value and sums every y it can find. Handles both
the flat counter shape ([{x, y}, ...]) and the stacked-chart shape
([{data: [{x, y}, ...]}, ...]). Coerces non-numeric y (Discourse
occasionally emits false/null/string for empty cells) to 0.
Sourcepub fn previous_total(&self) -> Option<f64>
pub fn previous_total(&self) -> Option<f64>
Total for the previous-window, when present.
Trait Implementations§
Source§impl Clone for AdminReport
impl Clone for AdminReport
Source§fn clone(&self) -> AdminReport
fn clone(&self) -> AdminReport
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more