google_timeline 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4080d5f46c4811933a99d3fed150e3de179fab4
4
- data.tar.gz: afbdcb2a5d67472f03b321f4fdacc4a9a4d127d6
3
+ metadata.gz: 69c627ec56797c6124b1ca3ec12c54019e3049a9
4
+ data.tar.gz: 2f063c57a1f62c3a5fb1d3bc0d16f120dabcf837
5
5
  SHA512:
6
- metadata.gz: 5ca7486f18d5816fff122992bf28cfedcd4ba7e1af0838e81abe4ccb716931674cd1fa3ca9166e7715ac977295096a899e5b0727b89aee1f2b28a633b67ccadf
7
- data.tar.gz: 6d0155d8a1b3e45dc6680285fa9f8c3f4098e3ea30c9983f86346f8c1a6d45d886337c4876628230643b84ff046387b745773267322c4e22746a4383cc265f07
6
+ metadata.gz: 10c6284610f01b77e8bf8da8ce0d1818341e226db2078f0b293a89aa510161e222dc809754e326faa5967d942c5aca366fbae22d4bc98bcf56772cbdd64eae4a
7
+ data.tar.gz: 98aa8c46503e3f846079ecce47eaf4223ff432d7a7d060c2f33534f9aa08d4b9dc335e2ef22435cf40f7582b78eda53fa29dd586ed9ef0fc38825d064e4a74ee
data/Gemfile.lock CHANGED
@@ -1,19 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- google_timeline (1.0)
4
+ google_timeline (1.0.2)
5
5
  nokogiri (~> 1.6)
