[store] bug plugin Calculator / calculateur mathématique

Discussion et échanges de scripts pour la box eedomus

[store] bug plugin Calculator / calculateur mathématique

Messagepar Gyvr » 25 Juil 2022 18:44

Bonjour,

J'ai des erreurs avec le calulateur qui génère l'erreur suivante ((en utilisant la fonction "tester" du script:
internal error 2<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /mnt/flash/puch/www/script/user/20164/calculator.php:430) in <b>/mnt/flash/puch/www/script/script_include.php</b> on line <b>74</b><br />
<result></result>

Après divers tests et simplification de la formule de calcul, je constate qu'avec la formule suivante dans VAR1 "15*(1-1)" j'ai l'erreur
internal error 2<result></result>

Par contre avec la formule "15*(2-1)" j'obtiens le bon résultat.

Il semble que si la valeur calculée entre parenthèses est égale à zéro ca plante, et si c'est non nul le résultat du calcul est bon.

Merci de votre aide.
Gérard
Gyvr
 
Messages : 100
Inscription : 08 Déc 2018

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar opa95 » 25 Juil 2022 19:33

Bonjour Gyvr
Gyvr a écrit:Bonjour,

J'ai des erreurs avec le calulateur qui génère l'erreur suivante ((en utilisant la fonction "tester" du script:
internal error 2<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /mnt/flash/puch/www/script/user/20164/calculator.php:430) in <b>/mnt/flash/puch/www/script/script_include.php</b> on line <b>74</b><br />
<result></result>

Après divers tests et simplification de la formule de calcul, je constate qu'avec la formule suivante dans VAR1 "15*(1-1)" j'ai l'erreur
internal error 2<result></result>

Par contre avec la formule "15*(2-1)" j'obtiens le bon résultat.

Il semble que si la valeur calculée entre parenthèses est égale à zéro ca plante, et si c'est non nul le résultat du calcul est bon.

Merci de votre aide.
Gérard

Je ne comprend pas pourquoi tu as la première erreur "Cannot modify header information" qui se produit généralement si on fait un "echo" ou un dump d'une variable au mauvais endroit.
As-tu la dernière version de Calculator?
Avec la dernière version, il demeure un problème et on obtient bien ton résultat "internal error 2<result></result>" si l'évaluation de la parenthèse est nulle.
Ceci est dû à une erreur du script qui cherche à tester si un contenant est indéfini, par exemple à la ligne 298, mais ne fait pas la différence entre "indéfini" et "0".
Pour corriger, il suffit de remplacer les tests
Code : Tout sélectionner
==null
par
Code : Tout sélectionner
===null
(3 signes = au lieu de 2).
J'ai corrigé la ligne 298 et par analogie toutes les lignes analogues (j'espère que ça ne crée pas d'autre problème, mais je n'ai pas testé (donc modifier les lignes 156, 185, 298 (c'est celle qui donne l'erreur 2), 299, 326 et 389.
:)
Voici le code obtenu, pour remplacer calculator.php
Code : Tout sélectionner
<?php

// Create an object to compute the formula
$evaleedomus = new sdk_EvalMath;

// Get formula from VAR1
$formula = getArg("formula");

if (!isset($formula)) $formula = "0";

// basic evaluation:
$result = $evaleedomus->sdk_evaluate($formula);

sdk_header('text/xml');
echo "<result>".$result."</result>";

/*
Script développé par :
Mickael VIALAT - http://www.planete-domotique.com

Basé sur l'excellent travail de Miles Kaufmann : EvalMath Class
Merci de partager toute modification ou amélioration de ce script avec la communauté eedomus
sur le forum : http://forum.eedomus.com

================================================================================
EvalMath - PHP Class to safely evaluate math expressions
Copyright (C) 2005 Miles Kaufmann <http://www.twmagic.com/>
================================================================================
LICENSE
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:
   
    1   Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
    2.  Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
    3.  The name of the author may not be used to endorse or promote
        products derived from this software without specific prior written
        permission.
   
    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.

*/

class sdk_EvalMath {

    var $suppress_errors = false;
    var $last_error = null;
   
    var $v = array('e'=>2.71,'pi'=>3.14); // variables (and constants)
    var $f = array(); // user-defined functions
    var $vb = array('e', 'pi'); // constants
    var $fb = array(  // built-in functions
        'device', 'abs', 'acos', 'asin', 'atan', 'cos', 'deg2rad', 'exp', 'floor', 'log', 'pow', 'rad2deg', 'rand', 'round', 'sin', 'sqrt');
       
    var $devicetab = array(); // user-defined functions
   
    function sdk_EvalMath()
    {
        // make the variables a little more accurate
        $this->v['pi'] = pi();
        $this->v['e'] = exp(1);
    }
   
    function sdk_evaluate($expr)
    {
        $this->last_error = null;
       
        $expr = trim($expr);
       
        if (substr($expr, -1, 1) == ';') $expr = substr($expr, 0, strlen($expr)-1); // strip semicolons at the end

        $arr =  $this->sdk_nfx($expr);

        return $this->sdk_pfx($arr); // straight up evaluation, woo
    }
   

    //===================== HERE BE INTERNAL METHODS ====================\\

    // Convert infix to postfix notation
    function sdk_nfx($expr)
    {
        $index = 0;
        $stack = new sdk_EvalMathStack;

        $output = array(); // postfix form of expression, to be passed to pfx()
        $expr = trim(strtolower($expr));
       
        $ops   = array('+', '-', '*', '/', '^', '_');
        $ops_r = array('+'=>0,'-'=>0,'*'=>0,'/'=>0,'^'=>1); // right-associative operator? 
        $ops_p = array('+'=>0,'-'=>0,'*'=>1,'/'=>1,'_'=>1,'^'=>2); // operator precedence
       
        $expecting_op = false; // we use this in syntax-checking the expression
                               // and determining when a - is a negation
   
   
        if (preg_match("/[^\w\s+*^\/()\.,-]/", $expr, $matches))
        { // make sure the characters are all good
            return $this->sdk_trigger("illegal character '{$matches[0]}'");
        }
   
        while(1)
        { // 1 Infinite Loop ;)
            $op = substr($expr, $index, 1); // get the first character at the current index
           
            // find out if we're currently at the beginning of a number/variable/function/parenthesis/operand
            $ex = preg_match('/^([a-z]\w*\(?|\d+(?:\.\d*)?|\.\d+|\()/', substr($expr, $index), $match);
           
            //===============
            if ($op == '-'  && !$expecting_op)
            { // is it a negation instead of a minus?
                $stack->sdk_push('_'); // put a negation on the stack
                $index++;
            }
            else
            if ($op == '_')
            { // we have to explicitly deny this, because it's legal on the stack
                return $this->sdk_trigger("illegal character '_'"); // but not in the input expression
            }
            else
            if ((in_array($op, $ops) || $ex) && $expecting_op)
            { // are we putting an operator on the stack?
                if ($ex) { // are we expecting an operator but have a number/variable/function/opening parethesis?
                    $op = '*'; $index--; // it's an implicit multiplication
                }
                // heart of the algorithm:
                while($stack->count > 0 && ($o2 = $stack->sdk_last()) && in_array($o2, $ops) && ($ops_r[$op] ? $ops_p[$op] < $ops_p[$o2] : $ops_p[$op] <= $ops_p[$o2]))
                {
                    $output[] = $stack->sdk_pop(); // pop stuff off the stack into the output
                }
                // many thanks: http://en.wikipedia.org/wiki/Reverse_Polish_notation#The_algorithm_in_detail
                $stack->sdk_push($op); // finally put OUR operator onto the stack
                $index++;
                $expecting_op = false;
            //===============
            }
            else
            if ($op == ')' && $expecting_op)
            { // ready to close a parenthesis?

                while (($o2 = $stack->sdk_pop()) != '(')
                { // pop off the stack back to the last (
                    if ($o2===null) return $this->sdk_trigger("unexpected ')'");
                    else $output[] = $o2;
                }
               
                if (preg_match("/^([a-z]\w*)\($/", $stack->sdk_last(2), $matches))
                { // did we just close a function?
                    $fnn = $matches[1]; // get the function name
                    $arg_count = $stack->sdk_pop(); // see how many arguments there were (cleverly stored on the stack, thank you)
                    $output[] = $stack->sdk_pop(); // pop the function and push onto the output
                    if (in_array($fnn, $this->fb))
                    { // check the argument count
                        if($arg_count > 1)
                            return $this->sdk_trigger("too many arguments ($arg_count given, 1 expected)");
                    }
                    else
                    { // did we somehow push a non-function on the stack? this should never happen
                        return $this->sdk_trigger("internal error 1");
                    }
                }
               
                $index++;
            //===============
            }
            else
            if ($op == ','  &&  $expecting_op)
            { // did we just finish a function argument?

                while (($o2 = $stack->sdk_pop()) != '(')
                {
                    if ($o2===null) return $this->sdk_trigger("unexpected ','"); // oops, never had a (
                    else $output[] = $o2; // pop the argument expression stuff and push onto the output
                }
                // make sure there was a function
                if (!preg_match("/^([a-z]\w*)\($/", $stack->sdk_last(2), $matches))
                    return $this->sdk_trigger("unexpected ','");
                $stack->sdk_push($stack->sdk_pop()+1); // increment the argument count
                $stack->sdk_push('('); // put the ( back on, we'll need to pop back to it again
                $index++;
                $expecting_op = false;
            //===============
            }
            else
            if ($op == '('  &&  !$expecting_op)
            {
                $stack->sdk_push('('); // that was easy
                $index++;
                $allow_neg = true;
            //===============
            }
            else
            if ($ex  && !$expecting_op)
            { // do we now have a function/variable/number?
                $expecting_op = true;
                $val = $match[1];
               
                if (preg_match("/^([a-z]\w*)\($/", $val, $matches))
                { // may be func, or variable w/ implicit multiplication against parentheses...
                    if (in_array($matches[1], $this->fb) or array_key_exists($matches[1], $this->f))
                    { // it's a func
                        $stack->sdk_push($val);
                        $stack->sdk_push(1);
                        $stack->sdk_push('(');
                        $expecting_op = false;
                    }
                    else
                    { // it's a var w/ implicit multiplication
                        $val = $matches[1];
                        $output[] = $val;
                    }
                }
                else
                { // it's a plain old var or num
                    $output[] = $val;
                }
               
                $index += strlen($val);
            //===============
            }
            else
            if ($op == ')')
            { // miscellaneous error checking
                return $this->sdk_trigger("unexpected ')'");
            }
            else
            if (in_array($op, $ops) && !$expecting_op)
            {
                return $this->sdk_trigger("unexpected operator '$op'");
            }
            else
            { // I don't even want to know what you did to get here
                return $this->sdk_trigger("an unexpected error occured");
            }
           
            if ($index == strlen($expr))
            {
                if (in_array($op, $ops))
                { // did we end with an operator? bad.
                    return $this->sdk_trigger("operator '$op' lacks operand");
                }
                else
                    break;
            }
           
            while (substr($expr, $index, 1) == ' ')
            { // step the index past whitespace (pretty much turns whitespace
                $index++;                             // into implicit multiplication if no operator is there)
            }
       
        }
       
        while (($op = $stack->sdk_pop())!=null)
        { // pop everything off the stack and push onto output
            if ($op == '(') return $this->sdk_trigger("expecting ')'"); // if there are (s on the stack, ()s were unbalanced
            $output[] = $op;
        }
       
        return $output;
    }
   
    function sdk_device($val)
    {
        $valtab = getValue($val);
       
        if (isset($valtab['value']))
            return $valtab['value'];
        else
            return 0;
    }

    // evaluate postfix notation
    function sdk_pfx($tokens, $vars = array())
    {
       
        if ($tokens == false) return false;
   
        $stack = new sdk_EvalMathStack;
       
        foreach ($tokens as $token)
        { // nice and easy
            // if the token is a binary operator, pop two values off the stack, do the operation, and push the result back on
            if (in_array($token, array('+', '-', '*', '/', '^')))
            {
                if (($op2 = $stack->sdk_pop())===null) return $this->sdk_trigger("internal error 2");
                if (($op1 = $stack->sdk_pop())===null) return $this->sdk_trigger("internal error 3");
                switch ($token) {
                    case '+':
                        $stack->sdk_push($op1+$op2); break;
                    case '-':
                        $stack->sdk_push($op1-$op2); break;
                    case '*':
                        $stack->sdk_push($op1*$op2); break;
                    case '/':
                        if ($op2 == 0) return $this->sdk_trigger("division by zero");
                        $stack->sdk_push($op1/$op2); break;
                    case '^':
                        $stack->sdk_push(pow($op1, $op2)); break;
                }
            // if the token is a unary operator, pop one value off the stack, do the operation, and push it back on
            }
            else
            if ($token == "_")
            {
                $stack->sdk_push(-1*$stack->sdk_pop());
            // if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
            }
            else
            if (preg_match("/^([a-z]\w*)\($/", $token, $matches))
            { // it's a function!
                $fnn = $matches[1];
                if (in_array($fnn, $this->fb)) { // built-in function:
                    if (($op1 = $stack->sdk_pop())===null) return $this->sdk_trigger("internal error 4");
                    $fnn = preg_replace("/^arc/", "a", $fnn); // for the 'arc' trig synonyms

                    switch ($fnn)
                    {
                    case "device" :
                      $stack->sdk_push($this->sdk_device($op1));
                      break;
                    case "abs":
                      $stack->sdk_push(abs($op1));
                      break;
                    case "acos":
                      $stack->sdk_push(acos($op1));
                      break;
                    case "asin":
                      $stack->sdk_push(asin($op1));
                      break;
                    case "atan":
                      $stack->sdk_push(atan($op1));
                      break;
                    case "cos":
                      $stack->sdk_push(cos($op1));
                      break;
                    case "deg2rad":
                      $stack->sdk_push(deg2rad($op1));
                      break;
                    case "exp":
                      $stack->sdk_push(exp($op1));
                      break;
                    case "floor":
                      $stack->sdk_push(floor($op1));
                      break;
                    case "log":
                      $stack->sdk_push(log($op1));
                      break;
                    case "pow":
                      $stack->sdk_push(pow($op1));
                      break;
                    case "rad2deg":
                      $stack->sdk_push(rad2deg($op1));
                      break;
                    case "rand":
                      $stack->sdk_push(rand($op1));
                      break;
                    case "round":
                      $stack->sdk_push(round($op1));
                      break;
                    case "sin":
                      $stack->sdk_push(sin($op1));
                      break;
                    case "sqrt":
                      $stack->sdk_push(sqrt($op1));
                      break;
                    }

                }
                else
                if (array_key_exists($fnn, $this->f))
                { // user function
                    // get args
                    $args = array();
                    for ($i = count($this->f[$fnn]['args'])-1; $i >= 0; $i--)
                    {
                        if (($args[$this->f[$fnn]['args'][$i]] = $stack->sdk_pop())===null) return $this->sdk_trigger("internal error 5");
                    }
                   
                    $stack->sdk_push($this->sdk_pfx($this->f[$fnn]['func'], $args)); // yay... recursion!!!!
                }
            // if the token is a number or variable, push it on the stack
            }
            else
            {
                if (is_numeric($token))
                {
                    $stack->sdk_push($token);
                }
                else
                if (array_key_exists($token, $this->v))
                {
                    $stack->sdk_push($this->v[$token]);
                }
                else
                if (array_key_exists($token, $vars))
                {
                    $stack->sdk_push($vars[$token]);
                }
                else
                {
                    return $this->sdk_trigger("undefined variable '$token'");
                }
            }
        }

        // when we're out of tokens, the stack should have a single element, the final result
        if ($stack->count != 1) return $this->sdk_trigger("internal error 6");
       
        return $stack->sdk_pop();
    }
   
    // trigger an error, but nicely, if need be
    function sdk_trigger($msg)
    {
        $this->last_error = $msg;
       
        if (!$this->suppress_errors) echo $msg;
        return false;
    }
}

class sdk_EvalMathStack
{

    var $stack = array();
    var $count = 0;
   
    function sdk_push($val)
    {
        $this->stack[$this->count] = $val;
        $this->count++;
    }
   
    function sdk_pop()
    {
        if ($this->count > 0)
        {
            $this->count--;
            return $this->stack[$this->count];
        }
        return null;
    }
   
    function sdk_last($n=1)
    {
        if (isset($this->stack[$this->count-$n]))
        {
          return $this->stack[$this->count-$n];
        }
        return;
    }


?>

eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 731
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar Gyvr » 25 Juil 2022 19:58

Bonsoir et merci.
réponse super rapide. Je vais essayer et dire ce que je constate après plusieurs jours de fonctionnement.
Gerard.
Gyvr
 
Messages : 100
Inscription : 08 Déc 2018

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar Gyvr » 26 Juil 2022 07:18

Bonjour,

En utilisant la version de calculateur fourni hier soir, et renomé New_Calculator.php, il y a du bon, ... et du moins bon.

Le bon: le calcul s'exécute correctement tant que j'utilise des valeurs numériques dans la formule -genre 15*(1-1) - J'ai testé plusieurs formules, y compris une division par zéro, et j'obtiens le résultat escompté.


Par contre si je mets device(device_API) dans VAR1 (le device définissant une liste de valeur), donc même pas de calcul, et que j'utilise la fonction de test du calculateur j'obtiens:

<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /mnt/flash/puch/www/script/user/20164/New_Calculator.php:1) in <b>/mnt/flash/puch/www/script/script_include.php</b> on line <b>74</b><br />
<result>0</result>

Résultat XPath :
ERREUR: Valeur lue vide

le résultat est exact par rapport à la valeur du device, mais précédé d'un warning ce qui am1ene à l'erreur valeur lue vide. J'ai essayé quelques formules de calcul simples le résultat est exact, mais toujours ce satané warning.

Des idées pour résoudre ca?
A priori la box est à jour (Version logicielle de la box
Votre box est à jour).

Merci
Gérard
Gyvr
 
Messages : 100
Inscription : 08 Déc 2018

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar opa95 » 26 Juil 2022 08:39

Bonjour gyvr
Je suis désolé, mais je ne rencontre pas ton erreur, même quand j'utilise une formule avec "device(id_device)" et même si le id_device n'existe pas.
Par contre, ça fonctionne toujours chez moi si je mets en commentaire la ligne 14 : c'est elle qui devrait initier le warning.
Code : Tout sélectionner
//sdk_header('text/xml');

Sans l'instruction sdk_header, chez moi ça fonctionne.
Teste pour voir
:)
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 731
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar lougarou60 » 26 Juil 2022 09:27

Bonjour à tous
J’utilise ce calculateur, et j’ai moi aussi été confronté à ce problème du zéro
Bien sur si notre ami opa95 résout l’affaire de manière « propre » c’est l’idéal et merci d’avance à lui car je serai preneur de sa solution
Sinon le contournement que j’ai utilisé est du genre : (device(xxx)-0.000001)-device(yyy)
C’est moins « propre » mais ça reste valide si xxx = yyy ; avec comme résultat : « presque » zéro
lougarou60
 
Messages : 257
Inscription : 07 Déc 2018

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar opa95 » 26 Juil 2022 10:00

Bonjour
Pour moi, la version mise en ligne plus haut devrait fonctionner, mais elle doit être validée par les divers utilisateurs.
Ensuite, il faudrait que l'auteur du script (Mickael) (ou la Team) dont je n'ai pas les coordonnées exactes mette sur le store la version correcte.
La nuance entre le == et le === n'est pas toujours bien utilisée, mais à part cela c'est un très beau script qui est bien pratique et avec lequel je n'avais pas rencontré de problème : merci Mickael
:)
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 731
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar Gyvr » 27 Juil 2022 05:39

