largeCsvProcessing 2.0.0 → 2.0.2

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
  SHA256:
3
- metadata.gz: 671b2e93fa94be4ce74653a45305197c664a94b21214cfd5dea94b0597cb7f05
4
- data.tar.gz: 6bc4b384f365b79b8431cbb395821f2765c0487b2d2e251c032b2706da5e955a
3
+ metadata.gz: '094da1c9e465643a29598234f0b9352c1eada76efeebb6c1c1b8762170bd92e0'
4
+ data.tar.gz: 89b4175724845002198a0359c28d24b128b276b86cb62b0ee04439fc510edc96
5
5
  SHA512:
6
- metadata.gz: a0b8ab28216f9fe287206ac382e1c834091fb4c41982aedb5364c77d00fcb55ab0e2c47223278cf19b37633be634ca3bec1e8e8dd3b54cadbd93f4295beba5da
7
- data.tar.gz: f3e387d3e000f71a0eeb225b9ac330c5fe83314da138f81fa198eb8ce973c10ce8cdd19512063881c2c462fa5f75adfc8b6643a4d442fd9e9aba68142ce6fc44
6
+ metadata.gz: e0940e608c299fade49bed0979619fa723031f7518bdfa775e047fd64d6b689ae12eccd6b01760fb72d2443a22833036fd9e77d6b271b0f615d20fccdaa9a22c
7
+ data.tar.gz: 28b955fb390bb14a366b0a407145a8511ca8da72d0f263062afba1b8c69ee2f91fb3958a17e05040e08d720821bdc95d5017681dc5fee5da883802d0094e088d
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  1. csv_generator.rb: is the main program in which a 'case' is used to access a 'normal' mode, 'benchmark/memory' mode and stok_stats. The first two create an object based on the class located in ./generatr/generator.rb, with the difference that the benchmark mode is more limited but returns other extra parameters.
8
8
 
9
- generator.rb: contains the Generator class, its variables are an input digit, the header and its 4 books. It also contains a "newFile" method which multiplies the input by a million and creates a file.csv by writing the header and so many million books to it.
9
+ generator.rb: contains the Generator class, its variables are an input digit, the header and its 4 books. It also contains a "newFile" method which multiplies the input by a million and creates a file.csv by writing the header and so many million books to it.
10
10
 
11
11
  2. file.csv: In the first line is the header and in the following there will be as many millions of books as the input data says.
12
12
 
@@ -26,7 +26,7 @@ With the following command the gem was built:
26
26
 
27
27
  The following command is used to install the gem locally:
28
28
 
29
- gem install ./largeCsvProcessing-2.0.0.gem
29
+ gem install ./largeCsvProcessing-2.0.2.gem
30
30
 
31
31
  The following command is used to install the gem remotely:
32
32
 
@@ -38,7 +38,7 @@ The following command is used to uninstall the gem:
38
38
 
39
39
  The following command is used to publish the gem to rubygems:
40
40
 
41
- gem push largeCsvProcessing-2.0.0.gem
41
+ gem push largeCsvProcessing-2.0.2.gem
42
42
 
43
43
  To run the installed gem it can be accessed by irb:
44
44
 
data/lib/csv_generator.rb CHANGED
@@ -1,16 +1,17 @@
1
- require_relative './generatr/generator.rb'
2
- require 'benchmark/memory'
3
-
4
1
  puts '******** welcome to your large csv processor ********'
5
2
  puts "options:\n0 for start benchmark mode\n1 for start normal mode program\n2 for run stock_stats (require run step 1)"
6
3
 
7
- lecturaSemanal = Generator.new
8
4
  option = gets.chomp
9
5
 
10
6
  case option
11
7
 
12
8
  when '0'
13
9
 
10
+ require 'benchmark/memory'
11
+ require_relative 'generatr/generator'
12
+
13
+ lecturaSemanal = Generator.new
14
+
14
15
  puts 'How many millions of books do you want??'
15
16
  puts "Alert!! Only give me the number (0,11], otherwise the memory goes BOOM and becomes a killer!!"
16
17
 
@@ -24,6 +25,9 @@ when '0'
24
25
 
25
26
  when '1'
26
27
 
28
+ require_relative 'generatr/generator'
29
+ lecturaSemanal = Generator.new
30
+
27
31
  puts 'How many millions of books do you want?? (give me the number)'
