It is currently April 18th, 2024, 11:51 pm

String to Number?

Get help with creating, editing & fixing problems with skins
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

String to Number?

Post by GTI.H »

Hi,

My WebParser returns me the strings "5:54 AM" and "7:37 PM" and numbers 0 and 0, I need to calculate the difference between these strings.

I could not figure out how to do it, could anyone help?
User avatar
jsmorley
Developer
Posts: 22629
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

[MeasureTime1]
Measure=String
String=5:54 AM

[MeasureTime2]
Measure=String
String=7:37 PM

[MeasureTimestamp1]
Measure=Time
TimeStamp=[MeasureTime1]
TimeStampFormat=%#I:%M %p
DynamicVariables=1

[MeasureTimestamp2]
Measure=Time
TimeStamp=[MeasureTime2]
TimeStampFormat=%#I:%M %p
DynamicVariables=1

[FormatDif]
Measure=Uptime
SecondsValue=([MeasureTimestamp2:timestamp] - [MeasureTimestamp1:timestamp])
Format=%3!i! Hours %2!02i! Minutes
DynamicVariables=1

[MeterDif]
Meter=String
MeasureName=FormatDif
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
1.png

Turning the strings into Time measures:
https://docs.rainmeter.net/manual/measures/time/
https://docs.rainmeter.net/manual/measures/time/#TimeStamp
https://docs.rainmeter.net/manual/measures/time/#TimeStampFormat
https://docs.rainmeter.net/manual/measures/time/#FormatCodes

Getting the timestamp numbers from the Time measures:
https://docs.rainmeter.net/manual/variables/section-variables/#Timestamp

Formatting the difference in seconds into hours and minutes:
https://docs.rainmeter.net/manual/measures/uptime
https://docs.rainmeter.net/manual/measures/uptime/#SecondsValue
https://docs.rainmeter.net/manual/measures/uptime/#Format

Note: Your example does not contain any date information, so the two times must be in the same day.
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 »

Amazing! :jawdrop
Direct and complete answer, thank you.
Rainmeter is a success!

I did not imagine that Measure Time could do that much and did not even know Measure Uptime.

Now I can calculate the length of day and night.

How will this be calculated once a day (When the Skin is loaded), can I remove the DynamicVariables = 1?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: String to Number?

Post by jsmorley »

GTI.H wrote: December 15th, 2018, 2:54 pm Amazing! :jawdrop
Direct and complete answer, thank you.
Rainmeter is a success!

I did not imagine that Measure Time could do that much and did not even know Measure Uptime.

Now I can calculate the length of day and night.

How will this be calculated once a day (When the Skin is loaded), can I remove the DynamicVariables = 1?
This will be calculated each time you load or refresh the skin, and each time the WebParser measure(s) go out and get the data you are using.

No, you need all the DynamicVariables=1 options I have in it. That is to support the use of [SectionVariables].
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: String to Number?

Post by GTI.H »

OK boss!
Understood. :great:
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: String to Number?

Post by GTI.H »

Something went wrong for me. :(

After implementing this code on my Skin:

[MSSunR]
Measure=Plugin
Plugin=WebParser
Url=[MSActualTodayData]
StringIndex=12
UpdateDivider=-1

[MSSunS]
Measure=Plugin
Plugin=WebParser
Url=[MSActualTodayData]
StringIndex=13
UpdateDivider=-1

[MSSunRTimestamp]
Group=WPCActualTodayData
Measure=Time
TimeStamp=[MSSunR]
TimeStampFormat=%#I:%M %p
UpdateDivider=-1
DynamicVariables=1

[MSSunSTimestamp]
Group=WPCActualTodayData
Measure=Time
TimeStamp=[MSSunS]
TimeStampFormat=%#I:%M %p
UpdateDivider=-1
DynamicVariables=1

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

I get errors:
Error.JPG
Even so I end up with the correct result in my meter:
Result.JPG
While I try to find the reason, suggestions for solutions are very very welcome! :yawn:
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: String to Number?

Post by jsmorley »

I need the whole skin.
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: String to Number?

Post by GTI.H »

Are ~ 3200 lines, how could it be done?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: String to Number?

Post by jsmorley »

Just zip it up and attach the .zip file to the message

At a minimum, I need what is in the parent WebParser measure [MSActualTodayData]

I can't help you if I can test your code...
User avatar
GTI.H
Posts: 75
Joined: December 15th, 2018, 3:35 am

Re: String to Number?

Post by GTI.H »

Of course, see if it's enough, if not I'll send more or the zip.

My Skin is not ready and I'd like to publish it only after it's done.

Code: Select all

[MSActualTodayData]
Measure=Plugin
Plugin=WebParser
UpdateRate=#UpdateWeather#
Url=http://wxdata.weather.com/wxdata/weather/local/#Location#?cc=*&unit=#Unit#&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>"
OnConnectErrorAction=[!SetVariable MSActualTodayDataError 1][!UpdateMeasure MSOutdated][!SetOptionGroup ActualInfoText FontColor #Red#][!SetOptionGroup ActualInfoText StringEffect None][!UpdateMeterGroup ActualInfoText][!SetOptionGroup Day0Text FontColor #Red#][!SetOptionGroup Day0Text StringEffect None][!UpdateMeterGroup Day0Text][!Redraw]
OnRegExpErrorAction=[!SetVariable MSActualTodayDataError 1][!UpdateMeasure MSOutdated][!SetOptionGroup ActualInfoText FontColor #Red#][!SetOptionGroup ActualInfoText StringEffect None][!UpdateMeterGroup ActualInfoText][!SetOptionGroup Day0Text FontColor #Red#][!SetOptionGroup Day0Text StringEffect None][!UpdateMeterGroup Day0Text][!Redraw]
FinishAction=[PlayStop][!Delay 1000][!SetVariable MSActualTodayDataError 0][!UpdateMeasure MSOutdated][!SetOptionGroup ActualInfoText FontColor #White#][!SetOptionGroup ActualInfoText StringEffect Border][!UpdateMeasureGroup WPCActualTodayData][!UpdateMeterGroup ActualInfo][!SetOptionGroup Day0Text FontColor #White#][!SetOptionGroup Day0Text StringEffect Border][!UpdateMeterGroup TodayTonightInfo][!Redraw]
Last edited by jsmorley on December 16th, 2018, 12:26 am, edited 1 time in total.
Reason: Please use [code] tags on long code snippets. It's the </> button.