Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Log smiles and smiles per hour to a CSV file

  • Loading branch information...
commit 39a9e324d58eea34186e16026b84b9f7d9387ab4 1 parent fa71b02
@quadule authored
Showing with 15 additions and 1 deletion.
  1. +15 −1 smileometer.rb
View
16 smileometer.rb
@@ -2,6 +2,7 @@ class Smiles < Array
MINUTES = 60
HOURS = 60*MINUTES
RECENT = 10*MINUTES
+ LOG_FILE = File.expand_path('~/Documents/smileometer.csv')
attr_accessor :start
def initialize(*args)
@@ -9,6 +10,14 @@ def initialize(*args)
@start = now
end
+ def dump
+ log_exists = File.exists?(LOG_FILE)
+ File.open(LOG_FILE, 'a') do |f|
+ f << "time,smiles_per_hour\n" unless log_exists
+ f << [Time.at(last), per_hour.round(2)].join(',') << "\n"
+ end
+ end
+
def now
Time.now.to_f
end
@@ -19,6 +28,7 @@ def elapsed
def log
push now
+ dump
end
def in_last(seconds)
@@ -45,7 +55,11 @@ def per_hour_smoothed
end
def per_hour_total
- count * (HOURS / elapsed)
+ if elapsed == 0
+ 0.0
+ else
+ count * (HOURS / elapsed)
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.