28
32
  puts 'Example: 27 make a file.csv of 1GB, 432 make a file.csv of 16GB'
29
33
 
@@ -0,0 +1,31 @@
1
+ require 'csv'
2
+ class Generator
3
+
4
+ attr_accessor :millions
5
+
6
+ @@cabecera = '"Date","ISBN","Amount"'
7
+
8
+ book1 = '"2008-04-12","978-1-9343561-0-4",39.45'
9
+ book2 = '"2008-04-13","978-1-9343561-6-6",45.67'
10
+ book3 = '"2008-04-14","978-1-9343560-7-4",36.95'
11
+ book4 = '"2008-04-15","978-1-9343560-9-9",40.69'
12
+
13
+ @@allBooks = book1+"\n"+book2+"\n"+book3+"\n"+book4+"\n"
14
+
15
+ def newFile
16
+
17
+ File.open( './file.csv', 'a' ) { |row| row.write @@cabecera+"\n" }
18
+
19
+ nRepeticiones = 1_000_000 * @millions.to_i / 4
20
+
21
+ nRepeticiones.times {
22
+
23
+ File.open( './file.csv', 'a' ) { |row| row.write @@allBooks }
24
+
25
+ }
26
+
27
+ true # <~ only valid for Rspec
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,25 @@
1
+ require 'csv'
2
+ class CsvReader
3
+
4
+ @@sum = 0
5
+
6
+ def read_in_csv_data(csv_file_name)
7
+
8
+ count = CSV.foreach(csv_file_name).inject(0) { | c, line | c + 1 }
9
+ libros = CSV.open(csv_file_name).each
10
+
11
+ count.times {
12
+
13
+ @@sum += libros.next[2].to_f
14
+
15
+ }
16
+
17
+ end
18
+
19
+ def total_value_in_stock
20
+
21
+ @@sum
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,8 @@
1
+ # los cambios realizados pra que pueda procesar un archivo csv de gran tamaño:
2
+
3
+ * book_in_stock.rf ahora es obsoleto
4
+
5
+ * csv_reader.rb :
6
+ la clase CsvReader se modificó por completo para que no guarde en un array las filas del archivo.csv
7
+ el método read_in_csv_data ahora recorre las filas del archivo csv, lee el dato precio, lo transforma a float y lo suma a la variable 'sum'
8
+ el método total_value_in_stock solo retorna la variable 'sum'
@@ -0,0 +1,18 @@
1
+ require_relative 'csv_reader'
2
+
3
+ reader = CsvReader.new
4
+
5
+ #csv_file_name = gets.chomp
6
+
7
+ # ARGV.each do |csv_file_name|
8
+
9
+ # STDERR.puts "Processing #{csv_file_name}"
10
+ # reader.read_in_csv_data(csv_file_name)
11
+
12
+ # end
13
+
14
+ puts 'Processing ...'
15
+
16
+ reader.read_in_csv_data('file.csv')
17
+
18
+ puts "Total value = #{reader.total_value_in_stock}"
data/readmeEs.txt CHANGED
@@ -26,7 +26,7 @@ Con el siguiente comando se construyó la gema:
26
26
 
27
27
  El siguiente comando sirve para instalar la gema de manera local:
28
28
 
29
- gem install ./largeCsvProcessing-2.0.0.gem
29
+ gem install ./largeCsvProcessing-2.0.2.gem
30
30
 
31
31
  El siguiente comando sirve para instalar la gema de manera remota:
32
32
 
@@ -38,7 +38,7 @@ El siguiente comando sirve para desinstalar la gema:
38
38
 
39
39
  El siguiente comando sirve para publicar la gema en rubygems:
40
40
 
41
- gem push largeCsvProcessing-2.0.0.gem
41
+ gem push largeCsvProcessing-2.0.2.gem
42
42
 
43
43
  Para ejecutar la gema instalada se puede acceder por irb:
44
44
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: largeCsvProcessing
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Dueñas
@@ -24,6 +24,10 @@ files:
24
24
  - autoEvaluacion.txt
25
25
  - bin/rspec
26
26
  - lib/csv_generator.rb
27
+ - lib/generatr/generator.rb
28
+ - lib/stockStats/csv_reader.rb
29
+ - lib/stockStats/leeme.txt
30
+ - lib/stockStats/stock_stats.rb
27
31
  - readmeEs.txt
28
32
  - spec/generator_spec.rb
29
33
  - spec/spec_helper.rb