Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Can someone check this math please?

I am using this in a Macro to make Kodi feedback into readable time:($feed_runtime_hours$-($feed_runtime_hours$%3600))/3600h
I have corresponding ones for mins and secs too.

It is broken now, and I am not sure if it is me or a new math behaviour in the new 4.7 version. If someone has time to check and comment I would appreciate it.
thanx in advance
1 person has
this question
+1
Reply
  • It looks like $feed_runtime_hours$ starts out as seconds, and you want to extract the number of whole hours?

    Try $hours$ = floor( $feed_runtime_hours$ / 3600 )

    I put the spaces in for readability. You may have to take them out for iRule to run it.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Thanx Mike. appreciate it!

    Yes, you are right in what I am doing. It worked on 4.5...
    As with my example, yours is not processed as a math expression for some reason.
    Are you on iRule 4.7?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • The calculation does work, but entering it is a little tricky. It should look like this when you are done:

    Set Variable: $hours$ = floor($feed_runtime_hours$/3600)

    Be sure to set 'Evaluate As' to Expression. You also need to create the variable names $feed_runtime_hours$ and $hours$ so that when you start to enter them in the Variable Value property, a box pops up when you enter the first letter, and you then click on the variable name. The first time I entered the expression, I typed the full variable names in, and I got back "floor(0" from the calculation.

    I deleted the Set Variable action and re-entered it. This time, when I typed $f, a box popped up, and I clicked $feed_runtime_hours$. When I typed $h, a box popped up, and I clicked $hours$. iRule does not like it when you just type in a variable name, so you have fiddle with it sometimes.

    After this, I saved the panel and synced to my iPad, and it worked. The Panel is named "Hours Calculation" and it is Shared, so you should be able to Browse Panels and download it. The first button uses the Input Variable action, so you can test different values. The second button calculates $hours$.

    Good Luck!

    Mike
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Thanx Mike,

    I think I have those things in place.
    As I mentioned, this math worked before in 4.5 so I am guessing that something else has changed. I will continue to troubleshoot though.
    So you are on 4.7 and that math works for you?
    thanx again!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Actually. Just to be clear.
    When you write "You also need to create the variable names "
    In what form specifically are you doing that?
    On the same page in the handset?
    thanx
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • By create the variable names, I meant type them in to the Set Variable Action. Once you type them in once, a box will pop up with the variables the next time you start to enter it in.

    I enter the Set Variable once, then delete it, and then enter the Set Variable again, iRule pops up the variables, I click them, iRule is happy, and the expression works. There may be an easier way to do this, but the way I do it works for me.

    By the way, I am running 4.7, and my formula works, that is, it takes the run time in seconds and returns the number of whole hours in that number of seconds. In your original post, your formula may have a couple of typos. Is the % supposed to be a /? Is the 3600h at the end supposed to be just 3600?

    Mike
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Mike, you're a star.
    Not sure where that typo was introduced, but removing the % fixed my error.
    Thanx so very much!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • It seems the % sign is not supported in 4.7 ATM.

    To replace it with other math, your suggestion for hours works perfectly
    Any chance of some advice on how to use "floor" to do minutes in a similar way?

    I have gotten this far, which gives me runtime seconds rounded off into minutes with decimals:
    ($feed_runtime_seconds$-$runtime_hours$*3600)/60
    Can I use "floor" or something else here to somehow lose the decimals for minutes in this math?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • 1
    Equations:

    Set Variable: $minutes$ = floor(($feed_runtime_hours$-($hours$*3600))/60)

    Set Variable: $seconds$ = $feed_runtime_hours$-($hours$*3600)-($minutes$*60)

    I assume $feed_runtime_hours$ is actually the total runtime in seconds. I have not tested these equations in iRule, but I think they are correct.

    Mike
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • I’m happy
    Your runtime minutes math works like a charm here.
    Wish I could buy you a beer!! Thanx mate!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated