blocktrain 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yjc1MTFiYTIzODY2MTBiZjA3MTdkZTI5ODE1MDM4Njc1ZTQxY2JiNQ==
4
+ YmRkYjIzOTU3YzM3MGFjMmI4NTdiYTYxMDhjMmI2ZDE1NWI3MTE2ZA==
5
5
  data.tar.gz: !binary |-
6
- YmMwNTgzZGRlMGMwZDUyZjUxMTZiMGNjNDI3NjY4ZWIyZDQ2NTRlNQ==
6
+ NWI5YmUyYmY1NzY5YWMxNjZkY2ZmZTgxYzJkZGMzMmJhZDBiOTBmOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzRmZDgwYzAyMThjYTJjZmI1NmM0NzVhYTI4MjJjNDBiYTc3MzZiYzRhNzVi
10
- YTkwODA0OTg1ZGI4YjAzNjZjMmU1NTY5ODI4ODhmNjM4ZmJiNGUxNzk4YTcw
11
- M2Y0YzZiNmMzZTljYzFhYTFiOTNjMDc4NmU0NTRmZGY4OWZjMjM=
9
+ ZTJjMTI0ZjU4NGMxYzA5YjEyYmFjY2E3MmYzNGM1OWI0M2ZhYmQ2YjI2NzQ2
10
+ ZTFlOGIwNTkxYTc1YTgxYzRlMTI1OTMyOTdmNWMyNGZkMzM1NzFlMmJhMTNh
11
+ OTg5NGFiOGFhZWM5N2M0YzU2M2MyMmExZTYyMDRiYWM4NWYwNWQ=
12
12
  data.tar.gz: !binary |-
