Sha256: 7b76a3aadd28c6e6d124d069418b5561972e30009bbfe75532a69d8d7cf8cf8a

Contents?: true

Size: 1.81 KB

Versions: 56

Compression:

Stored size: 1.81 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'gems'
require 'ostruct'
require 'terminal-table'

ATTRIBUTES = %i[
  authors
  built_at
  created_at
  description
  downloads_count
  metadata
  number
  summary
  platform
  rubygems_version
  ruby_version
  prerelease
  licenses
  requirements
  sha
].freeze
Version = Struct.new(*ATTRIBUTES, :keyword_init => true)

versions = Gems.versions('image_optim_pack').map(&Version.method(:new))

platforms = versions.map(&:platform).uniq.sort_by do |platform|
  platform.sub('amd64', 'x86_64').split('-').reverse
end

version_time = begin
  time_pairs = versions.group_by(&:number).map do |version_n, platform_versions|
    [version_n, platform_versions.map{ |v| Time.parse(v.created_at) }.min]
  end.sort
  time_pairs << [nil, Time.now]

  time_pairs.each_cons(2).to_h do |(version_n, created_at), (_, next_created_at)|
    [version_n, next_created_at - created_at]
  end
end

table = Terminal::Table.new

table.headings = ['version', 'days', 'base dls'] + platforms.map do |platform|
  platform.split('-').reverse.join("\n")
end + ['total']

versions.group_by(&:number).each do |version_n, platform_versions|
  next if platform_versions.length == 1

  downloads_by_platform = Hash[platform_versions.map do |version|
    [version.platform, version.downloads_count]
  end]

  base_downloads = platform_versions.map(&:downloads_count).min

  platform_values = downloads_by_platform.values_at(*platforms).map do |count|
    next '' unless count

    count == base_downloads ? '=' : format('%+d', count - base_downloads)
  end
  table.add_row [
    version_n,
    (version_time[version_n] / (24 * 60 * 60)).round,
    base_downloads,
  ] + platform_values + [downloads_by_platform.values.sum]
end

(1...table.number_of_columns).each do |column|
  table.align_column(column, :right)
end

puts table

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
image_optim_pack-0.9.1.20230828 script/platform_downloads
image_optim_pack-0.9.1.20230828-x86_64-linux script/platform_downloads
image_optim_pack-0.9.1.20230828-x86_64-darwin script/platform_downloads
image_optim_pack-0.9.1.20230828-x86-linux script/platform_downloads
image_optim_pack-0.9.1.20230814-x86-linux script/platform_downloads
image_optim_pack-0.9.1.20230814-x86_64-linux script/platform_downloads
image_optim_pack-0.9.1.20230814-x86_64-darwin script/platform_downloads
image_optim_pack-0.9.1.20230814 script/platform_downloads
image_optim_pack-0.9.1.20230625-x86-linux script/platform_downloads
image_optim_pack-0.9.1.20230625-x86_64-linux script/platform_downloads
image_optim_pack-0.9.1.20230625-x86_64-darwin script/platform_downloads
image_optim_pack-0.9.1.20230625 script/platform_downloads
image_optim_pack-0.9.1.20230622-x86-linux script/platform_downloads
image_optim_pack-0.9.1.20230622-x86_64-linux script/platform_downloads
image_optim_pack-0.9.1.20230622-x86_64-darwin script/platform_downloads
image_optim_pack-0.9.1.20230622 script/platform_downloads
image_optim_pack-0.9.1.20230526-x86-linux script/platform_downloads
image_optim_pack-0.9.1.20230526-x86_64-linux script/platform_downloads
image_optim_pack-0.9.1.20230526-x86_64-darwin script/platform_downloads
image_optim_pack-0.9.1.20230526 script/platform_downloads