Class: Birdwatcher::Punchcard
- Inherits:
-
Object
- Object
- Birdwatcher::Punchcard
- Defined in:
- lib/birdwatcher/punchcard.rb
Constant Summary collapse
- LEFT_PADDING =
10
- TOP_PADDING =
10
- WIDTH =
1100
- DAYS =
%w(Sat Fri Thu Wed Tue Mon Sun)
- HOURS =
%w(12am 1 2 3 4 5 6 7 8 9 10 11 12pm 1 2 3 4 5 6 7 8 9 10 11)
- FONT_FACE =
"sans-serif"
Instance Method Summary collapse
- #generate(destination) ⇒ Object
-
#initialize(timestamps) ⇒ Punchcard
constructor
A new instance of Punchcard.
Constructor Details
#initialize(timestamps) ⇒ Punchcard
Returns a new instance of Punchcard.
15 16 17 |
# File 'lib/birdwatcher/punchcard.rb', line 15 def initialize() @timestamps = end |
Instance Method Details
#generate(destination) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/birdwatcher/punchcard.rb', line 19 def generate(destination) @data_log = Hash.new { |h, k| h[k] = Hash.new } final_data = [] @timestamps.each do || day = .strftime("%a") hour = .strftime("%H").to_i @data_log[day][hour] = (@data_log[day][hour] || 0) + 1 end @data_log.each do |d, hour_pair| hour_pair.each do |h, value| glr = @data_log[d][h] * 1.0 glr /= max_value glr *= max_range glrb = get_weight(glr) final_data.push([glrb, get_x_y_from_day_and_hour(d, h)]) end end final_data.each do |x| draw_circle(x[1], x[0]) end surface.write_to_png(destination) end |