It is currently April 27th, 2024, 4:54 pm

CurrentObservationTime - Time measure to calculate X-position in shape meter

Get help with creating, editing & fixing problems with skins
emp00
Posts: 83
Joined: October 7th, 2022, 8:08 pm

CurrentObservationTime - Time measure to calculate X-position in shape meter

Post by emp00 »

Dear Team, I have the following measure containing the current time:
Image

Simple problem (stupid user): I want to use [@CurrentObservationTime] in a meter, drawing a vertical line (via shape) at an X-position based on the current hour. This is what I have, but it fails with the error below ... Why does the meter not calculate with the numerical value (15) -> the measure has the correct number as you can see. Can I prevent that the string is being used here?

Shape=Line (100+3*[@CurrentObservationTime]),1,(100+3*[@CurrentObservationTime]),100
Formula: Logical expression error: (100+3*15:45)

However, my final goal is to convert the current time (hour+minutes) to a full decimal number that I can use in the meter X-position calculation. In this example at 15:45 (current time from [@CurrentObservationTime]) I would like to calculate X = 100+3*15.75 giving 147 px. So the current time should be converted to a full decimal number, like this: HH + MM/60 ...

Can anybody show me a working measure giving this numerical value based on [@CurrentObservationTime] to be used in the shape meter? Thanks so much.
User avatar
Yincognito
Rainmeter Sage
Posts: 7177
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: CurrentObservationTime - Time measure to calculate X-position in shape meter

Post by Yincognito »

emp00 wrote: March 29th, 2024, 3:20 pm Dear Team, I have the following measure containing the current time:
Image

Simple problem (stupid user): I want to use [@CurrentObservationTime] in a meter, drawing a vertical line (via shape) at an X-position based on the current hour. This is what I have, but it fails with the error below ... Why does the meter not calculate with the numerical value (15) -> the measure has the correct number as you can see. Can I prevent that the string is being used here?

Shape=Line (100+3*[@CurrentObservationTime]),1,(100+3*[@CurrentObservationTime]),100
Formula: Logical expression error: (100+3*15:45)

However, my final goal is to convert the current time (hour+minutes) to a full decimal number that I can use in the meter X-position calculation. In this example at 15:45 (current time from [@CurrentObservationTime]) I would like to calculate X = 100+3*15.75 giving 147 px. So the current time should be converted to a full decimal number, like this: HH + MM/60 ...

Can anybody show me a working measure giving this numerical value based on [@CurrentObservationTime] to be used in the shape meter? Thanks so much.
I'm on my phone so can't post tested code, but you have at least 2 possibilities:
- use that string in a Time measure, then use its Timestamp, TimestampFormat and [YourTimeMeasure:Timestamp] to convert the string into a decimal numerical representation:
https://docs.rainmeter.net/manual/measures/time/
- use a (regex) Substitute in a String measure that has your [@CurrentObservationTime] as its value, to transform the "15:45" string into a "(15*60+45)" one or similar, so that the latter can be used directly in your Shape formula

The 2nd possibility is the easiest one, of course. Make sure you have DynamicVariables=1 in the right places.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16177
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: CurrentObservationTime - Time measure to calculate X-position in shape meter

Post by balala »