13
- NDUzNzRjYjNiMmFlMTNmNTNiZmYyOTI2ZDJhYjBkODdmYTlkODQzMDVmMzY2
14
- NDgyNGY0NDcyMDY4N2VlOWUwYmQxYWE3ZWNiYWQ3NDFlMDZiZmFkMzcxNzAz
15
- YTkyZWQwMDhkNzljMWJlMWUyNTZjZDFlMjdlYjdjNDgwZmQ2NjI=
13
+ YTMzZjA4ZjY2ODFkNGViNzEyYzc5YjI3Y2JlZGVkNzNmY2E2NzA2MGY0ZmU4
14
+ NjU4ZmZhZDNlZmVmMmIwZWEyNmRiM2Q2YzIxZmY4NmJhYzIxMzNlYmIwMGJi
15
+ NjE0MDg4MTBlYjBkYzZmM2I4Nzk3MjI0NTM5YTVmZWU5MmU0MmM=
@@ -0,0 +1,36 @@
1
+ # Change Log
2
+
3
+ ## [v0.2.0](https://github.com/TheODI-UD2D/blocktrain/tree/v0.2.0) (2015-11-10)
4
+ [Full Changelog](https://github.com/TheODI-UD2D/blocktrain/compare/v0.1.4...v0.2.0)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - Add simple query interface [\#6](https://github.com/TheODI-UD2D/blocktrain/pull/6) ([Floppy](https://github.com/Floppy))
9
+ - Genericise all the things [\#5](https://github.com/TheODI-UD2D/blocktrain/pull/5) ([pezholio](https://github.com/pezholio))
10
+
11
+ ## [v0.1.4](https://github.com/TheODI-UD2D/blocktrain/tree/v0.1.4) (2015-11-09)
12
+ [Full Changelog](https://github.com/TheODI-UD2D/blocktrain/compare/v0.1.2...v0.1.4)
13
+
14
+ **Merged pull requests:**
15
+
16
+ - Publish to rubygems when new tags are pushed [\#4](https://github.com/TheODI-UD2D/blocktrain/pull/4) ([pezholio](https://github.com/pezholio))
17
+ - Elasticsearch 2.0.0 [\#3](https://github.com/TheODI-UD2D/blocktrain/pull/3) ([pezholio](https://github.com/pezholio))
18
+
19
+ ## [v0.1.2](https://github.com/TheODI-UD2D/blocktrain/tree/v0.1.2) (2015-10-29)
20
+ [Full Changelog](https://github.com/TheODI-UD2D/blocktrain/compare/v0.1.1...v0.1.2)
21
+
22
+ **Merged pull requests:**
23
+
24
+ - Build lookups [\#2](https://github.com/TheODI-UD2D/blocktrain/pull/2) ([pikesley](https://github.com/pikesley))
25
+
26
+ ## [v0.1.1](https://github.com/TheODI-UD2D/blocktrain/tree/v0.1.1) (2015-10-27)
27
+ [Full Changelog](https://github.com/TheODI-UD2D/blocktrain/compare/v0.1.0...v0.1.1)
28
+
29
+ **Merged pull requests:**
30
+
31
+ - Pull out client [\#1](https://github.com/TheODI-UD2D/blocktrain/pull/1) ([pikesley](https://github.com/pikesley))
32
+
33
+ ## [v0.1.0](https://github.com/TheODI-UD2D/blocktrain/tree/v0.1.0) (2015-10-27)
34
+
35
+
36
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
@@ -39,4 +39,5 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency 'webmock', '~> 1.21'
40
40
  spec.add_development_dependency 'coveralls', '~> 0.8'
41
41
  spec.add_development_dependency 'terminal-notifier-guard', '~> 1.6'
42
+ spec.add_development_dependency 'github_changelog_generator', '~> 1.9'
42
43
  end
@@ -0,0 +1 @@
1
+ train_speed: "@.MWT.M_T3_1.MRV_TrnSpd_1.TON_4.MRV_Xv_Trn"
@@ -7,10 +7,12 @@ require 'singleton'
7
7
 
8
8
  require 'blocktrain/version'
9
9
  require 'blocktrain/client'
10
- require 'blocktrain/lookups'
11
10
  require 'blocktrain/query'
12
11
  require 'blocktrain/aggregation'
12
+ require 'blocktrain/aggregations/histogram_aggregation'
13
13
  require 'blocktrain/aggregations/average_aggregation'
14
14
  require 'blocktrain/aggregations/min_max_aggregation'
15
+ require 'blocktrain/aggregations/terms_aggregation'
16
+ require 'blocktrain/lookups'
15
17
 
16
18
  Dotenv.load
@@ -10,21 +10,7 @@ module Blocktrain
10
10
  end
11
11
 
12
12
  def aggs
13
- {
14
- results: {
15
- date_histogram: {
16
- field: 'timeStamp',
17
- interval: @interval,
18
- time_zone: '+01:00',
19
- min_doc_count: 1,
20
- extended_bounds: {
21
- min: @from,
22
- max: @to
23
- }
24
- },
25
- aggregations: local_aggregations
26
- }
27
- }
13
+ raise RuntimeError.new("Aggregation cannot be used directly. Use a derived class instead like AverageAggregation.")
28
14
  end
29
15
 
30
16
  def body
@@ -35,9 +21,5 @@ module Blocktrain
35
21
  }
36
22
  end
37
23
 
38
- def local_aggregations
39
- raise RuntimeError.new("Aggregation cannot be used directly. Use a derived class instead like AverageAggregation.")
40
- end
41
-
42
24
  end
43
25
  end
@@ -1,6 +1,6 @@
1
1
  module Blocktrain
2
2
  module Aggregations
3
- class AverageAggregation < Aggregation
3
+ class AverageAggregation < HistogramAggregation
4
4
 
5
5
  def local_aggregations
6
6
  {
@@ -0,0 +1,25 @@
1
+ module Blocktrain
2
+ module Aggregations
3
+ class HistogramAggregation < Aggregation
4
+
5
+ def aggs
6
+ {
7
+ results: {
8
+ date_histogram: {
9
+ field: 'timeStamp',
10
+ interval: @interval,
11
+ time_zone: '+01:00',
12
+ min_doc_count: 1,
13
+ extended_bounds: {
14
+ min: @from,
15
+ max: @to
16
+ }
17
+ },
18
+ aggregations: local_aggregations
19
+ }
20
+ }
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -1,6 +1,6 @@
1
1
  module Blocktrain
2
2
  module Aggregations
3
- class MinMaxAggregation < Aggregation
3
+ class MinMaxAggregation < HistogramAggregation
4
4
 
5
5
  def local_aggregations
6
6
  {
@@ -0,0 +1,33 @@
1
+ module Blocktrain
2
+ module Aggregations
3
+ class TermsAggregation < Aggregation
4
+
5
+ def initialize(options = {})
6
+ @term = options.fetch(:term, nil)
7
+ raise ArgumentError.new("TermAggregation requires a term: argument") unless @term
8
+ super
9
+ end
10
+
11
+ def query
12
+ {
13
+ filtered: {
14
+ filter: filtered_filter
15
+ }
16
+ }
17
+ end
18
+
19
+ def aggs
20
+ {
21
+ langs: {
22
+ terms: { field: @term }
23
+ }
24
+ }
25
+ end
26
+
27
+ def results
28
+ result['aggregations']['langs']['buckets']
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -2,14 +2,33 @@ module Blocktrain
2
2
  class Lookups
3
3
  include Singleton
4
4
 
5
- def initialize
6
- @lookups = OpenStruct.new fetch_yaml 'lookups'
7
- end
8
-
9
5
  def lookups
6
+ init! if @lookups.nil?
10
7
  @lookups
11
8
  end
12
9
 
10
+ def reset!
11
+ @lookups = nil
12
+ end
13
+
14
+ # Separate out initialization for testing purposes
15
+ def init!
16
+ @lookups ||= {}
17
+ # Get unique list of keys from ES
18
+ r = Aggregations::TermsAggregation.new(from: '2015-09-01 10:00:00Z', to: '2015-09-01 11:00:00Z', term: "memoryAddress").results
19
+ addresses = r.map {|x| x["key"]}
20
+ # Get a memory location for each key
21
+ addresses.each do |address|
22
+ r = Query.new(from: '2015-09-01 10:00:00Z', to: '2015-09-01 11:00:00Z', memory_address: address, limit: 1).results
23
+ @lookups[r.first["_source"]["signalName"].to_s] = address
24
+ end
25
+ # Read aliases from file
26
+ aliases = OpenStruct.new fetch_yaml 'signal_aliases'
27
+ aliases.each_pair do |key, value|
28
+ @lookups[key.to_s] = @lookups[value]
29
+ end
30
+ end
31
+
13
32
  private
14
33
 
15
34
  def fetch_yaml file
@@ -2,9 +2,8 @@ module Blocktrain
2
2
  class Query
3
3
 
4
4
  def initialize(options = {})
5
- @lookups = Lookups.instance.lookups
5
+ @memory_address = options.fetch(:memory_address, nil)
6
6
  @signal = options[:signal]
7
- @sub_signal = options[:sub_signal]
8
7
 
9
8
  @from = parse_datetime(options.fetch(:from, '2015-09-01T00:00:00'))
10
9
  @to = parse_datetime(options.fetch(:to, '2015-09-02T00:00:00'))
@@ -26,39 +25,47 @@ module Blocktrain
26
25
  end
27
26
 
28
27
  def address_query
29
- if @lookups[@signal].is_a?(Hash)
30
- if @sub_signal.nil?
31
- @lookups[@signal].map { |k, v| "memoryAddress:#{v}" }.join(' OR ')
32
- else
33
- "memoryAddress:#{@lookups[@signal][@sub_signal]}"
34
- end
35
- else
36
- "memoryAddress:#{@lookups[@signal]}"
37
- end
28
+ # Look up memory addresses directly if specified
29
+ return "memoryAddress:#{@memory_address}" if @memory_address
30
+ # No query if there isn't a signal specified
31
+ return nil if @signal.nil?
32
+ # Find the right memory address
33
+ lookups = Lookups.instance.lookups
34
+ "memoryAddress:#{lookups[@signal]}"
38
35
  end
39
36
 
40
37
  def query
41
38
  {
42
39
  filtered: {
43
- query: {
44
- query_string: {
45
- query: address_query
46
- }
47
- },
48
- filter: {
49
- bool: {
50
- must: [
51
- {
52
- range: {
53
- timeStamp: {
54
- gte: @from,
55
- lte: @to
56
- }
57
- }
40
+ query: filtered_query,
41
+ filter: filtered_filter
42
+ }
43
+ }
44
+ end
45
+
46
+ def filtered_query
47
+ q = address_query
48
+ return {} if q.nil?
49
+ {
50
+ query_string: {
51
+ query: q
52
+ }
53
+ }
54
+ end
55
+
56
+ def filtered_filter
57
+ {
58
+ bool: {
59
+ must: [
60
+ {
61
+ range: {
62
+ timeStamp: {
63
+ gte: @from,
64
+ lte: @to
58
65
  }
59
- ]
66
+ }
60
67
  }
61
- }
68
+ ]
62
69
  }
63
70
  }
64
71
  end
@@ -1,3 +1,3 @@
1
1
  module Blocktrain
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pikesley
@@ -165,6 +165,20 @@ dependencies:
165
165
  - - ~>
166
166
  - !ruby/object:Gem::Version
167
167
  version: '1.6'
168
+ - !ruby/object:Gem::Dependency
169
+ name: github_changelog_generator
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ~>
173
+ - !ruby/object:Gem::Version
174
+ version: '1.9'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ~>
180
+ - !ruby/object:Gem::Version
181
+ version: '1.9'
168
182
  description: Train of fools
169
183
  email:
170
184
  - ops@theodi.org
@@ -176,6 +190,7 @@ files:
176
190
  - .rspec
177
191
  - .ruby-version
178
192
  - .travis.yml
193
+ - CHANGELOG.md
179
194
  - Gemfile
180
195
  - Guardfile
181
196
  - LICENSE.md
@@ -184,11 +199,13 @@ files:
184
199
  - bin/console
185
200
  - bin/setup
186
201
  - blocktrain.gemspec
187
- - config/lookups.yml
202
+ - config/signal_aliases.yml
188
203
  - lib/blocktrain.rb
189
204
  - lib/blocktrain/aggregation.rb
190
205
  - lib/blocktrain/aggregations/average_aggregation.rb
206
+ - lib/blocktrain/aggregations/histogram_aggregation.rb
191
207
  - lib/blocktrain/aggregations/min_max_aggregation.rb
208
+ - lib/blocktrain/aggregations/terms_aggregation.rb
192
209
  - lib/blocktrain/client.rb
193
210
  - lib/blocktrain/lookups.rb
194
211
  - lib/blocktrain/query.rb
@@ -1,6 +0,0 @@
1
- passenger_load:
2
- A: 2E64930W
3
- B: 2E64932W
4
- C: 2E64934W
5
- D: 2E64936W
6
- train_speed: 2E491EEW