It is currently May 1st, 2024, 2:33 pm

String to Number?

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: String to Number?

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MSActualTodayData]
Measure=WebParser
UpdateRate=600
Url=http://wxdata.weather.com/wxdata/weather/local/USVA0944?cc=*&unit=i&dayf=5
RegExp="(?siU).*<locale>(.*)</locale>.*<ut>(.*)</ut>.*<ud>(.*)</ud>.*<us>(.*)</us>.*<up>(.*)</up>.*<ur>(.*)</ur>.*<loc id="(.*)">.*<dnam>(.*)</dnam>.*<tm>(.*)</tm>.*<lat>(.*)</lat>.*<lon>(.*)</lon>.*<sunr>(.*)</sunr>.*<suns>(.*)</suns>.*<zone>(.*)</zone>.*<cc>.*<lsup>(.*)</lsup>.*<obst>(.*)</obst>.*<tmp>(.*)</tmp>.*<flik>(.*)</flik>.*<t>(.*)</t>.*<icon>(.*)</icon>.*<bar>.*<r>(.*)</r>.*<d>(.*)</d>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<hmid>(.*)</hmid>.*<vis>(.*)</vis>.*<uv>.*<i>(.*)</i>.*<t>(.*)</t>.*<dewp>(.*)</dewp>.*<moon>.*<icon>(.*)</icon>.*<t>(.*)</t>.*<dayf>.*<lsup>(.*)</lsup>.*<day d="0" t="(.*)" dt="(.*)".*<hi>(.*)</hi>.*<low>(.*)</low>.*<sunr>(.*)</sunr>.*<suns>(.*)</suns>.*<part p="(.*)">.*<icon>(.*)</icon>.*<t>(.*)</t>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<bt>(.*)</bt>.*<ppcp>(.*)</ppcp>.*<hmid>(.*)</hmid>.*<part p="n">.*<icon>(.*)</icon>.*<t>(.*)</t>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<bt>(.*)</bt>.*<ppcp>(.*)</ppcp>.*<hmid>(.*)</hmid>"
FinishAction=[!EnableMeasureGroup FormatTime][!UpdateMeasureGroup FormatTime]

[MSSunR]
Measure=WebParser
Url=[MSActualTodayData]
StringIndex=12

[MSSunS]
Measure=WebParser
Url=[MSActualTodayData]
StringIndex=13

[MSSunRTimestamp]
Group=FormatTime
Measure=Time
TimeStamp=[MSSunR]
TimeStampFormat=%#I:%M %p
DynamicVariables=1
Disabled=1

[MSSunSTimestamp]
Group=FormatTime
Measure=Time
TimeStamp=[MSSunS]
TimeStampFormat=%#I:%M %p
DynamicVariables=1
Disabled=1

[MSSunDeclinationDayDuration]
Group=FormatTime
Measure=Uptime
SecondsValue=([MSSunSTimestamp:timestamp] - [MSSunRTimestamp:timestamp])
Format=%3!i!h %2!02i!m
DynamicVariables=1
Disabled=1

[MeterOne]
Meter=String
MeasureName=MSSunDeclinationDayDuration
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
The errors you are getting is because those Time measures are being executed before the WebParser has finished retrieving the data. If you look at what I did here, it will eliminate the errors. They are not fatal, but annoying.

Look at this, but don't copy and paste it as is. I have changed some stuff from your original code for my testing.

P.S. It's:

[SomeMeasureName]
Measure=WebParser

not:

[SomeMeasureName]
Measure=Plugin
Plugin=WebParser

Both work, but use the new syntax. WebParser is no longer a plugin.
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: String to Number?

Post by GTI.H »

jsmorley wrote: December 16th, 2018, 12:24 am
The errors you are getting is because those Time measures are being executed before the WebParser has finished retrieving the data. If you look at what I did here, it will eliminate the errors. They are not fatal, but annoying.

Look at this, but don't copy and paste it as is. I have changed some stuff from your original code for my testing.
Yeah, I figured that was it, that's why I use the [! Delay 1000], it was the way I found it, it solves other similar problems that have arisen.

As you may have noticed, I try to dominate updates time to save processing using UpdateDivider=-1/Update Group.

Your help is extremely important. Thanks.
I've implemented your technique and it worked like a charm !!! :D

Then I will try to remove my [! Delay 1000] and replace it with your technique presented here.
jsmorley wrote: December 16th, 2018, 12:24 am P.S. It's:

[SomeMeasureName]
Measure=WebParser

not:

[SomeMeasureName]
Measure=Plugin
Plugin=WebParser

Both work, but use the new syntax. WebParser is no longer a plugin.
Thank you,

You know how things are:
Nothing loses, nothing is created, everything is copied! 8-)

I've done this update in over a hundred sections and it's working.
Now I'm going to solve other issues.
Last edited by GTI.H on December 23rd, 2018, 8:54 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: String to Number?

Post by jsmorley »

Good deal!
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: String to Number?

Post by GTI.H »

I have another problem.

Why

SecondsValue = ([MSSunSTimestamp: timestamp] - [MSSunRTimestamp: timestamp])

and

SecondsValue = ([MSSunRTimestamp: timestamp] - [MSSunSTimestamp: timestamp])

produce the same value?

Do we have to enter the day?
How to calculate the duration of the night if this does not work?

We use this method or it is easier to do a subtraction 24 - {Value produced by SecondsValue = ([MSSunSTimestamp: timestamp] - [MSSunRTimestamp: timestamp])}?

What do you suggest?
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: String to Number?

Post by jsmorley »

GTI.H wrote: December 16th, 2018, 4:00 am I have another problem.

Why

SecondsValue = ([MSSunSTimestamp: timestamp] - [MSSunRTimestamp: timestamp])

and

SecondsValue = ([MSSunRTimestamp: timestamp] - [MSSunSTimestamp: timestamp])

produce the same value?

Do we have to enter the day?
How to calculate the duration of the night if this does not work?

We use this method or it is easier to do a subtraction 24 - {Value produced by SecondsValue = ([MSSunSTimestamp: timestamp] - [MSSunRTimestamp: timestamp])}?

What do you suggest?
Because SecondsValue in an Uptime measure is always treated as a positive number. If you want the raw difference in seconds positive or negative, do the subtraction in a Calc measure. But you won't be able to use Uptime with negative numbers. How can you have a negative "uptime"? Uptime is not about "time" really, it just a simple matter of a raw number of seconds, and telling you how many days/hours/minutes/seconds that works out to. 60 seconds is one minute, and -60 seconds is one minute.

To calculate the seconds difference between two times that are not on in the same day, you really need the full date as part of the string.

I don't really follow "How to calculate the duration of the night if this does not work?" What do you mean?

Figuring out the amount of time from 10pm today til 7am tomorrow will be complicated indeed without the dates as part of the string we pass to the Time measures. It will likely take an entirely different approach. It's nowhere near as simple as adding 12 hours to something.
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: String to Number?

Post by GTI.H »

jsmorley wrote: December 16th, 2018, 4:07 am Because SecondsValue in an Uptime measure is always treated as a positive number. If you want the raw difference in seconds positive or negative, do the subtraction in a Calc measure. But you won't be able to use Uptime with negative numbers. How can you have a negative "uptime"? Uptime is not about "time" really, it just a simple matter of a raw number of seconds, and telling you how many days/hours/minutes/seconds that works out to. 60 seconds is one minute, and -60 seconds is one minute.

To calculate the seconds difference between two times that are not on in the same day, you really need the full date as part of the string.
I thought, if
SecondsValue = ([MSSunSTimestamp:timestamp] - [MSSunRTimestamp:timestamp])
do
19:38 - 5:55 = 13h 43m (day duration)

then I thought about doing
SecondsValue = ([MSSunRTimestamp:timestamp] - [MSSunSTimestamp:timestamp])
I imagined that this expression could calculate something like this:
02/01/2000 5:55 - 01/01/2000 19:38 = 10h 17m (night duration)
jsmorley wrote: December 16th, 2018, 4:07 am I don't really follow "How to calculate the duration of the night if this does not work?" What do you mean?
I called
SecondsValue = ([MSSunSTimestamp: timestamp] - [MSSunRTimestamp: timestamp]) of day duration and
SecondsValue = ([MSSunRTimestamp: timestamp] - [MSSunSTimestamp: timestamp]) of night duration.

What I wanted to say is that, if
SecondsValue = ([MSSunRTimestamp: timestamp] - [MSSunSTimestamp: timestamp]) (night duration)
does not work on this way
02/01/2000 5:55 - 01/01/2000 19:38 = 10h 17m
then how to calculate night duration?
jsmorley wrote: December 16th, 2018, 4:07 am Figuring out the amount of time from 10pm today til 7am tomorrow will be complicated indeed without the dates as part of the string we pass to the Time measures. It will likely take an entirely different approach. It's nowhere near as simple as adding 12 hours to something.
My [MSSunDeclinationDayDuration] returns me 49380 (Number) and 13h 43m (Text).

As
24h - (Day Duration) = Night Duration
As
24h = 86 400s, then
it would not be possible to do
86 400 - 49 380 = 37 020 = 10h 17m?

How do you suggest this implementation or another better?
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: String to Number?

Post by jsmorley »

I'm not sure I entirely follow, but if you are looking to evaluate the time from sunrise to sunset / sunset to sunrise, you might look at this skin. It uses some Lua scripting to do the bulk of the work.

