Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do stats collection from Netlify in aggregate #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions collect-stats/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ruby '2.7.6'
source 'https://rubygems.org'

gem 'awesome_print', require: 'ap'
gem 'activesupport'
gem 'pry'
34 changes: 34 additions & 0 deletions collect-stats/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions collect-stats/collect-stats.rb
Original file line number Diff line number Diff line change
@@ -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}"
8 changes: 8 additions & 0 deletions do-netlify-stats-aggr.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member Author

@kingdonb kingdonb Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're testing and this hasn't been merged yet, you'll want to run this bundle exec command instead of the script (as it won't be present in the main branch yet)

It does a bunch of git checkout stuff and branch switching internally, so I just added these to avoid leaving the clone in an unpredictable or detached state after the script runs.


git checkout main