class Wms::Widget::Location1::Main
Run the widget
Open rails console >Widget.load_widgets >widget.run_widgets
Enjoy!
Attributes
widget[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/wms_location1/main.rb, line 37 def initialize super @logger.debug "Init widget [#{self.class.name}]" end
Public Instance Methods
register(options={})
click to toggle source
@override
# File lib/wms_location1/main.rb, line 43 def register(options={}) @widget = options[:widget] @begin = options[:begin] @end = options[:end] end
run()
click to toggle source
@override
# File lib/wms_location1/main.rb, line 50 def run # Call api @logger.debug "Running widget [#{self.class.name}]" @logger.debug @widget options = { #:device_id => "12345678", :type => "location", :begin => @begin, :end => @end } @events = get_events(options) (@events.count.to_i - 1).times do |i| cur = @events[i] nxt = @events[i + 1] analytic = { :device_id => "123456789", :widget_id => @widget.id, :user_id => @widget.user.id, :timestamp => Time.now, :src => { :latitude => cur["latitude"], :longitude => cur["longitude"] }, :dest => { :latitude => nxt["latitude"], :longitude => nxt["longitude"] }, :time_spent => (nxt["timestamp"].to_f - cur["timestamp"].to_f) * 1000.0 } save_analytics(analytic) end end