Skip to content

Instantly share code, notes, and snippets.

@discordianfish
Created May 20, 2011 16:21
Show Gist options
  • Save discordianfish/983257 to your computer and use it in GitHub Desktop.
Save discordianfish/983257 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use constant THRESHOLD => 5;
my $count;
while ($_ = <STDIN>)
{
next unless (my ($ts, $user, $msg) = m/(\d{2}:\d{2}) <?([^>]*)> (.*)/);
if ($msg =~ m/^([^ ]*): .*/)
{
my $to = $1;
$count->{$user}->{msg}->{$to}->{count}++;
$count->{$user}->{msg}->{$to}->{up}++
if ($msg =~ /:-?\)/);
$count->{$user}->{msg}->{$to}->{down}++
if ($msg =~ /:-?\(/);
}
$count->{$user}->{msgCount}++;
}
for my $user (keys %$count)
{
for my $to (keys %{ $count->{$user}->{msg} })
{
next unless
$count->{$user}->{msg}->{$to}->{count} > THRESHOLD;
my $data = $count->{$user}->{msg}->{$to};
$data->{up} ||= 0;
$data->{down} ||= 0;
my $data_rel_pa;
my $data_rel_pp;
for (keys %$data)
{
# how many % of all messages were send to a person (w/ smiley)
$data_rel_pa->{$_} = sprintf '%3.4f', $data->{$_}* 100 / $count->{$user}->{msgCount};
# how many % of messages to that person are send w/ smiley
$data_rel_pp->{$_} = sprintf '%3.4f', $data->{$_}* 100 / $count->{$user}->{msg}->{$to}->{count};
}
print join '; ',
$user, $to,
$data_rel_pp->{up}, $data_rel_pp->{down},
$data_rel_pa->{up}, $data_rel_pa->{down}, $data_rel_pa->{count},
$data->{count}, $data->{up}, $data->{down};
print "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment