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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c647e0772742ee162459334ede93428d12a7c79c
4
- data.tar.gz: 525ce8a01dab924bd16d94e5cad4981e9173194f
3
+ metadata.gz: 63541c85ddb7883a40974ac7a652e727a36d0eff
4
+ data.tar.gz: 6ebeefd2c9409ae071965facfa5ef7a661e155bc
5
5
  SHA512:
6
- metadata.gz: fd1e18e0a2e234c49af4d9a865aae858f262e5249b82464012e4f2d2bc3d661f0e1338261a03a06bcddb49f4eb1674da2bc2bc96986e8eb4b0b4ee86609cf055
7
- data.tar.gz: 62da5c7ea2c2990aa83ea5008f11c71494ba74cc1c2792a486e84d241535499057147a382f3e9e9a6e7b488a17b9d5917ffd5d9d236383ed130e3829ce109822
6
+ metadata.gz: 6af76625dde3414dfa982e555a1b782f13992928bc3fff403102dfca1a732040ee367a1e655ea5652ab0d1d69bc9659662560a09f47ef168df210bcf96d634ab
7
+ data.tar.gz: 7dec397202a2d9189872d3677172f9ecd4ce0bfc66b150dedcbd0b7a429d788478f9f1a720f96a8e1e5f1f7bf0317d4ea6221f513d4ec40e4869afd35261d4d8
@@ -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
- sampled = [data[a]] # Always add the first point
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 = (((i + 1) * every).floor + 1).to_i
40
- avg_range_end = (((i + 2) * every).floor + 1).to_i
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 = (((i + 0) * every).floor + 1).to_i
57
- range_to = (((i + 1) * every).floor + 1).to_i
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.push(max_area_point) # Pick this point from the bucket
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
@@ -1,3 +1,3 @@
1
1
  module Lttb
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-05-29 00:00:00.000000000 Z
11
+ date: 2016-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler