diff options
author | Daniel Friesel <derf@finalrewind.org> | 2010-10-27 18:31:02 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2010-10-27 18:31:02 +0200 |
commit | 24b16a2aaa44d2c2caf4cfaf9e4ec5588e615080 (patch) | |
tree | 1f610379e8136ef7b18403a81cb2c549cc66e909 | |
parent | 4ec7e4330df5baf6525cb20d22e4edb3cdafbf44 (diff) |
Add vzds
-rwxr-xr-x | bin/vdf | 13 | ||||
-rwxr-xr-x | bin/vzds | 87 |
2 files changed, 94 insertions, 6 deletions
@@ -45,13 +45,14 @@ sub bar_png { my $black = $bar->colorAllocate( 0, 0, 0); my $gray = $bar->colorAllocate(127, 127, 127); + my $lgray = $bar->colorAllocate(191, 191, 191); my $white = $bar->colorAllocate(255, 255, 255); my $vwidth = sprintf("%d", ($w- 2) * $percent / 100); - $bar->rectangle(0, 0, $w - 1, $h - 1, $black); + $bar->rectangle(0, 0, $w - 1, $h - 1, $gray); $bar->filledRectangle(1, 1, $w - 2, $h - 2, $white); - $bar->filledRectangle(1, 1, $vwidth, $h - 2, $gray); + $bar->filledRectangle(1, 1, $vwidth, $h - 2, $lgray); return $bar; } @@ -107,7 +108,7 @@ sub show_df_png { my $black = $im->colorAllocate( 0, 0, 0); my $gray = $im->colorAllocate(127, 127, 127); - my $lgray = $im->colorAllocate(250, 250, 250); + my $lgray = $im->colorAllocate(191, 191, 191); my $white = $im->colorAllocate(255, 255, 255); $im->rectangle(0, 0, $w - 1, $h - 1, $gray); @@ -118,11 +119,11 @@ sub show_df_png { my $mount = $mounts[$i]; my $percent = $mount->[4]->{'used'} * 100 / $mount->[4]->{'blocks'}; - $im->string(gdSmallFont, 10, $spacing * $i + 2, $mount->[1], + $im->string(gdSmallFont, 10, $spacing * $i + 7, $mount->[1], $black); - $im->string(gdSmallFont, $w - 46, $spacing * $i + 2, + $im->string(gdSmallFont, $w - 46, $spacing * $i + 7, sprintf("%6s", format_size($mount->[4]->{'bavail'})), $black); - $im->copy(bar_png($percent, $w - 20, 10), 10, $spacing * $i + 15, 0, + $im->copy(bar_png($percent, $w - 20, 10), 10, $spacing * $i + 20, 0, 0, $w - 20, 10); } diff --git a/bin/vzds b/bin/vzds new file mode 100755 index 0000000..b264c09 --- /dev/null +++ b/bin/vzds @@ -0,0 +1,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(127, 127, 200); +my $green = $im->colorAllocate(127, 200, 127); +my $yellow = $im->colorAllocate(200, 200, 127); +my $red = $im->colorAllocate(200, 127, 127); + +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 = $lgray; + 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, $black); + 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, $black); + +} + +$im->rectangle(0, 0, $w - 1, $h -1, $black); + +open(my $out_fh, '>', '/tmp/vzds.png'); +binmode $out_fh; +print $out_fh $im->png(); +close($out_fh); |