Changeset 107 for trunk/web/addons


Ignore:
Timestamp:
05/18/05 10:45:43 (19 years ago)
Author:
bastiaans
Message:

toga/toga-functions.php:

  • First working clusterimage
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/addons/toga/toga-functions.php

    r106 r107  
    269269
    270270                $this->hostname = $hostname;
    271                 $this->img = new NodeImg();
     271                //$this->img = new NodeImg();
    272272                $this->jobs = array();
    273273        }
     
    330330}
    331331
    332 class NodeImg {
     332class NodeImage {
    333333
    334334        var $image, $x, $y;
    335335
    336         function NodeImg( $image = null ) {
    337 
    338                 $imageWidth = 100;
    339                 $imageHeight = 100;
    340 
    341                 if( !$image ) {
    342                         $this->image = imageCreate( $imageWidth, $imageHeight );
    343                                 // or die( 'Cannot initialize new image stream: is GD installed?' );
    344                 } else {
    345                         $this->image = $image;
    346                 }
    347 
    348                 $background_color = imageColorAllocate( $this->image, 255, 255, 255 );
    349                 $black_color = imageColorAllocate( $this->image, 0, 0, 0 );
    350                 imageRectangle( $this->image, 0, 0, $imageWidth-1, $imageHeight-1, $black_color );
    351                 $this->x = null;
    352                 $this->y = null;
     336        function NodeImage( $image, $x, $y ) {
     337
     338                $this->image = $image;
     339                $this->x = $x;
     340                $this->y = $y;
    353341        }
    354342
    355343        function setCoords( $x, $y ) {
     344
    356345                $this->x = $x;
    357346                $this->y = $y;
     
    373362        }
    374363
    375         function drawNode( &$queuecolor, $load, &$jobcolor ) {
    376 
    377                 if( !$this->x or !$this->y or !$this->load ) {
     364        function drawNode( $load ) {
     365
     366                if( !isset( $this->x ) or !isset( $this->y ) or !isset( $load ) ) {
     367                        printf( "aborting\n" );
     368                        printf( "x %d y %d load %f\n", $this->x, $this->y, $load );
    378369                        return;
    379370                }
    380371
     372                $queue_color = imageColorAllocate( &$this->image, 0, 102, 304 );
     373                $job_color = imageColorAllocate( &$this->image, 204, 204, 0 );
    381374
    382375                // Convert Ganglias Hexadecimal load color to a Decimal one
     
    385378                imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+12, $this->y+12, $queuecolor );
    386379                imageFilledRectangle( $this->image, $this->x+2, $this->y+2, $this->x+10, $this->y+10, $my_loadcolor );
     380
    387381                // Een job markering?
    388382                //imageFilledEllipse( $this->image, ($this->x+9)/2, ($this->y+9)/2, 6, 6, $jobcolor );
     
    391385        function draw() {
    392386
    393                 $queue_color = imageColorAllocate( $this->image, 0, 102, 304 );
    394                 $job_color = imageColorAllocate( $this->image, 204, 204, 0 );
    395 
    396                 $this->drawNode( $queue_color, 0.1, $job_color );
    397         }
    398 }
    399 
    400 class ImageCreator {
     387                $cpus = $metrics[$this->hostname]["cpu_num"][VAL];
     388                if (!$cpus) $cpus=1;
     389                $load_one = $metrics[$this->hostname]["load_one"][VAL];
     390                $load = ((float) $load_one)/$cpus;
     391
     392                $this->drawNode( $load );
     393        }
     394}
     395
     396class ClusterImage {
    401397
    402398        var $dataget, $image;
    403399
    404         function ImageCreator() {
     400        function ClusterImage() {
    405401                $this->dataget = new DataGatherer();
    406402        }
    407403
    408404        function draw() {
    409                 $mydatag = &$this->dataget;
     405                $mydatag = $this->dataget;
    410406                $mydatag->parseXML();
    411407
     
    422418
    423419                if( $nodes_size > $max_width ) {
    424                         $nodes_per_row = (int) $max_width/$node_width;
     420                        $nodes_per_row = ( (int) ($max_width/$node_width) );
    425421                } else {
    426422                        $nodes_per_row = $nodes_size;
     
    429425
    430426                if( $nodes_per_row < $nodes_nr ) {
    431                         $node_rows = (int) $nodes_nr/$nodes_per_row;
    432                         if( ((int) fmod( $node_nr, ($nodes_nr*$nodes_per_row) )) > 0 ) {
     427                        $node_rows = ( (int) ($nodes_nr/$nodes_per_row) );
     428                        $node_rest = fmod( $nodes_nr, $nodes_per_row );
     429                        //printf( "nodesnr %d noderest %f\n", $nodes_nr, $node_rest );
     430                        if( $node_rest > 0 ) {
    433431                                $node_rows++;
     432                                //printf( "noderows %d\n", $node_rows );
    434433                        }
    435434                }
    436435
    437                 $image = imageCreate( ($nodes_per_row*$node_width), ($node_rows*$node_width) );
    438 
    439                 $cur_node = 0;
     436                //printf( "imagecreate: %dx%d", ($nodes_per_row*$node_width), ($node_rows*$node_width) );
     437                $image = imageCreateTrueColor( ($nodes_per_row*$node_width), ($node_rows*$node_width) );
     438                $colorwhite = imageColorAllocate( $image, 255, 255, 255 );
     439                imageFill( $image, 0, 0, $colorwhite );
    440440
    441441                for( $n = 0; $n < $node_rows; $n++ ) {
    442442                       
    443443                        for( $m = 0; $m < $nodes_per_row; $m++ ) {
    444                                
    445                                 $x = ($m*$node_width);
    446                                 $y = ($m*$node_width)+($n*$node_width);
     444                       
     445                                $x = ($m * $node_width);
     446                                $y = ($n * $node_width);
     447
     448                                $cur_node = ($n * $nodes_per_row) + ($m + 1);
    447449                                $host = $node_keys[$cur_node];
    448                                 //printf( "cur_node %d, host %s\n", $cur_node, $host );
    449                                 if( isset( $nodes[$host] ) and ($cur_node < $nodes_nr) ) {
    450                                         $nodes[$host]->setCoords( $x, $y );
    451                                         $nodes[$host]->setImage( &$image );
    452                                         $nodes[$host]->draw();
    453                                         $cur_node++;
     450
     451                                if( isset( $nodes[$host] ) and ($cur_node <= $nodes_nr) ) {
     452                                        $node = new NodeImage( $image, $x, $y );
     453                                        $node->draw();
     454                                        //$nodes[$host]->setCoords( $x, $y );
     455                                        //$nodes[$host]->setImage( &$image );
     456                                        //$nodes[$host]->draw();
     457                                        //$cur_node++;
    454458                                }
    455459                        }
     
    462466}
    463467
    464 //$my_node = new NodeImg();
    465 //$my_node->drawImage();
    466 
    467468//$my_data = new DataGatherer();
    468469//$my_data->parseXML();
    469470//$my_data->printInfo();
    470471
    471 $ic = new ImageCreator();
     472$ic = new ClusterImage();
    472473$ic->draw();
    473474?>
Note: See TracChangeset for help on using the changeset viewer.