ruby_px 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfa0ddb5f455e289afe1507164ab005e0896e7e091531a052472f36cfdfe11d3
4
- data.tar.gz: 3acf6d18b2ae29ddceab2c0859d4fe79be33a61a54be7f93632a014ebaf5dee7
3
+ metadata.gz: 9abe10d6ad1aed7bb9d28535671457cad398d7c17cab9c9bc49376dd46be5a3a
4
+ data.tar.gz: 95e9b594074e45eaa34e319c2ef58fc73edf4e5f6ceee9ae7c67bb2919407425
5
5
  SHA512:
6
- metadata.gz: c2439c7a3698ae78f288866cb91933325dbd48ec88a2bbc6b54353e6fe4567e768b7a2c6febb326c2e6566f1f4633eca4b6bb4d7e5ea471dacae21dbe6818f66
7
- data.tar.gz: 5482d50e2be5fc9fc4ab6c1b2d40bdf7e2b4b1ea8f2f528ef13d2c575cd9630208ff6e188ba3e3e8c3f17eb4e005787c7c64095c4619d77b0ed23125a5865d80
6
+ metadata.gz: ff283ea31198ae6fd560b591ac6c1d7dc649a148a61a3a4570953c380c22f4c667fe15a569454df1649d744845b62734051d89863e7e8c523e2f270ea77b3762
7
+ data.tar.gz: a36341f8e244874a2d588b0e28319c43da1f9f8b2488007ea79f1cccf16be8db544bf59839d6c1dc8f495e0581e2f3341922c41df9ef6a3d907f57748a0e31f2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.7.0 (2021-03-04)
4
+
5
+ - Performance in large datasets [#9](https://github.com/PopulateTools/ruby_px/pull/9)
6
+
3
7
  ## 0.6.0 (2020-04-28)
4
8
 
5
9
  - Nice badge with the current version
@@ -4,6 +4,8 @@ require 'open-uri'
4
4
 
5
5
  module RubyPx
6
6
  class Dataset
7
+ require 'ruby_px/dataset/data'
8
+
7
9
  attr_reader :headings, :stubs
8
10
 
9
11
  METADATA_RECORDS = %w[TITLE UNITS SOURCE CONTACT LAST-UPDATED CREATION-DATE].freeze
@@ -15,7 +17,7 @@ module RubyPx
15
17
  @headings = []
16
18
  @stubs = []
17
19
  @values = {}
18
- @data = []
20
+ @data = Data.new
19
21
 
20
22
  parse_resource(resource_uri)
21
23
  end
@@ -82,7 +84,7 @@ module RubyPx
82
84
  offset += (d ? p * d : p)
83
85
  end
84
86
 
85
- @data[offset]
87
+ @data.at(offset)
86
88
 
87
89
  # Return an array of options
88
90
  elsif options.length == dimensions.length - 1
@@ -0,0 +1,48 @@
1
+ module RubyPx
2
+ class Dataset
3
+ class Data
4
+
5
+ CHUNK_SIZE = 5_000
6
+ attr_accessor :current_chunk_index
7
+
8
+ def initialize
9
+ @current_chunk_index = 0
10
+ end
11
+
12
+ def at index
13
+ chunk_index = index/CHUNK_SIZE
14
+ index_inside_chunk = index%CHUNK_SIZE
15
+
16
+ get_chunk(chunk_index)[index_inside_chunk]
17
+ end
18
+
19
+ def concat array
20
+ current_chunk.concat(array)
21
+ if current_chunk.size > CHUNK_SIZE
22
+ excess = current_chunk.pop(current_chunk.size-CHUNK_SIZE)
23
+ self.current_chunk_index += 1
24
+ concat(excess)
25
+ end
26
+ end
27
+
28
+ def indexes_count
29
+ self.current_chunk_index+1
30
+ end
31
+
32
+ private
33
+
34
+
35
+ def current_chunk
36
+ current = instance_variable_get("@chunk_#{self.current_chunk_index}")
37
+ return current if current
38
+
39
+ instance_variable_set("@chunk_#{self.current_chunk_index}", [])
40
+ end
41
+
42
+ def get_chunk chunk_index
43
+ instance_variable_get("@chunk_#{chunk_index}")
44
+ end
45
+
46
+ end
47
+ end
48
+ end
data/ruby_px.gemspec CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'ruby_px'
8
- spec.version = '0.6.0'
8
+ spec.version = '0.7.0'
9
9
  spec.authors = ['Fernando Blat']
10
10
  spec.email = ['fernando@blat.es']
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_px
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Blat
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-20 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -86,6 +86,7 @@ files:
86
86
  - bin/setup
87
87
  - lib/ruby_px.rb
88
88
  - lib/ruby_px/dataset.rb
89
+ - lib/ruby_px/dataset/data.rb
89
90
  - ruby_px.gemspec
90
91
  homepage: https://github.com/PopulateTools/ruby_px
91
92
  licenses: