diff options
| author | fukachan <fukachan> | 2001-11-09 11:28:41 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-11-09 11:28:41 +0000 |
| commit | d70afc7a664bdba418a3bc1fe6c3b96834d85620 (patch) | |
| tree | 1866a5e9dd0ef9803941aa19a6a39c525f4d6727 | |
| parent | c8c9d60e344c33000fba46c5997120f659e09b8e (diff) | |
| download | fml8-d70afc7a664bdba418a3bc1fe6c3b96834d85620.tar.gz fml8-d70afc7a664bdba418a3bc1fe6c3b96834d85620.tar.bz2 fml8-d70afc7a664bdba418a3bc1fe6c3b96834d85620.zip | |
move sorting function to Mail::ThreadTrack::Print::Sort
| -rwxr-xr-x | fml/lib/Mail/ThreadTrack.pm | 69 | ||||
| -rw-r--r-- | fml/lib/Mail/ThreadTrack/Print/Sort.pm | 83 |
2 files changed, 84 insertions, 68 deletions
diff --git a/fml/lib/Mail/ThreadTrack.pm b/fml/lib/Mail/ThreadTrack.pm index 4edfa071..9d340c49 100755 --- a/fml/lib/Mail/ThreadTrack.pm +++ b/fml/lib/Mail/ThreadTrack.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: ThreadTrack.pm,v 1.11 2001/11/07 04:05:25 fukachan Exp $ +# $FML: ThreadTrack.pm,v 1.12 2001/11/07 09:28:28 fukachan Exp $ # package Mail::ThreadTrack; @@ -248,73 +248,6 @@ sub list_up_thread_id } -=head2 sort($thread_id_list) - -=cut - - -# Descriptions: -# Arguments: $self $args -# Side Effects: -# Return Value: none -sub sort -{ - my ($self, $thread_id_list) = @_; - - # get age HASH TABLE - my ($age, $cost) = $self->_calculate_age($thread_id_list); - $self->{ _age } = $age; - $self->{ _cost } = $cost; - - $self->_sort_thread_id($thread_id_list, $cost); -} - - -# Descriptions: -# Arguments: $self $args -# Side Effects: -# Return Value: none -sub _sort_thread_id -{ - my ($self, $thread_id_list, $cost) = @_; - - @$thread_id_list = sort { - $cost->{$b} cmp $cost->{$a}; - } @$thread_id_list; -} - - -# Descriptions: -# Arguments: $self $args -# Side Effects: -# Return Value: none -sub _calculate_age -{ - my ($self, $thread_id_list) = @_; - my (%age, %cost) = (); - my $now = time; # save the current UTC for convenience - my $rh = $self->{ _hash_table } || {}; - my $day = 24*3600; - - # $age hash referehence = { $thread_id => $age }; - my (@aid, $last, $age, $date, $status, $tid) = (); - for $tid (sort @$thread_id_list) { - # $last: get the latest one of article_id's - (@aid) = split(/\s+/, $rh->{ _articles }->{ $tid }); - $last = $aid[ $#aid ] || 0; - - # how long this thread is not concerned ? - $age = sprintf("%2.1f%s", ($now - $rh->{ _date }->{ $last })/$day); - $age{ $tid } = $age; - - # evaluate cost hash table which is { $thread_id => $cost } - $cost{ $tid } = $rh->{ _status }->{ $tid }.'-'. $age; - } - - return (\%age, \%cost); -} - - =head2 set_mode($mode) specify output format by $mode string. diff --git a/fml/lib/Mail/ThreadTrack/Print/Sort.pm b/fml/lib/Mail/ThreadTrack/Print/Sort.pm new file mode 100644 index 00000000..062ead50 --- /dev/null +++ b/fml/lib/Mail/ThreadTrack/Print/Sort.pm @@ -0,0 +1,83 @@ +#-*- perl -*- +# +# Copyright (C) 2001 Ken'ichi Fukamachi +# All rights reserved. This program is free software; you can +# redistribute it and/or modify it under the same terms as Perl itself. +# +# $FML: Utils.pm,v 1.1 2001/11/09 10:37:06 fukachan Exp $ +# + +package Mail::ThreadTrack::Print::Sort; +use strict; +use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); +use Carp; + + +=head2 sort($thread_id_list) + +=cut + + +# Descriptions: +# Arguments: $self $args +# Side Effects: +# Return Value: none +sub sort +{ + my ($self, $thread_id_list) = @_; + + # get age HASH TABLE + my ($age, $cost) = $self->_calculate_age($thread_id_list); + $self->{ _age } = $age; + $self->{ _cost } = $cost; + + $self->_sort_thread_id($thread_id_list, $cost); +} + + +# Descriptions: +# Arguments: $self $args +# Side Effects: +# Return Value: none +sub _sort_thread_id +{ + my ($self, $thread_id_list, $cost) = @_; + + @$thread_id_list = sort { + $cost->{$b} cmp $cost->{$a}; + } @$thread_id_list; +} + + +# Descriptions: +# Arguments: $self $args +# Side Effects: +# Return Value: none +sub _calculate_age +{ + my ($self, $thread_id_list) = @_; + my (%age, %cost) = (); + my $now = time; # save the current UTC for convenience + my $rh = $self->{ _hash_table } || {}; + my $day = 24*3600; + + # $age hash referehence = { $thread_id => $age }; + my (@aid, $last, $age, $date, $status, $tid) = (); + for $tid (sort @$thread_id_list) { + # $last: get the latest one of article_id's + (@aid) = split(/\s+/, $rh->{ _articles }->{ $tid }); + $last = $aid[ $#aid ] || 0; + + # how long this thread is not concerned ? + $age = sprintf("%2.1f%s", ($now - $rh->{ _date }->{ $last })/$day); + $age{ $tid } = $age; + + # evaluate cost hash table which is { $thread_id => $cost } + $cost{ $tid } = $rh->{ _status }->{ $tid }.'-'. $age; + } + + return (\%age, \%cost); +} + + +1; |
