#!/usr/bin/perl use lib "../lib"; use Rest::Topsy; use Data::Dumper; my $topsy = new Rest::Topsy; my $tasks = load_task_history($topsy); my $matches = []; foreach my $task (@$tasks) { next if $task->{'date'} == -1; foreach my $k (qw[all month week day hour]) { $task->{$k} =~ s/K$/000/; $task->{$k} =~ s/M$/000000/; } push @$matches, $task; } our $task_count = scalar(@$tasks); our $match_count = scalar(@$matches); our $percent = sprintf "%0.1f%%", 100* ($match_count/$task_count); print "Pulled $match_count/$task_count ($percent complete)\n"; print_report( "name", [(sort name_sort @$matches)] ); print_report( "all", [(sort { for $k (qw[all month week day hour]) { return $b->{$k} <=> $a->{$k} || next } } @$matches)] ); print_report( "month", [(sort { for $k (qw[month week day hour all]) { return $b->{$k} <=> $a->{$k} || next } } @$matches)] ); print_report( "week", [(sort { for $k (qw[week day hour all month]) { return $b->{$k} <=> $a->{$k} || next } } @$matches)] ); print_report( "day", [(sort { for $k (qw[day hour all month week]) { return $b->{$k} <=> $a->{$k} || next } } @$matches)] ); print_report( "hour", [(sort { for $k (qw[hour all month week day]) { return $b->{$k} <=> $a->{$k} || next } } @$matches)] ); sub print_report { my ($title, $matches) = @_; my $out .= header($title); foreach my $p (@$matches) { next unless $p->{$title}; $out .= ""; $out .= "". $p->{'all'} .""; $out .= "". $p->{'month'} .""; $out .= "". $p->{'week'} .""; $out .= "". $p->{'day'} .""; $out .= "". $p->{'hour'} .""; my $nndb_url = sprintf("http://www.nndb.com/people/%03d/%09d/", $p->{'id'} % 997, $p->{'id'}); my $topsy_url = "http://topsy.com/search?q=" . $p->{'name'}; $out .= "". $p->{'name'} .""; $out .= "(topsy)"; $out .= ""; } $out .= footer(); $topsy->write_data("../tmp/nndb/".$title.".html", $out); } sub header { my $current = shift; my $out .= <<__HEADER__; Pulled $match_count/$task_count ($percent complete)
"; $out .= ""; return $out; } sub footer { return "
__HEADER__ $out .= join "", map { $current eq $_ ? "$_" : "$_" } qw[all month week day hour]; $out .= "name
"; } sub nice_date { my ($date) = @_; $date =~ s/^_//; $date =~ s/\.html$//; return $date; } sub load_task_history { my ($self) = @_; my $data = $self->read_data('../tmp/nndb/tasks.txt'); my @lines = split "\n", $data; my @keys = qw[id name date doppelganger all month week day hour]; my $tasks = []; foreach my $line (@lines) { next unless $line; my (@input) = split "\t", $line; my $hash = {}; for (my $i = 0; $i < @input; $i++) { $hash->{$keys[$i]} = $input[$i]; } push @$tasks, $hash; } return $tasks; } sub name_sort { my $name_a = lc $a->{'name'}; my $name_b = lc $b->{'name'}; $name_a =~ s/\,.*$//; $name_b =~ s/\,.*$//; my $last_a = $name_a; my $last_b = $hame_b; $last_a =~ s/^.* //; $last_b =~ s/^.* //; return $last_a cmp $last_b || $name_a cmp $name_b; }