Author Topic: Temp panel script  (Read 1346 times)

0 Members and 1 Guest are viewing this topic.

Offline Axelvold

  • Forecaster
  • *****
  • Posts: 1704
    • Axelvold's weather and photo
Temp panel script
« on: July 07, 2009, 10:58:19 AM »
I'm trying to get this script working, so far i just have the image but no text on it.

Any ideas what could be wrong?



Code: [Select]
<?php
//===============================================
//===NOTE, you need TTF fonts for this to work===
//===============================================
//still have to include a thank you note to
//Kevin Reed for the function how to read the clientraw*-files
//whitch function I am using here to read a custom file
//
//you should use a custom-file with the tags in it you wish to use
//you can alter it for using humidity, ....but then you have a lot of work to do
//
//Note, it needs to be cleaned up, but hé it is working, have to make it work for USA, as for now it is metric
//as for the colors I use, I created a fake clientraw-file,changing temp by 1°C, point WDL to it and using MWsnap to now what colors Julian did use
//
//Pinto
//

$hostloc "H:/htdocs/temp_panel/";//Maybe you have to edit this
include "../jpgraph/jpgraph.php";//Maybe you have to edit this
include "../jpgraph/jpgraph_canvas.php";//Maybe you have to edit this
include "../jpgraph/jpgraph_canvtools.php";//Maybe you have to edit this

// Define work space
$width '366';//width of graph, all the rest is autoscaling
$title_color 'black';
$text_color 'black';
$backgroundcolor 'white';
$margincolor 'black';

//Define Text
$title_txt 'Outdoor Temperature';
$current_txt 'Current';
$high_txt 'Daily High';
$low_txt 'Daily Low';

//======================================================================================================================================
//You sure have to edit the folowing
//======================================================================================================================================
//======================================================================================================================================
$values get_raw("${hostloc}temp_panel.txt");//edit the filename you are using an the position of the values in that file
//Values
$current_time $values[5];
$high_time $values[1];
$low_time $values[3];
$current_value $values[4];
$high_value $values[0];
$low_value $values[2];


//======================================================================================================================================
//Normaly you don't have to edit anything below this, if you do the script can be broken
//======================================================================================================================================
//======================================================================================================================================
$current_color ValueColor($current_value);
$high_color ValueColor($high_value);
$low_color ValueColor($low_value);


//======================================================================================================================================
//functions
//======================================================================================================================================

//read the file we need

function get_raw$rawfile ) {
$rawdata = array();
$fd fopen($rawfile"r");
if (
$fd) {
$rawcontents '';
while (! 
feof ($fd) ) {
$rawcontents .= fread($fd8192);
}
fclose($fd);
$delimiter "|";
$rawdata explode ($delimiter$rawcontents);
} else {
$rawdata[0]= -9999;
}
return 
$rawdata;
}


//Calculate colors depending on value

    
function ValueColor(&$value) {
      if (
$value <= -15) {
        return 
'#0000CC';
      } else {
        if (
$value <= -10) {
          return 
'#0066cc';
        } else {
          if (
$value <= -5) {
            return 
'#0099cc';
          } else {
            if (
$value <= 0) {
              return 
'#00ccff';
            } else {
              if (
$value <= 5) {
                return 
'#00ffcc';
              } else {
                if (
$value <= 10) {
                  return 
'#00ff99';
                } else {
                  if (
$value <= 15) {
                    return 
'#ccff00';
                  } else {
                    if (
$value <= 20) {
                      return 
'#ffff66';
                    } else {
                      if (
$value <= 25) {
                        return 
'#ffcc00';
                      } else {
                        if (
$value <= 30) {
                          return 
'#ff9933';
                        } else {
                          if (
$value <= 35) {
                            return 
'#ff6600';
                          } else {
                            if (
$value <= 40) {
                              return 
'#ff3300';
                            } else {
                              if (
$value 40) {
                                return 
'#cc3300';
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
//======================================================================================================================================
//end of functions
//======================================================================================================================================

//======================================================================================================================================
//Create Graph
//======================================================================================================================================

// Setup a basic canvas we can work
$Margin_width $width/50;
$height $width/3;
$xmax=20;
$ymax=20;
$g = new CanvasGraph($width,$height,'auto');
$g->SetMargin($Margin_width,$Margin_width,$Margin_width,$Margin_width);
$g->SetColor($backgroundcolor);
$g->SetMarginColor($margincolor);

// We need to stroke the plotarea and margin before we add the
// text since we otherwise would overwrite the text.
$g->InitFrame();

// Create a new scale
$scale = new CanvasScale($g);
$scale->Set(0,$xmax,0,$ymax);

// The shape class is wrapper around the Imgage class which translates
// the coordinates for us
$shape = new Shape($g,$scale);
$shape->SetColor('black');

// .. add rectangles
$shape->ShadowRectangle(1,9,6.33,12,$current_color,0.05,$current_color.':0.8');
$shape->ShadowRectangle(7.33,9,12.66,12,$high_color,0.05,$high_color.':0.8');
$shape->ShadowRectangle(13.66,9,19,12,$low_color,0.05,$low_color.':0.8');
//and the rectangles for the legenda
$shape->SetColor('#0000CC');
$shape->FilledRectangle(1.32,14,2.65,15);
$shape->SetColor('#0066CC');
$shape->FilledRectangle(2.65,14,3.98,15);
$shape->SetColor('#0099CC');
$shape->FilledRectangle(3.98,14,5.31,15);
$shape->SetColor('#00CCFF');
$shape->FilledRectangle(5.31,14,6.64,15);
$shape->SetColor('#00FFCC');
$shape->FilledRectangle(6.64,14,7.97,15);
$shape->SetColor('#00FF99');
$shape->FilledRectangle(7.97,14,9.3,15);
$shape->SetColor('#CCFF00');
$shape->FilledRectangle(9.3,14,10.63,15);
$shape->SetColor('#FFFF66');
$shape->FilledRectangle(10.63,14,11.96,15);
$shape->SetColor('#FFCC00');
$shape->FilledRectangle(11.96,14,13.29,15);
$shape->SetColor('#FF9933');
$shape->FilledRectangle(13.29,14,14.62,15);
$shape->SetColor('#FF6600');
$shape->FilledRectangle(14.62,14,15.95,15);
$shape->SetColor('#FF3300');
$shape->FilledRectangle(15.95,14,17.28,15);
$shape->SetColor('#CC3300');
$shape->FilledRectangle(17.28,14,18.61,15);


//Text
// Create and add a title
$txt=new Text($title_txt);
$txt->SetPos(round($width*0.05),round($height*0.075));
$txt->SetFont(FF_ARIAL,FS_BOLDITALIC,round($width/25));
$txt->SetColor($title_color);
$g->AddText($txt);

// Create and add current value
$txt=new Text($current_value);
$txt->SetPos(round($width*0.18),round($height*0.515),'center','center');
$txt->SetFont(FF_ARIAL,FS_BOLD,round($width/30));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add current time
$txt=new Text($current_time);
$txt->SetPos(round($width*0.1),round($height*0.47),'center','center');
$txt->SetFont(FF_ARIAL,FS_BOLD,round($width/35));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add current text
$txt=new Text($current_txt);
$txt->SetPos(round($width*0.05),round($height*0.24));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/35));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add high value
$txt=new Text($high_value);
$txt->SetPos(round($width*0.5),round($height*0.515),'center','center');
$txt->SetFont(FF_ARIAL,FS_BOLD,round($width/30));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add high time
$txt=new Text($high_time);
$txt->SetPos(round($width*0.415),round($height*0.39),'center','center');
$txt->SetFont(FF_ARIAL,FS_BOLD,round($width/35));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add high text
$txt=new Text($high_txt);
$txt->SetPos(round($width*0.365),round($height*0.24));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/35));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add low value
$txt=new Text($low_value);
$txt->SetPos(round($width*0.82),round($height*0.515),'center','center');
$txt->SetFont(FF_ARIAL,FS_BOLD,round($width/30));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add low time
$txt=new Text($low_time);
$txt->SetPos(round($width*0.73),round($height*0.39),'center','center');
$txt->SetFont(FF_ARIAL,FS_BOLD,round($width/35));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add low text
$txt=new Text($low_txt);
$txt->SetPos(round($width*0.68),round($height*0.24));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/35));
$txt->SetColor($text_color);
$g->AddText($txt);

//===================================================================================================================================
// Create and add text for legenda
$txt=new Text('-15');
$txt->SetPos(round($width*0.11),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add a new text
$txt=new Text('-10');
$txt->SetPos(round($width*0.18),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add a new text
$txt=new Text('-5');
$txt->SetPos(round($width*0.25),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add a new text
$txt=new Text('0');
$txt->SetPos(round($width*0.32),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add a new text
$txt=new Text('5');
$txt->SetPos(round($width*0.39),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add a new text
$txt=new Text('10');
$txt->SetPos(round($width*0.45),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add a new text
$txt=new Text('15');
$txt->SetPos(round($width*0.52),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add a new text
$txt=new Text('20');
$txt->SetPos(round($width*0.58),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add a new text
$txt=new Text('25');
$txt->SetPos(round($width*0.65),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add a new text
$txt=new Text('30');
$txt->SetPos(round($width*0.715),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add a new text
$txt=new Text('35');
$txt->SetPos(round($width*0.78),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);

// Create and add a new text
$txt=new Text('40');
$txt->SetPos(round($width*0.845),round($height*0.80));
$txt->SetFont(FF_ARIAL,FS_ITALIC,round($width/50));
$txt->SetColor($text_color);
$g->AddText($txt);
//=========================================================================================================================================
//=========================================================================================================================================
//send all of it to the browser
// Stroke the graph
$g->Stroke();

?>
Lars Magnusson
Axelvold / Sweden
55° 57' 41" N / 13° 6' 1" E
WX Station: Davis Vantage Pro2 Plus