Last active
March 23, 2019 04:50
-
-
Save stereocat/1ee8552a5205a5d0b11ac7e7aa21a6f6 to your computer and use it in GitHub Desktop.
github grass parser (per day of the week)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DayRect | |
def initialize(line) | |
@line = line.strip! | |
@line.gsub!('<rect ', '') | |
@line.gsub!('/', '') | |
@line.gsub!('>', '') | |
@table = {} | |
set_table | |
end | |
def day_week | |
list = %w(Sun Mon Tue Wed Thu Fri Sat) | |
list[val('y') / 12] | |
end | |
def set_table | |
@line.split(' ').each do |kv_str| | |
kv_str.gsub!('"', '') | |
(key, value) = kv_str.split('=') | |
@table[key] = value =~ /^\d+$/ ? value.to_i : value.to_s | |
end | |
end | |
def val(key) | |
@table[key] | |
end | |
def to_s | |
@line | |
end | |
end | |
counter = {} | |
$stdin.each_line do |line| | |
if line =~ /rect class="day"/ | |
day_rect = DayRect.new(line) | |
# p day_rect | |
# p "#{day_rect.val('data-date')} -> #{day_rect.day_week}" | |
counter[day_rect.day_week] = 0 unless counter[day_rect.day_week] | |
counter[day_rect.day_week] += day_rect.val('data-count') | |
end | |
end | |
sum = counter.values.inject(0) { |v, s| s + v } | |
counter.each do |key, value| | |
rate = 100.0 * value / sum | |
puts sprintf( '%s: %6d commits (%4.1f%%) | %s', | |
key, value, rate.round(1), '*' * rate.round(0)) | |
end | |
puts sprintf('total: %4d commits', sum) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stereocat@lambda08:/mnt/d/dev$ curl -X GET --silent https://github.com/stereocat/ | ruby commit-count-gh-dotw.rb | |
Sun: 19 commits (25.7%) | ************************** | |
Mon: 17 commits (23.0%) | *********************** | |
Tue: 5 commits ( 6.8%) | ******* | |
Wed: 7 commits ( 9.5%) | ********* | |
Thu: 9 commits (12.2%) | ************ | |
Fri: 10 commits (13.5%) | ************** | |
Sat: 7 commits ( 9.5%) | ********* | |
total: 74 commits | |
stereocat@lambda08:/mnt/d/dev$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment