java/buildconf/build-webapp.xml | 2 satellite/fedora/setup-symlinks.sh | 1 satellite/setup-symlinks.sh | 1 spacewalk/package/spacewalk.spec | 1 web/modules/Makefile | 2 web/modules/moon/Changes | 6 web/modules/moon/MANIFEST | 13 web/modules/moon/Makefile | 8 web/modules/moon/Makefile.PL | 24 - web/modules/moon/Moon/Chart.pm | 401 --------------------- web/modules/moon/Moon/Chart/TimeAxes.pm | 195 ---------- web/modules/moon/Moon/Dataset.pm | 61 --- web/modules/moon/Moon/Dataset/Coordinate.pm | 531 ---------------------------- web/modules/moon/Moon/Dataset/Function.pm | 241 ------------ web/modules/moon/Moon/Image.pm | 197 ---------- web/modules/moon/README | 35 - web/modules/moon/t/chart-init.t | 33 - web/modules/moon/t/dataset-init.t | 101 ----- web/modules/moon/t/image-init.t | 46 -- web/spacewalk-web.spec | 14 20 files changed, 1 insertion(+), 1912 deletions(-)
New commits: commit ff2443a4aded3afa4a02f576f2c448730148ab57 Author: Jan Pazdziora jpazdziora@redhat.com Date: Tue Dec 15 12:01:08 2009 +0100
Remove the spacewalk-moon (sub)package as it is not used anywhere.
diff --git a/java/buildconf/build-webapp.xml b/java/buildconf/build-webapp.xml index 89e450d..f931b06 100644 --- a/java/buildconf/build-webapp.xml +++ b/java/buildconf/build-webapp.xml @@ -172,7 +172,6 @@ resource="${git.home}/web/modules/cypress/Cypress"/> <symlink link="/var/www/lib/Dobby" resource="${git.home}/web/modules/dobby/Dobby"/> <symlink link="/var/www/lib/Grail" resource="${git.home}/web/modules/grail/Grail"/> - <symlink link="/var/www/lib/Moon" resource="${git.home}/web/modules/moon/Moon"/> <symlink link="/var/www/lib/PXT" resource="${git.home}/web/modules/pxt/PXT"/> <symlink link="/var/www/lib/RHN" resource="${git.home}/web/modules/rhn/RHN"/> <symlink link="/var/www/lib/Sniglets" @@ -188,7 +187,6 @@ <symlink action="delete" link="/var/www/lib/Cypress"/> <symlink action="delete" link="/var/www/lib/Dobby"/> <symlink action="delete" link="/var/www/lib/Grail"/> - <symlink action="delete" link="/var/www/lib/Moon"/> <symlink action="delete" link="/var/www/lib/PXT"/> <symlink action="delete" link="/var/www/lib/RHN"/> <symlink action="delete" link="/var/www/lib/Sniglets"/> diff --git a/satellite/fedora/setup-symlinks.sh b/satellite/fedora/setup-symlinks.sh index cdaed1b..024e40f 100755 --- a/satellite/fedora/setup-symlinks.sh +++ b/satellite/fedora/setup-symlinks.sh @@ -109,7 +109,6 @@ cd /var/www/lib symlink $GITDIR/web/modules/cypress/Cypress symlink $GITDIR/web/modules/dobby/Dobby symlink $GITDIR/web/modules/grail/Grail -symlink $GITDIR/web/modules/moon/Moon symlink $GITDIR/web/modules/rhn/RHN symlink $GITDIR/web/modules/pxt/PXT symlink $GITDIR/web/modules/ diff --git a/satellite/setup-symlinks.sh b/satellite/setup-symlinks.sh index 534e0f1..b7473fa 100755 --- a/satellite/setup-symlinks.sh +++ b/satellite/setup-symlinks.sh @@ -127,7 +127,6 @@ chdir /var/www/lib symlink $SVNDIR/eng/web/modules/cypress/Cypress symlink $SVNDIR/eng/web/modules/dobby/Dobby symlink $SVNDIR/eng/web/modules/grail/Grail -symlink $SVNDIR/eng/web/modules/moon/Moon symlink $SVNDIR/eng/web/modules/rhn/RHN symlink $SVNDIR/eng/web/modules/pxt/PXT symlink $SVNDIR/eng/web/modules/ diff --git a/spacewalk/package/spacewalk.spec b/spacewalk/package/spacewalk.spec index 51e52fb..1e6f38a 100644 --- a/spacewalk/package/spacewalk.spec +++ b/spacewalk/package/spacewalk.spec @@ -37,7 +37,6 @@ Requires: spacewalk-cypress Requires: spacewalk-grail Requires: spacewalk-pxt Requires: spacewalk-sniglets -Requires: spacewalk-moon
# Python Requires: spacewalk-certs-tools diff --git a/web/modules/Makefile b/web/modules/Makefile index 5b11c52..5e59102 100644 --- a/web/modules/Makefile +++ b/web/modules/Makefile @@ -4,7 +4,7 @@
TOP = ..
-SUBDIRS = cypress grail pxt rhn sniglets moon dobby +SUBDIRS = cypress grail pxt rhn sniglets dobby
include $(TOP)/Makefile.defs # whitespace change to test checkin diff --git a/web/modules/moon/Changes b/web/modules/moon/Changes deleted file mode 100644 index 07e6262..0000000 --- a/web/modules/moon/Changes +++ /dev/null @@ -1,6 +0,0 @@ -Revision history for Perl extension Moon::Image. - -0.01 Fri Jul 12 16:06:02 2002 - - original version; created by h2xs 1.21 with options - -XA -n Moon::Image - diff --git a/web/modules/moon/MANIFEST b/web/modules/moon/MANIFEST deleted file mode 100644 index ac1002c..0000000 --- a/web/modules/moon/MANIFEST +++ /dev/null @@ -1,13 +0,0 @@ -Makefile.PL -README -MANIFEST -Changes -Moon/Chart.pm -Moon/Dataset.pm -Moon/Image.pm -Moon/Chart/TimeAxes.pm -Moon/Dataset/Coordinate.pm -Moon/Dataset/Function.pm -t/chart-init.t -t/dataset-init.t -t/image-init.t diff --git a/web/modules/moon/Makefile b/web/modules/moon/Makefile deleted file mode 100644 index 392f26c..0000000 --- a/web/modules/moon/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# dummy Makefile for perl module -# -# $Id$ - -TOP = ../.. -export TOP - -include $(TOP)/Makefile.defs diff --git a/web/modules/moon/Makefile.PL b/web/modules/moon/Makefile.PL deleted file mode 100644 index 5214dd5..0000000 --- a/web/modules/moon/Makefile.PL +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/perl -# perl makefile for the swab module -# -# $Id$ - -use ExtUtils::MakeMaker; -# See lib/ExtUtils/MakeMaker.pm for details of how to influence -# the contents of the Makefile that is written. - -my $file = qx|ls $ENV{'TOP'}/*.spec|; -chomp $file; -my $version = qx|grep '^Version: ' $file|; -chomp $version; -$version = (split /\s*:\s*/, $version)[-1]; - -die "No version or name from $file" unless $version; - -WriteMakefile('NAME' => "Moon", - 'VERSION' => $version, - 'LIBS' => [''], # e.g., '-lm' - 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' - 'INC' => '', # e.g., '-I/usr/include/other' - 'MAKEFILE' => "Makefile.perl", #the name of the output Makefile file -); diff --git a/web/modules/moon/Moon/Chart.pm b/web/modules/moon/Moon/Chart.pm deleted file mode 100644 index bbda2e6..0000000 --- a/web/modules/moon/Moon/Chart.pm +++ /dev/null @@ -1,401 +0,0 @@ -# -# Copyright (c) 2008 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -package Moon::Chart; - -use strict; - -use Data::Dumper; - -use Moon::Image; -use Moon::Chart::TimeAxes; -use Moon::Dataset::Coordinate; - -# args: (width, height) of final image -sub new { - my $class = shift; - my $self = bless { }, $class; - my ($size_x, $size_y) = @_; - - die "Must provide width, height of final png image to Moon::Chart constructor" - unless (defined $size_x and defined $size_y); - - $self->{__image__} = new Moon::Image($size_x, $size_y); - $self->{__datasets__} = {}; - - # defaults - $self->{__graph_stencil_min__} = [0.1 * $size_x, 0.1 * $size_y]; - $self->{__graph_stencil_max__} = [0.9 * $size_x, 0.9 * $size_y]; - - #$self->graph_stencil_min(0.1 * $size_x, 0.1 * $size_y); - #$self->graph_stencil_max(0.9 * $size_x, 0.9 * $size_y); - - return $self; -} - -sub add_dataset { - my $self = shift; - my $data_label = shift; - my $dataset = shift; - - die "duplicate datasets??" if ($self->{__datasets__}->{$data_label}); - - $self->{__datasets__}->{$data_label} = $dataset; -} - -sub get_datasets { - my $self = shift; - - return $self->{__datasets__}; -} - -sub set_axes { - my $self = shift; - my $axes = shift; - - $self->{__axes__} = $axes; -} - -# access to the image -sub image { - my $self = shift; - my $new_image = shift; - - if ($new_image) { - $self->{__image__} = $new_image; - } - else { - return $self->{__image__}; - } -} - -# accessors for the stencil area in chart cs (0->1, 0->1) -sub graph_stencil_min { - my $self = shift; - - if (@_) { - my ($size_x, $size_y) = $self->{__image__}->get_size(); - my ($min_x, $min_y) = @_; - $self->{__graph_stencil_min__} = [$min_x * $size_x, $min_y * $size_y]; - } - else { - return $self->{__graph_stencil_min__}; - } -} - -sub graph_stencil_max { - my $self = shift; - if (@_) { - my ($size_x, $size_y) = $self->{__image__}->get_size(); - my ($max_x, $max_y) = @_; - $self->{__graph_stencil_max__} = [$max_x * $size_x, $max_y * $size_y]; - } - else { - return $self->{__graph_stencil_max__}; - } -} - -sub _S { - my $self = shift; - my $term = shift; - - my ($data_min, $data_max) = $self->{__axes__}->get_bounds(); - - return ($self->{__graph_stencil_max__}->[$term] - $self->{__graph_stencil_min__}->[$term]) - / ($data_max->[$term] - $data_min->[$term]); -} - -sub _image_to_data_fn { - my $self = shift; - - my $Sx = $self->_S(0); - my $Sy = $self->_S(1); - - my @image_size = $self->{__image__}->get_size(); - - my ($data_min, $data_max) = $self->{__axes__}->get_bounds(); - -# int( ($x - $self->{__graph_min__}->[0]) / ($Sx) + $data_min[0] ), -# int($image_size[1] - ( ($y - $self->{__graph_min__}->[1]) / ($Sy) + $data_min[1] )) - - return sub { - my ($x, $y) = @_; - return ( - int( ($x - $self->{__graph_stencil_min__}->[0]) / ($Sx) + $data_min->[0]), - int($image_size[1] - ( ($y - $self->{__graph_stencil_min__}->[1]) / ($Sy) + $data_min->[1])) - ); - }; - -} - -sub _data_to_image_fn { - my $self = shift; - - my $Sx = $self->_S(0); - my $Sy = $self->_S(1); - - my @image_size = $self->{__image__}->get_size(); - - my ($data_min, $data_max) = $self->{__axes__}->get_bounds(); - - -# int($Sx * ($x - $data_min[0]) + $self->{__graph_min__}->[0]), -# int($image_size[1] - ($Sy * ($y - $data_min[1]) + $self->{__graph_min__}->[1])) - - return sub { - my ($x, $y) = @_; - return ( - int($Sx * ($x - $data_min->[0]) + $self->{__graph_stencil_min__}->[0]), - int($image_size[1] - ($Sy * ($y - $data_min->[1]) + $self->{__graph_stencil_min__}->[1])) - ); - }; -} - -sub render_to_file { - my $self = shift; - my $filename = shift; - - # figure out the cumulative mins/maxes of the datasets? Inefficient, and might belong elsewhere... - my @mins_maxes; - - foreach my $datalabel (keys %{$self->{__datasets__}}) { - my $dataset = $self->{__datasets__}->{$datalabel}; - push @mins_maxes, ([ $dataset->min_x(), $dataset->min_y() ], [ $dataset->max_x(), $dataset->max_y() ]); - } - - my $min_max_ds = new Moon::Dataset::Coordinate(); - $min_max_ds->coords(@mins_maxes); - - # if we don't already have the axes, make 'em from the dataset metadata - if (!defined $self->{__axes__}) { - $self->{__axes__} = new Moon::Chart::TimeAxes([ $min_max_ds->min_x(), $min_max_ds->min_y() ], - [ $min_max_ds->max_x(), $min_max_ds->max_y() ] - ); - } - - # either set manually on the axes, or generated by the axes from the data - my ($data_min, $data_max) = $self->{__axes__}->get_bounds(); - - - my @image_size = $self->{__image__}->get_size(); - - # directly map data pts to image space: (0,0) -> (300, 300) in pixels - # x' == (Sx)(x) + tx, Sx == some scale, x == xcoord from dataset, tx == some transformation, x' == new xcoord - # y' == (Sy)(y) + ty, Sy == some scale, y == ycoord from dataset, ty == some transformation, y' == new ycoord - - my ($stencil_min_x, $stencil_min_y) = ($self->{__graph_stencil_min__}->[0], $self->{__graph_stencil_min__}->[1]); - my ($stencil_max_x, $stencil_max_y) = ($self->{__graph_stencil_max__}->[0], $self->{__graph_stencil_max__}->[1]); - - my $map_data_to_image_cs = $self->_data_to_image_fn(); - my $map_image_to_data_cs = $self->_image_to_data_fn(); - - - # TODO: wrap this ugliness and cheating in Moon::Image... - my $watermark = Moon::Image->load_from_file("/var/www/html/img/rhn-logo-screened.png"); - -# foreach my $w_color_index (0 .. $watermark->{__image__}->colorsTotal()) { -# $self->{__image__}->add_color($watermark->get_rgb($w_color_index)); -# } - - # 1st color added seems to be the default background color... - my $white = $self->image()->get_color(255, 255, 255); - my $black = $self->image()->get_color(0, 0, 0); - my $grey = $self->image()->get_color(167, 167, 167); - - my @dataset_colors; - - my @colors = ( [ 0, 0, 255 ], [ 255, 0, 0 ], [ 0, 255, 0 ], - [ 255, 255, 0 ], [ 255, 0, 255 ], [ 0, 255, 255 ], - [ 0, 153, 255 ], [ 0, 255, 153 ], [ 255, 0, 153 ], - [ 255, 153, 0 ], [ 153, 255, 0 ], [ 153, 0, 255 ], - [ 255, 255, 255 ], [ 255, 127, 255 ], [ 127, 255, 127 ], - [ 127, 127, 255 ], [ 255, 127, 255 ], [ 63, 63, 63 ],); - - - foreach my $color (@colors) { - unshift @dataset_colors, $self->image()->get_color(@{$color}); - } - - # CRAP. GD::filledRectangle is broken, meethinks. - - $self->image()->draw_rectangle($stencil_min_x + 3, $image_size[1] - $stencil_min_y + 3, - $stencil_max_x + 3, $image_size[1] - $stencil_max_y + 3, - $grey); - - $self->image()->{__image__}->fillToBorder($stencil_min_x + ($stencil_max_x - $stencil_min_x)/2, - $image_size[1] - ($stencil_min_y + ($stencil_max_y - $stencil_min_y)/2), - $grey, $grey); - - - $self->image()->draw_rectangle($stencil_min_x, $image_size[1] - $stencil_min_y, - $stencil_max_x, $image_size[1] - $stencil_max_y, - $black); - - $self->image()->{__image__}->fillToBorder($stencil_min_x + ($stencil_max_x - $stencil_min_x)/2, - $image_size[1] - ($stencil_min_y + ($stencil_max_y - $stencil_min_y)/2), - $black, $white); - - my @watermark_size = $watermark->get_size(); - my $watermark_x = $stencil_min_x + ($stencil_max_x - $stencil_min_x)/2 - $watermark_size[0]/2; - my $watermark_y = $image_size[1] - ($stencil_min_y + ($stencil_max_y - $stencil_min_y)/2) - $watermark_size[1]/2; - - $self->{__axes__}->_draw($self->image(), $map_data_to_image_cs, - $stencil_max_x - $stencil_min_x, - $stencil_max_y - $stencil_min_y); - - - my $current_color; - - my $font_size = $self->{__image__}->get_font_size_normal(); - - my $dataset_counter = 1; - - my @labels = sort keys %{$self->{__datasets__}}; - my $longest = 0; #the length of the longest *odd numbered* label - for the legend - - foreach my $datalabel (@labels) { - if ($dataset_counter % 2 and length $datalabel > $longest) { - $longest = length $datalabel; - } - $dataset_counter++; - } - - $dataset_counter = 1; - - foreach my $datalabel (@labels) { - - if (@dataset_colors) { - $current_color = pop @dataset_colors; - } - else { - die "ran out of colors!"; - } - - my $dataset = $self->{__datasets__}->{$datalabel}; - - # draw MRTG'ish graph, using pixel cs - my $last_pt; - - my $ds_draw_min_x; - my ($ds_pixel_min_x, $foo) = $map_data_to_image_cs->($dataset->min_x(), 0); - - $ds_draw_min_x = $ds_pixel_min_x > $stencil_min_x ? $ds_pixel_min_x : $stencil_min_x; - - foreach my $pixel_x ($ds_draw_min_x .. $stencil_max_x) { - - my ($x, $foo) = $map_image_to_data_cs->($pixel_x, 0); - - my $y; - - eval { - $y = $dataset->value_at($x); - }; - if ($@) { - if ($@ =~ m/outside of bounds/) { - # what to do when we don't have data? - #warn "data point out of bounds..."; - next; - } - else { - die $@; - } - } - - if (defined $y) { - - if ($y > $data_max->[1]) { - $y = $data_max->[1]; - } - elsif ($y < $data_min->[1]) { - $y = $data_min->[1]; - } - - my ($throwaway, $pixel_y) = $map_data_to_image_cs->($x, $y); - - if ($last_pt) { - my @ics_last = ($last_pt->[0], $last_pt->[1]); - my @ics_current = ($pixel_x, $pixel_y); - - $self->{__image__}->draw_line(@ics_last, @ics_current, $current_color); - } - - $last_pt = [ $pixel_x, $pixel_y ]; - } - else { - $last_pt = 0; - } - - } - - my ($legend_x, $legend_y); - - if ($dataset_counter % 2) { - $legend_x = 60; - $legend_y = ($image_size[1] - $stencil_min_y) + int($font_size->[1] * .8) + $dataset_counter * (int($font_size->[1] * .6)); - #bottom of graph + room for time/date + the row number * height of font - } else { - $legend_x = $longest * $font_size->[0] + 85; - $legend_y = ($image_size[1] - $stencil_min_y) + int($font_size->[1] * .8) + ($dataset_counter - 1) * (int($font_size->[1] * .6)); - #bottom of graph + room for time/date + the row number * height of font - } - - $self->{__image__}->draw_text($legend_x, $legend_y, $datalabel, $black); - $self->{__image__}->draw_line($legend_x - 5, $legend_y + $font_size->[1]/2, $legend_x - 15, - $legend_y + $font_size->[1]/2, $current_color); - - $dataset_counter++; - } - - # draw border last... - $self->image()->draw_rectangle($stencil_min_x, $image_size[1] - $stencil_min_y, - $stencil_max_x, $image_size[1] - $stencil_max_y, - $black); - - $self->image()->save($filename); -} - -my $VERSION = '0.01'; - -1; -__END__ -# Below is stub documentation for your module. You better edit it! - -=head1 NAME - -Moon::Chart - Implementation of a Chart class for use with RHN Monitoring. - -=head1 SYNOPSIS - - use Moon::Chart; - -=head1 DESCRIPTION - -Uses Moon::Dataset and Moon::Image to draw a graph from a set of data - -=head2 EXPORT - -No. - -=head1 AUTHOR - -Spacewalk Team rhn-feedback@redhat.com - -=head1 SEE ALSO - -rhn.redhat.com - -L<perl>. - -=cut diff --git a/web/modules/moon/Moon/Chart/TimeAxes.pm b/web/modules/moon/Moon/Chart/TimeAxes.pm deleted file mode 100644 index ba870be..0000000 --- a/web/modules/moon/Moon/Chart/TimeAxes.pm +++ /dev/null @@ -1,195 +0,0 @@ -# -# Copyright (c) 2008 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -package Moon::Chart::TimeAxes; - -# class internal to Moon::Chart for rendering axes/tickmarks, etc... - -# for now, this class is mainly a timestamp-x-axis Axes class until the base class is more clearly -# defined - -use strict; - -use Data::Dumper; - -use Date::Format; -use Date::Manip; -use Moon::Image; -use RHN::Date; - -my %time_formats = ( - (60 * 1) => [ '%l:%M:%S%p', 'Minute', 10, 60], # minute - 2 * (60 * 60) => [ '%l:%M%p', 'Hourly', 600, 600], # hour - 2 * (24 * 3600) => [ '%l:%M%p', 'Daily', 14400, 3600], # day - 2 * 7 * (24 * 3600) => [ '%b %e', 'Weekly', 86400, 24 * 3600], - 2 * 31 * (24 * 3600) => [ '%b %e', 'Monthly', 345600, 24 * 3600], # month - 365 * (24 * 3600) => [ '%b %y', 'Yearly', 2592000, 24 * 3600] # year - ); - - -sub new { - my $class = shift; - my $self = bless { }, $class; - - $self->{__data_mins__} = shift; - $self->{__data_maxes__} = shift; - - if ($self->{__data_mins__} and $self->{__data_maxes__}) { - $self->_calc_ticks(); - } - - $self->{__y_axis_format__} = "%.2f"; - $self->{__y_axis_divisor__} = shift || 1; - - $self->{__user__} = shift || undef; - - return $self; -} - -sub set_y_axis_format { - my $self = shift; - $self->{__y_axis_format__} = shift; -} - -sub set_y_axis_divisor { - my $self = shift; - $self->{__y_axis_divisor__} = shift; -} - -sub set_bounds { - my $self = shift; - - $self->{__data_mins__} = shift; - $self->{__data_maxes__} = shift; - - $self->_calc_ticks(); -} - - -sub get_bounds { - my $self = shift; - return ($self->{__data_mins__}, $self->{__data_maxes__}); -} - -sub _calc_ticks { - my $self = shift; - - # figure out ticks - my $delta_x = $self->{__data_maxes__}->[0] - $self->{__data_mins__}->[0]; - - my $time_scale; - my @timescales = sort { $a <=> $b } map { int($_) } keys %time_formats; - - foreach my $timescale (@timescales) { - if ($delta_x < $timescale) { - $time_scale = $time_formats{$timescale}; - last; - } - } - - die "no time scale determined!" unless $time_scale; - - $self->{__time_scale__} = $time_scale; - - my @xs = $self->_x_ticks($time_scale->[2], $time_scale->[3], - $self->{__data_mins__}->[0], $self->{__data_maxes__}->[0]); - - $self->{__x_ticks__} = @xs; - - my @ys = $self->_y_ticks(); - - $self->{__y_ticks__} = @ys; -} - - -sub _y_ticks { - my $self = shift; - - my $delta_y = $self->{__data_maxes__}->[1] - $self->{__data_mins__}->[1]; - my $num_ticks = 5; - - return map { $self->{__data_mins__}->[1] + $_ * $delta_y / $num_ticks } (0..$num_ticks); -} - -sub _x_ticks { - my $self = shift; - my $delta = shift; - my $step_or_weird_var_that_is_not_needed_because_this_is_weird_code = shift; - my $start = shift; - my $end = shift; - - my @dates; - for (my $cur = $start; $cur <= $end; $cur += $delta) { - push @dates, $cur; - } - - push @dates, $end if $dates[-1] != $end; - - return @dates; -} - -sub _draw { - my $self = shift; - my $image = shift; - my $point_mapper = shift; - my $graph_width = shift; - my $graph_height = shift; - - - $self->_calc_ticks() if (!$self->{__x_ticks__}); - - my @x_ticks = @{$self->{__x_ticks__}}; - my @y_ticks = @{$self->{__y_ticks__}}; - - - # make sure we have grey and black for drawing - my $grey = $image->get_color(204, 204, 204); - my $black = $image->get_color(0, 0, 0); - - my $font_size = $image->get_font_size_tiny(); - - foreach my $x_tick (@x_ticks) { - - my $x_tick_str; - if ($self->{__user__}) { - #if the user object has been passed in, then set the x_ticks to be in that user's timezone - my $timestamp = new RHN::Date(-epoch => $x_tick, user => $self->{__user__}); - $x_tick_str = $timestamp->strftime($self->{__time_scale__}->[0]); - } - else { - #if not, use the default system timezone in the x_ticks - $x_tick_str = time2str($self->{__time_scale__}->[0], $x_tick); - } - - my ($pix_x, $pix_y) = $point_mapper->($x_tick, $self->{__data_mins__}->[1]); - my $pix_x_text = $pix_x - (int(length($x_tick_str) / 2) * $font_size->[0]); - - $image->draw_tiny_text($pix_x_text, $pix_y + 5, $x_tick_str, $black); - $image->draw_line($pix_x, $pix_y, $pix_x, $pix_y - $graph_height, $grey); - } - - foreach my $y_tick (@y_ticks) { - - my ($pix_x, $pix_y) = $point_mapper->($self->{__data_mins__}->[0], $y_tick); - - $y_tick = sprintf($self->{__y_axis_format__}, $y_tick / $self->{__y_axis_divisor__}); - my $pix_x_text = $pix_x - (int(length($y_tick)) * $font_size->[0] + 2); - - $image->draw_tiny_text($pix_x_text, $pix_y - $font_size->[1]/2, $y_tick, $black); - $image->draw_line($pix_x, $pix_y, $pix_x + $graph_width, $pix_y, $grey); - } -} - -1; diff --git a/web/modules/moon/Moon/Dataset.pm b/web/modules/moon/Moon/Dataset.pm deleted file mode 100644 index 68483d0..0000000 --- a/web/modules/moon/Moon/Dataset.pm +++ /dev/null @@ -1,61 +0,0 @@ -# -# Copyright (c) 2008 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -package Moon::Dataset; - -use strict; - -my $VERSION = '0.02'; - -#gaurunteed interfaces: - -sub new { die "sub new should never be called in Moon::Dataset" } -sub min_x { die "sub min_x should never be called in Moon::Dataset" } -sub max_x { die "sub max_x should never be called in Moon::Dataset" } -sub value_at { die "sub value_at should never be called in Moon::Dataset" } - -1; - -__END__ -# Below is stub documentation for your module. You better edit it! -# Nag, nag nag... - -=head1 NAME - -Moon::Dataset - Implementation of a Dataset parent class for use with RHN Monitoring. - -=head1 SYNOPSIS - -This is just a virtual parent class - see Moon::Dataset::Coordinate or Moon::Dataset::Function - -=head1 DESCRIPTION - -Provides a set of data - also interpolation, sampling and perhaps statistical analysis for use with the Spacewalk monitoring code. - -=head2 EXPORT - -No. - -=head1 AUTHOR - -Spacewalk Team rhn-feedback@redhat.com - -=head1 SEE ALSO - -rhn.redhat.com - -L<perl>. - -=cut diff --git a/web/modules/moon/Moon/Dataset/Coordinate.pm b/web/modules/moon/Moon/Dataset/Coordinate.pm deleted file mode 100644 index ea403cc..0000000 --- a/web/modules/moon/Moon/Dataset/Coordinate.pm +++ /dev/null @@ -1,531 +0,0 @@ -# -# Copyright (c) 2008 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -package Moon::Dataset::Coordinate; - -use strict; - -use lib '/var/www/lib'; - -use Moon::Dataset; -use RHN::DB; -use Date::Parse; -use Math::FFT; -use Data::Dumper; - -our @ISA = qw/Moon::Dataset/; - -my $VERSION = '0.01'; - -my @valid_interpolation_methods = qw/Linear/; -my @known_fields = qw/interpolation x_vals y_vals max_gap label/; - -#new - can set interpolation method, and coordinates - either as two -#array refs (x_vals, y_vals) or a nested arrayref (coords) -sub new { - my $class = shift; - my %attr = @_; - - my $self = bless { interpolation => 'Linear', - label => 'Set', - x_vals => [ ], - y_vals => [ ], - last_i => 0, - max_gap => undef }, $class; - - foreach (@known_fields) { - if (exists $attr{"-$_"}) { - $self->{$_} = $attr{"-$_"}; - } - } - - if (exists $attr{-coords}) { - $self->_load_coords($attr{-coords}); - } - - $self->_validate; - - $self->{interpolation} = 'Linear' - unless grep { $_ eq $self->{interpolation} } @valid_interpolation_methods; - - $self->_order if @{$self->{x_vals}}; - - return $self; -} - -#gets or sets the interpolation method -sub interpolation { - my $self = shift; - my $interp = shift; - - if (defined $interp && grep { $_ eq $interp} @valid_interpolation_methods) { - $self->{interpolation} = $interp; - } - - return $self->{interpolation}; -} - -sub label { - my $self = shift; - my $label = shift; - - if (defined $label) { - $self->{label} = $label; - } - - return $self->{label}; -} - -#getter for x_vals -sub x_vals { - my $self = shift; - - return $self->{x_vals}; -} - -#getter for y_vals -sub y_vals { - my $self = shift; - - return $self->{y_vals}; -} - - -#smallest x value -always the first, as the set is always-ordered -sub min_x { - my $self = shift; - - return $self->{x_vals}->[0]; -} - -#biggest x -always the last -sub max_x { - my $self = shift; - - return $self->{x_vals}->[-1]; -} - -#smallest y value -has to scan the full set right now -sub min_y { - my $self = shift; - - my $min = $self->{y_vals}->[0]; - - foreach my $y (@{$self->{y_vals}}) { - next unless defined $y; - - if ( $y < $min ) { - $min = $y; - } - } - - return $min; -} - -#biggest y -has to scan the full set right now -sub max_y { - my $self = shift; - - my $max = $self->{y_vals}->[0]; - - foreach my $y (@{$self->{y_vals}}) { - next unless defined $y; - - if ( $y > $max ) { - $max = $y; - } - } - - return $max; -} - -#call with a scaler to find the (possibly interpolated) y value for a given x -#call with an array ref to find y values for given xes -sub value_at { - my $self = shift; - my $xes = shift; - - if (ref $xes eq 'ARRAY') { - $self->{last_i} = 0; #clean the cache - - my $low_mark = 0; - - while ($xes->[$low_mark] < $self->{x_vals}->[0] and $low_mark < $#{$xes}) { - $low_mark++; - } - - my $high_mark = $#{$xes}; - while ($xes->[$high_mark] > $self->{x_vals}->[-1] and $high_mark > 0) { - $high_mark--; - } - - my $ret = $self->_values_in([ @{$xes}[$low_mark .. $high_mark] ]); - - my $pre = [ ]; - my $post = [ ]; - - if ($low_mark > 0) { - $pre = $self->_values_out([ @{$xes}[0 .. $low_mark - 1] ]); - } - - if ($high_mark < $#{$xes}) { - $post = $self->_values_out([ @{$xes}[$high_mark + 1 .. $#{$xes}] ]); - } - - $self->{last_i} = 0; #clean the cache - return [ @{$pre}, @{$ret}, @{$post} ]; - } else { - # $self->{last_i} = 0; #clean the cache - my $ret; - - if ($xes < $self->{x_vals}->[0] or $xes > $self->{x_vals}->[-1]) { - $ret = $self->_values_out([ $xes ]); - } - else { - $ret = $self->_values_in([ $xes ]); - } - # $self->{last_i} = 0; #clean the cache - return $ret->[0]; - } -} - -sub derivative_set { - my $self = shift; - - my @new_y; - my @new_x = @{$self->{x_vals}}; - shift @new_x; # throw away bottom data point - for my $i (0 .. $#new_x) { - push @new_y, ($self->{y_vals}->[$i + 1] - $self->{y_vals}->[$i]) / ($self->{x_vals}->[$i + 1] - $self->{x_vals}->[$i]); - } - - my $derived_set = new Moon::Dataset::Coordinate(-x_vals => @new_x, - -y_vals => @new_y, - -max_gap => $self->{max_gap}, - -interpolation => $self->{interpolation}, - -label => $self->{label}); - - return $derived_set; -} - -#get or set the coords in [ [1,2], [3,4], [5,6] ] format -sub coords { - my $self = shift; - my $coords = shift; - - if (defined $coords) { - $self->{last_i} = 0; #clean the cache - $self->_load_coords($coords); - $self->_order; - $self->_validate; - } - - my $num_elems = scalar @{$self->{x_vals}}; - return [ map { [ $self->{x_vals}->[$_], $self->{y_vals}->[$_] ] } ( 0 .. ($num_elems - 1) ) ]; -} - -#remesh the set over a given domain - domain must be - min_x <= domain >= max_x -sub remesh { - my $self = shift; - my $samples = shift; - my $lower_bound = shift || $self->min_x; - my $upper_bound = shift || $self->max_x; - - my $width = $upper_bound - $lower_bound; - - my $new_xs = [ map { $lower_bound + ($width / ($samples - 1)) * $_ } (0 .. ($samples - 1)) ]; - my $new_ys; - - if ($samples >= @{$self->{x_vals}}) { #if we are getting more values, find the value_ats - $new_ys = $self->value_at($new_xs); - } - else { #if we are getting fewer values, average surrounding value_ats... - my $bss = ($width / $samples) / 2; - - foreach my $x (@{$new_xs}) { - my $low_sample = ($x - $bss) < $self->min_x ? $self->min_x : ($x - $bss); - my $high_sample = ($x + $bss) > $self->max_x ? $self->max_x : ($x + $bss); - - push @{$new_ys}, _ave($self->value_at([ $low_sample, $high_sample ])); - } - } - - my $old_samples = scalar @{$self->{x_vals}} + 1; - - if (defined $self->{max_gap}) { - $self->{max_gap} = $self->{max_gap} * ($old_samples / $samples); - } - - $self->{x_vals} = $new_xs; - $self->{y_vals} = $new_ys; - - return 1; -} - -sub fft { - my $self = shift; - my $num_terms = shift || 96; - my $fft = new Math::FFT($self->y_vals); - my $coeff = $fft->ddct(); - - @{$coeff}[$num_terms .. $#$coeff] = map { 0 } ($num_terms .. $#$coeff); - my $smooth_data = $fft->invddct($coeff); - - $self->{y_vals} = $smooth_data; - - return 1; -} - -#average all of the y values for multiple datasets together, over the same domain of x values -#return a dataset with averages -#the x_vals for all sets are assumed to be the same, and they are assumed to have the same number of elements -sub average { - my $class = shift; - my @sets = @_; - - my @ave_ys = (); - my $num_sets = scalar @sets; - - my @aves = (0) x @{$sets[0]->{x_vals}}; - - foreach my $set (@sets) { - my $vals = $set->value_at($sets[0]->{x_vals}); - @aves = map { $aves[$_] += ($vals->[$_] / $num_sets) } (0 .. @{$vals} - 1); - } - - return $class->new( -x_vals => [ @{$sets[0]->{x_vals}} ], -y_vals => [ @aves ], - -interpolation => $sets[0]->{interpolation} ); -} - -#private function ordering the set - should be called whenever set is changed -sub _order { - my $self = shift; - - $self->{last_i} = 0; - my $num_elems = scalar @{$self->{x_vals}}; - my @order = sort { $self->{x_vals}->[$a] <=> $self->{x_vals}->[$b] } ( 0 .. ($num_elems - 1) ); - - @{$self->{x_vals}} = @{$self->{x_vals}}[@order]; - @{$self->{y_vals}} = @{$self->{y_vals}}[@order]; - - return; -} - -#private part of value_at function -sub _values_in { - my $self = shift; - my $xes = shift; - - die "No x values" unless @{$xes}; - - my $last_i = 0; - my @ret; - - if (($self->{last_i} > 0) and ($xes->[0] >= $self->{x_vals}->[$self->{last_i}])) { - $last_i = $self->{last_i}; - } - - my $num_elems = scalar @{$self->{x_vals}}; - my $gap = $self->{max_gap}; - - if ($xes->[0] == $self->{x_vals}->[0]) { - push @ret, $self->{y_vals}->[0]; - shift @{$xes}; - } - - foreach my $x (@{$xes}) { - my ($lower_x, $lower_y, $upper_x, $upper_y); - - foreach my $index ($last_i .. ($num_elems - 1)) { - - if ($self->{x_vals}->[$index] >= $x) { - $lower_x = $self->{x_vals}->[$index - 1]; - $upper_x = $self->{x_vals}->[$index]; - $lower_y = $self->{y_vals}->[$index - 1]; - $upper_y = $self->{y_vals}->[$index]; - - $last_i = $index - 1; - last; - } - } - - my $slope; - my $y; - if (defined $gap && $upper_x - $lower_x > $gap) { #asking for a value where there is a gap in the data.... - - if ($x <= $lower_x + $gap / 2) { #if we're 'pretty close' to the bottom of the gap - extrapolate - my $i = $last_i; - until (defined $self->{y_vals}->[$i--] || $i < 0) { }; - - if ($i >= 0) { - $slope = ($lower_y - $self->{y_vals}->[$i]) / ($lower_x - $self->{x_vals}->[$i]); - $y = ($x - $lower_x) * $slope + $lower_y; - } - } - elsif ($x >= $upper_x - $gap / 2) { #close to top of the gap - my $i = $last_i + 1; - until (defined $self->{y_vals}->[$i++] || $i > $#{$self->{y_vals}}) { }; - - if ($i <= $#{$self->{y_vals}}) { - $slope = ($self->{y_vals}->[$i] - $upper_y) / ($self->{x_vals}->[$i] - $upper_x); - $y = ($upper_x - $x) * $slope + $upper_y; - } - } - } - else { - if (defined $upper_y and defined $lower_y) { - $slope = ($upper_y - $lower_y) / ($upper_x - $lower_x); - $y = ($x - $lower_x) * $slope + $lower_y; - } - } - - if (defined $y) { - push @ret, $y; - } - else { - push @ret, 0; - } - - - } - - $self->{last_i} = $last_i; - - return @ret; -} - -sub _values_out { - my $self = shift; - my $xes = shift; - - die "No x values" unless @{$xes}; - - my @ret; - - foreach my $x (@{$xes}) { - if ($x < $self->{x_vals}->[0]) { - if ($self->{x_vals}->[0] - $x > $self->{max_gap}) { - push @ret, 0; - } - else { - my $slope = ($self->{y_vals}->[1] - $self->{y_vals}->[0]) / ($self->{x_vals}->[1] - $self->{x_vals}->[0]); - push @ret, ($x - $self->{x_vals}->[0]) * $slope + $self->{y_vals}->[0]; - } - } - elsif ($x > $self->{x_vals}->[-1]) { -# if ($x - $self->{x_vals}->[-1] > $self->{max_gap}) { - push @ret, undef; #just truncate now -# } -# else { -# my $slope = ($self->{y_vals}->[-1] - $self->{y_vals}->[-2]) / ($self->{x_vals}->[-1] - $self->{x_vals}->[-2]); -# push @ret, ($x - $self->{x_vals}->[-2]) * $slope + $self->{y_vals}->[-2]; -# } - } - else { - Data::Dumper->Dump([($self)]); - die "-values_out called with '$x'\n"; - } - } - return @ret; -} - -#private part of coords function - also used by constructor -sub _load_coords { - my $self = shift; - my $coords = shift; - - $self->{x_vals} = [ map { $_->[0] } @{$coords} ]; - $self->{y_vals} = [ map { $_->[1] } @{$coords} ]; - - return; -} - -#does some basic sanity checking - called by constructor, and wherever contents are changed -sub _validate { - my $self = shift; - - foreach my $n (@{$self->{x_vals}}) { - die "x value '$n' is not numeric enough." if $n =~ /[^\d.-]/; - } - - foreach my $n (@{$self->{y_vals}}) { - die "y value '$n' is not numeric enough." if $n =~ /[^\d.-]/; - } - - die "unequal number of x and y values." unless (scalar @{$self->{x_vals}} == scalar @{$self->{y_vals}}); - - return 1; -} - -#average some values from an arrayref -sub _ave { - my $vals = shift; - - my $sum = 0; - - foreach my $v (@{$vals}) { - next unless defined $v; - $sum += $v; - } - - return $sum / (scalar @{$vals}); -} - -1; - -__END__ -# Below is stub documentation for your module. You better edit it! -# Nag, nag nag... - -=head1 NAME - -Moon::Dataset - Implementation of a Dataset class for use with RHN Monitoring. - -=head1 SYNOPSIS - - use Moon::Dataset; - - my $ds = new Moon::Dataset (interpolate => 'Linear'); - - $ds->coords([ [1,2], [3,4], [5,6] ]); - - print $ds->value_at(1.5); # 2.5 - print join ", ", @{$ds->value_at([1,1.5,2,3,4,5])}; # 2, 2.5, 3, 4, 5, 6 - - print $ds->mix_x; # 1 - print $ds->max_y; # 6 - - print join ", ", @{$ds->x_vals}; # 1, 3, 5 - print join ", ", @{$ds->y_vals}; # 2, 4, 6 - -=head1 DESCRIPTION - -Provides a set of data - also interpolation, sampling and perhaps statistical analysis for use with the Spacewalk monitoring code. - -=head2 EXPORT - -No. - -=head1 AUTHOR - -Spacewalk Team rhn-feedback@redhat.com - -=head1 SEE ALSO - -rhn.redhat.com - -L<perl>. - -=cut diff --git a/web/modules/moon/Moon/Dataset/Function.pm b/web/modules/moon/Moon/Dataset/Function.pm deleted file mode 100644 index 2d0f67e..0000000 --- a/web/modules/moon/Moon/Dataset/Function.pm +++ /dev/null @@ -1,241 +0,0 @@ -# -# Copyright (c) 2008 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -package Moon::Dataset::Function; - -use strict; - -use Moon::Dataset; - -our @ISA = qw/Moon::Dataset/; - -my $VERSION = '0.01'; - -my @known_fields = qw/function x_vals/; - -#new - can set interpolation method, and coordinates - either as two -#array refs (x_vals, y_vals) or a nested arrayref (coords) -sub new { - my $class = shift; - my %attr = @_; - - my $self = bless { function => '$_', - x_vals => [ ] }, $class; - - foreach (@known_fields) { - if (exists $attr{"-$_"}) { - $self->{$_} = $attr{"-$_"}; - } - } - - $self->_validate; - $self->_order if @{$self->{x_vals}}; - - return $self; -} - -#getter/setter for function -sub function { - my $self = shift; - my $func = shift; - - if (defined $func) { - $self->{function} = $func; - } - - return $self->{function}; -} - -#getter/setter for x_vals -sub x_vals { - my $self = shift; - my $x_vals = shift; - - if (defined $x_vals) { - $self->{x_vals} = $x_vals; - $self->_order; - } - - return $self->{x_vals}; -} - -#smallest x value -always the first, as the set is always-ordered -sub min_x { - my $self = shift; - - return $self->{x_vals}->[0]; -} - -#biggest x -always the last -sub max_x { - my $self = shift; - - return $self->{x_vals}->[-1]; -} - -#smallest y value -has to scan the full set right now -sub min_y { - my $self = shift; - - my @vals = @{$self->y_vals}; - my $min = $vals[0]; - - foreach my $y (@vals) { - - if ( $y < $min ) { - $min = $y; - } - } - - return $min; -} - -#biggest y -has to scan the full set right now -sub max_y { - my $self = shift; - - my @vals = @{$self->y_vals}; - my $max = $vals[0]; - - foreach my $y (@vals) { - - if ( $y > $max ) { - $max = $y; - } - } - - return $max; -} - -#call with a scaler to find the y value for a given x -#call with an array ref to find y values for given xes -sub value_at { - my $self = shift; - my $input = shift; - - my $xes; - - if (ref $input eq 'ARRAY') { - $xes = $input; - } - else { - $xes = [ $input ]; - } - - my @ret; - - foreach my $x ( @{$xes} ) { - push @ret, eval $self->{function}; - if ($@) { - die "Error evaluating '$x' in '",$self->{function},"': $@"; - } - } - - if (ref $input eq 'ARRAY') { - return @ret; - } - else { - return $ret[0]; - } - -} - -#y values for all xes -sub y_vals { - my $self = shift; - - return $self->value_at($self->{x_vals}); -} - -#remesh the set over a given domain - domain must be - min_x <= domain >= max_x -sub remesh { - my $self = shift; - my $samples = shift; - my $lower_bound = shift || $self->min_x; - my $upper_bound = shift || $self->max_x; - - my $width = $upper_bound - $lower_bound; - - my $new_xs = [ map { $lower_bound + ($width / ($samples - 1)) * $_ } (0 .. ($samples - 1)) ]; - - return new Moon::Dataset::Function (-function => $self->{function}, -x_vals => $new_xs); -} - -#private function ordering the set - should be called whenever set is changed -sub _order { - my $self = shift; - - $self->{x_vals} = [ sort { $a <=> $b } @{$self->{x_vals}} ]; - - return; -} - -#does some basic sanity checking - called by constructor, and wherever contents are changed -sub _validate { - my $self = shift; - - foreach my $n (@{$self->{x_vals}}) { - die "x value '$n' is not numeric enough." if $n =~ /[^\d.-]/; - } - - return 1; -} - -1; - -__END__ -# Below is stub documentation for your module. You better edit it! -# Nag, nag nag... - -=head1 NAME - -Moon::Dataset - Implementation of a Dataset class for use with RHN Monitoring. - -=head1 SYNOPSIS - - use Moon::Dataset; - - my $ds = new Moon::Dataset (interpolate => 'Linear'); - - $ds->coords([ [1,2], [3,4], [5,6] ]); - - print $ds->value_at(1.5); # 2.5 - print join ", ", @{$ds->value_at([1,1.5,2,3,4,5])}; # 2, 2.5, 3, 4, 5, 6 - - print $ds->mix_x; # 1 - print $ds->max_y; # 6 - - print join ", ", @{$ds->x_vals}; # 1, 3, 5 - print join ", ", @{$ds->y_vals}; # 2, 4, 6 - -=head1 DESCRIPTION - -Provides a set of data - also interpolation, sampling and perhaps statistical analysis for use with the Spacewalk monitoring code. - -=head2 EXPORT - -No. - -=head1 AUTHOR - -Spacewalk Team rhn-feedback@redhat.com - -=head1 SEE ALSO - -rhn.redhat.com - -L<perl>. - -=cut diff --git a/web/modules/moon/Moon/Image.pm b/web/modules/moon/Moon/Image.pm deleted file mode 100644 index 21806bc..0000000 --- a/web/modules/moon/Moon/Image.pm +++ /dev/null @@ -1,197 +0,0 @@ -# -# Copyright (c) 2008 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -package Moon::Image; - -use strict; - -use GD; -use Data::Dumper; - -sub new { - my $class = shift; - my ($x, $y) = @_; - - my $self = bless { }, $class; - - $self->{__image__} = new GD::Image($x, $y); - - return $self; -} - -# returns (size_x, size_y) -sub get_size { - my $self = shift; - return $self->{__image__}->getBounds(); -} - -# returns true/false whether image loaded from file properly -sub load_from_file { - my $class = shift; - my $filename = shift; - - my $self = bless { }, $class; - - $self->{__image__} = GD::Image->new($filename); - - die "Problem loading image $filename ..." unless ($self->{__image__}); - - return $self; -} - -sub save { - my $self = shift; - my $filename = shift; - - open(NEW_IMAGE, ">$filename") or die "Problem saving $filename: $!"; - - print NEW_IMAGE $self->{__image__}->png; - - close(NEW_IMAGE); - - return 1; -} - -# adds a color (R, G, B) to the image's color table and returns the index of the color -# you have to use this before you can use colors -sub add_color { - my $self = shift; - return $self->{__image__}->colorAllocate(shift, shift, shift); -} - -# probably won't need this... -sub remove_color { - my $self = shift; - $self->{__image__}->colorDeallocate(shift); -} - -# gets (or adds and gets) desired RGB color -sub get_color { - my $self = shift; - return $self->{__image__}->colorResolve(@_) -} - -# returns (r, g, b) for given color index -sub get_rgb { - my $self = shift; - my $color_index = shift; - return $self->{__image__}->rgb($color_index); -} - -# marks a certain color as transparent -sub set_transparent { - my $self = shift; - - $self->{__image__}->transparent(shift); -} - -# gets the current transparent color index -sub get_transparent { - my $self = shift; - return $self->{__image__}->transparent(); -} - - -# Graphics primatives... -# ============================= - -# draw point given (x1, y1, color_index) -sub draw_pixel { - my $self = shift; - $self->{__image__}->setPixel(@_); -} - -# draw a line given (x1, y1, x2, y2, color_index) -sub draw_line { - my $self = shift; - $self->{__image__}->line(@_); -} - -# draw a dashed line given (x1, y1, x2, y2, color_index) -sub draw_dashed_line { - my $self = shift; - $self->{__image__}->dashedLine(@_); -} - -# draw a rectangle given (x1, y1, x2, y2, color_index) -sub draw_rectangle { - my $self = shift; - $self->{__image__}->rectangle(@_); -} - -# draw a filled rectangle given (x1, y1, x2, y2, color_index) -sub draw_filled_rectangle { - my $self = shift; - warn "drawing filled rectangle..."; - $self->{__image__}->filledRectangle(@_); -} - -# draw text in tiny font given (x, y, string, color) -sub draw_tiny_text { - my $self = shift; - $self->{__image__}->string(gdTinyFont, @_); -} - -# draw text in tiny font given (x, y, string, color) -sub draw_text { - my $self = shift; - $self->{__image__}->string(gdSmallFont, @_); -} - -# return [width, height] of tiny font -sub get_font_size_tiny { - my $self = shift; - return [ gdTinyFont->width, gdTinyFont->height ]; -} - -# return [width, height] of tiny font -sub get_font_size_normal { - my $self = shift; - return [ gdSmallFont->width, gdSmallFont->height ]; -} - -my $VERSION = '0.01'; - -1; -__END__ -#POD - -=head1 NAME - -Moon::Image - Implementation of a Image class for use with RHN Monitoring. - -=head1 SYNOPSIS - - use Moon::Image; - -=head1 DESCRIPTION - -An object which will render a Chart of a Dataset in png format. - -=head2 EXPORT - -No. - -=head1 AUTHOR - -Spacewalk Team rhn-feedback@redhat.com - -=head1 SEE ALSO - -rhn.redhat.com - -L<perl>. - -=cut diff --git a/web/modules/moon/README b/web/modules/moon/README deleted file mode 100644 index 0e26a59..0000000 --- a/web/modules/moon/README +++ /dev/null @@ -1,35 +0,0 @@ -Moon/Dataset version 0.01 -========================= - -The README is used to introduce the module and provide instructions on -how to install the module, any machine dependencies it may have (for -example C compilers and installed libraries) and any other information -that should be provided before the module is installed. - -A README file is required for CPAN modules since CPAN extracts the -README file from a module distribution so that people browsing the -archive can use it get an idea of the modules uses. It is usually a -good idea to provide version information here so that people can -decide whether fixes for the module are worth downloading. - -INSTALLATION - -To install this module type the following: - - perl Makefile.PL - make - make test - make install - -DEPENDENCIES - -This module requires these other modules and libraries: - - blah blah blah - -COPYRIGHT AND LICENCE - -Put the correct copyright and licence information here. - -Copyright (C) 2002 A. U. Thor blah blah blah - diff --git a/web/modules/moon/t/chart-init.t b/web/modules/moon/t/chart-init.t deleted file mode 100644 index 0a99955..0000000 --- a/web/modules/moon/t/chart-init.t +++ /dev/null @@ -1,33 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl test.pl' - -######################### - -# change 'tests => 1' to 'tests => last_test_to_print'; -use strict; -use Test; -BEGIN { plan tests => 4 }; -use Moon::Chart; -ok(1); # If we made it this far, we're ok. - -######################### - -# Insert your test code below, the Test module is use()ed here so read -# its man page ( perldoc Test ) for help writing this test script. - - -my @data = ( [6, -2], [0, 0], [2, -1.75], [2.5, -2], [3, 3], [4, 2.5], [1.02, 8] ); -my $dataset = new Moon::Dataset::Coordinate(); -$dataset->coords(@data); - -my $chart; - -ok($chart = new Moon::Chart(300, 300)); - - -$chart->add_dataset("random data", $dataset); -ok(1); - -my $time = time(); -ok($chart->render_to_file("images/$time.png") and -e "images/$time.png"); - diff --git a/web/modules/moon/t/dataset-init.t b/web/modules/moon/t/dataset-init.t deleted file mode 100644 index 40794e8..0000000 --- a/web/modules/moon/t/dataset-init.t +++ /dev/null @@ -1,101 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl test.pl' - -######################### - -# change 'tests => 1' to 'tests => last_test_to_print'; - -use Test; -BEGIN { plan tests => 27 }; -use Data::Dumper; -use Moon::Dataset::Coordinate; -use Moon::Dataset::Function; - -#check the constructor - -my $ds = new Moon::Dataset::Coordinate (-interpolation => 'Linear', - -coords => [ [1,1], [0,0] ] ); - -ok(ref $ds, 'Moon::Dataset::Coordinate'); #It is what we thought it was - -my $dump_1 = Data::Dumper->Dump([($ds)]); - -#check alternate construction method - should be identical to previous one - -$ds = new Moon::Dataset::Coordinate (-interpolation => 'Linear', - -x_vals => [1, 0], - -y_vals => [1, 0] ); - -my $dump_2 = Data::Dumper->Dump([($ds)]); - -ok($dump_1, $dump_2); - -#now check getter/setter methods - -ok($ds->interpolation, 'Linear'); -ok($ds->interpolation('Foo'), 'Linear'); #Shouldn't let us set to invalid value - -ok(scalar (@{$ds->coords}), 2); #two points in the dataset -ok(scalar (@{$ds->coords([ [2,2], [3,-1], [-5,4], [8,3], [-1,8], [100,-9], [-2,3], [0,0] ])}), 8); #replace points in dataset - - -my @mins = ($ds->min_x, $ds->min_y); #minimums of first and second elements (x,y) - -ok($mins[0], -5); -ok($mins[1], -9); - -my @maxs = ($ds->max_x, $ds->max_y); #maximums of first and second elements (x,y) - -ok($maxs[0], 100); -ok($maxs[1], 8); - -ok($mins[0],$ds->coords->[0]->[0]); #the first element of the first coordinate should be the minimum - -ok($maxs[0],$ds->coords->[-1]->[0]); #and the last should be the maximum - - -#check the value_at function - -ok($ds->value_at(-5), 4); -ok($ds->value_at(-1.5), 5.5); -ok($ds->value_at(100), -9); - -#now we do this wacked out database stuff - -$ds->load_from_db(1000560346, 5); - -my $vals = [ 1026845146, 1026845150, 1026845151, 1026845378, 1026846141, 1026846143, 1026846146 ]; -my $ret = [ 6.42, 6.18, 6.12, 11.174, 20.70, 21.024, 21.51 ]; - -ok($ds->value_at($vals->[1]), $ret->[1]); - -#this is slightly different from the last one - we are passing an arrayref instead of a single value -ok($ds->value_at($vals)->[5], $ret->[5]); - - -#test Moon::Dataset::Function - -$ds = new Moon::Dataset::Function (-function => '$x + 1', -x_vals => [-1, -2, -3, 0, 1, 2]); - -ok(ref($ds), 'Moon::Dataset::Function'); #It is what we thought it was - -ok($ds->y_vals->[4],2); - -ok($ds->min_x, -3); -ok($ds->max_x, 2); -ok($ds->min_y, -2); -ok($ds->max_y, 3); - - -#resampling - -$ds = $ds->remesh(11); - -ok($ds->x_vals->[3],-1.5); -ok($ds->y_vals->[3],-0.5); - -$ds = $ds->remesh(6); - -ok($ds->x_vals->[3], 0); -ok($ds->value_at(0), 1); - diff --git a/web/modules/moon/t/image-init.t b/web/modules/moon/t/image-init.t deleted file mode 100644 index b703c20..0000000 --- a/web/modules/moon/t/image-init.t +++ /dev/null @@ -1,46 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl test.pl' - -######################### - -# change 'tests => 1' to 'tests => last_test_to_print'; - -use Test; -BEGIN { plan tests => 7 }; -use Moon::Image; -ok(1); # If we made it this far, we're ok. - -######################### - -# Insert your test code below, the Test module is use()ed here so read -# its man page ( perldoc Test ) for help writing this test script. - -my $image; -eval { - $image = Moon::Image->load_from_file("images/non-existant.png"); -}; - -ok($@); - -ok($image = Moon::Image->load_from_file("images/chart.png")); - -ok($image = new Moon::Image(200, 200)); - -my $white = $image->add_color(0, 0, 0); -ok($white eq 0); - -my $red_and_green = $image->add_color(255, 255, 0); -my $black = $image->add_color(255, 255, 255); - -$image->set_transparent($red_and_green); -my $transparent = $image->get_transparent(); -ok($red_and_green, $transparent); - -$image->draw_pixel(10, 10, $black); -$image->draw_line(20, 0, 100, 145, $black); -$image->draw_rectangle(35, 35, 60, 80, $black); - -ok($image->draw_filled_rectangle(140, 140, 120, 89)); - -ok(1); - diff --git a/web/spacewalk-web.spec b/web/spacewalk-web.spec index 8491714..9d6a88a 100644 --- a/web/spacewalk-web.spec +++ b/web/spacewalk-web.spec @@ -117,15 +117,6 @@ Provides: rhn-sniglets = 5.3.0 This package contains the tag handlers for the PXT templates
-%package -n spacewalk-moon -Group: Applications/Internet -Summary: The Moon library for manipulating and charting data -Obsoletes: rhn-moon < 5.3.0 -Provides: rhn-moon = 5.3.0 - -%description -n spacewalk-moon -Modules for loading, manipulating, and rendering graphed data. - %prep %setup -q
@@ -301,11 +292,6 @@ rm -rf $RPM_BUILD_ROOT %{perl_vendorlib}/Sniglets.pm %{perl_vendorlib}/Sniglets/
-%files -n spacewalk-moon -%defattr(644,root,root,755) -%{perl_vendorlib}/Moon/ -%{_mandir}/man3/Moon* - %files -n spacewalk-html %defattr(644,root,root,755) %{_var}/www/html/*
spacewalk-commits@lists.fedorahosted.org