From 3cb41ae7805a578eecc9a335508881a21137011f Mon Sep 17 00:00:00 2001 From: Kingdon Barrett Date: Mon, 25 Apr 2022 13:00:30 -0400 Subject: [PATCH] do stats collection from netlify This is the laziest way to get all the Top Pages info, future enhancements could include going back to get older data, or some improved slicing and dicing/visualization of the data. Signed-off-by: Kingdon Barrett --- collect-stats/Gemfile | 6 ++++ collect-stats/Gemfile.lock | 34 ++++++++++++++++++++ collect-stats/collect-stats.rb | 57 ++++++++++++++++++++++++++++++++++ do-netlify-stats-aggr.sh | 8 +++++ 4 files changed, 105 insertions(+) create mode 100644 collect-stats/Gemfile create mode 100644 collect-stats/Gemfile.lock create mode 100755 collect-stats/collect-stats.rb create mode 100755 do-netlify-stats-aggr.sh diff --git a/collect-stats/Gemfile b/collect-stats/Gemfile new file mode 100644 index 000000000..c557c82ae --- /dev/null +++ b/collect-stats/Gemfile @@ -0,0 +1,6 @@ +ruby '2.7.6' +source 'https://rubygems.org' + +gem 'awesome_print', require: 'ap' +gem 'activesupport' +gem 'pry' diff --git a/collect-stats/Gemfile.lock b/collect-stats/Gemfile.lock new file mode 100644 index 000000000..aede75609 --- /dev/null +++ b/collect-stats/Gemfile.lock @@ -0,0 +1,34 @@ +GEM + remote: https://rubygems.org/ + specs: + activesupport (7.0.2.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + awesome_print (1.9.2) + coderay (1.1.3) + concurrent-ruby (1.1.10) + i18n (1.10.0) + concurrent-ruby (~> 1.0) + method_source (1.0.0) + minitest (5.15.0) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + +PLATFORMS + ruby + +DEPENDENCIES + activesupport + awesome_print + pry + +RUBY VERSION + ruby 2.7.6p219 + +BUNDLED WITH + 2.1.4 diff --git a/collect-stats/collect-stats.rb b/collect-stats/collect-stats.rb new file mode 100755 index 000000000..a397898e6 --- /dev/null +++ b/collect-stats/collect-stats.rb @@ -0,0 +1,57 @@ +#!/usr/bin/env ruby + +require 'ap' +require 'pry' + +require 'active_support/all' + +# commits_so_far = %w{03d50caa 18b2d4d6 b71353a4 62624387 128d3da5 e267f767 0773e5cf cb3feaa3 1bfa4c4e dd14c72e 1999ff43 aa3b4887 56625329 458602ad 036a5aff 8b877e28 1d51457c 3be3dc1b dbab09f2 373007bf d3c74fc6 f9b1515c 32310e84 5afe9a0a bc0c9a1f 30af67db b5b73107 79d4dce9 9a7205c9 dc38f527 0c4cd32b ec00ee72 76f446e2 73bd5f3c 23d2fcb0 2faf6f45 fe008045 3f112981 c7ac014a 97e183ce 0d062e6e f1cef3ee 92ff87e4} + +commits_so_far = `git log main..netlify-stats --oneline --reverse |awk '{print $1}'|grep -v 17353663`.split("\n") + +def fetch_from_commit(commit_hash) + `git co #{commit_hash}` + pages = File.open('pages.csv') + ret = {} + pages.lines.each do |line| + v = line.chomp.split(',') + ret[v.first] = v.last.to_i + end + + ret +end + +stats = commits_so_far.map do |c| + f = fetch_from_commit(c) + # binding.pry + f +end + +all_stats = {} +days_counted = 0 + +stats.each do |stat| + stat.keys.each do |key| + if all_stats[key].nil? + all_stats[key] = 0 + end + + all_stats[key] += stat[key] + end + + days_counted += 1 +end + +puts; puts + +o_hash = ActiveSupport::OrderedHash.new + +ordered_stats = all_stats.sort_by(&:last).reverse +ordered_stats.map do |n| + o_hash[n[0]] = n[1] + # puts "#{n[0]}: #{n[1]}" +end + +ap o_hash +puts; puts '---' +puts "days_counted: #{days_counted}" diff --git a/do-netlify-stats-aggr.sh b/do-netlify-stats-aggr.sh new file mode 100755 index 000000000..05d195f38 --- /dev/null +++ b/do-netlify-stats-aggr.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +git checkout netlify-stats && git pull --ff-only +git checkout main && git pull --ff-only + +bundle exec --gemfile collect-stats/Gemfile collect-stats/collect-stats.rb + +git checkout main