Class: Sentiero::Analytics::ProblemDetail
- Inherits:
-
Object
- Object
- Sentiero::Analytics::ProblemDetail
- Defined in:
- lib/sentiero/analytics/problem_detail.rb
Overview
Aggregations for the problem detail page: facet distributions over the already-fetched occurrences/session summaries, and the occurrence trend. The trend's rolling counts query the store (count_occurrences); the facets and the sparkline buckets are computed purely from the passed-in rows.
Constant Summary collapse
- FACET_LIMIT =
Rows shown per facet group on the problem detail page.
8- TREND_DAYS =
Day buckets in the problem-detail occurrence sparkline.
30
Instance Method Summary collapse
- #facets(occurrences, session_summaries) ⇒ Object
-
#initialize(store) ⇒ ProblemDetail
constructor
A new instance of ProblemDetail.
-
#trend(problem_id, occurrences) ⇒ Object
The 24h/7d/30d header counts are exact (count_occurrences after:); the sparkline buckets the already-fetched occurrences by UTC day, labeled with its sample size.
Constructor Details
#initialize(store) ⇒ ProblemDetail
Returns a new instance of ProblemDetail.
18 19 20 |
# File 'lib/sentiero/analytics/problem_detail.rb', line 18 def initialize(store) @store = store end |
Instance Method Details
#facets(occurrences, session_summaries) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sentiero/analytics/problem_detail.rb', line 22 def facets(occurrences, session_summaries) paths = Hash.new(0) environments = Hash.new(0) releases = {} browsers = Hash.new(0) occurrences.each do |occ| ctx = occ["context"] next unless ctx.is_a?(Hash) tally_facet(paths, ctx.dig("request", "path")) tally_facet(environments, ctx["environment"]) tally_release(releases, ctx["release"], occ["timestamp"]) end session_summaries.each { |s| tally_facet(browsers, s[:browser]) } { paths: top_facet(paths), environments: top_facet(environments), releases: releases.sort_by { |_release, info| -info[:count] }.first(FACET_LIMIT), browsers: top_facet(browsers), sample_size: occurrences.size } end |
#trend(problem_id, occurrences) ⇒ Object
The 24h/7d/30d header counts are exact (count_occurrences after:); the sparkline buckets the already-fetched occurrences by UTC day, labeled with its sample size.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/sentiero/analytics/problem_detail.rb', line 50 def trend(problem_id, occurrences) now = Time.now.to_f per_day = Hash.new(0) occurrences.each do |occ| ts = occ["timestamp"]&.to_f next unless ts && ts > 0 per_day[Time.at(ts).utc.to_date.to_s] += 1 end end_date = Time.now.utc.to_date series = ((end_date - (TREND_DAYS - 1))..end_date).map do |date| {date: date.to_s, count: per_day[date.to_s]} end { series: series, sample_size: occurrences.size, last_24h: occurrence_count_after(problem_id, now - 86_400), last_7d: occurrence_count_after(problem_id, now - 7 * 86_400), last_30d: occurrence_count_after(problem_id, now - TREND_DAYS * 86_400) } end |