Ubigraphで遊んだ

画面を見ながら、子供も大変愉しませてもらいました。
Ubigraph: Free dynamic graph visualization software

画面クリアのコード

#!/usr/bin/ruby
require 'ubigraph'

Rubigraph.init
Rubigraph.clear

ちょっとした描画を試した。元データはアクセスログ。「ドーナツ増えてく!」という感想をいただきました。

require 'rubigraph'
require 'set'

Rubigraph.init
Rubigraph.clear
$urlbag = Set.new
$linebag = Set.new
$vhash = Hash.new

def putline(l1, l2)
  if $urlbag.member?(l1) then
    v1 = $vhash[l1]
    if !$linebag.member?("#{l1}#{l2}") then
      v2  = Rubigraph::Vertex.new
      v2.shape = 'sphere'
      v2.size = 0.5
      v2.color = "#bb004b"
      e12 = Rubigraph::Edge.new(v1, v2)
    end
  else
    v1  = Rubigraph::Vertex.new
    v1.shape = 'torus'
    v1.color= "#22ff22"
    v1.label = l1
    v1.fontcolor = "#ff4444"
    v1.size = 5
    $vhash[l1] = v1
    $urlbag.add(l1)
    v2  = Rubigraph::Vertex.new
    v2.shape = 'sphere'
    v2.size = 0.5
    $linebag.add("#{l1}#{l2}")
    e12 = Rubigraph::Edge.new(v1, v2)
  end
end

IO.popen("awk '{print $1, $7}' /var/log/httpd/access_log").each {|line|
  line.chomp!
  sleep 1.25
  if /^([^\s]+)(\s)+([^\s]+)$/ =~ line then
    url = $3
    ipaddr = $1
    putline(url, ipaddr)
  end
}