module PgsqlStatsHelper def pages_to_human_size(pages) number_to_human_size(pages * 8.kilobytes) end def percentage_bar(text, percent, options = {}) percent = 0 unless percent.finite? percent = [[ 0, percent.to_i ].max, 100].min if options.keys.first.is_a?(Range) for range in options.keys if range === percent bar_class = options[range][:bar_class] bar_style = options[range][:bar_style] text_class = options[range][:text_class] text_style = options[range][:text_style] break end end else bar_class = options[:bar_class] bar_style = options[:bar_style] text_class = options[:text_class] text_style = options[:text_style] end bar_options = {} bar_options.merge!(:class => bar_class) if bar_class bar_options.merge!(:style => "position: absolute; left:0; width: #{percent}%; overflow: hidden; z-index: -1; #{bar_style}") text_options = {} text_options.merge!(:class => text_class) if text_class text_options.merge!(:style => "z-index: 1; #{text_style}") content_tag(:div, content_tag(:span, " ", bar_options) + content_tag(:span, text, text_options), :style => "width: 100%; height: 100%; position: relative; z-index: 1;") end def analysis_results(entity) if entity.respond_to?(:analysis) && analysis = entity.analysis results = "" if analysis.consider_adding_index? results << content_tag(:div, PgsqlStats::Analysis.analysis_hint_proc.call(@template), :title => "This table may benefit from the addition of an index.", :class => "analysishint") end if analysis.consider_dropping_index? results << content_tag(:div, PgsqlStats::Analysis.analysis_hint_proc.call(@template), :title => "This index does not appear to be frequently used in queries. You might consider dropping it to improve insert/update performance.", :class => "analysishint") end end end end