blocktrain 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Guardfile +14 -0
- data/LICENSE.md +22 -0
- data/README.md +9 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/blocktrain.gemspec +40 -0
- data/lib/blocktrain.rb +9 -0
- data/lib/blocktrain/client.rb +106 -0
- data/lib/blocktrain/version.rb +3 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 00f8d71661cf1f2ce7b8113fbd9d8596c53b4b01
|
4
|
+
data.tar.gz: 9ebae0e584ec5ae46f827ed4d7ee2f642ca3a9c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05428c8c6cd98ac5589e86a826d1ddbd89b8b3c2c2aa60f3bbd4e0b47324a1c7ae70e1bd8401f313478dac6dac29007fac8c3ba0c50e89ba0b2a7d9033db35fb
|
7
|
+
data.tar.gz: 8e1269d337f1d472930ef888c7885f5676db449b7434821c681102c751001cc1ded49e7c2fa87d0623c2882fcc999f820502f900ae78c82c532be8f611937e8a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2.0
|
4
|
+
before_install: gem install bundler -v 1.10.6
|
5
|
+
env:
|
6
|
+
global:
|
7
|
+
secure: nFiSRLqyRVSIfB4HBUdT7NtBN8sTb25SpFa9HUQUv9A9y89RC28fxVV0ZadgWmkBqiqgYGvdhrTOphamCab+k3jSJoTYCQ3kWf7KqCAG0rzz/KtHlMeRwmMJxBEREpe+pmLNoTKg3ezCil9msK0Ru9//A7tiz24CPbb9dSdHBFds+LT0sldcP/s5EDkuX1k+XuW1vzZIBni3uYtjJGmKSvJnpD6ycC9kbahpGvZjpvV3C1KRGFdLE7tFmzgoNRADJPXVAFUXA7hv9KkEXLGfVL81RHTQIJPl6sgCGujaT7JkizyLXQd11Kv19QZABzVtMpQjihO3V3Ye5iZ0bE2P4OHsI+h85MpPI5KlqF5e/MzgepHL1bYjeRdp8ZNuf7wO9rkWpgSo5eKz1UR4SKfrilG5PHjvOTT3ICAXKOODrp0ughe3GQpn3G+sZrBhkpXMSqN9AuQtE+5jEWRVvcKfm/yzlxtQc+542OBG9Dqy/+KTW6Ea6NoYv5fFY4+uAP0/5MLLpJm5XUbWSSLNBhdEKvvTo5ADCczjVfhgIN9fNo8uDQ0EwrfkiiQnTxOzLijdgmAoYpFUnQDs0ulf2HL8wW1bZiXwimcBXttLkyFfiEXI0lwmTP3p6zG7guC1yvSJ5i2AXmGoijaN8FFijZTqsL0r0L1wUzUbCZ+aEvc787U=
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
2
|
+
require 'guard/rspec/dsl'
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
# RSpec files
|
6
|
+
rspec = dsl.rspec
|
7
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
8
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
9
|
+
watch(rspec.spec_files)
|
10
|
+
|
11
|
+
# Ruby files
|
12
|
+
ruby = dsl.ruby
|
13
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
14
|
+
end
|
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
##Copyright (c) 2015 Open Data Institute
|
2
|
+
|
3
|
+
#MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
[](https://travis-ci.org/theodi/blocktrain)
|
2
|
+
[](https://gemnasium.com/theodi/blocktrain)
|
3
|
+
[](https://coveralls.io/r/theodi/blocktrain)
|
4
|
+
[](https://codeclimate.com/github/theodi/blocktrain)
|
5
|
+
[](https://rubygems.org/gems/blocktrain)
|
6
|
+
[](http://theodi.mit-license.org)
|
7
|
+
[](https://github.com/badges/badgerbadgerbadger)
|
8
|
+
|
9
|
+
# Blocktrain
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'blocktrain'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/blocktrain.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'blocktrain/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'blocktrain'
|
8
|
+
spec.version = Blocktrain::VERSION
|
9
|
+
spec.authors = ['pikesley', 'pkqk']
|
10
|
+
spec.email = ['ops@theodi.org']
|
11
|
+
|
12
|
+
spec.summary = %q{Train train train}
|
13
|
+
spec.description = %q{Train if fools}
|
14
|
+
spec.homepage = 'http://github.org/theodi/blocktrain'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_dependency 'dotenv', '~> 2.0'
|
31
|
+
spec.add_dependency 'curb', '~> 0.8'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.3'
|
36
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.6'
|
37
|
+
spec.add_development_dependency 'vcr', '~> 2.9'
|
38
|
+
spec.add_development_dependency 'webmock', '~> 1.21'
|
39
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
40
|
+
end
|
data/lib/blocktrain.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
module Blocktrain
|
2
|
+
class Client
|
3
|
+
|
4
|
+
CAR_CODES = {
|
5
|
+
'A' => '2E64930W',
|
6
|
+
'B' => '2E64932W',
|
7
|
+
'C' => '2E64934W',
|
8
|
+
'D' => '2E64936W'
|
9
|
+
}
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
@url = ENV['ES_URL']
|
13
|
+
@car = options[:car]
|
14
|
+
|
15
|
+
@from = parse_datetime(options.fetch(:from, '2015-09-01T00:00:00'))
|
16
|
+
@to = parse_datetime(options.fetch(:to, '2015-09-02T00:00:00'))
|
17
|
+
|
18
|
+
@interval = options.fetch(:interval, '10m')
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_datetime(datetime)
|
22
|
+
utc = Time.parse(datetime).utc
|
23
|
+
return utc.to_i * 1000
|
24
|
+
end
|
25
|
+
|
26
|
+
def search
|
27
|
+
@client = Curl::Easy.http_post("#{@url}/train_data/_search", body.to_json) do |c|
|
28
|
+
c.ssl_verify_peer = false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def results
|
33
|
+
search
|
34
|
+
JSON.parse(@client.body_str)
|
35
|
+
end
|
36
|
+
|
37
|
+
def address_query
|
38
|
+
if @car.nil?
|
39
|
+
CAR_CODES.map { |code| "memoryAddress:#{code}" }.join(' OR ')
|
40
|
+
else
|
41
|
+
"memoryAddress:#{CAR_CODES[@car]}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def query
|
46
|
+
{
|
47
|
+
'filtered' => {
|
48
|
+
'query' => {
|
49
|
+
'query_string' => {
|
50
|
+
'analyze_wildcard' =>true,
|
51
|
+
'query' =>address_query
|
52
|
+
}
|
53
|
+
},
|
54
|
+
'filter' => {
|
55
|
+
'bool' => {
|
56
|
+
'must' => [
|
57
|
+
{
|
58
|
+
'range' => {
|
59
|
+
'timeStamp' => {
|
60
|
+
'gte' =>@from,
|
61
|
+
'lte' =>@to
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
],
|
66
|
+
'must_not' => []
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def aggs
|
74
|
+
{
|
75
|
+
'weight_chart' => {
|
76
|
+
'date_histogram' => {
|
77
|
+
'field' => 'timeStamp',
|
78
|
+
'interval' => @interval,
|
79
|
+
'pre_zone' => '+01:00',
|
80
|
+
'pre_zone_adjust_large_interval' =>true,
|
81
|
+
'min_doc_count' => 1,
|
82
|
+
'extended_bounds' => {
|
83
|
+
'min' =>@from,
|
84
|
+
'max' =>@to
|
85
|
+
}
|
86
|
+
},
|
87
|
+
'aggregations' => {
|
88
|
+
'weight' => {
|
89
|
+
'avg' => {
|
90
|
+
'field' => 'value'
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
},
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def body
|
99
|
+
{
|
100
|
+
'query' => query,
|
101
|
+
'size' =>0,
|
102
|
+
'aggregations' => aggs,
|
103
|
+
}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blocktrain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pikesley
|
8
|
+
- pkqk
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-10-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: dotenv
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: curb
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0.8'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0.8'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.10'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.10'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '10.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '10.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.3'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.3'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: guard-rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '4.6'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '4.6'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: vcr
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '2.9'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '2.9'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: webmock
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '1.21'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '1.21'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: coveralls
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0.8'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0.8'
|
140
|
+
description: Train if fools
|
141
|
+
email:
|
142
|
+
- ops@theodi.org
|
143
|
+
executables: []
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rspec"
|
149
|
+
- ".travis.yml"
|
150
|
+
- Gemfile
|
151
|
+
- Guardfile
|
152
|
+
- LICENSE.md
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- bin/console
|
156
|
+
- bin/setup
|
157
|
+
- blocktrain.gemspec
|
158
|
+
- lib/blocktrain.rb
|
159
|
+
- lib/blocktrain/client.rb
|
160
|
+
- lib/blocktrain/version.rb
|
161
|
+
homepage: http://github.org/theodi/blocktrain
|
162
|
+
licenses:
|
163
|
+
- MIT
|
164
|
+
metadata:
|
165
|
+
allowed_push_host: https://rubygems.org
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
requirements: []
|
181
|
+
rubyforge_project:
|
182
|
+
rubygems_version: 2.4.5
|
183
|
+
signing_key:
|
184
|
+
specification_version: 4
|
185
|
+
summary: Train train train
|
186
|
+
test_files: []
|