blocktrain 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +5 -5
- data/config/lookups.yml +2 -1
- data/lib/blocktrain.rb +3 -2
- data/lib/blocktrain/aggregation.rb +9 -49
- data/lib/blocktrain/aggregations/{train_weight_aggregation.rb → average_aggregation.rb} +3 -2
- data/lib/blocktrain/aggregations/{car_weight_aggregation.rb → min_max_aggregation.rb} +5 -5
- data/lib/blocktrain/query.rb +80 -0
- data/lib/blocktrain/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Yjc1MTFiYTIzODY2MTBiZjA3MTdkZTI5ODE1MDM4Njc1ZTQxY2JiNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmMwNTgzZGRlMGMwZDUyZjUxMTZiMGNjNDI3NjY4ZWIyZDQ2NTRlNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzRmZDgwYzAyMThjYTJjZmI1NmM0NzVhYTI4MjJjNDBiYTc3MzZiYzRhNzVi
|
10
|
+
YTkwODA0OTg1ZGI4YjAzNjZjMmU1NTY5ODI4ODhmNjM4ZmJiNGUxNzk4YTcw
|
11
|
+
M2Y0YzZiNmMzZTljYzFhYTFiOTNjMDc4NmU0NTRmZGY4OWZjMjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDUzNzRjYjNiMmFlMTNmNTNiZmYyOTI2ZDJhYjBkODdmYTlkODQzMDVmMzY2
|
14
|
+
NDgyNGY0NDcyMDY4N2VlOWUwYmQxYWE3ZWNiYWQ3NDFlMDZiZmFkMzcxNzAz
|
15
|
+
YTkyZWQwMDhkNzljMWJlMWUyNTZjZDFlMjdlYjdjNDgwZmQ2NjI=
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
[![Build Status](http://img.shields.io/travis/
|
2
|
-
[![Dependency Status](http://img.shields.io/gemnasium/
|
3
|
-
[![Coverage Status](http://img.shields.io/coveralls/
|
4
|
-
[![Code Climate](http://img.shields.io/codeclimate/github/
|
1
|
+
[![Build Status](http://img.shields.io/travis/TheODI-UD2D/blocktrain.svg?style=flat-square)](https://travis-ci.org/TheODI-UD2D/blocktrain)
|
2
|
+
[![Dependency Status](http://img.shields.io/gemnasium/TheODI-UD2D/blocktrain.svg?style=flat-square)](https://gemnasium.com/TheODI-UD2D/blocktrain)
|
3
|
+
[![Coverage Status](http://img.shields.io/coveralls/TheODI-UD2D/blocktrain.svg?style=flat-square)](https://coveralls.io/r/TheODI-UD2D/blocktrain)
|
4
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/TheODI-UD2D/blocktrain.svg?style=flat-square)](https://codeclimate.com/github/TheODI-UD2D/blocktrain)
|
5
5
|
[![Gem Version](http://img.shields.io/gem/v/blocktrain.svg?style=flat-square)](https://rubygems.org/gems/blocktrain)
|
6
|
-
[![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://
|
6
|
+
[![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://TheODI-UD2D.mit-license.org)
|
7
7
|
|
8
8
|
# Blocktrain
|
9
9
|
|
data/config/lookups.yml
CHANGED
data/lib/blocktrain.rb
CHANGED
@@ -8,8 +8,9 @@ require 'singleton'
|
|
8
8
|
require 'blocktrain/version'
|
9
9
|
require 'blocktrain/client'
|
10
10
|
require 'blocktrain/lookups'
|
11
|
+
require 'blocktrain/query'
|
11
12
|
require 'blocktrain/aggregation'
|
12
|
-
require 'blocktrain/aggregations/
|
13
|
-
require 'blocktrain/aggregations/
|
13
|
+
require 'blocktrain/aggregations/average_aggregation'
|
14
|
+
require 'blocktrain/aggregations/min_max_aggregation'
|
14
15
|
|
15
16
|
Dotenv.load
|
@@ -1,62 +1,17 @@
|
|
1
1
|
module Blocktrain
|
2
|
-
class Aggregation
|
2
|
+
class Aggregation < Query
|
3
3
|
def initialize(options = {})
|
4
|
-
@lookups = Lookups.instance.lookups
|
5
|
-
@car = options[:car]
|
6
|
-
|
7
|
-
@from = parse_datetime(options.fetch(:from, '2015-09-01T00:00:00'))
|
8
|
-
@to = parse_datetime(options.fetch(:to, '2015-09-02T00:00:00'))
|
9
|
-
|
10
4
|
@interval = options.fetch(:interval, '10m')
|
5
|
+
super
|
11
6
|
end
|
12
7
|
|
13
8
|
def results
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def parse_datetime(datetime)
|
18
|
-
utc = Time.parse(datetime).utc
|
19
|
-
return utc.to_i * 1000
|
20
|
-
end
|
21
|
-
|
22
|
-
def address_query
|
23
|
-
if @car.nil?
|
24
|
-
@lookups['car_codes'].map { |car, code| "memoryAddress:#{code}" }.join(' OR ')
|
25
|
-
else
|
26
|
-
"memoryAddress:#{@lookups['car_codes'][@car]}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def query
|
31
|
-
{
|
32
|
-
filtered: {
|
33
|
-
query: {
|
34
|
-
query_string: {
|
35
|
-
analyze_wildcard: true,
|
36
|
-
query: address_query
|
37
|
-
}
|
38
|
-
},
|
39
|
-
filter: {
|
40
|
-
bool: {
|
41
|
-
must: [
|
42
|
-
{
|
43
|
-
range: {
|
44
|
-
timeStamp: {
|
45
|
-
gte: @from,
|
46
|
-
lte: @to
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}
|
50
|
-
]
|
51
|
-
}
|
52
|
-
}
|
53
|
-
}
|
54
|
-
}
|
9
|
+
result['aggregations']
|
55
10
|
end
|
56
11
|
|
57
12
|
def aggs
|
58
13
|
{
|
59
|
-
|
14
|
+
results: {
|
60
15
|
date_histogram: {
|
61
16
|
field: 'timeStamp',
|
62
17
|
interval: @interval,
|
@@ -79,5 +34,10 @@ module Blocktrain
|
|
79
34
|
aggregations: aggs,
|
80
35
|
}
|
81
36
|
end
|
37
|
+
|
38
|
+
def local_aggregations
|
39
|
+
raise RuntimeError.new("Aggregation cannot be used directly. Use a derived class instead like AverageAggregation.")
|
40
|
+
end
|
41
|
+
|
82
42
|
end
|
83
43
|
end
|
@@ -1,16 +1,17 @@
|
|
1
1
|
module Blocktrain
|
2
2
|
module Aggregations
|
3
|
-
class
|
3
|
+
class AverageAggregation < Aggregation
|
4
4
|
|
5
5
|
def local_aggregations
|
6
6
|
{
|
7
|
-
|
7
|
+
average_value: {
|
8
8
|
avg: {
|
9
9
|
field: 'value'
|
10
10
|
}
|
11
11
|
}
|
12
12
|
}
|
13
13
|
end
|
14
|
+
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
module Blocktrain
|
2
2
|
module Aggregations
|
3
|
-
class
|
3
|
+
class MinMaxAggregation < Aggregation
|
4
4
|
|
5
5
|
def local_aggregations
|
6
6
|
{
|
7
|
-
|
7
|
+
value: {
|
8
8
|
terms: { field: 'memoryAddress' },
|
9
9
|
aggregations: {
|
10
|
-
|
10
|
+
average_value: {
|
11
11
|
avg: {
|
12
12
|
field: 'value'
|
13
13
|
}
|
14
14
|
},
|
15
|
-
|
15
|
+
max_value: {
|
16
16
|
max: {
|
17
17
|
field: 'value'
|
18
18
|
}
|
19
19
|
},
|
20
|
-
|
20
|
+
min_value: {
|
21
21
|
min: {
|
22
22
|
field: 'value'
|
23
23
|
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Blocktrain
|
2
|
+
class Query
|
3
|
+
|
4
|
+
def initialize(options = {})
|
5
|
+
@lookups = Lookups.instance.lookups
|
6
|
+
@signal = options[:signal]
|
7
|
+
@sub_signal = options[:sub_signal]
|
8
|
+
|
9
|
+
@from = parse_datetime(options.fetch(:from, '2015-09-01T00:00:00'))
|
10
|
+
@to = parse_datetime(options.fetch(:to, '2015-09-02T00:00:00'))
|
11
|
+
|
12
|
+
@limit = options.fetch(:limit, 100)
|
13
|
+
end
|
14
|
+
|
15
|
+
def results
|
16
|
+
result['hits']['hits']
|
17
|
+
end
|
18
|
+
|
19
|
+
def hits
|
20
|
+
result['hits']['total']
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_datetime(datetime)
|
24
|
+
utc = Time.parse(datetime).utc
|
25
|
+
return utc.to_i * 1000
|
26
|
+
end
|
27
|
+
|
28
|
+
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
|
38
|
+
end
|
39
|
+
|
40
|
+
def query
|
41
|
+
{
|
42
|
+
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
|
+
}
|
58
|
+
}
|
59
|
+
]
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def body
|
67
|
+
{
|
68
|
+
query: query,
|
69
|
+
size: @limit
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def result
|
76
|
+
Client.results(body)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
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.
|
4
|
+
version: 0.2.0
|
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-11-
|
12
|
+
date: 2015-11-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dotenv
|
@@ -187,10 +187,11 @@ files:
|
|
187
187
|
- config/lookups.yml
|
188
188
|
- lib/blocktrain.rb
|
189
189
|
- lib/blocktrain/aggregation.rb
|
190
|
-
- lib/blocktrain/aggregations/
|
191
|
-
- lib/blocktrain/aggregations/
|
190
|
+
- lib/blocktrain/aggregations/average_aggregation.rb
|
191
|
+
- lib/blocktrain/aggregations/min_max_aggregation.rb
|
192
192
|
- lib/blocktrain/client.rb
|
193
193
|
- lib/blocktrain/lookups.rb
|
194
|
+
- lib/blocktrain/query.rb
|
194
195
|
- lib/blocktrain/version.rb
|
195
196
|
homepage: http://github.org/theodi/blocktrain
|
196
197
|
licenses:
|