Class: Aio::Warning::WarningSummarize
- Inherits:
-
Object
- Object
- Aio::Warning::WarningSummarize
- Defined in:
- lib/aio/core/warning/warning_summarize.rb
Instance Attribute Summary collapse
-
#device_warning ⇒ Object
readonly
设备的警告信息 device_warning = { device_name => device_warning_klass }.
-
#summary ⇒ Object
readonly
按结构保存警告信息 summary = { :serious => { :crc => { device_name => { :klass =>device_klass] , :detail => device_klass.warning }} }.
Instance Method Summary collapse
-
#append_issue(warning_info, level, device, klass) ⇒ Object
增加警告信息.
-
#append_issue_compare(warning_info, device, klass) ⇒ Object
针对compare添加警告信息 为了跟其他种类的警告信息一致,重复两次:compare.
- #compare_info ⇒ Object
-
#compare_number ⇒ Object
比较差异警告条数.
-
#device_ordinary_sort ⇒ Object
按照设备分类取到的一般警告数.
-
#device_serious_sort ⇒ Object
按照设备分类取到的严重警告数.
-
#device_warning_sort ⇒ Object
按照权重,对 device_warning 排序.
-
#get_desc(sym) ⇒ Object
通过case获取描述模块的实例.
- #has_compare? ⇒ Boolean
- #has_ordinary? ⇒ Boolean
- #has_serious? ⇒ Boolean
-
#initialize(device_manager) ⇒ WarningSummarize
constructor
A new instance of WarningSummarize.
- #inspect ⇒ Object
-
#number(hash) ⇒ Object
统计警告条目数.
- #ordinary_info ⇒ Object
-
#ordinary_number ⇒ Object
一般警告信息条数.
-
#problem_frequency ⇒ Object
发生频率高的问题.
-
#serious_description ⇒ Object
取得严重信息的描述列表 返回结构: :crc => { :description => CRC描述类, :devices => [[dev1, klass1], …] }.
-
#serious_info ⇒ Object
严重信息.
-
#serious_number ⇒ Object
严重警告条数.
-
#tidy_warning ⇒ Object
整理警告信息 改变结构变成.
-
#total_number ⇒ Object
全部警告条数.
Constructor Details
#initialize(device_manager) ⇒ WarningSummarize
Returns a new instance of WarningSummarize.
17 18 19 20 21 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 17 def initialize(device_manager) @device_manager = device_manager @description = Description.new(device_manager.module_manager) clear end |
Instance Attribute Details
#device_warning ⇒ Object (readonly)
设备的警告信息device_warning = { device_name => device_warning_klass }
15 16 17 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 15 def device_warning @device_warning end |
#summary ⇒ Object (readonly)
按结构保存警告信息summary = { :serious => { :crc => { device_name => { :klass =>device_klass] ,
:detail => device_klass.warning }} }
11 12 13 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 11 def summary @summary end |
Instance Method Details
#append_issue(warning_info, level, device, klass) ⇒ Object
增加警告信息
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 65 def append_issue(warning_info, level, device, klass) warning_info.each_pair do |issue, detail| # 如果没有, 则加入Hash unless summary[level].has_key?(issue) summary[level][issue] = {} end summary[level][issue][device] = { :klass => klass, :detail => detail } end end |
#append_issue_compare(warning_info, device, klass) ⇒ Object
针对compare添加警告信息为了跟其他种类的警告信息一致,重复两次:compare
78 79 80 81 82 83 84 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 78 def append_issue_compare(warning_info, device, klass) summary[:compare][:compare] = {} summary[:compare][:compare][device] = { klass: klass, detail: warning_info } end |
#compare_info ⇒ Object
214 215 216 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 214 def compare_info summary[:compare] end |
#compare_number ⇒ Object
比较差异警告条数
97 98 99 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 97 def compare_number number(summary[:compare]) end |
#device_ordinary_sort ⇒ Object
按照设备分类取到的一般警告数
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 159 def device_ordinary_sort st = [] @device_warning.each_pair do |name, klass| st << [name, klass.ordinary_number] end st.sort! do |x, y| y[1] <=> x[1] end st.delete_if do |x| x[0].empty? or x[1] == 0 end end |
#device_serious_sort ⇒ Object
按照设备分类取到的严重警告数
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 143 def device_serious_sort st = [] @device_warning.each_pair do |name, klass| st << [name, klass.serious_number] end st.sort! do |x, y| y[1] <=> x[1] end st.delete_if do |x| x[0].empty? or x[1] == 0 end end |
#device_warning_sort ⇒ Object
按照权重,对 device_warning 排序
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 129 def device_warning_sort arr = device_warning.to_a arr.sort! do |x, y| x1 = x[1] y1 = y[1] x_wgt = (x1.serious_number*5) + (x1.ordinary_number) + (x1.compare_number*3) y_wgt = (y1.serious_number*5) + (y1.ordinary_number) + (y1.compare_number*3) y_wgt <=> x_wgt end return arr end |
#get_desc(sym) ⇒ Object
通过case获取描述模块的实例
24 25 26 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 24 def get_desc(sym) @description.get_desc(sym) end |
#has_compare? ⇒ Boolean
124 125 126 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 124 def has_compare? compare_number > 0 ? true : false end |
#has_ordinary? ⇒ Boolean
120 121 122 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 120 def has_ordinary? ordinary_number > 0 ? true : false end |
#has_serious? ⇒ Boolean
116 117 118 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 116 def has_serious? serious_number > 0 ? true : false end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 28 def inspect "#<Aio::Warning::WarningSummarize @summary, @device_warning>" end |
#number(hash) ⇒ Object
统计警告条目数
107 108 109 110 111 112 113 114 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 107 def number(hash) num = 0 hash.each_value do |v| num += v.size end return num end |
#ordinary_info ⇒ Object
210 211 212 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 210 def ordinary_info summary[:ordinary] end |
#ordinary_number ⇒ Object
一般警告信息条数
92 93 94 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 92 def ordinary_number number(summary[:ordinary]) end |
#problem_frequency ⇒ Object
发生频率高的问题
175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 175 def problem_frequency tmp = [] summary.each_value do |info| info.each_pair do |prb, dvs| tmp << [prb, dvs.size] end end # 反向排序 tmp.sort { |x, y| x[1] <=> y[1] }.reverse end |
#serious_description ⇒ Object
取得严重信息的描述列表返回结构: :crc => { :description => CRC描述类, :devices => [[dev1, klass1], …] }
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 191 def serious_description res = {} serious_info.each_pair do |prb, dvs_info| res[prb] = { :description => @descripion.get(prb) } tmp = [] dvs_info.each_pair do |device_name, info| tmp << [device_name, info[:klass]] end res[prb][:devices] = tmp end return res end |
#serious_info ⇒ Object
严重信息
206 207 208 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 206 def serious_info summary[:serious] end |
#serious_number ⇒ Object
严重警告条数
87 88 89 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 87 def serious_number number(summary[:serious]) end |
#tidy_warning ⇒ Object
整理警告信息改变结构变成
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 34 def tidy_warning # 清除原先 summary clear devices.each_pair do |device, klass| warning_klass = klass.warning_klass @device_warning[device] = klass.warning_klass # 当有严重警告的时候 if warning_klass.has_warning_serious? append_issue(warning_klass.warning_info_serious, :serious, device, klass) end # 当有一般信息的时候 if warning_klass.has_warning_ordinary? append_issue(warning_klass.warning_info_ordinary, :ordinary, device, klass) end # 当有比较误差信息的时候 # NOTE 这个比较暂时去掉 if warning_klass.has_warning_compare? # append_issue(warning_klass.warning_info_compare, :compare, device, klass) append_issue_compare(warning_klass.warning_info_compare, device, klass) end end @summary end |
#total_number ⇒ Object
全部警告条数
102 103 104 |
# File 'lib/aio/core/warning/warning_summarize.rb', line 102 def total_number serious_number + ordinary_number + compare_number end |