lttb 0.1.0 → 0.2.0
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 +4 -4
- data/lib/lttb/process.rb +22 -10
- data/lib/lttb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63541c85ddb7883a40974ac7a652e727a36d0eff
|
|
4
|
+
data.tar.gz: 6ebeefd2c9409ae071965facfa5ef7a661e155bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6af76625dde3414dfa982e555a1b782f13992928bc3fff403102dfca1a732040ee367a1e655ea5652ab0d1d69bc9659662560a09f47ef168df210bcf96d634ab
|
|
7
|
+
data.tar.gz: 7dec397202a2d9189872d3677172f9ecd4ce0bfc66b150dedcbd0b7a429d788478f9f1a720f96a8e1e5f1f7bf0317d4ea6221f513d4ec40e4869afd35261d4d8
|
data/lib/lttb/process.rb
CHANGED
|
@@ -30,16 +30,27 @@ module Lttb
|
|
|
30
30
|
every = (data_length - 2) / (threshold - 2)
|
|
31
31
|
|
|
32
32
|
a = 0 # Initially a is the first point in the triangle
|
|
33
|
-
|
|
33
|
+
next_a = 0
|
|
34
|
+
max_area_point = nil
|
|
35
|
+
max_area = 0
|
|
36
|
+
area = 0
|
|
37
|
+
|
|
38
|
+
sampled = []
|
|
39
|
+
sampled[0] = data[a] # Always add the first point
|
|
40
|
+
sampled_index = 1 # Now we start at index 1
|
|
41
|
+
|
|
42
|
+
i = 0
|
|
43
|
+
while i < threshold - 2
|
|
44
|
+
# Calculate bucket points
|
|
45
|
+
bucket_start = (((i + 0) * every).floor + 1).to_i
|
|
46
|
+
bucket_mid = (((i + 1) * every).ceil).to_i
|
|
47
|
+
bucket_end = (((i + 2) * every).ceil).to_i
|
|
34
48
|
|
|
35
|
-
(0..(threshold - 3)).each do |i|
|
|
36
49
|
# Calculate point average for next bucket (containing c)
|
|
37
50
|
avg_x = 0
|
|
38
51
|
avg_y = 0
|
|
39
|
-
avg_range_start =
|
|
40
|
-
avg_range_end =
|
|
41
|
-
avg_range_end = avg_range_end < data_length ? avg_range_end : data_length
|
|
42
|
-
|
|
52
|
+
avg_range_start = bucket_mid
|
|
53
|
+
avg_range_end = bucket_end < data_length ? bucket_end : data_length
|
|
43
54
|
avg_range_length = avg_range_end - avg_range_start
|
|
44
55
|
|
|
45
56
|
while avg_range_start < avg_range_end
|
|
@@ -53,9 +64,8 @@ module Lttb
|
|
|
53
64
|
avg_y /= avg_range_length
|
|
54
65
|
|
|
55
66
|
# Get the range for this bucket
|
|
56
|
-
range_offs =
|
|
57
|
-
range_to =
|
|
58
|
-
range_to = range_to < data_length - 1 ? range_to : data_length - 1
|
|
67
|
+
range_offs = bucket_start
|
|
68
|
+
range_to = bucket_mid
|
|
59
69
|
|
|
60
70
|
# Point a
|
|
61
71
|
point_ax = data[a][0]
|
|
@@ -79,8 +89,10 @@ module Lttb
|
|
|
79
89
|
range_offs += 1 # increment
|
|
80
90
|
end
|
|
81
91
|
|
|
82
|
-
sampled
|
|
92
|
+
sampled[sampled_index] = max_area_point # Pick this point from the bucket
|
|
93
|
+
sampled_index += 1
|
|
83
94
|
a = next_a # This a is the next a (chosen b)
|
|
95
|
+
i += 1 # increase count
|
|
84
96
|
end
|
|
85
97
|
|
|
86
98
|
sampled.push(data[data.size - 1]) # Always add last
|
data/lib/lttb/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lttb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jubke
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|