sycsvpro 0.0.4 → 0.0.5
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/Gemfile.lock +1 -1
- data/README.md +14 -2
- data/bin/sycsvpro +6 -2
- data/html/README_rdoc.html +13 -12
- data/html/Sycsvpro/Counter.html +57 -6
- data/html/created.rid +4 -4
- data/html/index.html +13 -12
- data/html/js/search_index.js +1 -1
- data/lib/sycsvpro/counter.rb +20 -2
- data/lib/sycsvpro/version.rb +1 -1
- data/spec/sycsvpro/counter_spec.rb +20 -0
- data/sycsvpro.rdoc +13 -12
- 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: c52a71d74f5f9366239cad3e5fe9d2239d852c76
|
4
|
+
data.tar.gz: 1d61284a839cf80c666d4267444b1644991e6d06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a93e01b9623a2322e8de10fcc688c3967bb7a5a252f65e8e0d5c3d00b3ff99a2e848c7d2e210bdb07f821199039c56cd65f7bb14159db9fb6a2d60ebbb621eaf
|
7
|
+
data.tar.gz: 4e32352d9006bac2ebd54bcdd4b79bc212677a3f878aa55b46033fc70a3fa7496028419d63d0c420a77fe0445cb771318569598cf39975122af317c84f6d86e8
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,6 +7,7 @@ Processing of csv files. *sycsvpro* offers following functions
|
|
7
7
|
* extract rows and columns from a file
|
8
8
|
* collect values of rows and assign them to categories
|
9
9
|
* map column values to new values
|
10
|
+
* allocate column values to a key column (since version 0.0.4)
|
10
11
|
* count values in columns and use the value as column name
|
11
12
|
* arithmetic operations on values of columns
|
12
13
|
* execute a ruby script file that operates a csv file
|
@@ -95,17 +96,28 @@ The mapping file (mapping) uses the result from the collect command above
|
|
95
96
|
|
96
97
|
$ sycsvpro -f in.csv -o out.csv map mapping -c 2-4
|
97
98
|
|
99
|
+
Allocate
|
100
|
+
--------
|
101
|
+
Allocate all the machine types to the customer
|
102
|
+
|
103
|
+
$ sycsvpro -f in.csv -o out.csv assign -k 0 -r 1-20 -c 1
|
104
|
+
|
105
|
+
hello;h1;h2
|
106
|
+
indix;i1
|
107
|
+
chiro;c1;c2
|
108
|
+
|
98
109
|
Count
|
99
110
|
-----
|
100
111
|
|
101
|
-
Count all customers (key column) in rows 2 to 20 that have machines that start with *h* and have contract valid beginning after 1.1.2000
|
112
|
+
Count all customers (key column) in rows 2 to 20 that have machines that start with *h* and have a contract valid beginning after 1.1.2000. Add a sum row with title Total at column 1
|
102
113
|
|
103
|
-
$ sycsvpro -f in.csv -o out.csv count -r 2-20 -k 0 -c 1:/^h/,5:">1.1.2000" --df "%d.%m.%Y"
|
114
|
+
$ sycsvpro -f in.csv -o out.csv count -r 2-20 -k 0 -c 1:/^h/,5:">1.1.2000" --df "%d.%m.%Y" -s "Total:1"
|
104
115
|
|
105
116
|
The result in file out.csv is
|
106
117
|
|
107
118
|
$ cat out.csv
|
108
119
|
customer;>1.1.2000;^h
|
120
|
+
Total;5;2
|
109
121
|
hello;2;2
|
110
122
|
indix;1;0
|
111
123
|
chiro;2;0
|
data/bin/sycsvpro
CHANGED
@@ -126,7 +126,7 @@ end
|
|
126
126
|
|
127
127
|
desc 'Counts the occurences of column values. Uses column values as headings with count as ' +
|
128
128
|
'values. Columns with a condition will be added as new columns and the condition will ' +
|
129
|
-
'be set as column name'
|
129
|
+
'be set as column name. Optionally adds a sum row'
|
130
130
|
|
131
131
|
command :count do |c|
|
132
132
|
|
@@ -142,6 +142,10 @@ command :count do |c|
|
|
142
142
|
c.arg_name '1,2:<14.2.2014,10-30'
|
143
143
|
c.flag [:c, :col], :must_match => /^\d+(?:,\d+|(?::[<=>]\d+.\d+.\d+|:\d+.\d+.\d+-\d+.\d+.\d+|:\/.*?\/|-\d+)*)*/
|
144
144
|
|
145
|
+
c.desc 'Adds a sum row with TITLE for the counted columns at the specified row position'
|
146
|
+
c.arg_name 'TITLE:ROW'
|
147
|
+
c.flag [:s, :sum], :must_match => /^\w+:\d+/
|
148
|
+
|
145
149
|
c.desc 'Format of date values'
|
146
150
|
c.arg_name '%d.%m.%Y|%m/%d/%Y|...'
|
147
151
|
c.flag [:df]
|
@@ -153,7 +157,7 @@ command :count do |c|
|
|
153
157
|
puts "Counting..."
|
154
158
|
counter = Sycsvpro::Counter.new(infile: global_options[:f], outfile: global_options[:o],
|
155
159
|
key: options[:k], rows: options[:r], cols: options[:c],
|
156
|
-
df: options[:df])
|
160
|
+
df: options[:df], sum: options[:s])
|
157
161
|
counter.execute
|
158
162
|
puts "count done"
|
159
163
|
end
|
data/html/README_rdoc.html
CHANGED
@@ -144,7 +144,7 @@ bin</pre>
|
|
144
144
|
|
145
145
|
<p>VERSION</p>
|
146
146
|
|
147
|
-
<pre>0.0.
|
147
|
+
<pre>0.0.5</pre>
|
148
148
|
|
149
149
|
<p>GLOBAL OPTIONS</p>
|
150
150
|
|
@@ -155,17 +155,18 @@ bin</pre>
|
|
155
155
|
|
156
156
|
<p>COMMANDS</p>
|
157
157
|
|
158
|
-
<pre>
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
158
|
+
<pre>allocate - Allocate specified columns from the file to a key value
|
159
|
+
analyze - Analyze the CSV file regarding columns, rows and content
|
160
|
+
calc - Process math operations on columns
|
161
|
+
collect - Collect values of specified rows and columns from the file and group them in
|
162
|
+
categories
|
163
|
+
count - Counts the occurences of column values. Uses column values as headings with count as
|
164
|
+
values. Columns with a condition will be added as new columns and the condition will
|
165
|
+
be set as column name. Optionally adds a sum row
|
166
|
+
execute - Executes the code provided in a file
|
167
|
+
extract - Extract specified rows and columns from the file
|
168
|
+
help - Shows a list of commands or help for one command
|
169
|
+
map - Map values in columns to new values</pre>
|
169
170
|
</main>
|
170
171
|
|
171
172
|
|
data/html/Sycsvpro/Counter.html
CHANGED
@@ -218,6 +218,45 @@ names and uses the count as the column value</p>
|
|
218
218
|
</div>
|
219
219
|
</div>
|
220
220
|
|
221
|
+
<div id="attribute-i-sum_row" class="method-detail">
|
222
|
+
<div class="method-heading attribute-method-heading">
|
223
|
+
<span class="method-name">sum_row</span><span
|
224
|
+
class="attribute-access-type">[R]</span>
|
225
|
+
</div>
|
226
|
+
|
227
|
+
<div class="method-description">
|
228
|
+
|
229
|
+
<p>row where to add the sums of the columns of the sum columns</p>
|
230
|
+
|
231
|
+
</div>
|
232
|
+
</div>
|
233
|
+
|
234
|
+
<div id="attribute-i-sum_title" class="method-detail">
|
235
|
+
<div class="method-heading attribute-method-heading">
|
236
|
+
<span class="method-name">sum_title</span><span
|
237
|
+
class="attribute-access-type">[R]</span>
|
238
|
+
</div>
|
239
|
+
|
240
|
+
<div class="method-description">
|
241
|
+
|
242
|
+
<p>Title of the sum row</p>
|
243
|
+
|
244
|
+
</div>
|
245
|
+
</div>
|
246
|
+
|
247
|
+
<div id="attribute-i-sums" class="method-detail">
|
248
|
+
<div class="method-heading attribute-method-heading">
|
249
|
+
<span class="method-name">sums</span><span
|
250
|
+
class="attribute-access-type">[R]</span>
|
251
|
+
</div>
|
252
|
+
|
253
|
+
<div class="method-description">
|
254
|
+
|
255
|
+
<p>sums of the column values</p>
|
256
|
+
|
257
|
+
</div>
|
258
|
+
</div>
|
259
|
+
|
221
260
|
</section>
|
222
261
|
|
223
262
|
|
@@ -241,21 +280,25 @@ names and uses the count as the column value</p>
|
|
241
280
|
|
242
281
|
<div class="method-description">
|
243
282
|
|
244
|
-
<p>Creates a new counter
|
283
|
+
<p>Creates a new counter. Takes as attributes infile, outfile, key, rows,
|
284
|
+
cols, date-format and indicator whether to add a sum row</p>
|
245
285
|
|
246
286
|
|
247
287
|
|
248
288
|
|
249
289
|
<div class="method-source-code" id="new-source">
|
250
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line
|
290
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line 37</span>
|
251
291
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>={})
|
252
292
|
<span class="ruby-ivar">@infile</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:infile</span>]
|
253
293
|
<span class="ruby-ivar">@outfile</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:outfile</span>]
|
254
294
|
<span class="ruby-ivar">@key_column</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:key</span>].<span class="ruby-identifier">to_i</span>
|
255
295
|
<span class="ruby-ivar">@row_filter</span> = <span class="ruby-constant">RowFilter</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:rows</span>])
|
256
296
|
<span class="ruby-ivar">@col_filter</span> = <span class="ruby-constant">ColumnFilter</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:cols</span>], <span class="ruby-identifier">df</span><span class="ruby-operator">:</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:df</span>])
|
257
|
-
<span class="ruby-ivar">@key_values</span>
|
297
|
+
<span class="ruby-ivar">@key_values</span> = {}
|
258
298
|
<span class="ruby-ivar">@heading</span> = []
|
299
|
+
<span class="ruby-ivar">@sum_title</span>, <span class="ruby-ivar">@sum_row</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:sum</span>].<span class="ruby-identifier">split</span>(<span class="ruby-string">':'</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:sum</span>].<span class="ruby-identifier">nil?</span>
|
300
|
+
<span class="ruby-ivar">@sum_row</span> = <span class="ruby-ivar">@sum_row</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@sum_row</span>.<span class="ruby-identifier">nil?</span>
|
301
|
+
<span class="ruby-ivar">@sums</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>)
|
259
302
|
<span class="ruby-keyword">end</span></pre>
|
260
303
|
</div>
|
261
304
|
|
@@ -294,7 +337,7 @@ names and uses the count as the column value</p>
|
|
294
337
|
|
295
338
|
|
296
339
|
<div class="method-source-code" id="execute-source">
|
297
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line
|
340
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line 51</span>
|
298
341
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">execute</span>
|
299
342
|
<span class="ruby-identifier">process_file</span>
|
300
343
|
<span class="ruby-identifier">write_result</span>
|
@@ -328,7 +371,7 @@ names and uses the count as the column value</p>
|
|
328
371
|
|
329
372
|
|
330
373
|
<div class="method-source-code" id="process_file-source">
|
331
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line
|
374
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line 57</span>
|
332
375
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">process_file</span>
|
333
376
|
<span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">infile</span>).<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
|
334
377
|
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">col_filter</span>.<span class="ruby-identifier">process</span>(<span class="ruby-identifier">row_filter</span>.<span class="ruby-identifier">process</span>(<span class="ruby-identifier">line</span>.<span class="ruby-identifier">chomp</span>, <span class="ruby-identifier">row</span><span class="ruby-operator">:</span> <span class="ruby-identifier">index</span>))
|
@@ -338,6 +381,7 @@ names and uses the count as the column value</p>
|
|
338
381
|
<span class="ruby-identifier">result</span>.<span class="ruby-identifier">chomp</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">';'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">column</span><span class="ruby-operator">|</span>
|
339
382
|
<span class="ruby-identifier">heading</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">column</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">heading</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">column</span>).<span class="ruby-identifier">nil?</span>
|
340
383
|
<span class="ruby-identifier">key_value</span>[<span class="ruby-value">:elements</span>][<span class="ruby-identifier">column</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
384
|
+
<span class="ruby-identifier">sums</span>[<span class="ruby-identifier">column</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
341
385
|
<span class="ruby-keyword">end</span>
|
342
386
|
<span class="ruby-keyword">end</span>
|
343
387
|
<span class="ruby-keyword">end</span>
|
@@ -371,11 +415,18 @@ names and uses the count as the column value</p>
|
|
371
415
|
|
372
416
|
|
373
417
|
<div class="method-source-code" id="write_result-source">
|
374
|
-
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line
|
418
|
+
<pre><span class="ruby-comment"># File lib/sycsvpro/counter.rb, line 73</span>
|
375
419
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">write_result</span>
|
420
|
+
<span class="ruby-identifier">sum_line</span> = [<span class="ruby-identifier">sum_title</span>]
|
421
|
+
<span class="ruby-identifier">heading</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
|
422
|
+
<span class="ruby-identifier">sum_line</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">sums</span>[<span class="ruby-identifier">h</span>]
|
423
|
+
<span class="ruby-keyword">end</span>
|
424
|
+
<span class="ruby-identifier">row</span> = <span class="ruby-value">0</span>;
|
376
425
|
<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">outfile</span>, <span class="ruby-string">'w'</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">out</span><span class="ruby-operator">|</span>
|
426
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">sum_line</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">';'</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">row</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">sum_row</span> ; <span class="ruby-identifier">row</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
377
427
|
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> ([<span class="ruby-string">"key"</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">heading</span>.<span class="ruby-identifier">sort</span>).<span class="ruby-identifier">join</span>(<span class="ruby-string">';'</span>)
|
378
428
|
<span class="ruby-identifier">key_values</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
429
|
+
<span class="ruby-identifier">out</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">sum_line</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">';'</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">row</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">sum_row</span> ; <span class="ruby-identifier">row</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
379
430
|
<span class="ruby-identifier">line</span> = [<span class="ruby-identifier">k</span>]
|
380
431
|
<span class="ruby-identifier">heading</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">h</span><span class="ruby-operator">|</span>
|
381
432
|
<span class="ruby-identifier">line</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">v</span>[<span class="ruby-value">:elements</span>][<span class="ruby-identifier">h</span>]
|
data/html/created.rid
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Fri, 21 Feb 2014 21:23:23 +0100
|
2
2
|
README.rdoc Sun, 16 Feb 2014 22:01:46 +0100
|
3
3
|
lib/sycsvpro.rb Wed, 19 Feb 2014 18:42:14 +0100
|
4
4
|
lib/sycsvpro/allocator.rb Wed, 19 Feb 2014 20:34:28 +0100
|
@@ -6,7 +6,7 @@ lib/sycsvpro/analyzer.rb Tue, 18 Feb 2014 19:57:28 +0100
|
|
6
6
|
lib/sycsvpro/calculator.rb Tue, 18 Feb 2014 19:53:34 +0100
|
7
7
|
lib/sycsvpro/collector.rb Sun, 16 Feb 2014 20:59:27 +0100
|
8
8
|
lib/sycsvpro/column_filter.rb Sun, 16 Feb 2014 21:10:11 +0100
|
9
|
-
lib/sycsvpro/counter.rb
|
9
|
+
lib/sycsvpro/counter.rb Fri, 21 Feb 2014 21:11:49 +0100
|
10
10
|
lib/sycsvpro/dsl.rb Tue, 18 Feb 2014 21:34:51 +0100
|
11
11
|
lib/sycsvpro/extractor.rb Tue, 18 Feb 2014 19:42:16 +0100
|
12
12
|
lib/sycsvpro/filter.rb Tue, 18 Feb 2014 20:23:57 +0100
|
@@ -14,5 +14,5 @@ lib/sycsvpro/header.rb Tue, 18 Feb 2014 19:50:26 +0100
|
|
14
14
|
lib/sycsvpro/mapper.rb Tue, 18 Feb 2014 19:45:47 +0100
|
15
15
|
lib/sycsvpro/profiler.rb Sun, 16 Feb 2014 21:31:39 +0100
|
16
16
|
lib/sycsvpro/row_filter.rb Tue, 18 Feb 2014 19:45:25 +0100
|
17
|
-
lib/sycsvpro/version.rb
|
18
|
-
bin/sycsvpro
|
17
|
+
lib/sycsvpro/version.rb Fri, 21 Feb 2014 21:22:36 +0100
|
18
|
+
bin/sycsvpro Fri, 21 Feb 2014 21:21:29 +0100
|
data/html/index.html
CHANGED
@@ -170,7 +170,7 @@ bin</pre>
|
|
170
170
|
|
171
171
|
<p>VERSION</p>
|
172
172
|
|
173
|
-
<pre>0.0.
|
173
|
+
<pre>0.0.5</pre>
|
174
174
|
|
175
175
|
<p>GLOBAL OPTIONS</p>
|
176
176
|
|
@@ -181,17 +181,18 @@ bin</pre>
|
|
181
181
|
|
182
182
|
<p>COMMANDS</p>
|
183
183
|
|
184
|
-
<pre>
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
184
|
+
<pre>allocate - Allocate specified columns from the file to a key value
|
185
|
+
analyze - Analyze the CSV file regarding columns, rows and content
|
186
|
+
calc - Process math operations on columns
|
187
|
+
collect - Collect values of specified rows and columns from the file and group them in
|
188
|
+
categories
|
189
|
+
count - Counts the occurences of column values. Uses column values as headings with count as
|
190
|
+
values. Columns with a condition will be added as new columns and the condition will
|
191
|
+
be set as column name. Optionally adds a sum row
|
192
|
+
execute - Executes the code provided in a file
|
193
|
+
extract - Extract specified rows and columns from the file
|
194
|
+
help - Shows a list of commands or help for one command
|
195
|
+
map - Map values in columns to new values</pre>
|
195
196
|
</main>
|
196
197
|
|
197
198
|
|
data/html/js/search_index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var search_data = {"index":{"searchIndex":["dsl","object","sycsvpro","allocator","analyzer","calculator","collector","columnfilter","counter","extractor","filter","header","mapper","profiler","rowfilter","execute()","execute()","execute()","execute()","execute()","execute()","execute()","has_filter?()","method_missing()","method_missing()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","pivot_each_column()","process()","process()","process()","process()","process_file()","result()","rows()","unstring()","write_result()","write_to()","readme"],"longSearchIndex":["dsl","object","sycsvpro","sycsvpro::allocator","sycsvpro::analyzer","sycsvpro::calculator","sycsvpro::collector","sycsvpro::columnfilter","sycsvpro::counter","sycsvpro::extractor","sycsvpro::filter","sycsvpro::header","sycsvpro::mapper","sycsvpro::profiler","sycsvpro::rowfilter","sycsvpro::allocator#execute()","sycsvpro::calculator#execute()","sycsvpro::collector#execute()","sycsvpro::counter#execute()","sycsvpro::extractor#execute()","sycsvpro::mapper#execute()","sycsvpro::profiler#execute()","sycsvpro::filter#has_filter?()","sycsvpro::calculator#method_missing()","sycsvpro::filter#method_missing()","sycsvpro::allocator::new()","sycsvpro::analyzer::new()","sycsvpro::calculator::new()","sycsvpro::collector::new()","sycsvpro::counter::new()","sycsvpro::extractor::new()","sycsvpro::filter::new()","sycsvpro::header::new()","sycsvpro::mapper::new()","sycsvpro::profiler::new()","sycsvpro::filter#pivot_each_column()","sycsvpro::columnfilter#process()","sycsvpro::filter#process()","sycsvpro::header#process()","sycsvpro::rowfilter#process()","sycsvpro::counter#process_file()","sycsvpro::analyzer#result()","dsl#rows()","dsl#unstring()","sycsvpro::counter#write_result()","dsl#write_to()",""],"info":[["Dsl","","Dsl.html","","<p>Methods to be used in customer specific script files\n"],["Object","","Object.html","",""],["Sycsvpro","","Sycsvpro.html","","<p>Operating csv files\n<p>Operating csv files\n<p>Operating csv files\n"],["Sycsvpro::Allocator","","Sycsvpro/Allocator.html","","<p>Allocates columns to a key column\n"],["Sycsvpro::Analyzer","","Sycsvpro/Analyzer.html","","<p>Analyzes the file structure\n"],["Sycsvpro::Calculator","","Sycsvpro/Calculator.html","","<p>Processes arithmetic operations on columns of a csv file. A column value\nhas to be a number. Possible …\n"],["Sycsvpro::Collector","","Sycsvpro/Collector.html","","<p>Collects values from rows and groups them in categories\n"],["Sycsvpro::ColumnFilter","","Sycsvpro/ColumnFilter.html","","<p>Creates a new column filter\n"],["Sycsvpro::Counter","","Sycsvpro/Counter.html","","<p>Creates a new counter that counts values and uses the values as column\nnames and uses the count as the …\n"],["Sycsvpro::Extractor","","Sycsvpro/Extractor.html","","<p>Extracts rows and columns from a csv file\n"],["Sycsvpro::Filter","","Sycsvpro/Filter.html","","<p>Creates a new filter that can be extended by sub-classes. A sub-class needs\nto override the process method …\n"],["Sycsvpro::Header","","Sycsvpro/Header.html","","<p>Creates a header\n"],["Sycsvpro::Mapper","","Sycsvpro/Mapper.html","","<p>Map values to new values described in a mapping file\n"],["Sycsvpro::Profiler","","Sycsvpro/Profiler.html","","<p>A profiler takes a Ruby script and executes the provided method in the\nscript\n"],["Sycsvpro::RowFilter","","Sycsvpro/RowFilter.html","","<p>Filters rows based on provided patterns\n"],["execute","Sycsvpro::Allocator","Sycsvpro/Allocator.html#method-i-execute","()","<p>Executes the allocator and assigns column values to the key\n"],["execute","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-i-execute","()","<p>Executes the calculator\n"],["execute","Sycsvpro::Collector","Sycsvpro/Collector.html#method-i-execute","()","<p>Execute the collector\n"],["execute","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-execute","()","<p>Executes the counter\n"],["execute","Sycsvpro::Extractor","Sycsvpro/Extractor.html#method-i-execute","()","<p>Executes the extractor\n"],["execute","Sycsvpro::Mapper","Sycsvpro/Mapper.html#method-i-execute","()","<p>Executes the mapper\n"],["execute","Sycsvpro::Profiler","Sycsvpro/Profiler.html#method-i-execute","(method)","<p>Executes the provided method in the Ruby script\n"],["has_filter?","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-has_filter-3F","()","<p>Checks whether a filter has been set. Returns true if filter has been set\notherwise false\n"],["method_missing","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-i-method_missing","(id, *args, &block)","<p>Retrieves the values from a row as the result of a arithmetic operation\n"],["method_missing","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-method_missing","(id, *args, &block)","<p>Creates the filters based on the given patterns\n"],["new","Sycsvpro::Allocator","Sycsvpro/Allocator.html#method-c-new","(options={})","<p>Creates a new allocator. Options are infile, outfile, key, rows and columns\nto allocate to key\n"],["new","Sycsvpro::Analyzer","Sycsvpro/Analyzer.html#method-c-new","(file)","<p>Creates a new analyzer\n"],["new","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-c-new","(options={})","<p>Creates a new Calculator. Options expects :infile, :outfile, :rows and\n:columns. Optionally a header …\n"],["new","Sycsvpro::Collector","Sycsvpro/Collector.html#method-c-new","(options={})","<p>Creates a new Collector\n"],["new","Sycsvpro::Counter","Sycsvpro/Counter.html#method-c-new","(options={})","<p>Creates a new counter
|
1
|
+
var search_data = {"index":{"searchIndex":["dsl","object","sycsvpro","allocator","analyzer","calculator","collector","columnfilter","counter","extractor","filter","header","mapper","profiler","rowfilter","execute()","execute()","execute()","execute()","execute()","execute()","execute()","has_filter?()","method_missing()","method_missing()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","pivot_each_column()","process()","process()","process()","process()","process_file()","result()","rows()","unstring()","write_result()","write_to()","readme"],"longSearchIndex":["dsl","object","sycsvpro","sycsvpro::allocator","sycsvpro::analyzer","sycsvpro::calculator","sycsvpro::collector","sycsvpro::columnfilter","sycsvpro::counter","sycsvpro::extractor","sycsvpro::filter","sycsvpro::header","sycsvpro::mapper","sycsvpro::profiler","sycsvpro::rowfilter","sycsvpro::allocator#execute()","sycsvpro::calculator#execute()","sycsvpro::collector#execute()","sycsvpro::counter#execute()","sycsvpro::extractor#execute()","sycsvpro::mapper#execute()","sycsvpro::profiler#execute()","sycsvpro::filter#has_filter?()","sycsvpro::calculator#method_missing()","sycsvpro::filter#method_missing()","sycsvpro::allocator::new()","sycsvpro::analyzer::new()","sycsvpro::calculator::new()","sycsvpro::collector::new()","sycsvpro::counter::new()","sycsvpro::extractor::new()","sycsvpro::filter::new()","sycsvpro::header::new()","sycsvpro::mapper::new()","sycsvpro::profiler::new()","sycsvpro::filter#pivot_each_column()","sycsvpro::columnfilter#process()","sycsvpro::filter#process()","sycsvpro::header#process()","sycsvpro::rowfilter#process()","sycsvpro::counter#process_file()","sycsvpro::analyzer#result()","dsl#rows()","dsl#unstring()","sycsvpro::counter#write_result()","dsl#write_to()",""],"info":[["Dsl","","Dsl.html","","<p>Methods to be used in customer specific script files\n"],["Object","","Object.html","",""],["Sycsvpro","","Sycsvpro.html","","<p>Operating csv files\n<p>Operating csv files\n<p>Operating csv files\n"],["Sycsvpro::Allocator","","Sycsvpro/Allocator.html","","<p>Allocates columns to a key column\n"],["Sycsvpro::Analyzer","","Sycsvpro/Analyzer.html","","<p>Analyzes the file structure\n"],["Sycsvpro::Calculator","","Sycsvpro/Calculator.html","","<p>Processes arithmetic operations on columns of a csv file. A column value\nhas to be a number. Possible …\n"],["Sycsvpro::Collector","","Sycsvpro/Collector.html","","<p>Collects values from rows and groups them in categories\n"],["Sycsvpro::ColumnFilter","","Sycsvpro/ColumnFilter.html","","<p>Creates a new column filter\n"],["Sycsvpro::Counter","","Sycsvpro/Counter.html","","<p>Creates a new counter that counts values and uses the values as column\nnames and uses the count as the …\n"],["Sycsvpro::Extractor","","Sycsvpro/Extractor.html","","<p>Extracts rows and columns from a csv file\n"],["Sycsvpro::Filter","","Sycsvpro/Filter.html","","<p>Creates a new filter that can be extended by sub-classes. A sub-class needs\nto override the process method …\n"],["Sycsvpro::Header","","Sycsvpro/Header.html","","<p>Creates a header\n"],["Sycsvpro::Mapper","","Sycsvpro/Mapper.html","","<p>Map values to new values described in a mapping file\n"],["Sycsvpro::Profiler","","Sycsvpro/Profiler.html","","<p>A profiler takes a Ruby script and executes the provided method in the\nscript\n"],["Sycsvpro::RowFilter","","Sycsvpro/RowFilter.html","","<p>Filters rows based on provided patterns\n"],["execute","Sycsvpro::Allocator","Sycsvpro/Allocator.html#method-i-execute","()","<p>Executes the allocator and assigns column values to the key\n"],["execute","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-i-execute","()","<p>Executes the calculator\n"],["execute","Sycsvpro::Collector","Sycsvpro/Collector.html#method-i-execute","()","<p>Execute the collector\n"],["execute","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-execute","()","<p>Executes the counter\n"],["execute","Sycsvpro::Extractor","Sycsvpro/Extractor.html#method-i-execute","()","<p>Executes the extractor\n"],["execute","Sycsvpro::Mapper","Sycsvpro/Mapper.html#method-i-execute","()","<p>Executes the mapper\n"],["execute","Sycsvpro::Profiler","Sycsvpro/Profiler.html#method-i-execute","(method)","<p>Executes the provided method in the Ruby script\n"],["has_filter?","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-has_filter-3F","()","<p>Checks whether a filter has been set. Returns true if filter has been set\notherwise false\n"],["method_missing","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-i-method_missing","(id, *args, &block)","<p>Retrieves the values from a row as the result of a arithmetic operation\n"],["method_missing","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-method_missing","(id, *args, &block)","<p>Creates the filters based on the given patterns\n"],["new","Sycsvpro::Allocator","Sycsvpro/Allocator.html#method-c-new","(options={})","<p>Creates a new allocator. Options are infile, outfile, key, rows and columns\nto allocate to key\n"],["new","Sycsvpro::Analyzer","Sycsvpro/Analyzer.html#method-c-new","(file)","<p>Creates a new analyzer\n"],["new","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-c-new","(options={})","<p>Creates a new Calculator. Options expects :infile, :outfile, :rows and\n:columns. Optionally a header …\n"],["new","Sycsvpro::Collector","Sycsvpro/Collector.html#method-c-new","(options={})","<p>Creates a new Collector\n"],["new","Sycsvpro::Counter","Sycsvpro/Counter.html#method-c-new","(options={})","<p>Creates a new counter. Takes as attributes infile, outfile, key, rows,\ncols, date-format and indicator …\n"],["new","Sycsvpro::Extractor","Sycsvpro/Extractor.html#method-c-new","(options={})","<p>Creates a new extractor\n"],["new","Sycsvpro::Filter","Sycsvpro/Filter.html#method-c-new","(values, options={})","<p>Creates a new filter\n"],["new","Sycsvpro::Header","Sycsvpro/Header.html#method-c-new","(header)","<p>Create a new header\n"],["new","Sycsvpro::Mapper","Sycsvpro/Mapper.html#method-c-new","(options={})","<p>Creates new mapper\n"],["new","Sycsvpro::Profiler","Sycsvpro/Profiler.html#method-c-new","(pro_file)","<p>Creates a new profiler\n"],["pivot_each_column","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-pivot_each_column","(values=[])","<p>Yields the column value and whether the filter matches the column\n"],["process","Sycsvpro::ColumnFilter","Sycsvpro/ColumnFilter.html#method-i-process","(object, options={})","<p>Processes the filter and returns the values that respect the filter\n"],["process","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-process","(object, options={})","<p>Processes the filter. Needs to be overridden by the sub-class\n"],["process","Sycsvpro::Header","Sycsvpro/Header.html#method-i-process","(line)","<p>Returns the header\n"],["process","Sycsvpro::RowFilter","Sycsvpro/RowFilter.html#method-i-process","(object, options={})","<p>Processes the filter on the given row\n"],["process_file","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-process_file","()","<p>Processes the counting on the in file\n"],["result","Sycsvpro::Analyzer","Sycsvpro/Analyzer.html#method-i-result","()","<p>Analyzes the file and returns the result\n"],["rows","Dsl","Dsl.html#method-i-rows","(options={})","<p>Retrieves rows and columns from the file and returns them to the block\nprovided by the caller\n"],["unstring","Dsl","Dsl.html#method-i-unstring","(line)","<p>Remove leading and trailing “ and spaces as well as reducing more than 2\nspaces between words from …\n"],["write_result","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-write_result","()","<p>Writes the results\n"],["write_to","Dsl","Dsl.html#method-i-write_to","(file)","<p>writes values provided by a block to the given file\n"],["README","","README_rdoc.html","","<p>sycsvpro\n<p>Author — Pierre Sugar (pierre@sugaryourcoffee.de)\n<p>Copyright — Copyright © 2014 by Pierre Sugar\n"]]}}
|
data/lib/sycsvpro/counter.rb
CHANGED
@@ -25,16 +25,26 @@ module Sycsvpro
|
|
25
25
|
attr_reader :key_values
|
26
26
|
# header of the out file
|
27
27
|
attr_reader :heading
|
28
|
+
# Title of the sum row
|
29
|
+
attr_reader :sum_title
|
30
|
+
# row where to add the sums of the columns of the sum columns
|
31
|
+
attr_reader :sum_row
|
32
|
+
# sums of the column values
|
33
|
+
attr_reader :sums
|
28
34
|
|
29
|
-
# Creates a new counter
|
35
|
+
# Creates a new counter. Takes as attributes infile, outfile, key, rows, cols, date-format and
|
36
|
+
# indicator whether to add a sum row
|
30
37
|
def initialize(options={})
|
31
38
|
@infile = options[:infile]
|
32
39
|
@outfile = options[:outfile]
|
33
40
|
@key_column = options[:key].to_i
|
34
41
|
@row_filter = RowFilter.new(options[:rows])
|
35
42
|
@col_filter = ColumnFilter.new(options[:cols], df: options[:df])
|
36
|
-
@key_values
|
43
|
+
@key_values = {}
|
37
44
|
@heading = []
|
45
|
+
@sum_title, @sum_row = options[:sum].split(':') unless options[:sum].nil?
|
46
|
+
@sum_row = @sum_row.to_i unless @sum_row.nil?
|
47
|
+
@sums = Hash.new(0)
|
38
48
|
end
|
39
49
|
|
40
50
|
# Executes the counter
|
@@ -53,6 +63,7 @@ module Sycsvpro
|
|
53
63
|
result.chomp.split(';').each do |column|
|
54
64
|
heading << column if heading.index(column).nil?
|
55
65
|
key_value[:elements][column] += 1
|
66
|
+
sums[column] += 1
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
@@ -60,9 +71,16 @@ module Sycsvpro
|
|
60
71
|
|
61
72
|
# Writes the results
|
62
73
|
def write_result
|
74
|
+
sum_line = [sum_title]
|
75
|
+
heading.sort.each do |h|
|
76
|
+
sum_line << sums[h]
|
77
|
+
end
|
78
|
+
row = 0;
|
63
79
|
File.open(outfile, 'w') do |out|
|
80
|
+
out.puts sum_line.join(';') if row == sum_row ; row += 1
|
64
81
|
out.puts (["key"] + heading.sort).join(';')
|
65
82
|
key_values.each do |k,v|
|
83
|
+
out.puts sum_line.join(';') if row == sum_row ; row += 1
|
66
84
|
line = [k]
|
67
85
|
heading.sort.each do |h|
|
68
86
|
line << v[:elements][h]
|
data/lib/sycsvpro/version.rb
CHANGED
@@ -48,6 +48,26 @@ module Sycsvpro
|
|
48
48
|
|
49
49
|
end
|
50
50
|
|
51
|
+
it "should add a sum row" do
|
52
|
+
counter = Counter.new(infile: @in_file, outfile: @out_file, rows: "1-10",
|
53
|
+
cols: "2:<1.1.2013,2:1.1.2013-31.12.2014,2:>31.12.2014", key: "0",
|
54
|
+
df: "%d.%m.%Y", sum: "Total:1")
|
55
|
+
|
56
|
+
counter.execute
|
57
|
+
|
58
|
+
result = [ "key;1.1.2013-31.12.2014;<1.1.2013;>31.12.2014",
|
59
|
+
"Total;2;1;2",
|
60
|
+
"Fink;0;0;2",
|
61
|
+
"Haas;0;1;0",
|
62
|
+
"Gent;1;0;0",
|
63
|
+
"Rank;1;0;0" ]
|
64
|
+
|
65
|
+
File.open(@out_file).each_with_index do |line, index|
|
66
|
+
line.chomp.should eq result[index]
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
51
71
|
end
|
52
72
|
|
53
73
|
end
|
data/sycsvpro.rdoc
CHANGED
@@ -7,7 +7,7 @@ SYNOPSIS
|
|
7
7
|
sycsvpro [global options] command [command options] [arguments...]
|
8
8
|
|
9
9
|
VERSION
|
10
|
-
0.0.
|
10
|
+
0.0.5
|
11
11
|
|
12
12
|
GLOBAL OPTIONS
|
13
13
|
-f, --file=FILE - CSV file to operate on (default: none)
|
@@ -16,14 +16,15 @@ GLOBAL OPTIONS
|
|
16
16
|
--version - Display the program version
|
17
17
|
|
18
18
|
COMMANDS
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
allocate - Allocate specified columns from the file to a key value
|
20
|
+
analyze - Analyze the CSV file regarding columns, rows and content
|
21
|
+
calc - Process math operations on columns
|
22
|
+
collect - Collect values of specified rows and columns from the file and group them in
|
23
|
+
categories
|
24
|
+
count - Counts the occurences of column values. Uses column values as headings with count as
|
25
|
+
values. Columns with a condition will be added as new columns and the condition will
|
26
|
+
be set as column name. Optionally adds a sum row
|
27
|
+
execute - Executes the code provided in a file
|
28
|
+
extract - Extract specified rows and columns from the file
|
29
|
+
help - Shows a list of commands or help for one command
|
30
|
+
map - Map values in columns to new values
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sycsvpro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre Sugar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|