Page 1 of 2
Template help please - time difference **solved**
Posted: Thu Jul 06, 2017 5:20 pm
by glennpm
Hi,
I am struggling with common expressions. I would like to have a service report on the difference in hours and minutes for present sunset subtracted from the latest sunset of the year. I have tried many times but get nothing meaningful, below is one attempt. I am using the instructions posted on this link,
http://www.meteobridge.com/wiki/index.php/Templates.The latest sunset is 20:26
Hours and minutes lost = {*20:26-[mbsystem-Sunset]=hh:mm*} \n
Thank you
Re: Template help please - time difference
Posted: Fri Jul 07, 2017 12:24 am
by Mattk
Might require a little more explanation?
"Present sunset"? Is that for today?
"Latest sunset"? 20:26 relates to what sunset, yesterday? Where does the 20:26 come from and how do you intend to use a fixed format value in an expression as I image this value will be variable? based on your expression what do you expect the result to look like?
Anyway for now dealing with your expression =hh:mm is not a date/time convertor, see Time/date variables on the template page. 20:26 is not a numeric number, it is a format so subtraction (maths expressions) probably not applicable, similar with [mbsystem-Sunset] which returns a time format not a numeric expression.
For what you are trying to do you may have to use the convertor "epoch" to return a numeric value in seconds, subtract from whatever then reformat as a time format output?
Re: Template help please - time difference
Posted: Fri Jul 07, 2017 1:56 pm
by glennpm
Hi Mattk,
The "present sunset" is the sunset for the day I run the service.
The "latest sunset" is the latest sunset for the year and never changes. For me it is a fixed time of 20:26 or 73,560 seconds.
What I need to do is convert the value of [mbsystem-Sunset] into seconds and subtract that from 73,560 then change that number into a time format hh:mm as you mention.
Epoch is a date "... the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT) ..."
Thanks for your help.
Re: Template help please - time difference
Posted: Fri Jul 07, 2017 4:08 pm
by wvdkuil
It would be dead-simple doing it in PHP on your webserver.
But if the meteobridge has to do it:
Code: Select all
{*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60*t}
:
{*60*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60-floor((1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60)*t}
You should combine the three lines to one line. So that the uotput would look like 0:34 in the example code below.
To test at my place I had to modify the latest sunset time to 22:30 => that explains the 1350 in the calculation. Your value would be 1226 for 20 hours plus 26 gives a total of 1226 minutes.
Sunset today at my place is at 21:56 so the "the difference in hours and minutes for present sunset subtracted from the latest sunset of the year" at my place would be zero hours and 34 minutes.
Calculations and the use of
ab and
de for the hours and minute postion are explained in the wiki=>templates=>Numerical Expressions
Wim
Testfile:
Code: Select all
latest sunset for test 22:30 => 1350 minutes
[mbsystem-Sunset]
[mbsystem-Sunset.ab]
[mbsystem-Sunset.de]
{*(1350-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60*t}
:
{*60*(1350-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60-floor((1350-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60)*t}
Results after Meteobridge processed it:
Code: Select all
latest sunset for test 22:30 => 1350 minutes
21:56
21
56
0
:
34
Re: Template help please - time difference
Posted: Fri Jul 07, 2017 4:47 pm
by glennpm
Thank you Wim!
It worked fine for me. Now I'll add an entry for sunrise lost too.
Hours & Minutes of Sunset lost on [M]-[DD] – 34 Acorn#\n Hours:Minutes lost = {*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60*t}:{*60*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60-floor((1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60)*t}
email results:
Hours & Minutes of Sunset lost on 7-07 – 34 Acorn
Hours:Minutes lost = 0:2
Thanks for your help!
Re: Template help please - time difference
Posted: Fri Jul 07, 2017 10:22 pm
by glennpm
Here is a service report that I'll run daily now for daylength, sunrise and sunset records.
Weather at 34 Acorn at [hh]:[mm] – Yesterday’s Day Length Report# Report run on: [MM]-[DD]\n\n Daylength is [mbsystem-Daylength.ab:--] hours [mbsystem-Daylength.de:--] minutes\n Hours & Minutes of daylength lost from June 21st, the longest at 15 hours and 29 minutes is {*(929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60*t}:{*60*(929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60-floor((929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60)*t}\n Sunrise occured at [mbsystem-Sunrise:--]\n Hours & Minutes of Sunrise lost from earliest on June 18th (04:55) is {*(-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60*t}:{*60*(-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60-floor((-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60)*t}\n Sunset occured at [mbsystem-Sunset:--]\n Hours & Minutes of sunset time lost from June 21st (20:26) is {*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60*t}:{*60*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60-floor((1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60)*t}
email results:
Report run on: 07-08
Daylength is 15 hours 19 minutes
Hours & Minutes of daylength lost from June 21st, the longest at 15 hours and 29 minutes is 0:10
Sunrise occured at 05:05
Hours & Minutes of Sunrise lost from earliest on June 18th (04:55) is 0:10
Sunset occured at 20:23
Hours & Minutes of sunset time lost from June 21st (20:26) is 0:3
Re: Template help please - time difference
Posted: Tue Aug 08, 2017 1:02 am
by glennpm
Well all was good until the daylength time difference from the longest day was greater than one hour. The report now shows one hour but a total of the minutes and not those greater than an hour. In months to come this will be two, three, four hours, etc,
I'm not knowledgeble enough to fix this and seek help here please.
This:
Hours & Minutes of daylength lost from June 21st, the longest at 15 hours and 29 minutes is {*(929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60*t}:{*60*(929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60-floor((929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60)*t}
yields:
Daylength is 14 hours 21 minutes
Hours & Minutes of daylength lost from June 21st (15 hours and 29 minutes) is 1:67
It should have yielded 1:08
Glenn
Re: Template help please - time difference
Posted: Fri Aug 11, 2017 1:03 am
by glennpm
Can anyone help me with this please?
Re: Template help please - time difference
Posted: Fri Aug 11, 2017 4:25 pm
by admin
It would make your formular more generic, if Meteobridge would support "latest sunset" and "earliest sunrise" depending on the longitude/latitude you specified in Meteobridge settings. In addition having a converter that transfers time durations from astronomical variables into a "seconds" format might also help. Anybody apart from Glenn interested in this?
Re: Template help please - time difference
Posted: Sun Aug 13, 2017 3:07 pm
by glennpm
Well I would welcome the additions!!
Re: Template help please - time difference
Posted: Mon Aug 14, 2017 2:31 am
by hymrog
Yep. I would like to see added. Thanks
Re: Template help please - time difference
Posted: Tue Aug 15, 2017 1:40 pm
by admin
I started adding that features. Please see here:
http://meteobridge.com/wiki/index.php/Forum
Can someone please give me remote access to his system, so that I can install beta code and give it a test drive?
As I am on vacation and powered down all my stuff when leaving home, I don't have my own rig test test with.
Please send login credentials to "info(at)smartbedded.com".
Re: Template help please - time difference
Posted: Tue Aug 15, 2017 2:27 pm
by glennpm
link and password sent.
Thanks,
Glenn
Re: Template help please - time difference
Posted: Thu Aug 17, 2017 12:47 am
by glennpm
Seems to be working well.
Thank you!
This service event:
Weather at 34 Acorn at [hh]:[mm] – Yesterday’s Day Length Report# Report run on: [MM]-[DD]\n\n Daylength is [mbsystem-Daylength.ab:--] hours [mbsystem-Daylength.de:--] minutes\n
Minutes of daylength lost from June 21st (15 hours and 29 minutes) is {* [mbsystem-daylengthmax=mins.0] - [mbsystem-daylength=mins.0] *0}\n
Hours of daylength lost from June 21st (15 hours and 29 minutes) is {* ([mbsystem-daylengthmax=mins.0] - [mbsystem-daylength=mins.0])/60 *2}\n
Sunrise occurred at [mbsystem-Sunrise:--]\n
Minutes of Sunrise lost from earliest on June 18th (04:55) is {*60*(-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60-floor((-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60)*t}\n
Hours of Sunrise lost from earliest on June 18th (04:55) is {*(-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60*2}\n
Sunset occurred at [mbsystem-Sunset:--]\n
Minutes of sunset time lost from June 21st (20:26) is {*60*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60-floor((1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60)*t}\n
Hours of sunset time lost from June 21st (20:26) is {*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60*2}
Yields:
Daylength is 13 hours 57 minutes
Minutes of daylength lost from June 21st (15 hours and 29 minutes) is 92
Hours of daylength lost from June 21st (15 hours and 29 minutes) is 1.53
Sunrise occurred at 05:44
Minutes of Sunrise lost from earliest on June 18th (04:55) is 49
Hours of Sunrise lost from earliest on June 18th (04:55) is 0.82
Sunset occurred at 19:42
Minutes of sunset time lost from June 21st (20:26) is 44
Hours of sunset time lost from June 21st (20:26) is 0.73
Re: Template help please - time difference
Posted: Thu Aug 17, 2017 9:13 pm
by admin
I added an option to specify number of leading zeros, which helps to display time difference in an "HH:MM" style:
Code: Select all
{*([mbsystem-daylengthmax=mins.0]-[mbsystem-daylength=mins.0])/60*00t}:{*([mbsystem-daylengthmax=mins.0]-[mbsystem-daylength=mins.0])% 60*00t}