wms_location1 0.0.3 → 0.0.4
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.
- checksums.yaml +8 -8
- data/lib/wms_location1/main.rb +87 -0
- data/lib/wms_location1/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGMwMGQ4NTViODY1MzM5ZTZlZmUyZDI1ZWQ3M2Y2YzQzZWUzODA2Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjdlNjEwY2UyMTk5NGU0MWYwYmFlYWE4NzRhYjljZTFhY2I2MTE0MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjhiNjczOTUxNWQ2ZGQ3YTI0ZGFlOTJhNGMxM2ZiNTMyMmM0OGI5NDc5Yzgz
|
10
|
+
MWQwYjAxZDY2YmEyZWNmYmYyYTk3YjU2MTRjZGIxNTM4YzY5YzEzMDFkOWMw
|
11
|
+
MTMxZmRjMTRmYjM5MDFjMTFiNTU4ZWU2NGUyMDI0Y2I3Y2U0NzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzBiMWM5NTNmNjEyNDIyZDcxMDgxYTllNmRlMWU3ZGNiMWMyN2RjOWJlZWRl
|
14
|
+
Y2RkZTBjZTUxYjJjNTE5ZWI5M2I1Yjg4MmYwMDYxYTQ2OWQwYWMzMDc3ZjFk
|
15
|
+
YTFiNjM3ZmI0NTQ0MWVlNDlkZTUyM2VlZWJiNDFhYjM1ZDFkM2I=
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'wms/widget/base'
|
2
|
+
|
3
|
+
# This widget will read the location record from the event. It will then
|
4
|
+
# calculate how much time(in millisecond) did the user spend from one point to another.
|
5
|
+
#
|
6
|
+
# Input: a list of location events.
|
7
|
+
# Output: analytics
|
8
|
+
# {:device_id => "123456789", :widget_id = > '1', :user_id => '1',
|
9
|
+
# :timestamp => "2013-11-06 00:01:00 -0800",
|
10
|
+
# :src => {:latitude => 37.4127000, longitude => -122.05854944},
|
11
|
+
# :dest => {:latitude => 37.412619, longitude => -122.05859092},
|
12
|
+
# :time_spent => 4888123 #(miliseconds)
|
13
|
+
# }
|
14
|
+
# {:device_id => "123456789", :widget_id = > '1', :user_id => '1',
|
15
|
+
# :timestamp => "2013-11-06 00:01:30 -0800",
|
16
|
+
# :src => {:latitude => 37.412619, longitude => -122.05859092},
|
17
|
+
# :dest => {:latitude => 37.4126154 longitude => -122.05854005},
|
18
|
+
# :time_spent => 10000 #(miliseconds)
|
19
|
+
# }
|
20
|
+
|
21
|
+
# Run the widget
|
22
|
+
# Open rails console
|
23
|
+
# >Widget.load_widgets
|
24
|
+
# >widget.run_widgets
|
25
|
+
#
|
26
|
+
# Enjoy!
|
27
|
+
#
|
28
|
+
|
29
|
+
class Wms::Widget::Location1::Main < Wms::Widget::Base
|
30
|
+
include Wms::Api::Event
|
31
|
+
include Wms::Api::Analytic
|
32
|
+
|
33
|
+
attr_accessor :widget
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
super
|
37
|
+
@logger.debug "Init widget [#{self.class.name}]"
|
38
|
+
end
|
39
|
+
|
40
|
+
# @override
|
41
|
+
def register(options={})
|
42
|
+
@widget = options[:widget]
|
43
|
+
@begin = options[:begin]
|
44
|
+
@end = options[:end]
|
45
|
+
end
|
46
|
+
|
47
|
+
# @override
|
48
|
+
def run
|
49
|
+
# Call api
|
50
|
+
@logger.debug "Running widget [#{self.class.name}]"
|
51
|
+
|
52
|
+
@logger.debug @widget
|
53
|
+
|
54
|
+
options = {
|
55
|
+
#:device_id => "12345678",
|
56
|
+
:type => "location",
|
57
|
+
:begin => @begin,
|
58
|
+
:end => @end
|
59
|
+
}
|
60
|
+
|
61
|
+
@events = get_events(options)
|
62
|
+
|
63
|
+
(@events.count.to_i - 1).times do |i|
|
64
|
+
cur = @events[i]
|
65
|
+
nxt = @events[i + 1]
|
66
|
+
|
67
|
+
analytic = {
|
68
|
+
:device_id => "123456789",
|
69
|
+
:widget_id => @widget.id,
|
70
|
+
:user_id => @widget.user.id,
|
71
|
+
:timestamp => Time.now,
|
72
|
+
:src => {
|
73
|
+
:latitude => cur["latitude"],
|
74
|
+
:longitude => cur["longitude"]
|
75
|
+
},
|
76
|
+
:dest => {
|
77
|
+
:latitude => nxt["latitude"],
|
78
|
+
:longitude => nxt["longitude"]
|
79
|
+
},
|
80
|
+
:time_spent => (nxt["timestamp"].to_f - cur["timestamp"].to_f) * 1000.0
|
81
|
+
}
|
82
|
+
save_analytics(analytic)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wms_location1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phoorichet Thepdusith
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- Rakefile
|
53
53
|
- lib/namespace.rb
|
54
54
|
- lib/wms_location1.rb
|
55
|
+
- lib/wms_location1/main.rb
|
55
56
|
- lib/wms_location1/version.rb
|
56
57
|
- wms_location1.gemspec
|
57
58
|
homepage: ''
|