blocktrain 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 0188b5e441869b10f247af390e35a481eb2a9d3a
4
- data.tar.gz: f4ee99a885391d634d7653683c025ae76c08930e
3
+ metadata.gz: 8b519150dba476754b4e30a19676846a6c85aab3
4
+ data.tar.gz: 8c3f0aa9e1a3dac4cef1ba1533537cb876dbd4d8
5
5
  SHA512:
6
- metadata.gz: 50b481a7f794f4e65abc5b33930d9468bba70c43102251469f01ede84ab3d2133f25a69fa76ea587126a079136050e66839f877a1b3c0e587b0c72ee26f22a8e
7
- data.tar.gz: 6743e14e31e753b04f0d5d3709c50a9f0e3b0b32bc68bf332dc565f474f60df5da468ed1eb2a4fdb2fcef2923041f201ebb7f11685a0f38a1756371a795fdd6e
6
+ metadata.gz: 22bbe9a44d4120adfed3f8b91ab9316e5b0e36d00c85caeaaca708846eca9f00f5e6f47999e7839d453715aaba9383c6674715bb2e7532e5c9ed7239dc314e3e
7
+ data.tar.gz: ef1ee5078ed06d5e649e5bc72c6c9075a9fcfe88a72eaad2ceba43df5f9baebed1c3522f8261b24d1e9789b803818e8d99052f9df908dc3f69493f4426032647
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
2
- --color
1
+ --format PrideFormatter
3
2
  --require spec_helper
3
+ --require rspec/pride
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'bundler', '~> 1.10'
34
34
  spec.add_development_dependency 'rake', '~> 10.0'
35
35
  spec.add_development_dependency 'rspec', '~> 3.3'
36
+ spec.add_development_dependency 'rspec-pride', '~> 3.1'
36
37
  spec.add_development_dependency 'guard-rspec', '~> 4.6'
37
38
  spec.add_development_dependency 'vcr', '~> 2.9'
38
39
  spec.add_development_dependency 'webmock', '~> 1.21'
@@ -0,0 +1,5 @@
1
+ car_codes:
2
+ A: 2E64930W
3
+ B: 2E64932W
4
+ C: 2E64934W
5
+ D: 2E64936W
@@ -1,10 +1,15 @@
1
1
  require 'curb'
2
2
  require 'dotenv'
3
+ require 'yaml'
3
4
  require 'json'
4
5
  require 'date'
6
+ require 'singleton'
5
7
 
6
8
  require 'blocktrain/version'
7
9
  require 'blocktrain/client'
10
+ require 'blocktrain/lookups'
8
11
  require 'blocktrain/aggregation'
12
+ require 'blocktrain/aggregations/train_weight_aggregation'
13
+ require 'blocktrain/aggregations/car_weight_aggregation'
9
14
 
10
15
  Dotenv.load
@@ -1,14 +1,7 @@
1
1
  module Blocktrain
2
2
  class Aggregation
3
-
4
- CAR_CODES = {
5
- 'A' => '2E64930W',
6
- 'B' => '2E64932W',
7
- 'C' => '2E64934W',
8
- 'D' => '2E64936W'
9
- }
10
-
11
3
  def initialize(options = {})
4
+ @lookups = Lookups.instance.lookups
12
5
  @car = options[:car]
13
6
 
14
7
  @from = parse_datetime(options.fetch(:from, '2015-09-01T00:00:00'))
@@ -28,70 +21,44 @@ module Blocktrain
28
21
 
29
22
  def address_query
30
23
  if @car.nil?
31
- CAR_CODES.map { |code| "memoryAddress:#{code}" }.join(' OR ')
24
+ @lookups['car_codes'].map { |car, code| "memoryAddress:#{code}" }.join(' OR ')
32
25
  else
33
- "memoryAddress:#{CAR_CODES[@car]}"
26
+ "memoryAddress:#{@lookups['car_codes'][@car]}"
34
27
  end
35
28
  end
36
29
 
37
30
  def query
38
31
  {
39
- 'filtered' => {
40
- 'query' => {
41
- 'query_string' => {
42
- 'analyze_wildcard' =>true,
43
- 'query' =>address_query
32
+ filtered: {
33
+ query: {
34
+ query_string: {
35
+ analyze_wildcard: true,
36
+ query: address_query
44
37
  }
45
38
  },
46
- 'filter' => {
47
- 'bool' => {
48
- 'must' => [
39
+ filter: {
40
+ bool: {
41
+ must: [
49
42
  {
50
- 'range' => {
51
- 'timeStamp' => {
52
- 'gte' =>@from,
53
- 'lte' =>@to
43
+ range: {
44
+ timeStamp: {
45
+ gte: @from,
46
+ lte: @to
54
47
  }
55
48
  }
56
49
  }
57
- ],
58
- 'must_not' => []
50
+ ]
59
51
  }
60
52
  }
61
53
  }
62
54
  }
63
55
  end
64
56
 
65
- def aggs
66
- {
67
- 'weight_chart' => {
68
- 'date_histogram' => {
69
- 'field' => 'timeStamp',
70
- 'interval' => @interval,
71
- 'pre_zone' => '+01:00',
72
- 'pre_zone_adjust_large_interval' =>true,
73
- 'min_doc_count' => 1,
74
- 'extended_bounds' => {
75
- 'min' =>@from,
76
- 'max' =>@to
77
- }
78
- },
79
- 'aggregations' => {
80
- 'weight' => {
81
- 'avg' => {
82
- 'field' => 'value'
83
- }
84
- }
85
- }
86
- },
87
- }
88
- end
89
-
90
57
  def body
91
58
  {
92
- 'query' => query,
93
- 'size' =>0,
94
- 'aggregations' => aggs,
59
+ query: query,
60
+ size: 0,
61
+ aggregations: aggs,
95
62
  }
96
63
  end
97
64
  end
@@ -0,0 +1,50 @@
1
+ module Blocktrain
2
+ module Aggregations
3
+ class CarWeightAggregation < Aggregation
4
+
5
+ def aggs
6
+ {
7
+ weight_chart: {
8
+ date_histogram: {
9
+ field: 'timeStamp',
10
+ interval: @interval,
11
+ pre_zone: '+01:00',
12
+ pre_zone_adjust_large_interval: true,
13
+ min_doc_count: 1,
14
+ extended_bounds: {
15
+ min: @from,
16
+ max: @to
17
+ }
18
+ },
19
+ aggregations: car_weight_aggs
20
+ }
21
+ }
22
+ end
23
+
24
+ def car_weight_aggs
25
+ {
26
+ weight: {
27
+ terms: { field: 'memoryAddress' },
28
+ aggregations: {
29
+ avg_weight: {
30
+ avg: {
31
+ field: 'value'
32
+ }
33
+ },
34
+ max_weight: {
35
+ max: {
36
+ field: 'value'
37
+ }
38
+ },
39
+ min_weight: {
40
+ min: {
41
+ field: 'value'
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,31 @@
1
+ module Blocktrain
2
+ module Aggregations
3
+ class TrainWeightAggregation < Aggregation
4
+
5
+ def aggs
6
+ {
7
+ weight_chart: {
8
+ date_histogram: {
9
+ field: 'timeStamp',
10
+ interval: @interval,
11
+ pre_zone: '+01:00',
12
+ pre_zone_adjust_large_interval: true,
13
+ min_doc_count: 1,
14
+ extended_bounds: {
15
+ min: @from,
16
+ max: @to
17
+ }
18
+ },
19
+ aggregations: {
20
+ weight: {
21
+ avg: {
22
+ field: 'value'
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module Blocktrain
2
+ class Lookups
3
+ include Singleton
4
+
5
+ def initialize
6
+ @lookups = OpenStruct.new fetch_yaml 'lookups'
7
+ end
8
+
9
+ def lookups
10
+ @lookups
11
+ end
12
+
13
+ private
14
+
15
+ def fetch_yaml file
16
+ YAML.load(File.open(File.join(File.dirname(__FILE__), '..', '..', 'config/%s.yml' % file)))
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Blocktrain
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blocktrain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pikesley
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-10-27 00:00:00.000000000 Z
12
+ date: 2015-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dotenv
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '3.3'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec-pride
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.1'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.1'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: guard-rspec
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -169,9 +183,13 @@ files:
169
183
  - bin/console
170
184
  - bin/setup
171
185
  - blocktrain.gemspec
186
+ - config/lookups.yml
172
187
  - lib/blocktrain.rb
173
188
  - lib/blocktrain/aggregation.rb
189
+ - lib/blocktrain/aggregations/car_weight_aggregation.rb
190
+ - lib/blocktrain/aggregations/train_weight_aggregation.rb
174
191
  - lib/blocktrain/client.rb
192
+ - lib/blocktrain/lookups.rb
175
193
  - lib/blocktrain/version.rb
176
194
  homepage: http://github.org/theodi/blocktrain
177
195
  licenses: