summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-10-29 20:52:45 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-10-29 20:52:45 +0200
commit33eab21aedb69309006789d84741b33a9ef8f7cf (patch)
tree63a047b17be9d9f5de71f55f1a7211f465fe64c4
parentd6fb74fc9f292d1203421cc1f5fa0c34c94094ad (diff)
Proper destination shortening, add ?line= and ?platform= (the latter sucks)
-rw-r--r--cgi/index.pl38
-rw-r--r--lib/App/VRR/Fakedisplay.pm5
-rw-r--r--share/font.pngbin627 -> 636 bytes
3 files changed, 39 insertions, 4 deletions
diff --git a/cgi/index.pl b/cgi/index.pl
index fdf900b..1f3d61a 100644
--- a/cgi/index.pl
+++ b/cgi/index.pl
@@ -51,6 +51,25 @@ sub handle_request {
);
}
+sub shorten_destination {
+ my ($dest, $city) = @_;
+
+ $dest =~ s{ ^ $city \s }{}x;
+
+ if (length($dest) > 20) {
+ $dest =~ s{^Dortmund}{DO} or
+ $dest =~ s{^Duisburg}{DU} or
+ $dest =~ s{^Düsseldorf}{D} or
+ $dest =~ s{^Essen}{E} or
+ $dest =~ s{^Gelsenkirchen}{GE} or
+ $dest =~ s{^Mülheim}{MH};
+ }
+
+ $dest = substr($dest, 0, 20);
+
+ return $dest;
+}
+
sub render_image {
my $self = shift;
my $city = $self->stash('city');
@@ -62,11 +81,21 @@ sub render_image {
my $width = $self->param('width') || 180;
my $height = $self->param('height') || 50;
- $self->res->headers->content_type('image/png');
+ my (@grep_line, @grep_platform);
+
my ($results, $errstr) = get_results_for($city, $stop);
my $png = App::VRR::Fakedisplay->new(width => 180, height => 50, color => [split(qr{,}, $color)]);
+
+ if ($self->param('line')) {
+ @grep_line = split(qr{,}, $self->param('line'));
+ }
+ if ($self->param('platform')) {
+ @grep_platform = split(qr{,}, $self->param('platform'));
+ }
+
+ $self->res->headers->content_type('image/png');
for my $d (@{$results}) {
my $line = $d->line;
@@ -78,6 +107,11 @@ sub render_image {
my $dt_dep = DateTime::Format::DateParse->parse_datetime($time, 'floating');
my $dt;
+ if ((@grep_line and not ($line ~~ \@grep_line)) or
+ (@grep_platform and not ($platform ~~ \@grep_platform))) {
+ next;
+ }
+
if ($time =~ m{ ^ \d\d? : \d\d $ }x) {
$dt = DateTime->new(
year => $dt_now->year,
@@ -111,7 +145,7 @@ sub render_image {
last;
}
- $destination =~ s{ $city \s }{}ix;
+ $destination = shorten_destination($destination, $city);
$png->draw_at(0, $line);
$png->draw_at(25, $destination);
diff --git a/lib/App/VRR/Fakedisplay.pm b/lib/App/VRR/Fakedisplay.pm
index b380382..2546248 100644
--- a/lib/App/VRR/Fakedisplay.pm
+++ b/lib/App/VRR/Fakedisplay.pm
@@ -53,12 +53,13 @@ sub locate_char {
when (q{:}) { $y = 30; $x = 0 }
when (q{-}) { $y = 30; $x = 10 }
when (q{.}) { $y = 30; $x = 20 }
- when (q{,}) { $y = 30, $x = 30 }
+ when (q{,}) { $y = 30; $x = 30 }
+ when (q{/}) { $y = 30; $x = 40 }
}
given ($char) {
when (/[WwMm]/) { $w = 8 }
- when (/[BDErt ]/) { $w = 5 }
+ when (/[BDEFrt ]/) { $w = 5 }
when (/[il1:]/) { $w = 4 }
when (/[.,]/) { $w = 3 }
}
diff --git a/share/font.png b/share/font.png
index fee6637..893b2e4 100644
--- a/share/font.png
+++ b/share/font.png
Binary files differ