emp00 wrote: March 29th, 2024, 3:20 pm Can anybody show me a working measure giving this numerical value based on [@CurrentObservationTime] to be used in the shape meter? Thanks so much.
Since all parameters of a Line elements of a Shape option have to be numbers, you can't use there what the [@CurrentObservationTime] measure does return, because that's not a number, as you could see in the error message:
emp00 wrote: March 29th, 2024, 3:20 pm Formula: Logical expression error: (100+3*15:45)
You can't multiply 3 by 15:45, because this last value is not a number. Accordingly the appropriate elements of the Shape meter can't be calculated. But I think you've figured this out by yourself.
So, as Yincognito mentioned, there are two way to achieve what you want:
  • Yincognito wrote: March 29th, 2024, 4:25 pm - use that string in a Time measure, then use its Timestamp, TimestampFormat and [YourTimeMeasure:Timestamp] to convert the string into a decimal numerical representation:
    https://docs.rainmeter.net/manual/measures/time/
    To use this approach, add the following measures to your code:

    Code: Select all

    [@CurrentObservationTime]
    ...
    
    [MeasureToday]
    Measure=Time
    Format=%Y.%m.%d
    
    [MeasureTimeStamp]
    Measure=Time
    TimeStamp=[MeasureToday] [@CurrentObservationTime]
    TimeStampFormat=%Y.%m.%d %H:%M
    DynamicVariables=1
    
    [MeasureMidnight]
    Measure=Time
    Format=%Y.%m.%d %H:%M
    TimeStamp=[MeasureToday] 0:00
    TimeStampFormat=%Y.%m.%d %#H:%M
    DynamicVariables=1
    
    [MeasureDecimalTime]
    Measure=Calc
    Formula=( [MeasureTimeStamp:TimeStamp] - [MeasureMidnight:TimeStamp] )
    DynamicVariables=1
    [MeasureDecimalTime] returns the decimal number calculated as you need it.
  • Yincognito wrote: March 29th, 2024, 4:25 pm - use a (regex) Substitute in a String measure that has your [@CurrentObservationTime] as its value, to transform the "15:45" string into a "(15*60+45)" one or similar, so that the latter can be used directly in your Shape formula
    For this approach you need the following measures:

    Code: Select all

    [@CurrentObservationTime]
    ...
    
    [MeasureHour]
    Measure=STRING
    String=[@CurrentObservationTime]
    RegExpSubstitute=1
    Substitute="(\d{1,2}):(\d{2})":"\1"
    DynamicVariables=1
    
    [MeasureMinute]
    Measure=STRING
    String=[@CurrentObservationTime]
    RegExpSubstitute=1
    Substitute="(\d{1,2}):(\d{2})":"\2"
    DynamicVariables=1
    
    [MeasureDecimalTime]
    Measure=Calc
    Formula=( [MeasureHour] + [MeasureMinute] / 60 )
    DynamicVariables=1
    Same way as previously, [MeasureDecimalTime] returns the needed time as a decimal number.
You can use any of these approaches. Please come back if any question arises related to any of them.
emp00
Posts: 83
Joined: October 7th, 2022, 8:08 pm

Re: CurrentObservationTime - Time measure to calculate X-position in shape meter

Post by emp00 »

balala wrote: March 29th, 2024, 5:07 pm So, as Yincognito mentioned, there are two way to achieve what you want:
[...]
Two solutions, both working - confirmed --> Thanks to the both of you! (I only slightly renamed the measures)

Just one remaining super-stupid question: Check out my screenshot - the decimal time is calculated correctly. However, the numerical value of [@CurrentObservationMinute] equals 18 (highlighted red) --> this is the current hour! How does the hour end up as numerical value for the minute? The string for the minute is correct - and the calc measure works fine as well (so calc takes the String value?!) - this looks very odd to me, can you explain this? I just would like to understand the mechanics behind - it's completely surprising to me...

Image
User avatar
Yincognito
Rainmeter Sage
Posts: 7177
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: CurrentObservationTime - Time measure to calculate X-position in shape meter

Post by Yincognito »

emp00 wrote: March 29th, 2024, 5:46 pm Two solutions, both working - confirmed --> Thanks to the both of you! (I only slightly renamed the measures)
Balala was gracious enough to lay down nicely what I mentioned earlier, so he deserves the thanks more than I do. For the record, on a second thought now that I'm on my laptop, both variants can be simplified into a single measure, if you don't care about the actual time, hours or minutes, and just want them to work in your Shape meter (I only added [Rainmeter] and a replacement of [@CurrentObservationTime] for testing purposes below).

1st variant (in the end, one can get the formula string right in the Format option, avoiding [YourTimeMeasure:Timestamp] parts entirely):

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,1

---Measures---

[@CurrentObservationTime]
Measure=String
String=15:45

[MeasureDecimalTime]
Measure=Time
TimeStampFormat=%H:%M
TimeStamp=[@CurrentObservationTime]
Format=(%H+%M/60)
DynamicVariables=1

---Meters---

[Test]
Meter=Shape
Shape=Line (100+3*[MeasureDecimalTime]),1,(100+3*[MeasureDecimalTime]),100 | StrokeWidth 3 | Stroke Color 255,0,0,255
DynamicVariables=1
2nd variant (similarly, one can get the formula string by manipulating the \1 and \2 captures in a single Subtitute part):

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,1

---Measures---

[@CurrentObservationTime]
Measure=String
String=15:45

[MeasureDecimalTime]
Measure=String
String=[@CurrentObservationTime]
RegExpSubstitute=1
Substitute="(\d{1,2}):(\d{2})":"(\1+\2/60)"
DynamicVariables=1

---Meters---

