How to optimize this code? [SOLVED]

  • This is the large way, It is works ok, but isn't ideal code...almost the same 80 times!!!

    if(videotime GE (tiempos[ruta1].t0)
    AND videotime LE (tiempos[ruta1].t1),
    aproxima(videotime,tiempos[ruta1].t0,tiempos[ruta1].t1,0,1);
    );

    if(videotime GE (tiempos[ruta1].t1)
    AND videotime LE (tiempos[ruta1].t2),
    aproxima(videotime,tiempos[ruta1].t1,tiempos[ruta1].t2,1,2);
    );

    if(videotime GE (tiempos[ruta1].t2)
    AND videotime LE (tiempos[ruta1].t3),
    aproxima(videotime,tiempos[ruta1].t2,tiempos[ruta1].t3,2,3);
    );

    --------
    I want anything as:

    for (set i,0), i LT 84, inc(i)

    if(videotime GE (tiempos[ruta1].t(i) )... etc

    ---------
    Note:
    My original array is:
    <tiempos name="ruta1"
    t0="0" t1="10" t2="18" t3="26" t4="35" t5="44" t6="53" t7="63"...t84="793"
    />
    --------

    Any idea, thanks!!

  • Hi

    Try this:

    Code
    <action name="for84" >  
     for(set(i,0),i LT 84,inc(i),    
      copy(t1, i);    
      calc(t2, t1+1);    
      if(videotime GE calc('tiempos[ruta1].t'+t1) AND videotime LE calc('tiempos[ruta1].t'+t2),      
       aproxima(videotime,calc('tiempos[ruta1].t'+t1),calc('tiempos[ruta1].t'+t2),get(t1),get(t2));    
      );  
     );
    </action>


    Best regards
    Piotr

  • Thanks Piotr for your help, very interesting, CALC is new, from 1.19 and is the good way. thanks for teach me this great function, and your example.

    But there is a problem in the code:

    if check by trace... calc('tiempos[ruta1].t'+t1) ... It is return a correct result from array, but fails in the comparison function GE ... LE as the result was a string, no a number.

    Any idea?

    Thanks very much,
    Greets,
    Fdo.

  • Hi

    I do not know your entire code so I can only guess...

    Maybe use a GET function in this code *question*

    if(videotime GE calc('get(tiempos[ruta1].t'+t1+')') AND videotime LE calc('get(tiempos[ruta1].t'+t2+')'),
    aproxima(videotime,calc('get(tiempos[ruta1].t'+t1+')'),calc('get(tiempos[ruta1].t'+t2+')'),get(t1),get(t2));
    );


    Best regards
    Piotr

  • Thanks Piotr, but... why to use GET?: The variable get the correct value, the problem is in the comparison. See the example:

    Greets,
    Fdo

  • You must separate the code like this:



    Let me know if this work

    Best regards
    Piotr

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!