Hi
I am new on this forum and need help. I am French Canadian but try to do my best in English.
Here my problem: I have an amateur weather station: www.jeanrobertmarion.com Every hour, my weather program upload a customtextout.txt file that you can see here: www.jeanrobertmarion.com/customtextout.txt
The column before the last in the snowdepth. If it is snowing, the next hour, the snowdepth will increase. So if i want to know how much snow fall in the last hour, i just have to subtrac the previous snowdepth from the last one and the answer in the amount of snow wich fell in the last hour.
So, i need a PHP script that can do that !
Is it possible ?
Thanks for helping.
Jean-Robert
Jean-Robert
Forum Newbie
Posts: 1
Joined: Mon Dec 10, 2012 1:53 pm
Amateur weather station help
Moderator: General Moderators
-
Jean-Robert
- Forum Newbie
- Posts: 4
- Joined: Mon Dec 10, 2012 12:53 pm
Re: Amateur weather station help
Welcome to PHP DevNet forums, Jean-Robert. Don't worry, your English is much better than my French.
The short answer to your question is that it should be possible to do what you want to do. Everything depends on just what you do with this customtextout.txt file. Is it saved to a database? Is it used to construct a graph on your web page? I must ask of you, are you planning to modify your script, yourself? Are you familiar with PHP programming? If you are, we may be able to guide you in making these changes. If you are not experienced writing PHP code, the situation is somewhat different and I can move this topic to our Volunteer Work forum, where you originally posted a copy of your question. In response to a member report here, I deleted that post because we ask our users to not post duplicates in several forums. This is not a problem, I will be happy to move this post if it is more appropriate to our Volunteer Work forum.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Amateur weather station help
Reading through the file and calculating the change in snow depth is easy. How do you want to display the information in the file (plus calculated values)?
(#10850)
Re: Amateur weather station help
My guess is that he only wants to show the previous day's snowfall, since the rest of the site (nice, informative site, by the way) is dynamically updated in real time. But you see why we ask, Jean-Robert? The approach will be very different depending on exactly what you will do with this data.
-
Jean-Robert
- Forum Newbie
- Posts: 4
- Joined: Mon Dec 10, 2012 12:53 pm
Re: Amateur weather station help
Hi
Please transfer the post where it should be, sorry for my mistake.
I do understand a little PHP code but can't create a script myself.
Now what i want is a script that can read the last snowdepth in the customtextout.txt on my website and compare with the one before the last one and make the difference. If the difference is positive, create another let say customtexout2.txt file with the result.
Example: 14:00 pm 6.0
15:00 pm 8.0
16:00 pm 11.0
17:00 pm 12.0
18:00 pm 11.0
and create a customtextout2.txt like this:
15:00 pm 2.0
16:00 pm 5.0
17:00 pm 6.0
18:00 pm 6.0
The logic is at 14:00 pm i have a snowdepth of 6.0, at 15:00 pm i have a snowdepth of 8.0 so the snowtoday is 8.0 - 6.0 = 2.0 at 16:00 pm the snowdepth is 11.0 so the snowtoday is now 11.0 - 8.0 = 3.0 + 2.0 = 5.0 etc etc between 17:00 pm and 18:00 pm noaddition to the snowtoday because the result is negativ. The snow melt.
So do you think that it is possible to do that ?
Jean-Robert
Please transfer the post where it should be, sorry for my mistake.
I do understand a little PHP code but can't create a script myself.
Now what i want is a script that can read the last snowdepth in the customtextout.txt on my website and compare with the one before the last one and make the difference. If the difference is positive, create another let say customtexout2.txt file with the result.
Example: 14:00 pm 6.0
15:00 pm 8.0
16:00 pm 11.0
17:00 pm 12.0
18:00 pm 11.0
and create a customtextout2.txt like this:
15:00 pm 2.0
16:00 pm 5.0
17:00 pm 6.0
18:00 pm 6.0
The logic is at 14:00 pm i have a snowdepth of 6.0, at 15:00 pm i have a snowdepth of 8.0 so the snowtoday is 8.0 - 6.0 = 2.0 at 16:00 pm the snowdepth is 11.0 so the snowtoday is now 11.0 - 8.0 = 3.0 + 2.0 = 5.0 etc etc between 17:00 pm and 18:00 pm noaddition to the snowtoday because the result is negativ. The snow melt.
So do you think that it is possible to do that ?
Jean-Robert
Re: Amateur weather station help
So you want to result in an hourly cumulative value throughout the day? That is certainly possible, but I would have to know more about how such data is already being used by your present script and how you wish to display this data. Is it practical for you to show us the part of your present script that uses your customtextout.txt file? If it is a very long script, can you recognize the part that reads the data and operates with it?
Speaking for myself (and perhaps for the majority of other members here), I am happy to spend a half hour or so reading a small script and trying to provide suggestions for anyone with a code question, but I am not willing to spend hours analyzing a full system and then rewriting it. I just don't have that much time available. If it gets to that point, that's when it would make more sense to post a request in our Volunteer Work forum, requesting someone to volunteer to help you rewrite your script.
Addendum: Sorry, I meant to comment that my first impression is that you may not need to rewrite the customtextout.txt file; if you are already processing the file in your existing script, it is probably easier to simply calculate the necessary values within your script. But I would need to understand how it is being processed now.
Speaking for myself (and perhaps for the majority of other members here), I am happy to spend a half hour or so reading a small script and trying to provide suggestions for anyone with a code question, but I am not willing to spend hours analyzing a full system and then rewriting it. I just don't have that much time available. If it gets to that point, that's when it would make more sense to post a request in our Volunteer Work forum, requesting someone to volunteer to help you rewrite your script.
Addendum: Sorry, I meant to comment that my first impression is that you may not need to rewrite the customtextout.txt file; if you are already processing the file in your existing script, it is probably easier to simply calculate the necessary values within your script. But I would need to understand how it is being processed now.
Last edited by califdon on Mon Dec 10, 2012 6:10 pm, edited 1 time in total.
Reason: Added another paragraph.
Reason: Added another paragraph.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Amateur weather station help
Yes, we will need to know whether the second file is needed or just an idea of yours.
To start with, you will need to read the file. Luckily, PHP has a function to read CSV files. So to start with we open the file. Here is some code I copied from the manual here to open the file :
And here is some code I copied from the manual here (and modified a little) to read the file:
Once you can read the file ... then doing the calculation will be fairly simple.
To start with, you will need to read the file. Luckily, PHP has a function to read CSV files. So to start with we open the file. Here is some code I copied from the manual here to open the file :
Code: Select all
$handle = fopen("/path/to/htdocs/customtextout.txt", "r");Code: Select all
<?php
$handle = fopen("/path/to/htdocs/customtextout.txt", "r");
if (($handle !== false) {
while (($data = fgetcsv($handle, 1000, ",")) !== false) {
for ($c=0; $c < $num; $c++) {
echo $data[0] . '-' $data[1] . '-' $data[2] . ' ' . $data[3] . ':' $data[4] . '-' $data[6] . ', ' . $data[] . "<br />\n";
}
}
fclose($handle);
}(#10850)
-
Jean-Robert
- Forum Newbie
- Posts: 4
- Joined: Mon Dec 10, 2012 12:53 pm
Re: Amateur weather station help
Hi
Thanks to take time to help me out.
Ok, now the customtextout.txt file is generated by my Wearher software and uploau to the server at the hour. Here the path to the file. http://www.jeanrobertmarion.com/customtextout.txt
I have a Laser beam to measure the snowdepth and the snowdepth value is the column before the last in the customtextout.txt file
so the difference between the previous and the last value is the snow fall in the last hour. If i add this difference to the previous difference and so on until the end of the 24 hours period, it will be my total snow fall of the day and i call that snowtoday.
At the moment, i have a php script (i include this script to my post) this php script (neige2.php) take the value in the customtextout.txt file to build a graph. You can see it here: http://www.jeanrobertmarion.com/neige2.php
You can see in this graph, the snowdepth every hours for 24 hours period. All i need is to have a table to show hour after hour the snowtoday !
I know my English is not very good but don't be effraid shy to ask me to explain more i will not be frustrated.......i will learn.
Here my neige2.php script:
<?php
date_default_timezone_set("America/New_York");
include ("./jpgraph/src/jpgraph.php");
include ("./jpgraph/src/jpgraph_line.php");
//jr - you need the date functions
include ("./jpgraph/src/jpgraph_date.php");
//jr - add code to import the data
//Import and re-format data
$row = 0;
if (($handlex = fopen("customtextout.txt", "r")) !== FALSE) {
while (($rdata = fgetcsv($handlex, 1440, ",")) !== FALSE) {
$num = count($rdata);
//06/10/2011 14:28
//jr - need to put the columns together as a date/time string
$datestring=$rdata[1]."/".$rdata[0]."/".$rdata[2]." ".$rdata[3].":".$rdata[4];
//jr - convert that date string to a time code
$bigxdata[$row] = strtotime($datestring);
$bigydata[$row] = $rdata[6];
$row++;
}
fclose($handlex);
}
//get the last 24 hours data
$xdata = array_slice($bigxdata,-25);
$ydata = array_slice($bigydata,-25);
// Create the graph. These two calls are always required
$graph = new Graph(860,400,"auto");
//jr - set scale datlin and the x axis to date format
$graph->SetScale("datlin",0,80);
$graph->xaxis->scale->SetDateFormat('H:i');
//jr - add $xdata to the line plot
// Create the linear plot
$lineplot=new LinePlot($ydata,$xdata);
$lineplot->mark->SetType(MARK_UTRIANGLE);
$lineplot->value->show();
// Add the plot to the graph
$graph->Add($lineplot);
$graph->img->SetMargin(40,20,20,40);
$graph->title->Set("Epaisseur de neige au sol dernieres 24 heures St-Etienne-Des-Gres, Québec Canada, Sonde Laser Fluke/LR3");
$graph->xaxis->title->Set("Heures");
$graph->yaxis->title->Set("Centimetres");
// Show the gridlines
$graph->ygrid->Show(true,true);
$graph->xgrid->Show(true,false);
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$lineplot->SetColor("red");
$lineplot->SetWeight(3);
$graph->yaxis->SetColor("red");
$graph->yaxis->SetWeight(2);
$graph->SetShadow();
// Display the graph
$graph->Stroke();
?>
Thanks to take time to help me out.
Ok, now the customtextout.txt file is generated by my Wearher software and uploau to the server at the hour. Here the path to the file. http://www.jeanrobertmarion.com/customtextout.txt
I have a Laser beam to measure the snowdepth and the snowdepth value is the column before the last in the customtextout.txt file
so the difference between the previous and the last value is the snow fall in the last hour. If i add this difference to the previous difference and so on until the end of the 24 hours period, it will be my total snow fall of the day and i call that snowtoday.
At the moment, i have a php script (i include this script to my post) this php script (neige2.php) take the value in the customtextout.txt file to build a graph. You can see it here: http://www.jeanrobertmarion.com/neige2.php
You can see in this graph, the snowdepth every hours for 24 hours period. All i need is to have a table to show hour after hour the snowtoday !
I know my English is not very good but don't be effraid shy to ask me to explain more i will not be frustrated.......i will learn.
Here my neige2.php script:
<?php
date_default_timezone_set("America/New_York");
include ("./jpgraph/src/jpgraph.php");
include ("./jpgraph/src/jpgraph_line.php");
//jr - you need the date functions
include ("./jpgraph/src/jpgraph_date.php");
//jr - add code to import the data
//Import and re-format data
$row = 0;
if (($handlex = fopen("customtextout.txt", "r")) !== FALSE) {
while (($rdata = fgetcsv($handlex, 1440, ",")) !== FALSE) {
$num = count($rdata);
//06/10/2011 14:28
//jr - need to put the columns together as a date/time string
$datestring=$rdata[1]."/".$rdata[0]."/".$rdata[2]." ".$rdata[3].":".$rdata[4];
//jr - convert that date string to a time code
$bigxdata[$row] = strtotime($datestring);
$bigydata[$row] = $rdata[6];
$row++;
}
fclose($handlex);
}
//get the last 24 hours data
$xdata = array_slice($bigxdata,-25);
$ydata = array_slice($bigydata,-25);
// Create the graph. These two calls are always required
$graph = new Graph(860,400,"auto");
//jr - set scale datlin and the x axis to date format
$graph->SetScale("datlin",0,80);
$graph->xaxis->scale->SetDateFormat('H:i');
//jr - add $xdata to the line plot
// Create the linear plot
$lineplot=new LinePlot($ydata,$xdata);
$lineplot->mark->SetType(MARK_UTRIANGLE);
$lineplot->value->show();
// Add the plot to the graph
$graph->Add($lineplot);
$graph->img->SetMargin(40,20,20,40);
$graph->title->Set("Epaisseur de neige au sol dernieres 24 heures St-Etienne-Des-Gres, Québec Canada, Sonde Laser Fluke/LR3");
$graph->xaxis->title->Set("Heures");
$graph->yaxis->title->Set("Centimetres");
// Show the gridlines
$graph->ygrid->Show(true,true);
$graph->xgrid->Show(true,false);
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$lineplot->SetColor("red");
$lineplot->SetWeight(3);
$graph->yaxis->SetColor("red");
$graph->yaxis->SetWeight(2);
$graph->SetShadow();
// Display the graph
$graph->Stroke();
?>
Last edited by Jean-Robert on Tue Dec 11, 2012 10:31 am, edited 1 time in total.