From 8d71ed1c017da94a30c2db9188355004d2741836 Mon Sep 17 00:00:00 2001 From: nwf Date: Fri, 28 Aug 2009 03:06:57 -0400 Subject: [PATCH] Add stats.pl, a simplistic statistics collector Ignore-this: 592d472d2083480548d346757e15d7cd darcs-hash:20090828070657-4d648-b7cfedec828d0dd96e8cae0643de29a3cae43038.gz --- stats.pl | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 stats.pl diff --git a/stats.pl b/stats.pl new file mode 100644 index 0000000..501bf89 --- /dev/null +++ b/stats.pl @@ -0,0 +1,69 @@ +use strict; + +use Data::Dumper; +use Instance::Definitions qw( %known_types + @default_code_chars + $instance_huffman_table1 + $MESSAGE_START $MESSAGE_END ); +require Instance::MasterCoder; +require Instance::HuffmanCoder; +use Instance::Protoutils qw( dump_message ); + +my $mc = Instance::MasterCoder->new(\@default_code_chars, $MESSAGE_START, $MESSAGE_END); +my $hc = Instance::HuffmanCoder->new($mc, $instance_huffman_table1); + +my $cmsg_from; + +my $taglines = 0; +my %tags = ( ); +sub cb_it ($$) { + my ($t,$v) = @_; + die unless $t = $known_types{'InstanceLabelHuffman1'}; + + $taglines++; + + my $dcv = $hc->decode($v); + $tags{$dcv} = 0 if not exists $tags{$dcv}; + $tags{$dcv}++; +} + +my $botlines = 0; +my %bots = ( ); +sub cb_mmf ($$) { + my ($t,$v) = @_; + my $dcv = $mc->tdecode($v); + my $is_bot = $dcv & 1 if ($dcv > 2); + + if($is_bot) { + $botlines++; + $bots{$cmsg_from}++ if defined $cmsg_from; + } +} + + +while(my $text = ) { + chomp $text; + + # CTCP + $text =~ s///g; + + $cmsg_from = $text =~ /^([^<]*<\s*([^>]+)>|.*-!- ([^ ]+) )/ + ? ($2 or $3) : undef; + + my ($succ, $rem) = $mc->tlv_run_callbacks( + { + $known_types{'InstanceLabelHuffman1'} => \&cb_it, + $known_types{'MiscMessageFlags'} => \&cb_mmf, + }, + $text + ); +} + +print "TOTAL OF $taglines INSTANCE LABELS:\n"; +foreach my $l (sort { $tags{$b} <=> $tags{$a} } (keys %tags)) { + print " $l : $tags{$l}\n"; +} +print "TOTAL OF $botlines MMF BOT TAGS:\n"; +foreach my $b (sort { $bots{$b} <=> $bots{$a} } (keys %bots)) { + print " $b : $bots{$b}\n"; +} -- 2.50.1