It is currently March 29th, 2024, 1:55 pm

sunrise/sunset

Get help with creating, editing & fixing problems with skins
scub
Posts: 30
Joined: May 16th, 2015, 10:37 pm

sunrise/sunset

Post by scub »

i have a webparser that fetches the sunrise/sunset time (Hour:Min) and moves the sun position based on time of day.
it's a broken skin that i've otherwise fixed (Yahoo feed)..

thought it would be cool to show the amount of daylight left and after sunset show time remaining to sunrise.

would like it to shows something like hours/mins day light left, and change to time left to sunrise after it sets.

below is the skin i have, and an example.
my math calculation is terrible, wondering if someone can give me an idea how to do this.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: sunrise/sunset

Post by balala »

scub wrote:i have a webparser that fetches the sunrise/sunset time (Hour:Min) and moves the sun position based on time of day.
it's a broken skin that i've otherwise fixed (Yahoo feed)..

thought it would be cool to show the amount of daylight left and after sunset show time remaining to sunrise.

would like it to shows something like hours/mins day light left, and change to time left to sunrise after it sets.

below is the skin i have, and an example.
my math calculation is terrible, wondering if someone can give me an idea how to do this.
You have to add a few measures to your code:

Code: Select all

[MeasureAstronomySunrise]
Measure=Calc
Formula=( 12 * 60 * [MeasureAstronomySunriseAMPM] + 60 * MeasureAstronomySunriseHour + MeasureAstronomySunriseMin )
DynamicVariables=1

[MeasureAstronomySunset]
Measure=Calc
Formula=( 12 * 60 * [MeasureAstronomySunsetAMPM] + 60 * MeasureAstronomySunsetHour + MeasureAstronomySunsetMin )
DynamicVariables=1
This measures convert the Sunrise and Sunset respectively, to minutes (10:00 AM being for example returned as 600 - the number of minutes since last midnight)
Then add the following measures:

Code: Select all

[MeasureCurrent]
Measure=Calc
Formula=( 60 * MeasureCurrentHour + MeasureCurrentMin )

[MeasureToSunrise]
Measure=Calc
Formula=( MeasureAstronomySunrise - MeasureCurrent )

[MeasureToSunset]
Measure=Calc
Formula=( MeasureAstronomySunset - MeasureCurrent )
From these ones, [MeasureCurrent] converts the current time, based on the same rules, returning the number of minutes since last midnight. [MeasureToSunrise] and [MeasureToSunset] are returning the number of minutes up to the current day Sunrise and Sunset, respectively. These values can be both positive or negative. Eg during the day, the [MeasureToSunrise] is negative, because Sunrise passed, but [MeasureToSunset] is positive, because certain number of minutes remaind to current Sunset.
And finally the [MeasureLeft] measure, will return the number of minutes to the next Sunrise/Sunset, depending which one will occur sooner. This value is converted to hours and minutes by the [MeasureLeftHours] and [MeasureLeftMin] measures:

Code: Select all

[MeasureLeft]
Measure=Calc
Formula=((( MeasureToSunrise < 0 ) && ( MeasureToSunset < 0 )) ? MeasureToSunrise : ((( MeasureToSunrise < 0 ) && ( MeasureToSunset > 0 )) ? MeasureToSunset : MeasureToSunrise ))

[MeasureLeftHours]
Measure=Calc
Formula=( Floor ( MeasureLeft / 60 ))

[MeasureLeftMin]
Measure=Calc
Formula=( MeasureLeft - 60 * MeasureLeftHours )
I hope all these will work properly, however I didn't test this solution. If you're encountering any problem, please let me know.
scub
Posts: 30
Joined: May 16th, 2015, 10:37 pm

Re: sunrise/sunset

Post by scub »

thanks a bunch balala, got it to work for the most part. i do see a notice/warning in the log calc extra/operation for MeasureAstronomySunrise and MeasureAstronomySunset

do you need to put parentheses between each calculation (like in ifconditon operators?)

edit: looks like it starts giving negative time when sunset is only a couple hours away and shows negative time after sunset as well.

attached the skin in zip. maybe have a look when you have a chance. thanks!
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: sunrise/sunset

