-
Notifications
You must be signed in to change notification settings - Fork 0
/
charts.rb
executable file
·54 lines (43 loc) · 1.32 KB
/
charts.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/env ruby
# frozen_string_literal: true
require 'image-charts'
require 'nokogiri'
# https://coolors.co/114b5f-456990-e4fde1-f45b69-6b2737-efbcd5
COLORS = %w[114b5f 456990 e4fde1 f45b69 6b2737 efbcd5].freeze
data = {}
(2015..2020).each do |year|
data[year] = {}
page = `curl -sS -XGET https://adventofcode.com/#{year}/stats`
document = Nokogiri::HTML.parse(page)
document.css('a').each do |link|
next unless link.attribute('href').to_s =~ %r{^/#{year}/day/(\d+)$}
day = $1.to_i
both = link.at_css('.stats-both').text.to_i
first_only = link.at_css('.stats-firstonly').text.to_i
data[year][day] = { first: first_only + both, both: both }
end
end
def val(value)
value
# Math.log10(value).round(2)
end
chd = []
chdl = []
chco = []
chls = []
data.keys.sort.each_with_index do |year, i|
chd << data[year].keys.sort.map { |day| val(data[year][day][:both]) }.join(',')
chd << data[year].keys.sort.map { |day| val(data[year][day][:first]) }.join(',')
chdl << "#{year} - both stars" << "#{year} - each day"
chco << COLORS[i] << COLORS[i]
chls << '2' << '2,10,5'
end
chart = ImageCharts()
.cht('lc')
.chxt('x,y')
.chd("a:#{chd.join('|')}")
.chdl(chdl.join('|'))
.chco(chco.join(','))
.chls(chls.join('|'))
.chs('900x600')
puts chart.to_url