Attempting to create a percent-to-time script

Posted by Faedara on Sun 17 Apr 2011 02:09 AM — 11 posts, 45,516 views.

#0
I have a rather large and complicated scheme going for a script I've built to tell me how long I have until completing the current project I'm building in the MUD, but I've been having multiple problems with the math part of the equation, some of them being because I don't know how to convert everything into the proper formats. Right now I have this:


<aliases>
  <alias
   match="ptest"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>EnableTrigger("test1", true)
Send("list")
DoAfter(1, "list")
EnableTimer("math", true)
ResetTimer("math")</send>
  </alias>
</aliases>

<triggers>
  <trigger
   expand_variables="y"
   keep_evaluating="y"
   match="^(.*?) taken\) (.*?)\% Complete$"
   name="test1"
   regexp="y"
   send_to="12"
   sequence="99"
  >
  <send>test1 = "%2"
Note (test1)
EnableTrigger("test1", false)
ResetTimer("test2")
EnableTimer("test2", true)</send>
  </trigger>
  <trigger
   expand_variables="y"
   match="^(.*?) taken\) (.*?)\% Complete$"
   name="test2"
   regexp="y"
   send_to="12"
   sequence="99"
  >
  <send>test2 = "%2"
Note (test2)
EnableTrigger("test2", false)</send>
  </trigger>
</triggers>

<timers>
  <timer name="test2" second="0.50" offset_second="0.00"    send_to="12"
>
  <send>EnableTrigger("test2", true)
EnableTimer("test2", false)</send>

  </timer>

  <timer name="math" second="2.00" offset_second="0.00"    send_to="12"
>
  <send>test3 = 100/(test2-test1)
Note "Total time:"
Note (test3)
Note "Remaining time:"
EnableTimer("math", false)</send>

  </timer>
</timers>


The goal is to take this line:
Hydra Regen Soft (Alpha) - 6 144Mp (158Mp taken) 18.33% Complete
Two times (one second apart) and get the % from it each time, then examine the difference and convert that into a time estimate (it doesn't have to be exact but thus far it's been anything but accurate). Some of it I accidentally lost when copying these here (I tend to leave bits of code on my copyboard) so the math timer is now completely broken.
If anyone can help me figure out where I'm going wrong, how to convert the end product into time, or give me general tips for fixing this heaping mess of newbstink, it would be greatly appreciated.
Finland #1
the almighty GetInfo (232) will get you accuracy!
(try doing a few Note(GetInfo(232))'s in the immediate screen to get the idea)

I noticed that you're looking for a "mentor" (it's in your signature) ... I'm not a pro but I might be able to give you some tips I've learned so far!

You can add me on AIM: AlexRaato
#2
Sorry but I don't get how that's supposed to help me at all...
Finland #3
make an alias to start it up, make the alias send whatever command that invokes the "Hydra Regen Soft (Alpha) - 6 144Mp (158Mp taken) 18.33% Complete" thing, the alias should also enable trigger1 and add a timer to disable it and prompty enable trigger2

trigger1 (responds to the "Hydra Regen Soft (Alpha) - 6 144Mp (158Mp taken) *% Complete" string)
time1 = GetInfo(232)
percent1 = *

trigger2 (responds to the "Hydra Regen Soft (Alpha) - 6 144Mp (158Mp taken) *% Complete" string)
time2 = GetInfo(232)
percent2 = *

periode = time2 - time1
growth = percent2 - percent1

to_go = 100 - percent2
time_until_done = to_go/periode


is that of any help? I can try to write some code for you if you'd prefer that
#4
And now it all makes perfect sense... well played.
Only one problem, when I subtract a number with a decimal from a number with a decimal it comes out with unprovoked infinite number syndrome.
Finland #5
this ancient scripture might hold the answer:
http://www.gammon.com.au/forum/?id=7805
Australia Forum Administrator #6
And more self-documenting if you are using a recent version:

http://www.gammon.com.au/scripts/doc.php?lua=utils.timer


It came out in version 4.62.
Amended on Sun 17 Apr 2011 05:12 AM by Nick Gammon
Australia Forum Administrator #7
Faedara said:

Only one problem, when I subtract a number with a decimal from a number with a decimal it comes out with unprovoked infinite number syndrome.


Subtracting two numbers should never give you infinity. Are you sure you didn't do a divide in there somewhere? (Or if the two times are the same then subtracting one from the other gives you zero, which then might eventually lead to a divide by zero).
#8
Maybe infinite alone is the wrong word for it, it's actually returning a randomly repeating decimal such as if I do:
12.34-12.30 I might get something like 0.049999999
#9
Aha! I finally figured out what was wrong with my original script. The MUD updates on even seconds, so I had to take the result of a one second scan and then divide that by two for the rest of the equations!
USA #10
Faedara said:
Maybe infinite alone is the wrong word for it, it's actually returning a randomly repeating decimal such as if I do: 12.34-12.30 I might get something like 0.049999999

Well, the 9's don't continue infinitely. That missing 0.0000000000000001 (or so) is called "epsilon", which is the resolution of a floating-point number. (It's not a constant like e or pi is, though: it depends on how many bits are used.) When you do any kind of arithmetic with floating point numbers, you necessarily involve some amount of inaccuracy, because there are some values that can't be stored precisely.

[EDIT]: The tl;dr is, the inaccuracies you're seeing are expected side-effects of floating-point numbers.

[EDIT] 2: http://en.wikipedia.org/wiki/Machine_epsilon