Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum Goto page 1, 2  Next
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Wed Aug 18, 2010 2:09 pm   

Help turning a % into a time
 
CMud Pro Beta 3.22a
Windows 7 64bit

Can I get someones assistance on this please. I kind of got it working, but it's not exactly pretty, and it's got way too much going on.

What I have is the following line:

Likelihood of Flux: 5.94%

The trigger I have set up is this:

Likelihood of Flux: (%d)*

and my code is as follows:

Code:

#math flux1 (100 - %1)
#math flux2 (@flux1 / (0.6))
#math flux3 (@flux2 * 2)
#math flux4 (@flux3 / 10)
#var fluxtime %format(2,@flux4)
#sub (@fluxtime minutes~])


The % increases .06% every 2 seconds, and it goes from 0 to 100% and resets back to 0. so when the timer is at 99.94%, there are 2 seconds remaining until it resets.

I'm positive there's something better than can be done, but I don't know how to extract the seconds from it, and I have so many math in there because if I tried to do it all on one line it wouldn't calculate properly.

Any assistance would be wonderful, thanks.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Wed Aug 18, 2010 3:31 pm   
 
Ok we can simply things greatly here. First thing to note is that it resets every hour which we all know is 3600 seconds. Second for speed we are going to use local variables and get rid of a lot of the intermediary variables we don't need. Finally we will tweak your trigger just a bit to be more precise.

Here's what you end up with.

First I know it's 3600 secs (1 hour) by working backwards. It came so close I assumed that's that it was then confirmed. That would mean it goes up 1% every 36 seconds. 1 divided by 18 is 0.0555..(repeating) hence it goes up by 0.06% every two seconds by rounding up.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger priority="10" copy="yes">
    <pattern>Likelihood of Flux: (%d*)~%</pattern>
    <value>#echo %1
#echo (100 - %float(%1))
#echo ((100 - %float(%1)) / 3600)
#echo ((100 - %float(%1)) / 60  ) // Converting to minutes

$fluxCalc = (100 - %float(%1)) / 60
#var fluxtime %format(2,$fluxCalc)
#sub (@fluxtime minutes~])

// If you want to be really precise you can do this instead
$fluxMin = %int((100 - %float(%1)) / 60  )
$fluxSec = %int((100 - %float(%1)) \ 60  ) // Take the modulus
#echo $fluxMin min and $fluxSec sec.</value>
  </trigger>
</cmud>


That code includes alot of extra #ECHOs to walk you through the calculations. It also echos a minute and seconds version if you prefer that.
_________________
Asati di tempari!
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Wed Aug 18, 2010 3:42 pm   
 
Thank you for the reply.

Something didn't quite work properly. When I use your trigger, it's supposed to return approx 11 minutes, but it shows this instead.

68.31
31.69
0.00880277777777778
0.528166666666667
0 min and 31 sec.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2307

PostPosted: Wed Aug 18, 2010 4:38 pm   
 
There's nothing wrong at all. Tech told you that he added some extra #ECHO lines to show you various forms of the calculations. The 0.008802777777778 is the value in hours, the 0.527166666667 is the value in minutes, and the last line is minutes and seconds. He only put those lines in to help you see what was going on. You can remove those lines, or change the output however you want.
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Wed Aug 18, 2010 4:54 pm   
 
That's what I mean tho, it returns 0 minutes when it should be 11.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Wed Aug 18, 2010 5:13 pm   
 
What should be 11 exactly? You said [quote" Loftaris"]The % increases .06% every 2 seconds[/quote], although in your code you used "0.6" vs "0.06".

That what i used as the basis for my calculations. The #ECHOs were to reinforce how I arrived at my calculations so that you can easily make corrections if they were incorrect.

What was your percentage value when you expected the remaining time to be 11 minutes? Does is it increase "0.06%" every 2 seconds, or "0.6%" every 2 seconds? In either case the trigger is easily correctible.

Can you include the text you received and the full output text of the trigger I posted.
_________________
Asati di tempari!
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Wed Aug 18, 2010 6:14 pm   
 
Maybe my math was wrong, like I said I was having troubles with it, and it's quite possible I borked it up.


With my trigger, it turns

Timescan <Dark room>:[yellow] [Likelihood of Flux: 75.70%]

into

Timescan <Dark room>:[yellow] [Flux: (8.33 minutes])

each heartbeat (every 2 seconds) it will increase from 75.70, to 75.76.

if I change it to .06 in my math, it goes from 8 minutes, to 83 minutes. I'm not entirely certain (as I just got the power and haven't had much time to test it), but I thought I figured out 100% is approx 30 minutes.

if 1% is 33.33 seconds, 100% would be 33.33 minutes. (1 percent / .06 * 2(each tick is 2 seconds instead of 1) = 33.33)

Tell me my math is faulty?
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Wed Aug 18, 2010 7:26 pm   
 
It is. As I explained in my math even though it increases 0.06% every two seconds, this is really an artifact of rounding it is 0.55555555 (the five repeats ad infinitum).