Bonjour,
en commentant la ligne 14 ca marche chez moi. J'ai pu remettre ma formule d'origine. Vive les === à la place des ==.

C'est une belle amélioration du déjà très bon plugin.

En espérant que l'auteur soit toujours sur le forum et nous fasse une mise à jour.

Merci encore à opa95
Gérard
Gyvr
 
Messages : 100
Inscription : 08 Déc 2018

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar opa95 » 27 Juil 2022 09:43

Bonjour Gvyr
Je suis content que ça marche maintenant chez toi.
Je ne comprend pas pourquoi tu avais cette erreur liée au "sdk_header('text/xml');" que je n'ai pas.
J'ai pu la reproduire en rajoutant un echo et obtenir un résultat correct en empêchant la notification.
En fait je pense qu'il serait donc plus correct pour toi de ne pas mettre la ligne 14 en commentaire
"//sdk_header('text/xml');" mais plutôt d'empêcher la notification d'erreur en mettant
"@sdk_header('text/xml');" (si ça marche chez toi).
Sinon, quand je peux, j'aime bien tenter de résoudre ce genre de problèmes, ça m'occupe (pas trop longtemps dans ce cas précis) et ça me ramène 10 ans en arrière avec mes élèves ingénieurs.
Bonnes vacances à tous
:)
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 731
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar Gyvr » 27 Juil 2022 18:36

