clumpy 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/lib/clumpy.rb +2 -0
- data/lib/clumpy/bounds.rb +27 -0
- data/lib/clumpy/cluster_behavior.rb +11 -28
- data/lib/clumpy/extensions/chewy_hit.rb +20 -0
- data/lib/clumpy/extensions/sunspot_hit.rb +2 -2
- data/lib/clumpy/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bdbfef1adbfd8fb569226453e2d580c65e7a348
|
4
|
+
data.tar.gz: 3c199636374d074c3bdb37f5f1f3eb0fa83ee068
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f97faf5c646c9079980b883adf831e57fe44b3013553bae88101b4bfc84772139b9d548f8bba145c6f09eb6b57c9fcafe30876894bd0adc177d9df9e01acbea
|
7
|
+
data.tar.gz: f9cbee56548ea77c69f13d97fc4a379bb01c6ee43252451fd0e2558a18fe6863c4f5342a6fe72bdc38711e79fa376539332c83f15a7906bda8ac3332b341f11f
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.1.2
|
data/lib/clumpy.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Clumpy
|
2
|
+
class Bounds
|
3
|
+
def initialize(latitude, longitude, side_length)
|
4
|
+
side_length ||= 10
|
5
|
+
@latitude = (latitude - side_length)..(latitude + side_length)
|
6
|
+
@longitude = (longitude - side_length*2)..(longitude + side_length*2)
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :latitude
|
10
|
+
|
11
|
+
attr_reader :longitude
|
12
|
+
|
13
|
+
def as_json(*)
|
14
|
+
{
|
15
|
+
northeast: {
|
16
|
+
latitude: @latitude.end,
|
17
|
+
longitude: @longitude.end,
|
18
|
+
},
|
19
|
+
southwest: {
|
20
|
+
latitude: @latitude.begin,
|
21
|
+
longitude: @longitude.begin,
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -8,54 +8,37 @@ module Clumpy
|
|
8
8
|
@points = [point]
|
9
9
|
@options = options
|
10
10
|
|
11
|
-
|
12
|
-
@bounds = OpenStruct.new(
|
13
|
-
latitude: (latitude - side_length)..(latitude + side_length),
|
14
|
-
longitude: (longitude - side_length*2)..(longitude + side_length*2)
|
15
|
-
)
|
11
|
+
@bounds = Bounds.new(@latitude, @longitude, options[:side_length])
|
16
12
|
end
|
17
13
|
|
18
14
|
def contains?(point)
|
19
|
-
bounds.latitude.include?(point.latitude) &&
|
20
|
-
bounds.longitude.include?(point.longitude)
|
15
|
+
@bounds.latitude.include?(point.latitude) &&
|
16
|
+
@bounds.longitude.include?(point.longitude)
|
21
17
|
end
|
22
18
|
|
23
19
|
def reposition
|
24
|
-
@latitude = points.inject(0.0) { |m, p| m + p.latitude } / points.size
|
25
|
-
@longitude = points.inject(0.0) { |m, p| m + p.longitude } / points.size
|
20
|
+
@latitude = @points.inject(0.0) { |m, p| m + p.latitude } / @points.size
|
21
|
+
@longitude = @points.inject(0.0) { |m, p| m + p.longitude } / @points.size
|
26
22
|
end
|
27
23
|
|
28
24
|
def as_json(*)
|
29
25
|
{
|
30
|
-
latitude:
|
26
|
+
latitude: latitude,
|
31
27
|
longitude: longitude,
|
32
|
-
size:
|
33
|
-
bounds:
|
34
|
-
values:
|
28
|
+
size: @points.size,
|
29
|
+
bounds: @bounds.as_json,
|
30
|
+
values: value_list,
|
35
31
|
}
|
36
32
|
end
|
37
33
|
|
38
34
|
def value_list
|
39
35
|
case @options[:include_values]
|
40
|
-
when true then points
|
36
|
+
when true then @points
|
41
37
|
when false then []
|
42
38
|
else
|
43
39
|
values_threshold = @options[:values_threshold] || 10
|
44
|
-
points.size <= values_threshold ? points : []
|
40
|
+
@points.size <= values_threshold ? @points : []
|
45
41
|
end
|
46
42
|
end
|
47
|
-
|
48
|
-
def bounds_as_json
|
49
|
-
{
|
50
|
-
northeast: {
|
51
|
-
latitude: bounds.latitude.max,
|
52
|
-
longitude: bounds.longitude.max
|
53
|
-
},
|
54
|
-
southwest: {
|
55
|
-
latitude: bounds.latitude.min,
|
56
|
-
longitude: bounds.longitude.min
|
57
|
-
}
|
58
|
-
}
|
59
|
-
end
|
60
43
|
end
|
61
44
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Clumpy
|
2
|
+
module Extensions
|
3
|
+
module ChewyHit
|
4
|
+
def latitude
|
5
|
+
@latitude ||= lat.to_f
|
6
|
+
end
|
7
|
+
|
8
|
+
def longitude
|
9
|
+
@longitude ||= lng.to_f
|
10
|
+
end
|
11
|
+
|
12
|
+
def as_json(*)
|
13
|
+
{
|
14
|
+
id: id,
|
15
|
+
type: _source.full?(:type) || type.classify
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/clumpy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clumpy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johannes Opper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,9 +82,11 @@ files:
|
|
82
82
|
- Rakefile
|
83
83
|
- clumpy.gemspec
|
84
84
|
- lib/clumpy.rb
|
85
|
+
- lib/clumpy/bounds.rb
|
85
86
|
- lib/clumpy/builder.rb
|
86
87
|
- lib/clumpy/cluster.rb
|
87
88
|
- lib/clumpy/cluster_behavior.rb
|
89
|
+
- lib/clumpy/extensions/chewy_hit.rb
|
88
90
|
- lib/clumpy/extensions/sunspot_hit.rb
|
89
91
|
- lib/clumpy/version.rb
|
90
92
|
- spec/builder_spec.rb
|
@@ -111,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
113
|
version: '0'
|
112
114
|
requirements: []
|
113
115
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.2.2
|
115
117
|
signing_key:
|
116
118
|
specification_version: 4
|
117
119
|
summary: Cluster a bunch of points
|