Mercurial > hg > lukkari
changeset 8:a52a0bdb5ea1
Crop off empty hours (time slots) and days.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 11 Jan 2011 22:22:45 +0200 |
parents | 2bb40c5945bc |
children | fe5b563eaae5 |
files | parsedata.pl |
diffstat | 1 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/parsedata.pl Tue Jan 11 22:04:18 2011 +0200 +++ b/parsedata.pl Tue Jan 11 22:22:45 2011 +0200 @@ -268,7 +268,6 @@ my $node = fnode(fnode($tree, "body"), "table"); die("No table element found in document. Perhaps the format has changed? :(\n") unless defined($node); - ### Parse through the HTML document node tree to find the data we need my $id = 0; my $q = $$node{"nodes"}; @@ -277,7 +276,7 @@ my $maxdays = 6; my $maxhours = 0; -# Skip zero this way +# Skip zero position this way (can't use foreach here) for (my $i = 1; $i < scalar(@{$q}); $i++) { my $d = $$q[$i]{"nodes"}; if (defined($d)) { @@ -333,6 +332,24 @@ } +### Go through hour table, find last day and hour of the week, crop +my $flag = 1; +for (my $y = $maxhours - 1; $y >= 0 && $flag; $y--) { + for (my $x = 0; $x < $maxdays && $flag; $x++) { + $flag = 0 if (defined($$taulu{$y}{$x}) && $$taulu{$y}{$x} != 0); + } + $maxhours-- if ($flag); +} + +$flag = 1; +for (my $x = $maxdays - 1; $x >= 0 && $flag; $x--) { + for (my $y = 0; $y < $maxhours && $flag; $y++) { + $flag = 0 if (defined($$taulu{$y}{$x}) && $$taulu{$y}{$x} != 0); + } + $maxdays-- if ($flag); +} + + ### Open output file, if specified if (defined($opt_outfile)) { open(STDOUT, '>', $opt_outfile) or die("Could not open output file '$opt_outfile'.\n"); @@ -397,8 +414,6 @@ print "</timetable>\n"; } - - elsif ($opt_mode eq "simple") { for (my $y = 0; $y < $maxhours; $y++) { for (my $x = 0; $x < $maxdays; $x++) {