more G-Labs products

Author Topic: Decimal value comparison  (Read 3735 times)

April 20, 2014, 02:47:55 PM
Read 3735 times

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Hi,

I try a simple automation wizard script :
Code: [Select]
If the temperature is more than 19
Then close shutter
But after some test (value at 19.1) :
1/ Greater than 19 => No close shutter
2/ Equal 19.1 => Shutter close

So my question, is the comparison : "greater than" and "less than" doesn't manage decimal value ?

Bye

April 20, 2014, 02:58:14 PM
Reply #1

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
After a look in the source code, i think i can confirm :) "ComparisonOperator.cs" :
Code: [Select]
.......
    public enum ComparisonOperator
    {
        LessThan = -1,
        Equals = 0,
        GreaterThan = 1
    }
....

April 20, 2014, 03:00:44 PM
Reply #2

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer

April 20, 2014, 03:18:43 PM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
I think there might be a bug with parsing "," and "." as decimal separator with different locales.
What locale is set in the hg hosting server?

g.
« Last Edit: April 20, 2014, 03:21:25 PM by Gene »

April 20, 2014, 03:44:13 PM
Reply #4

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
I don't understand why but :
  • greater than "18.0" => doesn't work
  • greater than "18.1" => work

My "locale" :
Code: [Select]
LANG=en_GB.UTF-8

April 20, 2014, 03:52:50 PM
Reply #5

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Look how the sensor value is store by searching for it in the modules list:

http://192.168.0.2/api/HomeAutomation.HomeGenie/Config/Modules.List

Does it have a comma separator or a dot one?
Btw... one question... why would you close the shutter on a temperature basis? =D

g.

April 20, 2014, 04:22:22 PM
Reply #6

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
I have dot separator.

I prepare for hot summer, with some parameters (interior+exterior temperature, interior luminance, and alarm on), it will close the shutter to prevent south windows to have so much sun. So it won't be 19 or 18 for interior temperature but probably 25 ;).

April 20, 2014, 04:33:47 PM
Reply #7

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Cool idea =)
In the meantime I changed some lines of code that should fix the issue.

https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Automation/ProgramEngine.cs#L677

Code: [Select]
                    else if (double.TryParse(parameter.Value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out dval))
                    {
                        lvalue = dval;
                        rvalue = double.Parse(comparisonValue, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                    }

perhaps with LANG=en_GB.UTF-8 locale, by default double.Parse is looking for comma separator.
Specifying InvariantCulture may fix the bug.
I also remove the surrounding try...catch so that any parsing error will be reported to the UI.

Do you have any chance to recompile and test by yourself? After compiling you've to copy just the HomeGenie.exe file.

g.
« Last Edit: April 20, 2014, 04:43:46 PM by Gene »

April 20, 2014, 08:11:43 PM
Reply #8

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi nolio can you test the fix I posted here:

http://www.homegenie.it/forum/index.php?topic=156.msg843#msg843

it also fixes the Wizard Script values comparison bug.

g.

April 20, 2014, 09:48:00 PM
Reply #9

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Thank you for compilation.

I try again, but it doesn't work.
I got the following message :
Code: [Select]
Errors:
[{"Line":0,"Column":0,"ErrorMessage":"String was not recognized as a valid DateTime.","ErrorNumber":"-1","CodeBlock":"TC"}]
Program disabled, fix errors first.

Bye

April 20, 2014, 10:32:49 PM
Reply #10

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
My gosh! :) this has never worked since any number was interpreted as a DateTime =/
I switched the two if blocks so that it first tries to parse the value as a number and then, if it fails, it tries to parse the value as a date.
Let me know if this work now. I did a quick test and it worked.

g.


April 20, 2014, 11:11:12 PM
Reply #11

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Yes, it work fine.
But when i save the script (several times), i have still a pop "Errors" but with nothing else in the popup ... Juste the "close" button :)


April 20, 2014, 11:20:57 PM
Reply #12

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
I think that updating to r366 from the Configure->Maintenance section should fix this too (refresh the browser by pressing F5 after the update).

Cheers,
g.

April 21, 2014, 07:05:59 PM
Reply #13

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Hi,
Woo. I updated from webUI, but now when i
  • save = error with nothing
  • run =  Errors:
    [{"Line":0,"Column":0,"ErrorMessage":"String was not recognized as a valid DateTime.","ErrorNumber":"-1","CodeBlock":"TC"}]
    Program disabled, fix errors first.
So i don't really understand :/

Bye

April 21, 2014, 07:36:50 PM
Reply #14

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
If you updated from HG < r364 probably the HomeGenie.exe got overwritten.
So copy the fixed HomeGenie.exe again.
Let me know if it fixes the problem.

g.