OK, ca marche avec le "@" à la place du commentaire.
Merci
Gerard
Gyvr
 
Messages : 100
Inscription : 08 Déc 2018

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar Kepasub » 31 Oct 2022 15:59

Je m'excuse pour mon mauvais français. Je dois utiliser Google traduction.
De là, mes félicitations à l'auteur, pour ce merveilleux plugin qu'est la calculatrice mathématique.
La première utilisation était de remplacer un capteur de lumière, qui avait une résolution si élevée qu'il faisait que les stores ne s'arrêtaient pas.
En utilisant l'expression suivante dans la variable [VAR1] : "round(device(API Code) /1000)", j'ai pu réduire la résolution et éliminer le problème
Nous avons vérifié qu'il fonctionne très bien, avec de nombreux opérateurs, en plus de +, -, X ou /.
En essayant de créer une cinquième racine, nous avons vu que l'opérateur "POW" ne fonctionnait pas pour nous, mais avec beaucoup de persévérance, nous avons pu vérifier que l'opérateur "^" fonctionnait.
Exemples:
5^2= 25
16807^(1/5) = 7
16807^0.2 = 7
device(API code)^(1/3) serait la racine cubique de la valeur de l'appareil

J'espère que l'expérience pourra être utile à quelqu'un.

Et encore une fois, un grand merci à l'auteur du plugin. Parce qu'il y a des choses qui semblent très simples, mais qui résolvent nos vies (Pensez par exemple à la roue).

