Skip to content

Instantly share code, notes, and snippets.

@aapis
Last active October 12, 2017 17:33
Show Gist options
  • Save aapis/188830940d3acf5222319b040acc1315 to your computer and use it in GitHub Desktop.
Save aapis/188830940d3acf5222319b040acc1315 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# !IMPORTANT
# requires evertils-common 0.3.4/0.3.4.1-dev
require 'evertils/common'
require 'notifaction'
require 'date'
en = Evertils::Common::Query::Simple.new
daily_notes = en.notes_by_notebook('Daily')
notes = []
daily_notes.each do |note|
created_date = Time.at(note.created.to_s[0...-3].to_i).to_datetime
notes.push({title: note.title, created: created_date, size: note.contentLength})
end
notes.sort_by! { |note| -note[:size] }
Notify.info "10 busiest days in this dataset"
notes.take(10).each do |note|
Notify.spit "#{note[:created].strftime('%B %d, %Y')} with #{(note[:size].to_f/1000).round(2)}kb"
end
Notify.info "10 busiest months in this dataset"
busy_months_notes = []
by_months = notes.group_by { |note| note[:created].strftime('%B %Y') }
by_months.each do |month|
total_size = month[1].sum { |note| note[:size] }.to_f
busy_months_notes.push({month: month[0], size: total_size})
end
busy_months_notes.sort_by! { |group| -group[:size] }
busy_months_notes.take(10).each do |note|
Notify.spit "#{note[:month]} with #{(note[:size]/1000).round(2)}kb"
end
Notify.info "Total stats for this dataset"
total_size = (notes.sum { |note| note[:size] }.to_f) / 1000
unit = 'kb'
if total_size > 1024
total_size = (total_size/1000)
unit = 'mb'
end
Notify.spit "Total notes in this dataset: #{notes.size}"
Notify.spit "Total size of all notes in this dataset: #{total_size.round(2)}#{unit}"
# SAMPLE OUTPUT
# ‑ 10 busiest days in this dataset
# April 21, 2017 with 11.17kb
# August 04, 2017 with 9.95kb
# October 14, 2016 with 9.65kb
# August 02, 2017 with 9.12kb
# April 06, 2017 with 8.51kb
# August 28, 2017 with 8.49kb
# October 06, 2017 with 7.85kb
# December 21, 2016 with 7.8kb
# October 18, 2016 with 7.63kb
# March 16, 2017 with 7.62kb
# ‑ 10 busiest months in this dataset
# August 2017 with 126.04kb
# April 2017 with 112.83kb
# March 2017 with 108.34kb
# January 2017 with 94.83kb
# October 2016 with 88.17kb
# November 2016 with 85.67kb
# June 2017 with 83.89kb
# December 2016 with 72.49kb
# February 2017 with 70.66kb
# September 2017 with 67.39kb
# ‑ Total stats for this dataset
# Total notes in this dataset: 250
# Total size of all notes in this dataset: 1.11mb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment