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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTY2NWYwMTg2NWZmYmE3MGRiNjMwNGI0YzI0ZjZmOTMwNmM4NTFhOA==
4
+ Yjc1MTFiYTIzODY2MTBiZjA3MTdkZTI5ODE1MDM4Njc1ZTQxY2JiNQ==
5
5
  data.tar.gz: !binary |-
6
- ZTk2OWE1YjFmMzc2MjJiYzZlMjUzMGI4YWQ2OTU1YTNmMTFiMDkwOQ==
6
+ YmMwNTgzZGRlMGMwZDUyZjUxMTZiMGNjNDI3NjY4ZWIyZDQ2NTRlNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjQ0Nzk4NGY3NjMyYTljYjFiOWJkZWI2ZDhiZDVkNDBiZGM1YjMzODgxZTgy
10
- YjczZGM0ZTk4NDhlY2FhMWU1YWUxNjNjNjZkYmEyZDU2OTg3MGE1NDgwODk3
11
- MTkxY2RiMjU1ZTE3NWI5NTY2ZGFlYjdlMmIwMjhiOTA5NjFhMTQ=
9
+ YzRmZDgwYzAyMThjYTJjZmI1NmM0NzVhYTI4MjJjNDBiYTc3MzZiYzRhNzVi
10
+ YTkwODA0OTg1ZGI4YjAzNjZjMmU1NTY5ODI4ODhmNjM4ZmJiNGUxNzk4YTcw
11
+ M2Y0YzZiNmMzZTljYzFhYTFiOTNjMDc4NmU0NTRmZGY4OWZjMjM=
12
12
  data.tar.gz: !binary |-
13
- MmZiYjNkZTY2NGY3MzdlODg3OTJlNGYwN2MwYjczZWUyOWVkY2Q3ZDBjZGYz
14
- YWNlZGJkNzIxNTE4OWE1MTQ4YWQyZGE2ZTFkOTYxYjY2YjZjZTE0NGMwZTRl
15
- MGJjZTdhMDlhN2RjNDBkNzNjMzUyYzNhZGQxNzZkNzcwMTUzMTk=
13
+ NDUzNzRjYjNiMmFlMTNmNTNiZmYyOTI2ZDJhYjBkODdmYTlkODQzMDVmMzY2
14
+ NDgyNGY0NDcyMDY4N2VlOWUwYmQxYWE3ZWNiYWQ3NDFlMDZiZmFkMzcxNzAz
15
+ YTkyZWQwMDhkNzljMWJlMWUyNTZjZDFlMjdlYjdjNDgwZmQ2NjI=
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- [![Build Status](http://img.shields.io/travis/theodi/blocktrain.svg?style=flat-square)](https://travis-ci.org/theodi/blocktrain)
2
- [![Dependency Status](http://img.shields.io/gemnasium/theodi/blocktrain.svg?style=flat-square)](https://gemnasium.com/theodi/blocktrain)
3
- [![Coverage Status](http://img.shields.io/coveralls/theodi/blocktrain.svg?style=flat-square)](https://coveralls.io/r/theodi/blocktrain)
4
- [![Code Climate](http://img.shields.io/codeclimate/github/theodi/blocktrain.svg?style=flat-square)](https://codeclimate.com/github/theodi/blocktrain)
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://theodi.mit-license.org)
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
@@ -1,5 +1,6 @@
1
- car_codes:
1
+ passenger_load:
2
2
  A: 2E64930W
3
3
  B: 2E64932W
4
4
  C: 2E64934W
5
5
  D: 2E64936W
6
+ train_speed: 2E491EEW
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/train_weight_aggregation'
13
- require 'blocktrain/aggregations/car_weight_aggregation'
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
- Client.results(body)['aggregations']
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
- weight_chart: {
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 TrainWeightAggregation < Aggregation
3
+ class AverageAggregation < Aggregation
4
4
 
5
5
  def local_aggregations
6
6
  {
7
- weight: {
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 CarWeightAggregation < Aggregation
3
+ class MinMaxAggregation < Aggregation
4
4
 
5
5
  def local_aggregations
6
6
  {
7
- weight: {
7
+ value: {
8
8
  terms: { field: 'memoryAddress' },
9
9
  aggregations: {
10
- avg_weight: {
10
+ average_value: {
11
11
  avg: {
12
12
  field: 'value'
13
13
  }
14
14
  },
15
- max_weight: {
15
+ max_value: {
16
16
  max: {
17
17
  field: 'value'
18
18
  }
19
19
  },
20
- min_weight: {
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
@@ -1,3 +1,3 @@
1
1
  module Blocktrain
2
- VERSION = '0.1.4'
2
+ VERSION = '0.2.0'
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.4
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-09 00:00:00.000000000 Z
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/car_weight_aggregation.rb
191
- - lib/blocktrain/aggregations/train_weight_aggregation.rb
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: