PHP Web Host - Quality Web Hosting For All PHP Applications Just Great Software
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
Dawg
RavenNuke(tm) Development Team


Joined: Nov 07, 2003
Posts: 889

PostPosted: Mon Jul 25, 2005 11:01 pm Reply with quote Back to top

Greetings All,
I am working on bringing in some new buoy data on my offshore fishing site. The group that creates the data has a text file.

time|2005-07-25 16:00:35

lat | 34.14

lon | -77.71

wind_speed | 1.9

wind_from_direction | 181

wind_gust | 1.9

air_temperature | 28.3

air_pressure | 1.0168

relative_humidity | 62

solar_radiation | 1878

sea_bottom_salinity | 36.1249

sea_bottom_temperature | 25.1635

sea_bottom_current_speed | 6.17

sea_bottom_current_to_direction | 17

sea_surface_current_speed | 12.18

sea_surface_current_to_direction | 110.7

Simply enough.....I got the file...cached it and now I want to display it....

Easy too....

Code:
<?
$newline = "<br />";
$arr=file("cache/test_txt.txt");

   foreach($arr as $str)
   {
    list($name,$message)=explode("|",$str);
   echo $name,$message,$newline,$newline;
    }

?>


This array outputs the data.....

time2005-07-25 16:00:35



lat 34.14



lon -77.71



wind_speed 1.9


The hard part is figuring out how to break the array apart so I can then display the $name as NAME

Let me say that again.....
Currettly I am displaying

wind_from_direction 181

I wish to display.....

Wind From Direction
181

Could you be so kind as to point me in the proper direction? I have been messing with this all night! It's killing me!

Thank You for your time!!

Dawg
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

PostPosted: Mon Jul 25, 2005 11:33 pm Reply with quote Back to top

Code:
<?
$newline = "<br />";
$arr=file("cache/test_txt.txt");
foreach($arr as $str) {
   list($name,$message)=explode("|",$str);
   echo '<b>'.ucwords(str_replace('_',' ',$name)).'</b>'.$newline.$message.$newline.$newline;
}
?>


Time
2005-07-25 16:00:35

Lat
34.14

Lon
-77.71

Wind Speed
1.9

Wind From Direction
181

Wind Gust
1.9

Air Temperature
28.3

Air Pressure
1.0168

Relative Humidity
62

Solar Radiation
1878

Sea Bottom Salinity
36.1249

Sea Bottom Temperature
25.1635

Sea Bottom Current Speed
6.17

Sea Bottom Current To Direction
17

Sea Surface Current Speed
12.18

Sea Surface Current To Direction
110.7


Last edited by Raven on Mon Jul 25, 2005 11:39 pm; edited 1 time in total
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
count
New Member
New Member


Joined: Jun 23, 2005
Posts: 16

PostPosted: Mon Jul 25, 2005 11:37 pm Reply with quote Back to top

d*** raven is quick

RavensScripts
View user's profile Send private message
Dawg
RavenNuke(tm) Development Team


Joined: Nov 07, 2003
Posts: 889

PostPosted: Tue Jul 26, 2005 4:56 am Reply with quote Back to top

Raven is Da Man!

Thank You!

Maybe one day I will grow up to be a "Raven"!!

LOL
Wave

When I get finished with this script....Can I talk you into a once over of it before I release it to make sure I did not do anything STUPID! Having the Master review the work with comments is a HAPPY thang!

Dawg
View user's profile Send private message
Dawg
RavenNuke(tm) Development Team


Joined: Nov 07, 2003
Posts: 889

PostPosted: Mon Aug 01, 2005 5:38 pm Reply with quote Back to top

Greetings Raven, and All,

I have been working on this script for a while and I have it working....sort of.

Here is the deal. One of the local .EDU's has several buoys in the water and several more planned to come online soon. I have made a deal with them to display their data.

This works but it takes forever to run. 6-8 secs and you have to hit reload to get the current data if it has timed out.

/* Based on the orginal script by Chris Karakas <chris@karakas-online.de> */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License. */
/* */

/*-----------------------------AIR TEMP-----------------------------------*/

$q = 7200; //cache time delay in seconds, 3600=one minute

$filesize = filesize("cache/ILM2air_temp1-day.png");
$lastvisit = filemtime("cache/ILM2air_temp1-day.png");
$currenttime = getdate(time());
$currentdate = $currenttime["0"];
$difference = $currentdate - $lastvisit;
$diff = $q-$difference;
$hrs = intval($diff/3600);
$min = intval(($diff-($hrs*3600))/60);

$ufurl = "http://www.cormp.org/images2/";
$content = "<i>ufurl:</i> $ufurl<br>";

$imagefile = "/cache/ILM2air_temp1-day.png";


if (!($textfile = fopen( "$ufurl", "r"))) {
$content .= "$ufurl<br> could not be opened<br>";
die();
}

while (!feof($textfile)) {
$line = fgets($textfile, 1500);
if (eregi( ".*<IMG ALT=\"ILM2\".*SRC=\"(.*)\">.*", $line, $out)) {
$imagefile = $out[1];
break;
}
}

fclose($textfile);

$content = "<p align=center>";
$content .= "<A HREF=\"http://www.cormp.org/images2/ILM2air_temp1-day.png\" target=\"_blank\"><IMG SRC=\"$imagefile\" alt=\"Data By CORMP\"></A>";
$content .= "<tr><td align=\"center\">Next Update<br>$hrs hrs $min mins";
echo $content;
$content .= "<p>";


if ( ($difference < $q) AND ($filesize != 0) )
{ }
elseif ( ($difference > $q) OR ($filesize == 0) )

{
$fc = fopen("cache/ILM2air_temp1-day.png", "wb");
$file = fopen ("http://www.cormp.org/images2/ILM2air_temp1-day.png", "rb");
if (!$file) {
$info = "E";
exit;
}
else
{
while (!feof ($file)) {
$line = fread ($file, 4096);
fwrite($fc,$line);
}
}
fclose($fc);
fclose($file);


$info = "F"; }
?>


Like I said this works......just not very well. I have about 10 of these calls on a single page......the text file we talked about earlier and all of the graphs that go along with it.

My guess is that I need to turn the time part of this script into a function and then call that function for each part of the script that needs to be updated. In order to get around the hitting reload to get the current data I guess I will have to put the time function in something that is called more often....like the config file or the main file and then have this script call it?????

This is where I really get lost. So I have come to you. I do not wish for you to code it for me (althought it would be easier on both of us) I really wish to learn so I do not have to ask.

Do I have the right idea here or am I barking up the wrong tree?

Would you be kind enough to point me in the right direction?

Dawg
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

PostPosted: Mon Aug 01, 2005 11:37 pm Reply with quote Back to top

I can't really get the picture of what this does, unfortunately. I would have to set it up locally and play with it. But, you could install timers throughout the code to profile different sections to see where the time is being eaten up. Then, armed with exactly where it takes the time, you can work on making that section more efficient. Make sense?
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

PostPosted: Tue Aug 02, 2005 4:47 am Reply with quote Back to top

It took 4.5 seconds for me. With all that graph work I'd say that is very respectable.
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Dawg
RavenNuke(tm) Development Team


Joined: Nov 07, 2003
Posts: 889

PostPosted: Tue Aug 02, 2005 5:08 am Reply with quote Back to top

WOW....You are fast....

Did you notice the timers under each one.....once they count down to 0 they go to -4 hrs 32 mins or what ever the time was of it's last refresh.

Currently.....if it has been longer than 2 hrs.....and you pull the page....it does not refresh the graphs until you hit the refresh button.

What I would realy like it to do is check the time before it displays the graphs to make sure it is up to date then display the up to date info not the old graphs......

Thank You for your time!

Dawg
View user's profile Send private message
Dawg
RavenNuke(tm) Development Team


Joined: Nov 07, 2003
Posts: 889

PostPosted: Tue Aug 02, 2005 5:17 am Reply with quote Back to top

Talking about the time to display the graphs....

If it was doing all the graphing work on the fly...I would agree but these are premade images....one I just looked at was only 4713 bytes...even if there are 10 of them on a page....that is not that much info.

I get much faster load times in my gallery or front page and I know my front page is loaded down. It just seemed that these pages were loading real slow. I was guessing I made an error in the code somewhere.

Dawg
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

PostPosted: Tue Aug 02, 2005 5:28 am Reply with quote Back to top

Then I would profile different sections of the code to see where the time is being eaten up. That should solve the riddle Wink
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Dawg
RavenNuke(tm) Development Team


Joined: Nov 07, 2003
Posts: 889

PostPosted: Tue Aug 02, 2005 6:23 am Reply with quote Back to top

Here is an easy to use Script timer I found....

<?php

// Filename: STOPWATCH.PHP
// =======================

// Start TIMER
// -----------
$stimer = explode( ' ', microtime() );
$stimer = $stimer[1] + $stimer[0];
// -----------

/* ------------------------------------- */
// Add your PHP script and/or content here
/* ------------------------------------- */

// End TIMER
// ---------
$etimer = explode( ' ', microtime() );
$etimer = $etimer[1] + $etimer[0];
echo '<p style="margin:auto; text-align:center">';
printf( "Script timer: <b>%f</b> seconds.", ($etimer-$stimer) );
echo '</p>';
// ---------

?>

My results were............


Script timer: 0.511784 seconds.
Script timer: 0.519668 seconds.
Script timer: 0.508725 seconds.
Script timer: 0.509885 seconds.
Script timer: 0.517278 seconds.
Script timer: 0.520487 seconds.
Script timer: 0.602185 seconds.
Script timer: 0.520353 seconds.


More or less I am burning .5 secs per image. That is the time to figure out the time....pull the image....and display it.

Would I be better off the change the time portion of each of these to a function and then call that function for each graph?

If so......and this is my timing code....

$q = 7200;

$filesize = filesize("cache/ILM2air_temp1-day.png");
$lastvisit = filemtime("cache/ILM2air_temp1-day.png");
$currenttime = getdate(time());
$currentdate = $currenttime["0"];
$difference = $currentdate - $lastvisit;
$diff = $q-$difference;
$hrs = intval($diff/3600);
$min = intval(($diff-($hrs*3600))/60);


I do not know how to make a $ to decide whether or not to update.

In the orginal script I guess this one is doing it....

$content .= "<p>";
if ( ($difference < $q) AND ($filesize != 0) )
{ }
elseif ( ($difference > $q) OR ($filesize == 0) )

But I do not think that would work overall because there are a lot of content calls in this script.

Could you point me in the right direction?

Thank you for your time!

Dawg
View user's profile Send private message
Dawg
RavenNuke(tm) Development Team


Joined: Nov 07, 2003
Posts: 889

PostPosted: Fri Aug 12, 2005 8:35 am Reply with quote Back to top

This project is complete. Thank You Raven for your help!

Dawg
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

PostPosted: Fri Aug 12, 2005 8:55 am Reply with quote Back to top

RavensScripts
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum