streamer 0.2.0 → 0.2.1
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/docker-compose.yml +1 -1
- data/examples/example1/example.rb +8 -1
- data/examples/example1/sb_config.yml +12 -1
- data/lib/streamer/fact_providers.rb +1 -0
- data/lib/streamer/fact_providers/csv_provider.rb +52 -0
- data/lib/streamer/functors/sum.rb +0 -1
- data/lib/streamer/version.rb +1 -1
- data/script/example1 +4 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88c63cc9998dbe3ae65b37738ac19c3faf23b44c
|
4
|
+
data.tar.gz: 5a2bf3b5b8f6b0cb4440e927dcf77bc94167c160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 153f8a814e055843c837b4d3d80c81d9d4134aef72fcdc203a2f90bf101ab6d63c21ce09aed91c25ffa78f2d008d1c68934cfaa9260bf828498186adc16cc5f7
|
7
|
+
data.tar.gz: 071b2a6bb0118435dc21467136ccd226e54799a5633676cbdf028e8bf1eccf280cd115d7935ecbc6f7ea6db353a9241a2781b3315b7a7dfcb8d4755d8abc4838
|
data/Gemfile.lock
CHANGED
data/docker-compose.yml
CHANGED
@@ -4,19 +4,26 @@ require 'streamer'
|
|
4
4
|
require 'csv'
|
5
5
|
require 'pry'
|
6
6
|
|
7
|
+
# create a base document to house the sales data
|
7
8
|
sales_numbers = {
|
8
|
-
'
|
9
|
+
'name' => 'example sales filtering and calculation',
|
9
10
|
'sales' => []
|
10
11
|
}
|
11
12
|
|
13
|
+
# load sales data from a csv and place it into the document
|
12
14
|
data_file_path = File.join(__dir__, 'data.csv')
|
13
15
|
CSV.foreach(data_file_path, headers: true) do |row|
|
14
16
|
sales_numbers['sales'] << row.to_hash
|
15
17
|
end
|
16
18
|
|
19
|
+
# configure a new stream, loading the configuration from a file
|
17
20
|
config_file_path = File.join(__dir__, 'sb_config.yml')
|
18
21
|
sb = Streamer::StreamBuilder.new(YAML.load_file(config_file_path))
|
22
|
+
|
23
|
+
# process the data document using the configured stream
|
19
24
|
sb.process(sales_numbers)
|
25
|
+
|
26
|
+
# output the results to stdout
|
20
27
|
sb.payload['summary']['sales_by_product'].each do |k, v|
|
21
28
|
printf "%-20s %d\n", k, v
|
22
29
|
end
|
@@ -19,7 +19,18 @@
|
|
19
19
|
:property: summary.sales_by_product
|
20
20
|
:function:
|
21
21
|
:type: group
|
22
|
-
:list:
|
22
|
+
:list:
|
23
|
+
:function:
|
24
|
+
:type: list_filter
|
25
|
+
:list: sales
|
26
|
+
:filters:
|
27
|
+
- :function:
|
28
|
+
:type: member
|
29
|
+
:properties:
|
30
|
+
- customer_state
|
31
|
+
:facts:
|
32
|
+
- IA
|
33
|
+
- KS
|
23
34
|
:by: product
|
24
35
|
:operator: +
|
25
36
|
:operand: amount
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Streamer
|
4
|
+
module FactProviders
|
5
|
+
# CSVProvider implements Finder Provider interface
|
6
|
+
class CSVProvider
|
7
|
+
attr_reader :path, :key
|
8
|
+
|
9
|
+
def initialize(path)
|
10
|
+
@path = path
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(key)
|
14
|
+
@key = key
|
15
|
+
return hash_result if segments.size == 2
|
16
|
+
return scalar_result if segments.size == 3
|
17
|
+
end
|
18
|
+
|
19
|
+
def segments
|
20
|
+
key.split('.')
|
21
|
+
end
|
22
|
+
|
23
|
+
def hash_result
|
24
|
+
Hash[headers.zip CSV.parse_line(lines)]
|
25
|
+
end
|
26
|
+
|
27
|
+
def scalar_result
|
28
|
+
hash_result[segments[2]]
|
29
|
+
end
|
30
|
+
|
31
|
+
def lines
|
32
|
+
`#{processing_statement}`.strip
|
33
|
+
end
|
34
|
+
|
35
|
+
def headers
|
36
|
+
@headers ||= CSV.parse_line(`head -n 1 #{path}`)
|
37
|
+
end
|
38
|
+
|
39
|
+
def field_number(field)
|
40
|
+
headers.index(field) + 1
|
41
|
+
end
|
42
|
+
|
43
|
+
def processing_statement
|
44
|
+
segs = segments
|
45
|
+
return unless segs.size > 1 && segs.size < 4
|
46
|
+
<<-STMT
|
47
|
+
awk -F'","|,' '($#{field_number(segs[0])} ~ /^#{segs[1]}$/){print $0}' #{path}
|
48
|
+
STMT
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/streamer/version.rb
CHANGED
data/script/example1
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: streamer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Helm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- examples/example1/sb_config.yml
|
178
178
|
- lib/streamer.rb
|
179
179
|
- lib/streamer/fact_providers.rb
|
180
|
+
- lib/streamer/fact_providers/csv_provider.rb
|
180
181
|
- lib/streamer/fact_providers/hash_provider.rb
|
181
182
|
- lib/streamer/fact_providers/yaml_provider.rb
|
182
183
|
- lib/streamer/finder.rb
|
@@ -202,6 +203,7 @@ files:
|
|
202
203
|
- lib/streamer/stream_builder.rb
|
203
204
|
- lib/streamer/version.rb
|
204
205
|
- script/console
|
206
|
+
- script/example1
|
205
207
|
- script/init
|
206
208
|
- script/itest
|
207
209
|
- script/shell
|
@@ -228,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
230
|
version: '0'
|
229
231
|
requirements: []
|
230
232
|
rubyforge_project:
|
231
|
-
rubygems_version: 2.5.
|
233
|
+
rubygems_version: 2.5.2
|
232
234
|
signing_key:
|
233
235
|
specification_version: 4
|
234
236
|
summary: streams a hash through a set of configurable functions
|