It is currently April 19th, 2024, 6:10 am

Substitution issue

Get help with creating, editing & fixing problems with skins
D_Reckoning
Posts: 10
Joined: July 14th, 2010, 10:15 pm

Substitution issue

Post by D_Reckoning »

Small but annoying issue... I'm basicly substituting a number (from a calculation) with text. The number needs to be able to reach at least 24, but whenever it gets into the 2-digit numbers, it substitutes each digit individually - which isn't exactly looking as intended -.-

I've tried reversing the order in the list of substitutes (i.e. highest number first), but that had no effect.

I've tried separating the prociess into two different measures (one for 0-9, one for 10+), but that yielded even worse results - suddenly always returning the number as '0' with no substitution whatsoever.

I'm starting to come up short on ideas, so any help is appreciated ^^
User avatar
Alex2539
Rainmeter Sage
Posts: 642
Joined: July 19th, 2009, 5:59 am
Location: Montreal, QC, Canada

Re: Substitution issue

Post by Alex2539 »

Could you post the code you are using here? It's very difficult to help you if we can't see what you're doing. If you're getting just the numbers 0 to 24, then this substitution should work:

Code: Select all

Substitute=".00000":"",".0":"","24":"Twenty-four","23":"Twenty-three","22":"Twenty-two","21":"Twenty-one","20":"Twenty","19":"Nineteen","18":"Eighteen","17":"Seventeen","16":"Sixteen","15":"Fifteen","14":"Fourteen","13":"Thirteen","12":"Twelve","11":"Eleven","10":"Ten","9":"Nine","8":"Eight","7":"Seven","6":"Six","5":"Five","4":"Four","3":"Three","2":"Two","1":"One","0":"Zero"
ImageImageImageImage
D_Reckoning
Posts: 10
Joined: July 14th, 2010, 10:15 pm

Re: Substitution issue

Post by D_Reckoning »

Sadly, that looks remarkably like the first thing I've tried...

anyway; here's the code:

Code: Select all

;----------MEASURES----------

[MeasureRise]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=360
Url=http://weather.yahooapis.com/forecastrss?p=#WeatherCode#&u=f
RegExp=(?siU)<link.*>(.*)</link>.*city=\"(.*)\".*sunrise=\"(.*)\".*sunset=\"(.*)\".*<image>.*<url>(.*)</url>.*<title>.*:.*m .*(.*)</title>.*lat>(.*)<.*long>(.*)<.*yweather:condition.*text=\"(.*)\".*code=\"(.*)\".*temp=\"(.*)\".*yweather:forecast.*day=\"(.*)\".*high=\"(.*)\".*code=\"(.*)\".*yweather:forecast.*day=\"(.*)\".*high=\"(.*)\".*code=\"(.*)\".*
StringIndex=3
Substitute=" am":"",":":"."

[MeasureSet]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureRise]
StringIndex=4
Substitute=" pm":"",":":"."

[Ctime]
Measure=Time
Format=%H.%M

[Crise]
Measure=Calc
Formula=(MeasureRise)

[Cset]
Measure=Calc
Formula=(MeasureSet+12.0)

[cCase]
Measure=Calc
Formula=(Ctime<Crise?1:cCaseb)

[cCaseb]
Measure=Calc
Formula=(Ctime>Cset?3:2)

[cTimeleft]
Measure=Calc
Formula=(cCase=1?Crise-Ctime:cTimeleftb)

[cTimeleftb]
Measure=Calc
Formula=(cCase=2?Cset-Ctime:(24-Ctime)+Crise)

[CTLmod]
Measure=Calc
Formula=(TRUNC(cTimeleft))
Substitute="24":"another 24 hours","23":"another 23 hours","22":"another 22 hours","21":"another 21 hours","20":"another 20 hours","19":"another 19 hours","18":"another 18 hours","17":"another 17 hours","16":"another 16 hours","15":"another 15 hours","14":"another 14 hours","13":"another 13 hours","12":"another twelve hours","11":"another eleven hours","10":"another ten hours","9":"another 
nine hours","8":"another eight hours","7":"another seven hours","6":"another six hours","5":"another 
five hours","4":"another four hours","3":"another three hours","2":another two hours","1":"another 
hour","0":"less then an hour"