Even assuming it is 0.06 exactly you have
Code:
 (((  T / i ) * c) / sM)


Where 'T' is the Total Round percentage, i.e. 100, 'i' is the amount we increment be, i.e. 0.06%, 'c' the constant time elapsed in each increment and 60 represents the number of seconds in a minute.

T/i are the total number increments to go from 0% to 100% and is equal to 1667 (after rounding up to the nearest integer). (T/i ) * c is the total number of seconds to reset which equals 3334. Dividing that by 60 we get 55.567 after rounding the third decimal, or roughly an hour. As I explained in my first post, I then guessed that it's more likely it resets hourly and worked backwords i.e. [quote=Tech]First I know it's 3600 secs (1 hour) by working backwards. It came so close I assumed that's that it was then confirmed. That would mean it goes up 1% every 36 seconds. 1 divided by 18 is 0.0555..(repeating) hence it goes up by 0.06% every two seconds by rounding up. [/quote]

The flaw in your math is you are miscalculating your minutes. 100% * 33.33 secs does not equal 33.33 minutes because there are 60 seconds in a minute, not 100.


That said in either scenario the time remaining is fairly constant for 75.70%

Using our (((T/i)*c)/60) result of 3334 we get
Code:
3334 - (3334 (75.70%)) ==> 3334 - (3334 * 0.757) ==> 810.162 secs or roughly 13.5027 minutes

Using your formula of 33.33 seconds per 1% we get simply
Code:
33.33 * (100 - 75.7) ==> 33.33 * 24.7 ==> 809.919 secs or roughly  13.49865 minutes

Using my assumption of an hourly reset and corresponding code you get
Code:
 ((100 - 75.7) / 60)  ==> 0.405
Which is clearly wrong.

The corrected formula for my assumption would have been
Code:
 (((100 - 75.7) / 60) * 3600) /100 ==>  ((100 - 75.7) / 60 ) * 36 ==> 24.3 /60 * 36 ==> 0.405 * 36 ==> 14.58 minutes.



[Note] I wrote this long post before I saw my own math error, i.e. I screwed up the conversion too. But I saved the entire post for posterity and to offer myself some humble pie.

The updated trigger is
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger priority="10" copy="yes">
    <pattern>Likelihood of Flux: (%d*)~%</pattern>
    <value>#echo %1
#echo (100 - %float(%1))
#echo ((100 - %float(%1)) / 3600)
#echo ((100 - %float(%1)) / 60  ) // Converting to minutes

$decimal= (100 - %float(%1)) / 100
$totalSecs = $decimal * 3600
$fluxCalc = $decimal * 60
#var fluxtime %format(2,$fluxCalc)
#sub (@fluxtime minutes~])

// If you want to be really precise you can do this instead
$fluxMin = %int($totalSecs / 60  )
$fluxSec = %int($totalSecs \ 60  ) // Take the modulus
#echo $fluxMin min and $fluxSec sec.</value>
  </trigger>
</cmud>
_________________
Asati di tempari!
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Wed Aug 18, 2010 7:40 pm   
 
Excellent, thanks so much for your time/help! I appreciate it!
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Wed Dec 14, 2011 3:14 pm   
 
I know this is an old post, but it's relevant to this exact trigger.

Code:
#sub {$fluxMin min and $fluxSec sec. ~(%1~%~)}


I added the previous line to the above trigger.

Is there a way I can add the future time to this trigger? So it'll show something like this:

Likelihood of flux: 49 minutes and 37 seconds {11:34am}

The flux is never greater than 60 minutes, so I don't need to worry about rounding days.

I tried using a current post as an example, but I failed miserably. As always, any help is totally appreciated!
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Dec 14, 2011 8:42 pm   
 
Code:
$TimeBase = %eval($fluxMin+%time("nn"))
$Hour = %time("hh")+%if($TimeBase>60,1,0)
$Min = %if($TimeBase>60,%eval(%time("nn")-%eval($TimeBase-60)),$TimeBase)


That /should/ get you at least the 11:34 part. Do you really need the am/pm bit? It's not that difficult to add, but just requires more coding than seems necessary. Please note, this isn't tested, so I'm not 100% sure it'll work.
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Wed Dec 14, 2011 8:49 pm   
 
I jumped the gun. Something's wrong in the calculation.. It's not displaying the proper time.

However it's working, somewhat.
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Wed Dec 14, 2011 8:52 pm   
 
This is the output I get using your code.

14:51:32 Timescan <The Center of Town>:[purple] [22 min and 34 sec. (59.37%) 15:38]

Each time I scan it, the ETA increases, it never decreases..? hrm.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Dec 14, 2011 10:12 pm   
 
Yeah, that was my fault. The $Min should only be:

Code:
$Min = %if($TimeBase>60,%eval($TimeBase-60), $TimeBase)


By the way, looking over the code, decided the Hour needs to change a bit, too...

Code:
$Hour = %time("h")+%if($TimeBase>60,1,0)
$Hour = %if($Hour>12, %eval($Hour-12), $Hour)


