google_otg 1.0.17 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/google_otg.gemspec +1 -1
  3. data/lib/google_otg.rb +23 -22
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.17
1
+ 1.0.18
data/google_otg.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{google_otg}
8
- s.version = "1.0.17"
8
+ s.version = "1.0.18"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["esilverberg"]
data/lib/google_otg.rb CHANGED
@@ -4,7 +4,7 @@ require 'uri'
4
4
 
5
5
  module GoogleOtg
6
6
 
7
- DEFAULT_RANGE = 1 # 1 day
7
+ DEFAULT_INCREMENT = 1 # 1 day
8
8
 
9
9
  def google_line_graph(hits, args = {})
10
10
 
@@ -25,10 +25,6 @@ module GoogleOtg
25
25
  shape_markers = [['D','6699CC',0,'-1.0',4],['D','FF9933',1,'-1.0',2],['o','0000ff',0,'-1.0',8],['o','FF6600',1,'-1.0',8]]
26
26
  line_colors = ['6699CC','FF9933']
27
27
 
28
- lower_bound_time = nil
29
- hits.map{|series| lower_bound_time = series[0] if !lower_bound_time || series[0].created_at < lower_bound_time.created_at}
30
- args[:lower_bound_time] = lower_bound_time if lower_bound_time
31
-
32
28
  hits.map{|h|
33
29
  converted = hits_to_gchart_range(h, args)
34
30
  data.push(converted[:points])
@@ -71,16 +67,12 @@ module GoogleOtg
71
67
  src = args.has_key?(:src) ? args[:src] : "http://www.google.com/analytics/static/flash/OverTimeGraph.swf"
72
68
 
73
69
  if hits.is_a?(Array) and hits[0].is_a?(Array)
74
- lower_bound_time = nil
75
- hits.map{|series| lower_bound_time = series[0] if !lower_bound_time || (series[0] && series[0].created_at < lower_bound_time.created_at)}
76
- args[:lower_bound_time] = lower_bound_time if lower_bound_time
77
-
78
70
  range = hits.map{|h| hits_to_otg_range(h, args) }
79
71
  else
80
72
  range = [hits_to_otg_range(hits, args)]
81
73
  end
82
74
  vars = range_to_flashvars(range)
83
-
75
+
84
76
  html = <<-eos
85
77
  <embed width="100%" height="#{height}"
86
78
  wmode="opaque" salign="tl" scale="noScale" quality="high" bgcolor="#FFFFFF"
@@ -222,7 +214,8 @@ eos
222
214
  time_fn = args.has_key?(:time_fn) ? args[:time_fn] : lambda {|h|
223
215
  return tz.local(h.created_at.year, h.created_at.month, h.created_at.day, h.created_at.hour, h.created_at.min, h.created_at.sec) # create zoned time
224
216
  }
225
- range = args.has_key?(:range) ? args[:range] : DEFAULT_RANGE
217
+ increment = args.has_key?(:increment) ? args[:increment] : DEFAULT_INCREMENT
218
+
226
219
  x_label_format = args.has_key?(:x_label_format) ? args[:x_label_format] : "%A %I:%M%p"
227
220
 
228
221
  max_y = 0
@@ -236,18 +229,22 @@ eos
236
229
  points = []
237
230
  point_dates = []
238
231
 
239
- now_days = tz.now # use this get the right year, month and day
240
- now_minutes = tz.at((now_days.to_i/(60*(range * 1440)))*(60*(range * 1440))).gmtime
241
- now_floored = tz.local(now_days.year, now_days.month, now_days.day,
242
- now_minutes.hour, now_minutes.min, now_minutes.sec)
243
-
244
- if args[:lower_bound_time]
245
- current = time_fn.call(args[:lower_bound_time])
232
+ if args[:range] && args[:range][:lower_bound]
233
+ current = args[:range][:lower_bound]
246
234
  else
247
235
  current = hits.length > 0 ? time_fn.call(hits[0]) : now_floored
248
236
  end
237
+
238
+ if args[:range] && args[:range][:upper_bound]
239
+ now_floored = args[:range][:upper_bound]
240
+ else
241
+ now_days = tz.now # use this get the right year, month and day
242
+ now_minutes = tz.at((now_days.to_i/(60*(increment * 1440)))*(60*(increment * 1440))).gmtime
243
+ now_floored = tz.local(now_days.year, now_days.month, now_days.day,
244
+ now_minutes.hour, now_minutes.min, now_minutes.sec)
245
+ end
249
246
 
250
- while (current < now_floored + range.days && range > 0) do
247
+ while (current < now_floored + increment.days && increment > 0) do
251
248
  if hits_dict[current]
252
249
  count = hits_dict[current].count.to_i
253
250
  max_y = count if count > max_y
@@ -268,10 +265,14 @@ eos
268
265
  end
269
266
  # Save the date for the x labels later
270
267
  point_dates.push({:key => date_key, :value => date_value})
271
- current = current + range.days
272
- break if points.length > 100
268
+ current = current + increment.days
269
+ break if points.length > 365 # way too long dudes - no data fetching over 1 yr
273
270
  end
274
-
271
+
272
+ if points.length > 100
273
+ points = points[points.length - 100..points.length - 1]
274
+ end
275
+
275
276
  ## Setup Y axis labels ##
276
277
  max_y = args.has_key?(:max_y) ? (args[:max_y] > max_y ? args[:max_y] : max_y) : max_y
277
278
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_otg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.17
4
+ version: 1.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - esilverberg