blocktrain 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 +8 -8
- data/CHANGELOG.md +36 -0
- data/blocktrain.gemspec +1 -0
- data/config/signal_aliases.yml +1 -0
- data/lib/blocktrain.rb +3 -1
- data/lib/blocktrain/aggregation.rb +1 -19
- data/lib/blocktrain/aggregations/average_aggregation.rb +1 -1
- data/lib/blocktrain/aggregations/histogram_aggregation.rb +25 -0
- data/lib/blocktrain/aggregations/min_max_aggregation.rb +1 -1
- data/lib/blocktrain/aggregations/terms_aggregation.rb +33 -0
- data/lib/blocktrain/lookups.rb +23 -4
- data/lib/blocktrain/query.rb +35 -28
- data/lib/blocktrain/version.rb +1 -1
- metadata +19 -2
- data/config/lookups.yml +0 -6
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmRkYjIzOTU3YzM3MGFjMmI4NTdiYTYxMDhjMmI2ZDE1NWI3MTE2ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWI5YmUyYmY1NzY5YWMxNjZkY2ZmZTgxYzJkZGMzMmJhZDBiOTBmOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTJjMTI0ZjU4NGMxYzA5YjEyYmFjY2E3MmYzNGM1OWI0M2ZhYmQ2YjI2NzQ2
|
10
|
+
ZTFlOGIwNTkxYTc1YTgxYzRlMTI1OTMyOTdmNWMyNGZkMzM1NzFlMmJhMTNh
|
11
|
+
OTg5NGFiOGFhZWM5N2M0YzU2M2MyMmExZTYyMDRiYWM4NWYwNWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTMzZjA4ZjY2ODFkNGViNzEyYzc5YjI3Y2JlZGVkNzNmY2E2NzA2MGY0ZmU4
|
14
|
+
NjU4ZmZhZDNlZmVmMmIwZWEyNmRiM2Q2YzIxZmY4NmJhYzIxMzNlYmIwMGJi
|
15
|
+
NjE0MDg4MTBlYjBkYzZmM2I4Nzk3MjI0NTM5YTVmZWU5MmU0MmM=
|
data/CHANGELOG.md
ADDED
@@ -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)*
|
data/blocktrain.gemspec
CHANGED
@@ -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"
|
data/lib/blocktrain.rb
CHANGED
@@ -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
|
@@ -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
|
@@ -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
|
data/lib/blocktrain/lookups.rb
CHANGED
@@ -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
|
data/lib/blocktrain/query.rb
CHANGED
@@ -2,9 +2,8 @@ module Blocktrain
|
|
2
2
|
class Query
|
3
3
|
|
4
4
|
def initialize(options = {})
|
5
|
-
@
|
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
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
data/lib/blocktrain/version.rb
CHANGED
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.
|
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/
|
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
|