[Test]
Meter=Shape
Shape=Line (100+3*[MeasureDecimalTime]),1,(100+3*[MeasureDecimalTime]),100 | StrokeWidth 3 | Stroke Color 255,0,0,255
DynamicVariables=1
emp00 wrote: March 29th, 2024, 5:46 pmHowever, the numerical value of [@CurrentObservationMinute] equals 18 (highlighted red) --> this is the current hour! How does the hour end up as numerical value for the minute?
This is normal. I'm assuming both your measures are String ones, so any numerical value of both will be based on the initial "18:30" string before the substitution occurs. Since such a string cannot be entirely converted to a number, only the part until the ":" (aka "18") "survives", hence the seemingly strange number value of these measures.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
emp00
Posts: 83
Joined: October 7th, 2022, 8:08 pm

Re: CurrentObservationTime - Time measure to calculate X-position in shape meter

Post by emp00 »

Yincognito wrote: March 29th, 2024, 6:05 pm Balala was gracious enough to lay down nicely what I mentioned earlier, so he deserves the thanks more than I do. For the record, on a second thought now that I'm on my laptop, both variants can be simplified into a single measure, if you don't care about the actual time, hours or minutes, and just want them to work in your Shape meter [...}

[Hour in Minutes number value issue]
This is normal. I'm assuming both your measures are String ones, so any numerical value of both will be based on the initial "18:30" string before the substitution occurs. Since such a string cannot be entirely converted to a number, only the part until the ":" (aka "18") "survives", hence the seemingly strange number value of these measures.
:thumbup: :rosegift:

Your simplification into a single measure is greatly appreciated - and confirmed working! This also removes the "Hour in Minutes" number issue which is a strange effect in my eyes. Thanks for explaining this as well. All problems solved, user very happy!! Many thanks to both of you.
User avatar
Yincognito
Rainmeter Sage
Posts: 7177
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: CurrentObservationTime - Time measure to calculate X-position in shape meter

Post by Yincognito »

emp00 wrote: March 29th, 2024, 6:35 pmAll problems solved, user very happy!!
That's all we wanted - now you can grow that happiness for Christmas and still have enough for after the New Year's Eve! If you share it, even better! ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16177
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: CurrentObservationTime - Time measure to calculate X-position in shape meter

Post by balala »

emp00 wrote: March 29th, 2024, 5:46 pm Two solutions, both working - confirmed
I'm glad.
emp00 wrote: March 29th, 2024, 5:46 pm Just one remaining super-stupid question: Check out my screenshot - the decimal time is calculated correctly. However, the numerical value of [@CurrentObservationMinute] equals 18 (highlighted red) --> this is the current hour! How does the hour end up as numerical value for the minute?
There are no stupid (and even less super-stupid) questions: what might is a hard question for one, might be a super easy for someone else. But none these questions is stupid. Trust more yourself.
Yincognito wrote: March 29th, 2024, 6:05 pm I'm assuming both your measures are String ones, so any numerical value of both will be based on the initial "18:30" string before the substitution occurs. Since such a string cannot be entirely converted to a number, only the part until the ":" (aka "18") "survives", hence the seemingly strange number value of these measures.
To be honest I better believe [@CurrentObservationTime] is a WebParser measure. Don't know precisely, has not been yet confirmed, but based on its name, I'd vote for a WebParser measure.
But in fact this doesn't matter too much: no matter if that's a WebParser, a String or a Time measure, your explanation applies in any of these cases.
User avatar
Yincognito
Rainmeter Sage
Posts: 7177
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: CurrentObservationTime - Time measure to calculate X-position in shape meter

Post by Yincognito »

balala wrote: March 29th, 2024, 8:24 pmTo be honest I better believe [@CurrentObservationTime] is a WebParser measure.
Yep, that is almost certainly a WebParser - one of jsmorley's inspired weather measures, probably. However, I was talking about the [@CurrentObservationHour] and [@CurrentObservationMinute], which I suspect are the renamed versions of [MeasureHour] and [MeasureMinute] from the code you provided above for the 2nd variant. :)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16177
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: CurrentObservationTime - Time measure to calculate X-position in shape meter

Post by balala »

Yincognito wrote: March 29th, 2024, 11:52 pm However, I was talking about the [@CurrentObservationHour] and [@CurrentObservationMinute], which I suspect are the renamed versions of [MeasureHour] and [MeasureMinute] from the code you provided above for the 2nd variant. :)
Aha, alright. Misunderstood you? Once again? My bad...