Cordialement : Kepa
Dernière édition par Kepasub le 03 Nov 2022 21:54, édité 1 fois.
Kepasub
 
Messages : 55
Inscription : 29 Oct 2022
Localisation : Durango , Vizcaya, Spain

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar opa95 » 01 Nov 2022 18:57

Bonjour Kepa
Les opérations que tu cites fonctionnent aussi.
L'opération ((5*device(2395007)+7)-14)/10 avec device(2395007) =814 donne dans la fenêtre de test
((5*device(2395007)%2b7)-14)/10
résultat affiché : 406.3
((5*814+7)-14)/10 = ((4070+7)-14)/10 =((4077)-14)/10 =(4063)/10 =406.3
:)
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 731
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar Kepasub » 03 Nov 2022 22:04

Je suis désolé opa95.
Merci pour ton commentaire.
Je pense que le problème est dans mon mauvais français.
J'essaie juste de dire qu'avec les opérateurs classiques (+,-,X et /) la calculatrice fonctionne très bien, mais qu'elle marche aussi très bien avec d'autres opérateurs un peu plus complexes. Et tous les utilisateurs ne le savent pas.
Si j'ai commis une erreur par mon expression inappropriée, je m'excuse auprès de tous les participants.

Cordialement : Kepa
Kepasub
 
Messages : 55
Inscription : 29 Oct 2022
Localisation : Durango , Vizcaya, Spain

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar Kepasub » 12 Juil 2023 09:00

opa95 a écrit:Bonjour
Pour moi, la version mise en ligne plus haut devrait fonctionner, mais elle doit être validée par les divers utilisateurs.
Ensuite, il faudrait que l'auteur du script (Mickael) (ou la Team) dont je n'ai pas les coordonnées exactes mette sur le store la version correcte.
La nuance entre le == et le === n'est pas toujours bien utilisée, mais à part cela c'est un très beau script qui est bien pratique et avec lequel je n'avais pas rencontré de problème : merci Mickael
:)

J'ai eu le même problème d'erreur due à un zéro dans le calcul et il a été résolu avec la version proposée ici. Je le commente, au cas où cela aiderait à contribuer à la validation de la proposition. Merci opa95 pour vos collaborations. Et à l'auteur du script (Mickael), pour la calculatrice, que je trouve phénoménale.
Kepasub
 
Messages : 55
Inscription : 29 Oct 2022
Localisation : Durango , Vizcaya, Spain

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar opa95 » 12 Juil 2023 13:54

Bonjour à tous les utilisateurs
Kepasub a écrit:J'ai eu le même problème d'erreur due à un zéro dans le calcul et il a été résolu avec la version proposée ici. Je le commente, au cas où cela aiderait à contribuer à la validation de la proposition. Merci opa95 pour vos collaborations. Et à l'auteur du script (Mickael), pour la calculatrice, que je trouve phénoménale.

J'ai une version en cours de finalisation qui reprend la version initiale (adaptée) de la bibliothèque et l'adaptation de (Mickael) à l'eedomus.
- Utilisation d'opérateurs supplémentaires
- Fonctions plus nombreuses : mathématiques, logiques, temporelles et sur les chaînes pour le formatage
- Fonctions de récupération des infos des devices (eedomus)
- Structures de décision : if, case, seuils
- Création de variables et fonctions (temporaires ou permanentes)
- Opérations de filtrage ou lissage sur plusieurs capteurs ou sur plusieurs valeurs successives d'un capteur (stockées en local)
Encore un peu de patience :)
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 731
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: [store] bug plugin Calculator / calculateur mathématique

Messagepar Kepasub » 13 Juil 2023 09:02

Merci opa95 . Il va falloir être patient, mais j'ai déjà hâte de tester cette nouvelle version.
Merci encore :
kepa
Kepasub
 
Messages : 55
Inscription : 29 Oct 2022
Localisation : Durango , Vizcaya, Spain


Retour vers Scripts & Périphériques du store

Qui est en ligne ?

Utilisateurs parcourant ce forum : Aucun utilisateur inscrit et 40 invité(s)