Changeset 2632
- Timestamp:
- 2001-07-09T19:14:52+12:00 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/classify/DateList.pm
r2503 r2632 26 26 # classifier plugin for sorting by date 27 27 28 # no options -always sorts by 'Date' metadata28 # always sorts by 'Date' metadata 29 29 30 30 # date is assumed to be in the form yyyymmdd 31 31 32 32 # at present dates are split by year - this should change 33 # jrm21 - added option "bymonth", which splits by year and month. 33 34 34 35 package DateList; … … 43 44 sub print_usage { 44 45 print STDERR " 45 usage: classify DateList 46 47 Classifier plugin for sorting by date. 48 No options - always sorts by 'Date' metadata 49 Date is assumed to be in the form yyyymmdd 50 At present dates are split by year - this should change 51 52 Any errors are Dana's problem. 46 usage: classify DateList [options] 47 options: 48 -bymonth [or bymonth=1] Classify by year and month 49 50 Classifier plugin for sorting by date. 51 Always sorts by 'Date' metadata. 52 Date is assumed to be in the form yyyymmdd (all digits). 53 By default dates are split by year - this should change. 54 55 Any errors are Dana's problem. 53 56 "; 54 57 } … … 59 62 60 63 $self->{'list'} = {}; 61 64 if (!parsargv::parse(\@_, 65 q^bymonth^, \$self->{'bymonth'}, 66 "allow_extra_options")) { 67 &print_usage(); 68 die "\n"; 69 } 62 70 return bless $self, $class; 63 71 } … … 111 119 } 112 120 113 # splitlist takes an ordered list of classifications (@$classlistref) and splits it114 # up into sub-sections by date121 # splitlist takes an ordered list of classifications (@$classlistref) and 122 # splits it up into sub-sections by date 115 123 sub splitlist { 116 124 my $self = shift (@_); … … 131 139 } 132 140 133 # first split up the list into separate year classifications 134 foreach $classification (@$classlistref) { 135 my $date = $self->{'list'}->{$classification}; 136 $date =~ s/^(\d\d\d\d).*$/$1/; 137 $classhash->{$date} = [] unless defined $classhash->{$date}; 138 push (@{$classhash->{$date}}, $classification); 139 } 140 141 142 if ($self->{'bymonth'}) { 143 # first split up the list into separate year+month classifications 144 foreach $classification (@$classlistref) { 145 my $date = $self->{'list'}->{$classification}; 146 $date =~ s/^(\d\d\d\d)(\d\d).*$/$1 _textmonth$2_/; 147 # sanity check if month is zero 148 if ($date =~ /00_$/) { 149 $date =~ s/^(\d\d\d\d).*$/$1/g; 150 } 151 $classhash->{$date} = [] unless defined $classhash->{$date}; 152 push (@{$classhash->{$date}}, $classification); 153 } 154 } else { 155 # first split up the list into separate year classifications 156 foreach $classification (@$classlistref) { 157 my $date = $self->{'list'}->{$classification}; 158 $date =~ s/^(\d\d\d\d).*$/$1/; 159 $classhash->{$date} = [] unless defined $classhash->{$date}; 160 push (@{$classhash->{$date}}, $classification); 161 } 162 } 141 163 $classhash = $self->compactlist ($classhash); 142 164 … … 157 179 my $compactedhash = {}; 158 180 my @currentOIDs = (); 159 my $currentfirst letter= "";160 my $currentlast letter= "";181 my $currentfirstdate = ""; 182 my $currentlastdate = ""; 161 183 my $lastkey = ""; 162 184 … … 168 190 my $min = 10; 169 191 my $max = 30; 170 171 foreach $subsection (sort keys %$classhashref) { 172 $currentfirstletter = $subsection if $currentfirstletter eq ""; 192 foreach my $subsection (sort keys %$classhashref) { 193 $currentfirstdate = $subsection if $currentfirstdate eq ""; 173 194 if ((scalar (@currentOIDs) < $min) || 174 195 ((scalar (@currentOIDs) + scalar (@{$classhashref->{$subsection}})) <= $max)) { 175 196 push (@currentOIDs, @{$classhashref->{$subsection}}); 176 $currentlast letter= $subsection;197 $currentlastdate = $subsection; 177 198 } else { 178 199 179 if ($currentfirst letter eq $currentlastletter) {180 @{$compactedhash->{$currentfirst letter}} = @currentOIDs;181 $lastkey = $currentfirst letter;200 if ($currentfirstdate eq $currentlastdate) { 201 @{$compactedhash->{$currentfirstdate}} = @currentOIDs; 202 $lastkey = $currentfirstdate; 182 203 } else { 183 @{$compactedhash->{"$currentfirst letter-$currentlastletter"}} = @currentOIDs;184 $lastkey = "$currentfirst letter-$currentlastletter";204 @{$compactedhash->{"$currentfirstdate-$currentlastdate"}} = @currentOIDs; 205 $lastkey = "$currentfirstdate-$currentlastdate"; 185 206 } 186 207 if (scalar (@{$classhashref->{$subsection}}) >= $max) { 187 208 $compactedhash->{$subsection} = $classhashref->{$subsection}; 188 209 @currentOIDs = (); 189 $currentfirst letter= "";210 $currentfirstdate = ""; 190 211 $lastkey = $subsection; 191 212 } else { 192 213 @currentOIDs = @{$classhashref->{$subsection}}; 193 $currentfirst letter= $subsection;194 $currentlast letter= $subsection;214 $currentfirstdate = $subsection; 215 $currentlastdate = $subsection; 195 216 } 196 217 } … … 203 224 @currentOIDs = (@{$compactedhash->{$lastkey}}, @currentOIDs); 204 225 delete $compactedhash->{$lastkey}; 205 @{$compactedhash->{"$newkey-$currentlast letter"}} = @currentOIDs;226 @{$compactedhash->{"$newkey-$currentlastdate"}} = @currentOIDs; 206 227 } else { 207 if ($currentfirst letter eq $currentlastletter) {208 @{$compactedhash->{$currentfirst letter}} = @currentOIDs;228 if ($currentfirstdate eq $currentlastdate) { 229 @{$compactedhash->{$currentfirstdate}} = @currentOIDs; 209 230 } else { 210 @{$compactedhash->{"$currentfirst letter-$currentlastletter"}} = @currentOIDs;231 @{$compactedhash->{"$currentfirstdate-$currentlastdate"}} = @currentOIDs; 211 232 } 212 233 }
Note:
See TracChangeset
for help on using the changeset viewer.