Let me know how that works out for you.
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Wed Dec 14, 2011 11:52 pm   
 
That fixed the counting problem.

My last question. It's currently showing 6:6 instead 6:06 .. Is that easy to fix?

Thanks so much! I love this. I've been counting it in my head for a long time heh.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Dec 14, 2011 11:55 pm   
 
Quite easy.

Where you display the $Min, do this instead:

Code:
%if($Min<10,%concat("0",$Min),$Min)


Glad to help out.
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Wed Dec 14, 2011 11:58 pm   
 
that sends it to the mud, I put it under the $min and in the #sub, but it still sends it to the mud instead.
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Thu Dec 15, 2011 12:05 am   
 
I also just realize there's a little glitch.

18:02:58 Timescan <The Center of Town>:[red] [3 min and 16 sec. (94.10%) 18:5:11]
18:03:03 Timescan <The Center of Town>:[red] [3 min and 8 sec. (94.34%) 18:6:11]

It doesn't count the seconds properly, when it should say 18:06:11, it's showing 18:05:11

I also added seconds to the calculation using your examples, probably obvious tho. heh
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Fri Dec 16, 2011 7:00 pm   
 
I've been unable to fix this by tinkering with the script.

Any suggestions on how to correct the calculation trouble?
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Fri Dec 16, 2011 9:33 pm   
 
I'm not sure why it would send it to the MUD. I said where you display the $Min. It seems like you're putting it on its own line.

You'd need it to be:

Code:
#sub {whatever %if($Min<10, %concat("0",$Min),$Min)}


You need to add seconds? That's easy enough, actually... just takes a bit more coding. And actually, I'm going to go about it in a MUCH easier way than has been mentioned before. You may not understand it, but it should work much more efficiently.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <func name="fluxsub" language="Lua" copy="yes">
    <value>totalsecs = ((100-zs.params(1))/100)*3600
fluxtime = os.time()+totalsecs
fluxhour = os.date('*t',fluxtime).hour
fluxmin = os.date('*t',fluxtime).min
fluxsec = os.date('*t',fluxtime).sec

if fluxhour > 12 then
fluxhour = fluxhour - 12
fluxap = "p"
else
fluxap = "a"
end

return fluxhour .. ":" .. fluxmin .. ":" .. fluxsec .. fluxap</value>
  </func>
</cmud>


Delete everything in your trigger except for the #SUB. Where you have it displaying the expected time (1:37pm, for example), you'll need to change it to:
Code:
@fluxtime(%1)


Also, I see you're using %d* in the trigger pattern. Change the %d* to %f.

If you have any questions, please, let me know.
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Fri Dec 16, 2011 10:46 pm   
 
Thanks. I won't be able to test this for a day or two.. When I do, I'll let you know.

Thank you!
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 270

PostPosted: Sat Dec 17, 2011 4:35 pm   
 
Uh.. I'm quite possibly mentally retarded, but I have no idea what's going on.

I imported your example, but it's not anywhere to be found.. if I try to import it again, it says there's already one there.

I've "searched" and manually browsed every trigger I have and it's nowhere to be found, nor does it work...

You managed to create an invisible trigger...
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sat Dec 17, 2011 6:24 pm   
 
It's not a trigger, it's a function.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sat Dec 17, 2011 8:51 pm   
 
It's a function, as Daern said. That's why I said in the trigger YOU have created (from the above posts), all you need to do is, in the #SUB {blah blah blah} line, change the part that displays the time to @fluxtime(%1).

I don't know exactly what your trigger looks like, so I can't quite copy/paste it for you. The only change you need to make is putting the @fluxtime(%1) in there where you display 11:34.

Edit:

Actually, give me a few, and I'll remake the trigger for you so that it can be just imported over and we should be done.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sat Dec 17, 2011 9:21 pm   
 
Here: This is the trigger you should use. It utilizes #SAYADD (which adds information to the line instead of needing to completely sub it out). This works as-is (tested it on my end), but if you have any questions whatsoever, let me know.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger priority="10" language="Lua" copy="yes">
    <pattern>Likelihood of Flux: (%f)~%</pattern>
    <value>local function addZero(n)
  if n < 10 then
  n = "0" .. n
  end
  return n
end

totalsecs = ((100-zs.param(1))/100)*3600
totalmins = math.floor(totalsecs/60)
remaindersecs = math.floor(totalsecs%60)
fluxtime = os.time()+totalsecs
fluxhour = os.date('*t',fluxtime).hour
fluxmin = os.date('*t',fluxtime).min
fluxsec = os.date('*t',fluxtime).sec

if fluxhour > 12 then
fluxhour = fluxhour - 12
fluxap = "p"
else
fluxap = "a"
end

zs.sayadd(" [ " .. totalmins .. "m " .. addZero(remaindersecs) .. "s (" .. fluxhour .. ":" .. addZero(fluxmin) .. "." .. addZero(fluxsec) .. fluxap .. ") ]")</value>
  </trigger>
</cmud>
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net