Skip to content

Commit

Permalink
fix metrics bug, add published metric
Browse files Browse the repository at this point in the history
  • Loading branch information
hexylena committed Mar 1, 2024
1 parent 51713a5 commit b2b54e8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion _plugins/gtn/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.histogram(values)
end

def self.histogram_dates(values)
day_bins = [1, 7, 28, 90, 365, 365 * 2, 365 * 3, 365 * 5]
day_bins = [1, 7, 28, 90, 365, 365 * 2, 365 * 3, 365 * 5, Float::INFINITY]
last_bin = 0
day_bins.map do |bin, _idx|
count = values.select { |x| last_bin <= x and x < bin }.length
Expand Down Expand Up @@ -87,6 +87,8 @@ def self.segment_page_by_key(values, key)

def self.collect_metrics(site)
tutorials = site.pages.select { |x| x.data['layout'] == 'tutorial_hands_on' }
# TODO: materials
# materials = site.pages.select { |x| x.data['layout'] == 'tutorial_hands_on' }
first_commit = Date.parse('2015-06-29')
today = Date.today

Expand Down Expand Up @@ -138,6 +140,18 @@ def self.collect_metrics(site)
.map { |seconds| seconds / 3600.0 / 24.0 }
)
},
'tutorial_published_age_days' => {
type: 'histogram',
help: 'How recently was every single Hands-on Tutorial published within the GTN, ' \
'grouped by days since first published.',
value: histogram_dates(
tutorials
.map do |page|
Time.now - Gtn::PublicationTimes.obtain_time(page['path'])
end
.map { |seconds| seconds / 3600.0 / 24.0 }
)
},
'contributor_join_age_days' => {
type: 'histogram',
help: 'When did contributors join? Buckets of their ages by days since joined.',
Expand Down

0 comments on commit b2b54e8

Please sign in to comment.