[watriteA]
Measure=Calc
Formula=(cCase)
Substitute="1":"The sun won't rise for ","2":"I estimate there's ","3":"The sun won't rise for "

[watriteB]
Measure=Calc
Formula=(cCase)
Substitute="1":"...","2":"of daylight left...","3":"..."


;----------METERS------------

[Part1]
Meter=String
MeasureName=watriteA
W=500
Y=0
FontColor=#Colour#, 200
FontSize=20
FontFace=#Font#
StringAlign=LEFT
StringStyle=BOLD
AntiAlias=1

[Part2]
Meter=String
MeasureName=CTLmod
W=500
Y=30
X=10
NumOfDecimals=0
FontColor=#Colour#, 200
FontSize=20
FontFace=#Font#
StringAlign=LEFT
;StringStyle=BOLD
AntiAlias=1

[Part3]
Meter=String
MeasureName=WatriteB
W=500
Y=30
X=1R
FontColor=#Colour#, 200
FontSize=20
FontFace=#Font#
StringAlign=LEFT
;StringStyle=BOLD
AntiAlias=1

What I'm trying to do is have the skin politely pointing out the number of hours left untill the next sunrise/sunset.

how it works (basicly):
1. taking in the time of rise and set from an external source ([MeasureRise],[MeasureSet])
2. turning those times (and the current time) into workable numbers ([Ctime],[Crise],[Cset])
3. comparing these to decide if we're counting towards a sunrise or sunset ([cCase],[cCaseb])
4. using that information to decide by which formula to count the "time left" ([cTimeleft],[cTimeleftb])
5. claculating time left ([cTimeleft],[cTimeleftb])
6. time left will be a number with decimals, but I'm only interested in hours - thus, I truncate the results. ([CTLmod])
7. the truncated number is substituted for text (in most of the probable cases). ([CTLmod])
User avatar
Alex2539
Rainmeter Sage
Posts: 642
Joined: July 19th, 2009, 5:59 am
Location: Montreal, QC, Canada

Re: Substitution issue

Post by Alex2539 »

Your problem is that the substitution doesn't terminate once it finds a match. It makes the substitution then keeps going. With the substitution you have there, the values larger than 12 all include numbers within their substitutions. So once it reaches the single-digit substitutions it will still find matches and perform the substitutions. For example, if the value is 17, the first substitution match it finds is "17":"another 17 hours", so the value is turned into "another 17 hours". Then it keeps going down the list. It finds another match at "7":"another seven hours" and the value now becomes "another 1another seven hours hours". Finally, it finds a final match with "1":"another
hour" so the value becomes "another another houranother seven hours hours".

The simplest fix for this is to just use words for all of the values like I did in my substitution. That way there won't be any more matches once it performs a substitution. However, if you insist on keeping the mix of numbers and words that you have, the following should work:

Code: Select all

Substitute="24":"another aa hours","23":"another bb hours","22":"another cc hours","21":"another dd hours","20":"another ee hours","19":"another ff hours","18":"another gg hours","17":"another hh hours","16":"another ii hours","15":"another jj hours","14":"another kk hours","13":"another ll hours","12":"another twelve hours","11":"another eleven hours","10":"another ten hours","9":"another
nine hours","8":"another eight hours","7":"another seven hours","6":"another six hours","5":"another
five hours","4":"another four hours","3":"another three hours","2":another two hours","1":"another
hour","0":"less then an hour","aa":"24","bb":"23","cc":"22","dd":"21","ee":"20","ff":"19","gg":"18","hh":"17","ii":"16","jj":"15","kk":"14","ll":"13"
This way the values you want to keep as digits are temporarily turned into strings that aren't going to be found elsewhere, essentially protecting them from further substitution. Then at the end they are converted back into digits. Keep in mind that if you decide to change the phrase to something that includes words with double letters you'll need to change it again since it will match those and turn them into digits (ex: "Hello" would become "He13o").
ImageImageImageImage
D_Reckoning
Posts: 10
Joined: July 14th, 2010, 10:15 pm

Re: Substitution issue

Post by D_Reckoning »

All I can say is "Ahaaaa" and "thank you" ^_^

It all makes sense now, thanks a bunch! :)