Mailinglist Archive: yast-commit (1914 mails)

< Previous Next >
[yast-commit] <rest-service> network : status module: code review, adapting jreidingers suggestions
  • From: Bjoern Geuken <bgeuken@xxxxxxx>
  • Date: Tue, 1 Sep 2009 15:16:08 +0200
  • Message-id: <E1MkYlM-0001e8-SK@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit a3bcb824d67e618485e7710eff276038ebfafd68
Author: Bjoern Geuken <bgeuken@xxxxxxx>
Date: Tue Sep 1 15:16:08 2009 +0200

status module: code review, adapting jreidingers suggestions
---
plugins/status/lib/status.rb | 37 +++++++++++++-----------------
plugins/status/test/unit/status_test.rb | 4 +++
2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/plugins/status/lib/status.rb b/plugins/status/lib/status.rb
index 58b7344..a5154d7 100644
--- a/plugins/status/lib/status.rb
+++ b/plugins/status/lib/status.rb
@@ -204,29 +204,24 @@ class Status
nexttime = 9.9e+99
result["starttime"] = 9.9e+99
lines.each do |l| # each time
- unless l.blank?
- if l =~ /\d*:\D*/
- pair = l.split ":"
- values = pair[1].split " "
- column = 0
- values.each do |v| # each label
- if result["interval"].nil?
- if pair[0].to_i < result["starttime"].to_i
- result["starttime"] = pair[0].to_i
- elsif pair[0].to_i < nexttime and pair[0].to_i >
result["starttime"].to_i
- nexttime = pair[0].to_i
- end
- end
-
- if v != "nan" #store valid values only
- result["#{labels[column]}"] ||= Hash.new
- result["#{labels[column]}"].merge!({"#{pair[0].chomp(": ")}"
=> v})
- column += 1
- else
- result["#{labels[column]}"] ||= Hash.new
- result["#{labels[column]}"].merge!({"#{pair[0].chomp(": ")}"
=> "invalid"})
+ next if l.blank?
+ if l =~ /\d*:\D*/
+ pair = l.split ":"
+ values = pair[1].split " "
+ column = 0
+ values.each do |v| # each label
+ unless result["interval"] # already defined?
+ # get the least distance to evaluate time interval
+ if pair[0].to_i < result["starttime"].to_i
+ result["starttime"] = pair[0].to_i
+ elsif pair[0].to_i < nexttime and pair[0].to_i >
result["starttime"].to_i
+ nexttime = pair[0].to_i
end
end
+ v = "invalid" if v == "nan" #store valid values only
+ result[labels[column]] ||= Hash.new
+ result[labels[column]][pair[0]] = v
+ column += 1
end
end
end
diff --git a/plugins/status/test/unit/status_test.rb
b/plugins/status/test/unit/status_test.rb
index 06eb93b..42ae54d 100644
--- a/plugins/status/test/unit/status_test.rb
+++ b/plugins/status/test/unit/status_test.rb
@@ -87,16 +87,20 @@ EOF

expected_response = {"tx"=>
{"1248092580"=>"4.3878571429e+01",
+ "1248093140"=>"invalid",
"1248092790"=>"4.0714285714e+00",
+ "1248092230"=>"invalid",
"1248092440"=>"4.0992857143e+01",
"1248093000"=>"1.5542857143e+01",
"1248092650"=>"9.7942857143e+01",
"1248092860"=>"2.4142857143e+00",
+ "1248092090"=>"invalid",
"1248092300"=>"4.0500000000e+00",
"1248092510"=>"3.4264285714e+01",
"1248093070"=>"2.7071428571e+00",
"1248092720"=>"2.9928571429e+00",
"1248092930"=>"2.8285714286e+00",
+ "1248092160"=>"invalid",
"1248092370"=>"2.1435714286e+01"},
"rx"=>
{"1248092580"=>"7.7485714286e+01",
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages