#! /usr/local/bin/ruby # Copyright (c) 2006 Frédéric Senault. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. Neither the name of the author or any contributors may be used to # endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. class IncomingFeedsGrapher < Grapher KEYS = [ 'accepted', 'accsize', 'duplicated', 'dupsize', 'refused', 'rejected', 'rejsize', 'seconds' ] def subtitle(id) case id when :feed_art "Feed entrant (articles/s)" when :feed_byt "Feed entrant (bytes/s)" when :feed_part "Feed entrant (% articles)" when :feed_pbyt "Feed entrant (% bytes)" end end def index(file) if(file == 'me_incoming') then yield('me_incoming', "Feeds entrants (résumé)") elsif(file =~ /^(.*)_incoming$/) then t = $1 t.gsub!(/_/, ' ') t.sub!(/^[^.]+\./, '') yield(file, "Feed entrant, #{t}") end end def register(link) if(link =~ /_incoming$/) then yield(:feed_art) yield(:feed_part) yield(:feed_byt) yield(:feed_pbyt) end end def graph(link, id, gfx, file) lg = { 'acc' => [ 'accepted', 'Acceptés', :green ], 'cacc' => [ 'accepted', 'Acceptés', :green ], 'ref' => [ 'refused', 'Refusés', :yellow ], 'cref' => [ 'refused', 'Refusés', :yellow ], 'dup' => [ 'duplicated', 'Doublons', :magenta ], 'rej' => [ 'rejected', 'Rejetés', :red ] } oa = [ 'rej', 'acc', 'ref', 'dup' ] os = [ 'rej', 'acc', 'dup' ] isart = ( id.to_s =~ /art$/ ) case id when :feed_byt, :feed_art (isart ? oa : os).each do |k| gfx.adddef(k, file, (isart ? lg[k][0] : "#{k}size"), :AVERAGE, lg[k][1]) gfx.addgraph(:AREA, k, lg[k][2], lg[k][1], (k != 'rej')) end when :feed_pbyt, :feed_part gfx.percent = true (isart ? oa : os).each do |k| gfx.adddef(k, file, (isart ? lg[k][0] : "#{k}size"), :AVERAGE, nil, nil) end gfx.addcdef('ttot', rpn_sum((isart ? oa : os)) + ',100,/', nil, nil) (isart ? oa : os).each do |k| gfx.addcdef("p#{k}", "#{k},ttot,/", lg[k][1]) gfx.addgraph(:AREA, "p#{k}", lg[k][2], lg[k][1], (k != 'rej')) end end end end