SunRiseSet_1.0.rmskin

It's moderately complicated.

The long and the short of it is that if you want to determine the amount of time from sometime today, say 5:00PM, and sometime tomorrow, say 7:00AM, you need to know how many seconds it is from 5:00PM until midnight, then how many seconds from midnight until 7:00AM. Also, if we are talking about sunrise / sunset, that shouldn't be based on the amount of time between them, that has little value in my view. What you want is the amount of time from "now" until the next sunrise / sunset.

Understand as well that the sunrise / sunset times you get from a weather site are both "today". So no matter what time it is, sunrise is when it was/will be today. That's not really important in the grand scheme of things as the time of sunrise doesn't change much from one day to the next, but it's worth noting. It's close enough if you want to know when to get up to go fishing, but probably not good for calculating a free-return trajectory for a mission to Mars.

It would help if I was clear what you are trying to do. Don't talk in terms of your measure names, which I don't have, but a plain explanation of what data you are getting, what it means, and what you are trying to do with it. Your initial question was "I have two times, no dates, so obviously in the same day, and I want to know how many seconds are between them". It's morphed into something else now, and I fear we have wasted some time.
You do not have the required permissions to view the files attached to this post.
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: String to Number?

Post by GTI.H »

Surely you did not understand because if you had understood you would solve in fractions of seconds!

I was able to make it work with this code here:

Code: Select all

[MSSunDeclinationDayDuration]
Group=WPCActualTodayData | FormatSunRSTimestamp
Measure=Uptime
SecondsValue=([MSSunSTimestamp:timestamp] - [MSSunRTimestamp:timestamp])
Format=%3!i!h %2!02i!m
UpdateDivider=-1
DynamicVariables=1
Disabled=1

[MSSunDeclinationNightDurationCalc]
Group=WPCActualTodayData | FormatSunRSTimestamp
Measure=Calc
Formula=(86400 - MSSunDeclinationDayDuration)
UpdateDivider=-1
DynamicVariables=1
Disabled=1

[MSSunDeclinationNightDuration]
Group=WPCActualTodayData | FormatSunRSTimestamp
Measure=Uptime
SecondsValue=[MSSunDeclinationNightDurationCalc]
Format=%3!i!h %2!02i!m
UpdateDivider=-1
DynamicVariables=1
Disabled=1
MSs.JPG
If you have no better suggestion, the issue is solved.

PS. I have seen but have not read your new post yet.
You do not have the required permissions to view the files attached to this post.
Last edited by GTI.H on December 23rd, 2018, 8:59 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: String to Number?

Post by jsmorley »

Hey, as long as it is working! Great!
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: String to Number?

Post by GTI.H »

jsmorley wrote: December 16th, 2018, 1:50 pm I'm not sure I entirely follow, but if you are looking to evaluate the time from sunrise to sunset / sunset to sunrise, you might look at this skin. It uses some Lua scripting to do the bulk of the work.


SunRiseSet_1.0.rmskin


It's moderately complicated.

The long and the short of it is that if you want to determine the amount of time from sometime today, say 5:00PM, and sometime tomorrow, say 7:00AM, you need to know how many seconds it is from 5:00PM until midnight, then how many seconds from midnight until 7:00AM. Also, if we are talking about sunrise / sunset, that shouldn't be based on the amount of time between them, that has little value in my view. What you want is the amount of time from "now" until the next sunrise / sunset.

Understand as well that the sunrise / sunset times you get from a weather site are both "today". So no matter what time it is, sunrise is when it was/will be today. That's not really important in the grand scheme of things as the time of sunrise doesn't change much from one day to the next, but it's worth noting. It's close enough if you want to know when to get up to go fishing, but probably not good for calculating a free-return trajectory for a mission to Mars.

It would help if I was clear what you are trying to do. Don't talk in terms of your measure names, which I don't have, but a plain explanation of what data you are getting, what it means, and what you are trying to do with it. Your initial question was "I have two times, no dates, so obviously in the same day, and I want to know how many seconds are between them". It's morphed into something else now, and I fear we have wasted some time.
Thank you and I'm sorry.

We try to be as clear and summarized as possible but we can not always explain well and sometimes we do not even know if what we want is logical and we also made mistakes.

I found out what you said about the accuracy of the results and that sunrise and sunset is not on different days and it leaves my solution half fake and uncool.

My goal here is simple, I want to see on my screen the duration of the day and night for personal monitoring, not to go to Mars, using for this the information I have here http://wxdata.weather.com/wxdata/weather/location/#Location#?cc=*&unit=#Unit#&dayf=5 (or better)
with the least amount of code and allocated PC resources possible.

One way that occurred to me when I wrote this post was to store the sunrise and sunset from the previous day to use in calculations, what do you think?