6
6
  polylines (~> 0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ diff-lcs (1.2.5)
11
12
  mini_portile2 (2.0.0)
12
13
  nokogiri (1.6.7.2)
13
14
  mini_portile2 (~> 2.0.0.rc2)
14
15
  polylines (0.3.0)
15
16
  rake (10.5.0)
16
- rspec (0.9.4)
17
+ rspec (3.4.0)
18
+ rspec-core (~> 3.4.0)
19
+ rspec-expectations (~> 3.4.0)
20
+ rspec-mocks (~> 3.4.0)
21
+ rspec-core (3.4.4)
22
+ rspec-support (~> 3.4.0)
23
+ rspec-expectations (3.4.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.4.0)
26
+ rspec-mocks (3.4.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.4.0)
29
+ rspec-support (3.4.1)
17
30
 
18
31
  PLATFORMS
19
32
  ruby
@@ -22,7 +35,7 @@ DEPENDENCIES
22
35
  bundler (~> 1.10)
23
36
  google_timeline!
24
37
  rake (~> 10.0)
25
- rspec (~> 0)
38
+ rspec (~> 3.0)
26
39
 
27
40
  BUNDLED WITH
28
41
  1.11.2
data/README.md CHANGED
@@ -24,23 +24,23 @@ Or install it yourself as:
24
24
  ```ruby
25
25
  GoogleTimeline.get_timeline("/home/surajit/Downloads/history-2016-04-03.kml")
26
26
  ```
27
- => {:url=>"http://maps.googleapis.com/maps/api/staticmap?scale=2&path=enc:}lvmA{f}xMVYi@GGAAAf@n@i@o@IDCKIC@?A?f@LLBFDaAYKCRFCAybCWn[vjEmXbbJk_CjhFhR`UjbGfwJrhN~cIjtJfoO~tI|{KxuIvdMz|E~~Sz[jzC~~JfpQ`zCznPljHdzSziJpyPliL|oLgfAfcJxtCnfI????tIjhDvI|wO~tC|hMsR`nAksAzhNyoAh`Im@G_@rzLweKnyMgaJb{IxvE~`G|wHztChCsq@imFy]ayEohBaDarHnwBirC??aWbS`WcS||BwvA`jLgyLhAyzGtpCaaVjSakMumDcmMbk@cxMshCa{MxuAcrIc|@avF}nD}fDamIgpFmxJe~NszEucRczBosHgsEyxQelEg_EEj@fAeFmLybCeqB_dFk{BqvNcpGqiHwlEygEa{Fg_LezHoiKswL}zGt_Bc|FfjCahSmbBmkI_|DbK&size=600x600&sensor=false"}
27
+ => {:date=>#<Date: 2016-04-03 ((2457482j,0s,0n),+0s,2299161j)>, :url=>"http://maps.googleapis.com/maps/api/staticmap?scale=2&path=enc:}lvmA{f}xMVYi@GGAAAf@n@i@o@IDCKIC@?A?f@LLBFDaAYKCRFCAybCWn[vjEmXbbJk_CjhFhR`UjbGfwJrhN~cIjtJfoO~tI|{KxuIvdMz|E~~Sz[jzC~~JfpQ`zCznPljHdzSziJpyPliL|oLgfAfcJxtCnfI????tIjhDvI|wO~tC|hMsR`nAksAzhNyoAh`Im@G_@rzLweKnyMgaJb{IxvE~`G|wHztChCsq@imFy]ayEohBaDarHnwBirC??aWbS`WcS||BwvA`jLgyLhAyzGtpCaaVjSakMumDcmMbk@cxMshCa{MxuAcrIc|@avF}nD}fDamIgpFmxJe~NszEucRczBosHgsEyxQelEg_EEj@fAeFmLybCeqB_dFk{BqvNcpGqiHwlEygEa{Fg_LezHoiKswL}zGt_Bc|FfjCahSmbBmkI_|DbK&size=600x600&sensor=false"}
28
28
 
29
29
  or
30
30
  ```ruby
31
31
  GoogleTimeline.get_timeline("/home/surajit/Downloads/history-2016-04-03.kml", {:distance=>true})
32
32
  ```
33
- => {:url=>"http://maps.googleapis.com/maps/api/staticmap?scale=2&path=enc:}lvmA{f}xMVYi@GGAAAf@n@i@o@IDCKIC@?A?f@LLBFDaAYKCRFCAybCWn[vjEmXbbJk_CjhFhR`UjbGfwJrhN~cIjtJfoO~tI|{KxuIvdMz|E~~Sz[jzC~~JfpQ`zCznPljHdzSziJpyPliL|oLgfAfcJxtCnfI????tIjhDvI|wO~tC|hMsR`nAksAzhNyoAh`Im@G_@rzLweKnyMgaJb{IxvE~`G|wHztChCsq@imFy]ayEohBaDarHnwBirC??aWbS`WcS||BwvA`jLgyLhAyzGtpCaaVjSakMumDcmMbk@cxMshCa{MxuAcrIc|@avF}nD}fDamIgpFmxJe~NszEucRczBosHgsEyxQelEg_EEj@fAeFmLybCeqB_dFk{BqvNcpGqiHwlEygEa{Fg_LezHoiKswL}zGt_Bc|FfjCahSmbBmkI_|DbK&size=600x600&sensor=false", :distance=>{:value=>520181.2852676145, :unit=>"meter"}}
33
+ => {:date=>#<Date: 2016-04-03 ((2457482j,0s,0n),+0s,2299161j)>, :url=>"http://maps.googleapis.com/maps/api/staticmap?scale=2&path=enc:}lvmA{f}xMVYi@GGAAAf@n@i@o@IDCKIC@?A?f@LLBFDaAYKCRFCAybCWn[vjEmXbbJk_CjhFhR`UjbGfwJrhN~cIjtJfoO~tI|{KxuIvdMz|E~~Sz[jzC~~JfpQ`zCznPljHdzSziJpyPliL|oLgfAfcJxtCnfI????tIjhDvI|wO~tC|hMsR`nAksAzhNyoAh`Im@G_@rzLweKnyMgaJb{IxvE~`G|wHztChCsq@imFy]ayEohBaDarHnwBirC??aWbS`WcS||BwvA`jLgyLhAyzGtpCaaVjSakMumDcmMbk@cxMshCa{MxuAcrIc|@avF}nD}fDamIgpFmxJe~NszEucRczBosHgsEyxQelEg_EEj@fAeFmLybCeqB_dFk{BqvNcpGqiHwlEygEa{Fg_LezHoiKswL}zGt_Bc|FfjCahSmbBmkI_|DbK&size=600x600&sensor=false", :distance=>{:value=>520181.2852676145, :unit=>"meter"}}
34
34
 
35
35
  or
36
36
  ```ruby
37
37
  GoogleTimeline.get_timeline("/home/surajit/Downloads/history-2016-04-03.kml", {:distance=>true}, {:home_coordinate=>[0,0]})
38
38
  ```
39
- => {:url=>"http://maps.googleapis.com/maps/api/staticmap?scale=2&path=enc:}lvmA{f}xMVYi@GGAAAf@n@i@o@IDCKIC@?A?f@LLBFDaAYKCRFCAybCWn[vjEmXbbJk_CjhFhR`UjbGfwJrhN~cIjtJfoO~tI|{KxuIvdMz|E~~Sz[jzC~~JfpQ`zCznPljHdzSziJpyPliL|oLgfAfcJxtCnfI????tIjhDvI|wO~tC|hMsR`nAksAzhNyoAh`Im@G_@rzLweKnyMgaJb{IxvE~`G|wHztChCsq@imFy]ayEohBaDarHnwBirC??aWbS`WcS||BwvA`jLgyLhAyzGtpCaaVjSakMumDcmMbk@cxMshCa{MxuAcrIc|@avF}nD}fDamIgpFmxJe~NszEucRczBosHgsEyxQelEg_EEj@fAeFmLybCeqB_dFk{BqvNcpGqiHwlEygEa{Fg_LezHoiKswL}zGt_Bc|FfjCahSmbBmkI_|DbK&size=600x600&sensor=false", :distance=>{:value=>520181.2852676145, :unit=>"meter"}}
39
+ => {:date=>#<Date: 2016-04-03 ((2457482j,0s,0n),+0s,2299161j)>, :url=>"http://maps.googleapis.com/maps/api/staticmap?scale=2&path=enc:}lvmA{f}xMVYi@GGAAAf@n@i@o@IDCKIC@?A?f@LLBFDaAYKCRFCAybCWn[vjEmXbbJk_CjhFhR`UjbGfwJrhN~cIjtJfoO~tI|{KxuIvdMz|E~~Sz[jzC~~JfpQ`zCznPljHdzSziJpyPliL|oLgfAfcJxtCnfI????tIjhDvI|wO~tC|hMsR`nAksAzhNyoAh`Im@G_@rzLweKnyMgaJb{IxvE~`G|wHztChCsq@imFy]ayEohBaDarHnwBirC??aWbS`WcS||BwvA`jLgyLhAyzGtpCaaVjSakMumDcmMbk@cxMshCa{MxuAcrIc|@avF}nD}fDamIgpFmxJe~NszEucRczBosHgsEyxQelEg_EEj@fAeFmLybCeqB_dFk{BqvNcpGqiHwlEygEa{Fg_LezHoiKswL}zGt_Bc|FfjCahSmbBmkI_|DbK&size=600x600&sensor=false", :distance=>{:value=>520181.2852676145, :unit=>"meter"}}
40
40
 
41
41
  distance and home_coordinate are optional.
42
42
  distance: To measure the travel distance which will return value in meter
43
- home_coordinate: to mention the home coordinate
43
+ home_coordinate: to mention the home coordinate
44
44
 
45
45
 
46
46
  ## Development
@@ -27,11 +27,11 @@ Gem::Specification.new do |spec|
27
27
  spec.bindir = "exe"
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
-
30
+
31
31
  spec.add_dependency 'polylines', '~> 0'
32
32
  spec.add_dependency 'nokogiri', '~> 1.6'
33
-
33
+
34
34
  spec.add_development_dependency "bundler", "~> 1.10"
35
35
  spec.add_development_dependency "rake", "~> 10.0"
36
- spec.add_development_dependency "rspec", '~> 0'
36
+ spec.add_development_dependency "rspec", '~> 3.0'
37
37
  end
@@ -0,0 +1,106 @@
1
+ class GoogleMapTimeline
2
+ attr_accessor :home_coordinate
3
+ attr_accessor :file_path
4
+
5
+ def initialize(file_path, home_coordinate)
6
+ self.file_path = file_path
7
+ self.home_coordinate = home_coordinate
8
+ end
9
+
10
+ def get_timeline_url(args)
11
+ op_hash = {}
12
+ url=default_map
13
+ coordinates = []
14
+ value = self.file_path
15
+ key = Date.parse(value.split("/").last.split(".").first.gsub("history-", "")) rescue nil
16
+ op_hash[:date] = key
17
+
18
+ if key.nil? == false and File.exists?(value)
19
+ kml = File.read(value)
20
+ doc = Nokogiri::XML(kml)
21
+ coordinates = doc.search('//gx:coord').map{|c| c.content.split(" ")[0..1].map{|co| co.to_f}.reverse} rescue []
22
+ location_str = polylines_encoding(coordinates)
23
+
24
+ if location_str.length < 1900
25
+ url = location_url(location_str)
26
+ else
27
+ times = doc.search('when').map{|c| DateTime.parse(c.content)} rescue []
28
+
29
+ coordinate_time_hash = {}
30
+ times.each_with_index do |t, i|
31
+ coordinate_time_hash[t] = coordinates[i]
32
+ end
33
+
34
+ interval = 10*60 #10min
35
+ selected_coordinates = []
36
+ prev_time = nil
37
+ coordinate_time_hash.each do |k,v|
38
+ if prev_time.nil?
39
+ selected_coordinates << v
40
+ prev_time = k
41
+ else
42
+ if (((k - prev_time) * 24 * 60 * 60).to_i >= interval)
43
+ selected_coordinates << v
44
+ prev_time = k
45
+ end
46
+ end
47
+ end
48
+ location_str = polylines_encoding(selected_coordinates)
49
+ url=location_url(location_str)
50
+ end
51
+ end
52
+ op_hash[:url] = url
53
+
54
+ if (args.empty?)==false and (args.select{|a| a.is_a?(Hash) and a[:distance]==true}.first).nil? == false
55
+ distance = {:value => overall_distance(coordinates), :unit=>"meter"}
56
+ op_hash[:distance] = distance
57
+ end
58
+ return op_hash
59
+ end
60
+
61
+ private
62
+ def location_url(location_str)
63
+ "http://maps.googleapis.com/maps/api/staticmap?scale=2&path=enc:#{location_str}&size=600x600&sensor=false"
64
+ end
65
+
66
+ def polylines_encoding(str)
67
+ Polylines::Encoder.encode_points(str)
68
+ end
69
+
70
+ def default_map
71
+ location_url(polylines_encoding(self.home_coordinate))
72
+ end
73
+
74
+ def overall_distance(coordinates)
75
+ total_distance = 0
76
+ for i in 0..(coordinates.count - 1)
77
+ coo = coordinates[i]
78
+ if i==0
79
+ loc1 = coo
80
+ else
81
+ loc2 = coo
82
+ total_distance += distance(loc1,loc2)
83
+ loc1 = loc2
84
+ end
85
+ end
86
+ return total_distance
87
+ end
88
+
89
+ def distance(loc1, loc2)
90
+ rad_per_deg = Math::PI/180 # PI / 180
91
+ rkm = 6371 # Earth radius in kilometers
92
+ rm = rkm * 1000 # Radius in meters
93
+
94
+ dlat_rad = (loc2[0]-loc1[0]) * rad_per_deg # Delta, converted to rad
95
+ dlon_rad = (loc2[1]-loc1[1]) * rad_per_deg
96
+
97
+ lat1_rad, lon1_rad = loc1.map {|i| i * rad_per_deg }
98
+ lat2_rad, lon2_rad = loc2.map {|i| i * rad_per_deg }
99
+
100
+ a = Math.sin(dlat_rad/2)**2 + Math.cos(lat1_rad) * Math.cos(lat2_rad) * Math.sin(dlon_rad/2)**2
101
+ c = 2 * Math::atan2(Math::sqrt(a), Math::sqrt(1-a))
102
+
103
+ rm * c # Delta in meters
104
+ end
105
+
106
+ end
@@ -1,3 +1,3 @@
1
1
  module GoogleTimeline
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "google_timeline/version"
2
+ require "google_timeline/google_map_timeline"
2
3
  require 'date'
3
4
  require 'nokogiri'
4
5
  require 'polylines'
@@ -13,108 +14,3 @@ module GoogleTimeline
13
14
  google_timeline.get_timeline_url(args)
14
15
  end
15
16
  end
16
- class GoogleMapTimeline
17
- attr_accessor :home_coordinate
18
- attr_accessor :file_path
19
-
20
- def initialize(file_path, home_coordinate)
21
- self.file_path = file_path
22
- self.home_coordinate = home_coordinate
23
- end
24
-
25
- def get_timeline_url(args)
26
- op_hash = {}
27
- url=default_map
28
- coordinates = []
29
- value = self.file_path
30
- key = Date.parse(value.split("/").last.split(".").first.gsub("history-", "")) rescue nil
31
-
32
- if key.nil? == false and File.exists?(value)
33
- kml = File.read(value)
34
- doc = Nokogiri::XML(kml)
35
- coordinates = doc.search('//gx:coord').map{|c| c.content.split(" ")[0..1].map{|co| co.to_f}.reverse} rescue []
36
- location_str = polylines_encoding(coordinates)
37
-
38
- if location_str.length < 1900
39
- url = location_url(location_str)
40
- else
41
- times = doc.search('when').map{|c| DateTime.parse(c.content)} rescue []
42
-
43
- coordinate_time_hash = {}
44
- times.each_with_index do |t, i|
45
- coordinate_time_hash[t] = coordinates[i]
46
- end
47
-
48
- interval = 10*60 #10min
49
- selected_coordinates = []
50
- prev_time = nil
51
- coordinate_time_hash.each do |k,v|
52
- if prev_time.nil?
53
- selected_coordinates << v
54
- prev_time = k
55
- else
56
- if (((k - prev_time) * 24 * 60 * 60).to_i >= interval)
57
- selected_coordinates << v
58
- prev_time = k
59
- end
60
- end
61
- end
62
- location_str = polylines_encoding(selected_coordinates)
63
- url=location_url(location_str)
64
- end
65
- end
66
- op_hash[:url] = url
67
-
68
- if (args.empty?)==false and (args.select{|a| a.is_a?(Hash) and a[:distance]==true}.first).nil? == false
69
- distance = {:value => overall_distance(coordinates), :unit=>"meter"}
70
- op_hash[:distance] = distance
71
- end
72
- return op_hash
73
- end
74
-
75
- private
76
- def location_url(location_str)
77
- "http://maps.googleapis.com/maps/api/staticmap?scale=2&path=enc:#{location_str}&size=600x600&sensor=false"
78
- end
79
-
80
- def polylines_encoding(str)
81
- Polylines::Encoder.encode_points(str)
82
- end
83
-
84
- def default_map
85
- location_url(polylines_encoding(self.home_coordinate))
86
- end
87
-
88
- def overall_distance(coordinates)
89
- total_distance = 0
90
- for i in 0..(coordinates.count - 1)
91
- coo = coordinates[i]
92
- if i==0
93
- loc1 = coo
94
- else
95
- loc2 = coo
96
- total_distance += distance(loc1,loc2)
97
- loc1 = loc2
98
- end
99
- end
100
- return total_distance
101
- end
102
-
103
- def distance(loc1, loc2)
104
- rad_per_deg = Math::PI/180 # PI / 180
105
- rkm = 6371 # Earth radius in kilometers
106
- rm = rkm * 1000 # Radius in meters
107
-
108
- dlat_rad = (loc2[0]-loc1[0]) * rad_per_deg # Delta, converted to rad
109
- dlon_rad = (loc2[1]-loc1[1]) * rad_per_deg
110
-
111
- lat1_rad, lon1_rad = loc1.map {|i| i * rad_per_deg }
112
- lat2_rad, lon2_rad = loc2.map {|i| i * rad_per_deg }
113
-
114
- a = Math.sin(dlat_rad/2)**2 + Math.cos(lat1_rad) * Math.cos(lat2_rad) * Math.sin(dlon_rad/2)**2
115
- c = 2 * Math::atan2(Math::sqrt(a), Math::sqrt(1-a))
116
-
117
- rm * c # Delta in meters
118
- end
119
-
120
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_timeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Surajit Khan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-14 00:00:00.000000000 Z
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: polylines
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '3.0'
83
83
  description: Integrate Map Timeline (Google)
84
84
  email:
85
85
  - surajit16@gmail.com
@@ -97,6 +97,7 @@ files:
97
97
  - bin/setup
98
98
  - google_timeline.gemspec
99
99
  - lib/google_timeline.rb
100
+ - lib/google_timeline/google_map_timeline.rb
100
101
  - lib/google_timeline/version.rb
101
102
  homepage: https://github.com/surajit16/google_timeline
102
103
  licenses: