expedition 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88b001358532eca38c34e829587ff88f5ce5e0f0
4
- data.tar.gz: 38bf70bc6eec3aee3453487d19833170eac1c4af
3
+ metadata.gz: b469b07e45e60d178dbfa91fa63c46c7d3d0f3ea
4
+ data.tar.gz: 88fdd81ad47d6d705cf314c72a6b66f0d4dacffe
5
5
  SHA512:
6
- metadata.gz: 111ba58baef943aac22bd2b4a618f56e40b375d27b8395b0f6fcd016bf30922eadb588f9275cb5e9c91ee2f96b67a1bbb3f63cde0b53b07c764f7614c200b7d2
7
- data.tar.gz: b51384cbb26b4c65bb5a075f59a9ba4a24a562cce966c8f8a875051af0585e27cb313866a4b70cec78c54a5d52709e317e6b537de0af3fa8214452267abd73c2
6
+ metadata.gz: 263182dee4dc4eaf432fb2bd3e1df358d9f90345f8203965e144b27665f354944af9e735ea0c0253c3eeeab4559a852863679f2bb312af54ab261d3b37b6d7e2
7
+ data.tar.gz: 05b339be299f3f259dbd023e5899d97c817795d77d2aee47f27ed8addacbbabc6a8197df5a3b7f2d63e8b8e2ef379e00b485d14a22cb26c611eafead42773ddd
@@ -41,12 +41,7 @@ module Expedition
41
41
 
42
42
  def metrics
43
43
  send(:devs) do |body|
44
- body[:devs].collect { |attrs|
45
- attrs.merge(
46
- enabled: attrs[:enabled] == 'Y',
47
- status: attrs[:status].downcase
48
- )
49
- }
44
+ body[:devs].collect(&method(:parse_metrics))
50
45
  end
51
46
  end
52
47
 
@@ -85,5 +80,22 @@ module Expedition
85
80
  def command_json(command, *parameters)
86
81
  MultiJson.dump(command: command, parameter: parameters.join(','))
87
82
  end
83
+
84
+ def parse_metrics(attrs)
85
+ attrs.merge!(
86
+ enabled: attrs[:enabled] == 'Y',
87
+ status: attrs[:status].downcase,
88
+ last_share_time: (Time.at(attrs[:last_share_time]) rescue attrs[:last_share_time]),
89
+ last_valid_work: (Time.at(attrs[:last_valid_work]) rescue attrs[:last_valid_work])
90
+ )
91
+
92
+ interval = attrs.keys.detect { |k| k =~ /^mhs_\d+s$/ }[/\d+s$/]
93
+
94
+ # Remove the `_Ns` suffix from hash rate fields.
95
+ attrs.merge!(
96
+ mhs: attrs.delete("mhs_#{interval}"),
97
+ khs: attrs.delete("khs_#{interval}")
98
+ )
99
+ end
88
100
  end # Client
89
101
  end # Expedition
@@ -1,3 +1,3 @@
1
1
  module Expedition
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -61,4 +61,205 @@ describe Expedition::Client do
61
61
  end
62
62
  end
63
63
  end
64
+
65
+ describe '#devices' do
66
+
67
+ subject(:devices) do
68
+ client.devices
69
+ end
70
+
71
+ let(:client) do
72
+ described_class.new
73
+ end
74
+
75
+ let(:socket) do
76
+ double(TCPSocket)
77
+ end
78
+
79
+ let(:response) do
80
+ {
81
+ 'STATUS' => [
82
+ {
83
+ 'STATUS' => 'S',
84
+ 'When' => 1399577859,
85
+ 'Code' => 69,
86
+ 'Msg' => 'Device Details',
87
+ 'Description' => 'sgminer 4.1.153'
88
+ }
89
+ ],
90
+ 'DEVDETAILS' => [
91
+ {
92
+ 'DEVDETAILS' => 0,
93
+ 'Name' => 'GPU',
94
+ 'ID' => 0,
95
+ 'Driver' => 'opencl',
96
+ 'Kernel' => 'ckolivas',
97
+ 'Model' => 'AMD Radeon R9 200 Series',
98
+ 'Device Path' => ''
99
+ },
100
+ {
101
+ 'DEVDETAILS' => 1,
102
+ 'Name' => 'GPU',
103
+ 'ID' => 1,
104
+ 'Driver' => 'opencl',
105
+ 'Kernel' => 'ckolivas',
106
+ 'Model' => 'AMD Radeon R9 200 Series',
107
+ 'Device Path' => ''
108
+ },
109
+ {
110
+ 'DEVDETAILS' => 2,
111
+ 'Name' => 'GPU',
112
+ 'ID' => 2,
113
+ 'Driver' => 'opencl',
114
+ 'Kernel' => 'ckolivas',
115
+ 'Model' => 'AMD Radeon R9 200 Series',
116
+ 'Device Path' => ''
117
+ }
118
+ ],
119
+ 'id' => 1
120
+ }.to_json
121
+ end
122
+
123
+ before do
124
+ allow(TCPSocket).to receive(:new).with(client.host, client.port).and_return(socket)
125
+ allow(socket).to receive(:puts)
126
+ allow(socket).to receive(:gets).and_return(response)
127
+ end
128
+
129
+ specify do
130
+ expect(devices.body).to eq([
131
+ {
132
+ 'device_path' => '',
133
+ 'driver' => 'opencl',
134
+ 'id' => 0,
135
+ 'kernel' => 'ckolivas',
136
+ 'model' => 'AMD Radeon R9 200 Series',
137
+ 'variant' => 'gpu'
138
+ },
139
+ {
140
+ 'device_path' => '',
141
+ 'driver' => 'opencl',
142
+ 'id' => 1,
143
+ 'kernel' => 'ckolivas',
144
+ 'model' => 'AMD Radeon R9 200 Series',
145
+ 'variant' => 'gpu'
146
+ },
147
+ {
148
+ 'device_path' => '',
149
+ 'driver' => 'opencl',
150
+ 'id' => 2,
151
+ 'kernel' => 'ckolivas',
152
+ 'model' => 'AMD Radeon R9 200 Series',
153
+ 'variant' => 'gpu'
154
+ }
155
+ ])
156
+ end
157
+ end
158
+
159
+ describe '#metrics' do
160
+
161
+ subject(:metrics) do
162
+ client.metrics
163
+ end
164
+
165
+ let(:client) do
166
+ described_class.new
167
+ end
168
+
169
+ let(:socket) do
170
+ double(TCPSocket)
171
+ end
172
+
173
+ let(:response) do
174
+ {
175
+ 'STATUS' => [
176
+ {
177
+ 'STATUS' => 'S',
178
+ 'When' => 1399419744,
179
+ 'Code' => 9,
180
+ 'Msg' => '3 GPU(s)',
181
+ 'Description' => 'sgminer 4.1.153'
182
+ }
183
+ ],
184
+ 'DEVS' => [
185
+ {
186
+ 'Accepted' => 2,
187
+ 'Device Elapsed' => 11,
188
+ 'Device Hardware%' => 0.0,
189
+ 'Device Rejected%' => 0.0,
190
+ 'Diff1 Work' => 158,
191
+ 'Difficulty Accepted' => 256.0,
192
+ 'Difficulty Rejected' => 0.0,
193
+ 'Enabled' => 'Y',
194
+ 'Fan Percent' => 50,
195
+ 'Fan Speed' => -1,
196
+ 'GPU Activity' => 100,
197
+ 'GPU Clock' => 944,
198
+ 'GPU Voltage' => 0.0,
199
+ 'GPU' => 0,
200
+ 'Hardware Errors' => 0,
201
+ 'Intensity' => '0',
202
+ 'KHS 1s' => 923,
203
+ 'KHS av' => 915,
204
+ 'Last Share Difficulty' => 128.0,
205
+ 'Last Share Pool' => 0,
206
+ 'Last Share Time' => 1399419741,
207
+ 'Last Valid Work' => 1399419743,
208
+ 'MHS 1s' => 0.923,
209
+ 'MHS av' => 0.9148,
210
+ 'Memory Clock' => 1500,
211
+ 'Powertune' => 30,
212
+ 'Rejected' => 0,
213
+ 'Status' => 'Alive',
214
+ 'Temperature' => 68.0,
215
+ 'Total MH' => 10.1489,
216
+ 'Utility' => 10.8166
217
+ }
218
+ ],
219
+ 'id' => 1
220
+ }.to_json
221
+ end
222
+
223
+ before do
224
+ allow(TCPSocket).to receive(:new).with(client.host, client.port).and_return(socket)
225
+ allow(socket).to receive(:puts)
226
+ allow(socket).to receive(:gets).and_return(response)
227
+ end
228
+
229
+ specify do
230
+ expect(metrics.body).to eq([
231
+ 'accepted' => 2,
232
+ 'device_elapsed' => 11,
233
+ 'device_hardware_percent' => 0.0,
234
+ 'device_rejected_percent' => 0.0,
235
+ 'diff1_work' => 158,
236
+ 'difficulty_accepted' => 256.0,
237
+ 'difficulty_rejected' => 0.0,
238
+ 'enabled' => true,
239
+ 'fan_percent' => 50,
240
+ 'fan_speed' => -1,
241
+ 'gpu' => 0,
242
+ 'gpu_activity' => 100,
243
+ 'gpu_clock' => 944,
244
+ 'gpu_voltage' => 0.0,
245
+ 'hardware_errors' => 0,
246
+ 'intensity' => '0',
247
+ 'khs' => 923,
248
+ 'khs_av' => 915,
249
+ 'last_share_difficulty' => 128.0,
250
+ 'last_share_pool' => 0,
251
+ 'last_share_time' => Time.utc(2014, 05, 06, 23, 42, 21),
252
+ 'last_valid_work' => Time.utc(2014, 05, 06, 23, 42, 23),
253
+ 'memory_clock' => 1500,
254
+ 'mhs' => 0.923,
255
+ 'mhs_av' => 0.9148,
256
+ 'powertune' => 30,
257
+ 'rejected' => 0,
258
+ 'status' => 'alive',
259
+ 'temperature' => 68.0,
260
+ 'total_mh' => 10.1489,
261
+ 'utility' => 10.8166
262
+ ])
263
+ end
264
+ end
64
265
  end
data/spec/spec_helper.rb CHANGED
@@ -19,6 +19,15 @@ RSpec.configure do |config|
19
19
  config.order = 'random'
20
20
  config.run_all_when_everything_filtered = true
21
21
  config.treat_symbols_as_metadata_keys_with_true_values = true
22
+
23
+ config.before(:suite) do
24
+ @time_zone = ENV['TZ']
25
+ ENV['TZ'] = 'UTC'
26
+ end
27
+
28
+ config.after(:suite) do
29
+ ENV['TZ'] = @time_zone
30
+ end
22
31
  end
23
32
 
24
33
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expedition
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabe Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-04 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json