1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use autodie;
use Date::Format;
use GD;
use POSIX 'ceil';
use Simplestore;
my $count = shift // 5;
my $file = '/home/derf/stuff/work/zivildienst/schichten';
my $table = Simplestore::load($file);
my ($w, $h) = (($count < 8) ? ($count * 40) : (7 * 40), ceil($count / 7) * 40);
my $im = GD::Image->new($w, $h);
my $black = $im->colorAllocate( 0, 0, 0);
my $gray = $im->colorAllocate(127, 127, 127);
my $lgray = $im->colorAllocate(191, 191, 191);
my $white = $im->colorAllocate(255, 255, 255);
my $blue = $im->colorAllocate(200, 200, 255);
my $green = $im->colorAllocate(200, 255, 200);
my $yellow = $im->colorAllocate(255, 255, 200);
my $red = $im->colorAllocate(255, 191, 191);
for my $i (1 .. $count) {
my @time = localtime(time + (3600 * 24 * $i));
my $day = strftime('%a', @time);
my $mday = strftime('%d', @time);
my $date = strftime('%m/%d', @time);
my $cur = $table->{ $date };
my $colour = $white;
my $x_off = 40 * (($i - 1) % 7);
my $y_off = int(($i - 1) / 7) * 40;
if (not defined $cur) {
next;
}
if ($cur !~ /^ \d+ $/x) {
$im->filledRectangle($x_off + 1, $y_off + 1, $x_off + 39, $y_off +
39, $colour);
$im->string(gdSmallFont, $x_off + 2, $y_off + 2, "${day} ${mday}",
$black);
$im->rectangle($x_off, $y_off, $x_off + 40, $y_off + 40, $gray);
next;
}
if ($cur ~~ [qw[s S]]) {
$cur = 13;
}
if ($cur < 8) {
$colour = $blue;
}
elsif ($cur < 10) {
$colour = $green;
}
elsif ($cur < 13) {
$colour = $yellow;
}
else {
$colour = $red;
}
$im->filledRectangle($x_off + 1, $y_off + 1, $x_off + 39, $y_off + 39,
$colour);
$im->string(gdSmallFont, $x_off + 2, $y_off + 2, "${day} ${mday}",
$black);
$im->string(gdSmallFont, $x_off + 6, $y_off + 20, sprintf('%02d:00',
$cur), $black);
$im->rectangle($x_off, $y_off, $x_off + 40, $y_off + 40, $gray);
}
$im->rectangle(0, 0, $w - 1, $h -1, $gray);
open(my $out_fh, '>', '/tmp/vzds.png');
binmode $out_fh;
print $out_fh $im->png();
close($out_fh);
|