Post by balala »

scub wrote:thanks a bunch balala, got it to work for the most part. i do see a notice/warning in the log calc extra/operation for MeasureAstronomySunrise and MeasureAstronomySunset
I get the following error messages:
  • "Division by 0", on the [MeasurePosition1] measure. This is caused by the fact that in the denominator of the used function you have the MeasureDifferenceinMin measure. On refresh, the value of this measure (like every other), is 0, causing this message. The simplest way to avoid it is to add an extremely small, non zero value to the denominator, which doesn't modify the result, but avoid this message: Formula=(((MeasureCurrentHour*60+MeasureCurrentMin)-(MeasureAstronomySunriseHourAdjust*60+MeasureAstronomySunriseMin))/(MeasureDifferenceinMin[color=#FF0000]+0.0000001[/color]))
  • "Extra calc" on the [MeasureAstronomySunrise], [MeasureAstronomySunset], [MeasureAstronomySunriseHourAdjust] and [MeasureAstronomySunsetHourAdjust] measures. You can read the description of the cause, here. The simplest way to avoid them, is to add some options to the child WebParser measures, to make them to return 0, while the parent measure didn't get the proper values yet. Add the following two options, to all of the [MeasureAstronomySunriseHour], [MeasureAstronomySunriseMin], [MeasureAstronomySunsetHour] and [MeasureAstronomySunsetMin] measures:

    Code: Select all

    RegExpSubstitute=1
    Substitute="^$":"0"
    then add the RegExpSubstitute=1 to [MeasureAstronomySunriseAMPM] and [MeasureAstronomySunsetAMPM] and modify their Substitute options to: Substitute="am":"0","pm":"1"[color=#FF0000],"^$":"0"[/color] (marked with red, the newly added parts).
These two steps will avoid the error messages, I hope. Please check.
scub wrote:do you need to put parentheses between each calculation (like in ifconditon operators?)
No, not necessary, but I got used to put them. It's just my habit, it's not absolutely necessary. I see better the expression if it has the proper number of parenthesis.
scub wrote:edit: looks like it starts giving negative time when sunset is only a couple hours away and shows negative time after sunset as well.
After the first update cycle, he [MeasureLeftHours] and [MeasureLeftMin] measures are returning the proper values, but the hour and min variables don't get them. This is caused by the fact that on refresh, the IfConditions of the two mentioned measures execute either the IfTrueAction, or the IfFalseAction, according to the initial, "unparsed" values of the WebParser measures, then, when these measures get their values, if the same condition remains true, the variable setting operations aren't executed once again (because to execute them, the condition should modify). That's why the variables keep their initial, wrong (negative) values. To fix, just add an IfConditionMode=1 option to the [MeasureLeftHours] and [MeasureLeftMin] measures.
scub
Posts: 30
Joined: May 16th, 2015, 10:37 pm

Re: sunrise/sunset

Post by scub »

works fine until it pass sunset time, then it goes to negative value -16hr should be 8hrs.
errors are gone though. thanks.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: sunrise/sunset

Post by balala »

scub wrote:works fine until it pass sunset time, then it goes to negative value -16hr should be 8hrs.
Right. That's happening because after Sunset, the skin calculates the the difference between the current moment and the today Sunrise, the result being negative.
To fix, replace the Formula option of the [MeasureLeft] measure, with the following one: Formula=(((MeasureToSunrise < 0) && (MeasureToSunset < 0)) ? [color=#FF0000]( 1440 + [/color]MeasureToSunrise[color=#FF0000] )[/color] : (((MeasureToSunrise < 0) && (MeasureToSunset > 0)) ? MeasureToSunset : MeasureToSunrise)) (to see it better, I colored red the new elements of the formula).
This solution is very simple, but it has a small disadvantage: after Sunset, the calculation isn't quite acurate, because in fact it uses today Sunrise, instead of the tomorrow one. The difference is not more then a few minutes. If you necessary want a better calculation, will have to get the Sunrise of tomorrow and use it after Sunset. I'm not sure if it worth, but if you anyway would like to modify the skin in such way, please let me know.