extcsv 0.12.1 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
data/gemspec CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  spec = Gem::Specification.new do |s|
4
4
  s.name = "extcsv"
5
- s.version = "0.12.1"
5
+ s.version = "0.12.2"
6
6
  s.date = Time.new.strftime("%Y-%m-%d")
7
7
  s.author = "Ralf Mueller"
8
8
  s.email = "stark.dreamdetective@gmail.com"
data/lib/extcsv.rb CHANGED
@@ -30,7 +30,7 @@ end
30
30
  # ==== License: BSD - see {license file}[http:/extcsv.rubyforge.org/svn/extcsv/trunk/LICENSE]
31
31
  ################################################################################
32
32
  class ExtCsv < OpenStruct
33
- VERSION = '0.12.0'
33
+ VERSION = '0.12.2'
34
34
 
35
35
  include Comparable
36
36
  include Enumerable
@@ -48,6 +48,9 @@ class ExtCsv < OpenStruct
48
48
  # Non-Data fields
49
49
  METADATA = %w{mode datatype datacolumns cellsep rowsep filename filemtime}
50
50
 
51
+ # ShunkSize for handling large objects with MRI
52
+ ShunkSize = 65536
53
+
51
54
  # mode can be one of the allowed MODES
52
55
  # datatype can be one of the TYPES
53
56
  #
@@ -133,7 +136,7 @@ class ExtCsv < OpenStruct
133
136
  # remove blank lines
134
137
  filecontent = filecontent.gsub(/\r\r/,"\r").gsub(/(\r\n){2,}/,"\r\n").gsub(/\n{2,}/,"\n")
135
138
  csv = CSV.parse(filecontent, :col_sep => obj_hash[:cellsep])#, obj_hash[:rowsep])
136
-
139
+
137
140
  # read @datatype specific header
138
141
  header = csv.shift
139
142
  # remove comments sign from the header
@@ -252,7 +255,7 @@ class ExtCsv < OpenStruct
252
255
  end
253
256
  }
254
257
  # default is the lookup in the whole array of values for each var
255
- lookup = (0..@table[vars[0]].size-1).to_a
258
+ lookup = (0...@table[vars[0]].size).to_a
256
259
 
257
260
  vars.each { |var|
258
261
  operation = nil
@@ -304,14 +307,25 @@ class ExtCsv < OpenStruct
304
307
  raise
305
308
  end
306
309
  #test stdout << "\n NEW VALUE :::::::::::::::\n"
307
- obj_values = @table[var]
308
- obj_values = [(0..obj_values.size-1).to_a, obj_values].transpose.values_at(*lookup)
309
-
310
+ obj_values = @table[var]
311
+ size = @table[var].size
312
+ checkValues = [(0...size).to_a, obj_values].transpose
313
+ if ShunkSize < size
314
+ container = []
315
+ (0..size/ShunkSize).collect {|i|
316
+ checkValues.values_at(*(lookup[i*ShunkSize,ShunkSize]))
317
+ }.each {|v| v.each {|vv| container << vv} }
318
+ checkValues = container
319
+ else
320
+ checkValues = checkValues.values_at(*lookup)
321
+ end
322
+
310
323
  if operation.kind_of?(Regexp)
311
- lookup = lookup & obj_values.find_all {|i,v| operation.match(v.to_s)}.transpose[0].to_a
324
+ lookup = lookup & checkValues.find_all {|i,v| operation.match(v.to_s)}.transpose[0].to_a
312
325
  else
313
- lookup = lookup & obj_values.find_all {|i,v|
314
- next if v.nil? or v.empty?
326
+ lookup = lookup & checkValues.find_all {|i,v|
327
+ next if v.nil?
328
+ next if v.empty? if v.respond_to?(:empty?)
315
329
  v = "'" + v + "'" if type == :string
316
330
  #test $stdout <<[v,operation,value].join(" ") << "\n"
317
331
  eval([v,operation,value].join(" "))
@@ -381,7 +395,7 @@ class ExtCsv < OpenStruct
381
395
  return self.class.new("hash","plain",h)
382
396
  end
383
397
  def clear
384
- @table.each {|k,v| @table[k] = [] if v.kind_of?(Array)}
398
+ @table.each {|k,v| @table[k] = [] if v.kind_of?(Array)}
385
399
  end
386
400
  def empty?
387
401
  return true if @table.empty?
@@ -109,7 +109,7 @@ module ExtCsvDiagram
109
109
  def ExtCsvDiagram.checkColumns(obj,*cols)
110
110
  cols.each {|col|
111
111
  next if col.kind_of?(Hash)
112
- unless obj.datacolumns.include?(col)
112
+ unless obj.datacolumns.include?(col.to_s)
113
113
  print "[plot] Input data does NOT contain column '#{col.to_s}'\n"
114
114
  raise ArgumentError
115
115
  end
@@ -175,7 +175,7 @@ module ExtCsvDiagram
175
175
  def ExtCsvDiagram.plot_xy(obj,xColumn,yColumn,title,options={})
176
176
  checkColumns(obj,xColumn,yColumn) unless options[:skipColumnCheck]
177
177
  options = GRAPH_OPTIONS.merge(options)
178
- outputfilename = (options[:filename].nil?) ? obj.filename : options[:filename]
178
+ #outputfilename = (options[:filename].nil?) ? obj.filename : options[:filename]
179
179
  groupBy = (options[:groupBy]).nil? ? [] : options[:groupBy]
180
180
  Gnuplot.open {|gp|
181
181
  Gnuplot::Plot.new(gp) {|plot|
data/test/test_extcsv.rb CHANGED
@@ -50,7 +50,7 @@ class TestExtCsv < Test::Unit::TestCase
50
50
  assert_equal(org.x2,td_by_str.x2)
51
51
  end
52
52
  def test_datasets
53
- test_simple = ExtCsv.new(IMPORT_TYPE,"txt",TEST_DATA)
53
+ test_simple = ExtCsv.new(IMPORT_TYPE,"tsv",TEST_DATA)
54
54
  assert_equal(["100.0", "950.0"], test_simple.datasets("col1","col2")[29])
55
55
  end
56
56
  def test_csv
@@ -228,9 +228,10 @@ class TestExtCsv < Test::Unit::TestCase
228
228
  end
229
229
  def test_clear
230
230
  simple = ExtCsv.new(IMPORT_TYPE,"txt",TEST_DATA)
231
- assert_equal(false, simple.col1.empty?)
231
+ mycol = simple.datacolumns[0]
232
+ assert_equal(false, simple.send(mycol).empty?)
232
233
  simple.clear
233
- assert(simple.col1.empty?)
234
+ assert_equal(true, simple.send(mycol).empty?)
234
235
  assert(simple.empty?)
235
236
  end
236
237
  def test_each_by
@@ -495,7 +496,7 @@ class TestExtCsv < Test::Unit::TestCase
495
496
  assert_nil(csv + simple0)
496
497
  end
497
498
  def test_version
498
- assert_equal('0.12.0',ExtCsv::VERSION)
499
+ assert_equal('0.12.2',ExtCsv::VERSION)
499
500
  end
500
501
 
501
502
  def test_add
@@ -520,4 +521,16 @@ class TestExtCsv < Test::Unit::TestCase
520
521
  d = c.columns(*c.datacolumns[-3..-1])
521
522
  assert_equal(c.datasets(*d.datacolumns),d.datasets)
522
523
  end
524
+ def test_MRI_bug
525
+ # MRI has problems with long list of optional arguments like
526
+ # values_at(*ins) where ins.size > 160000 (happens with large objects
527
+ # jruby works though
528
+ size = 2*10**5+1
529
+ limit = size/2
530
+ a = (0...size).to_a.map(&:to_s)
531
+ a = (0...size).to_a
532
+ obj = ExtCsv.new("hash","plain",{:a => a})
533
+ upper = obj.selectBy(:a => "> #{limit}")
534
+ assert_equal(limit,upper.size)
535
+ end
523
536
  end
@@ -29,14 +29,15 @@ class TestExtCsvDisplay < Test::Unit::TestCase
29
29
 
30
30
  def test_simple
31
31
  f=ExtCsv.new("file","txt",TEST_DATA)
32
- ExtCsvDiagram.plot(f,["col4"],"col0",["col1"])
32
+ ExtCsvDiagram.plot_xy(f,"col5","col3",'') #,"col0",["col1"])
33
33
  end
34
- def test_icon
34
+ def _test_icon
35
35
  icon = ExtCsv.new(IMPORT_TYPE,"psv",ICON)
36
36
 
37
37
  icon.datetime = []
38
38
  icon.date.each_with_index{|date,i| icon.datetime << [date,icon.time[i]].join(' ') }
39
39
 
40
+ puts "SIZE: #{icon.size}"
40
41
  [:date,:time,:depth,VAR.downcase.to_sym].each {|col| puts [col.to_s,icon.send(col).max].join('[max]: ') }
41
42
  ExtCsvDiagram.plot_xy(icon,"datetime",VAR.downcase,'ICON OCE_BASE: Mean. Temperatur (uneven levels, r8656, full run: 2001-2012)',
42
43
  :label_position => 'below',:skipColumnCheck => true,
@@ -45,7 +46,7 @@ class TestExtCsvDisplay < Test::Unit::TestCase
45
46
  # :xrange => "",
46
47
  :onlyGroupTitle => true,
47
48
  # :addSettings => ["logscale y"],
48
- :terminal => "png",
49
+ # :terminal => "png",
49
50
  :ylabel => "#{VAR} [degC]",
50
51
  :input_time_format => "'%Y%m%d %H:%M:%S'",
51
52
  :filename => "icon-OCE_BASE_uneven-r8656-fullrun-Mean#{VAR}",
@@ -110,13 +111,14 @@ class TestExtCsvDisplay < Test::Unit::TestCase
110
111
  end
111
112
  def test_extcsv_diagram_limits
112
113
  td = ExtCsv.new("file","txt",TEST_DATA_NEW)
114
+ td.add(:step,(1...td.size).to_a)
113
115
  ExtCsvDiagram.plot(td[0,21],
114
- [:col1],
115
- :index,
116
- [:col3],
117
- :zeit,
118
- [:col8],
119
- 'limit test',
116
+ ["col1"],
117
+ :step,
118
+ ["col3"],
119
+ "step",
120
+ ["col8"],
121
+ 'limit test',
120
122
  :y1limits => [1.9],
121
123
  :y1limitname => "y1 Limit",
122
124
  :y2limits => [8.2],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extcsv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-16 00:00:00.000000000 Z
12
+ date: 2012-04-30 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: stark.dreamdetective@gmail.com