Sie sind nicht angemeldet.

publicitarios360

Fortgeschrittener

  • »publicitarios360« ist der Autor dieses Themas

Beiträge: 330

Wohnort: Habana, Cuba

Beruf: Architect, Photographer.

  • Nachricht senden

1

Mittwoch, 9. August 2017, 00:35

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!!

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »publicitarios360« (10. August 2017, 19:08)


Beiträge: 1 117

Wohnort: Poland, Europe

Beruf: krpano developer : virtual tours : the cms4vr owner

  • Nachricht senden

2

Mittwoch, 9. August 2017, 01:28

Hi

Try this:

Quellcode

1
2
3
4
5
6
7
8
9
<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
Your own professional, online cloud tool for creating virtual tours - www.cms4vr.com

facebook page :: youtube :: wiki.cms4vr.com

cms4vr team *thumbsup*

publicitarios360

Fortgeschrittener

  • »publicitarios360« ist der Autor dieses Themas

Beiträge: 330

Wohnort: Habana, Cuba

Beruf: Architect, Photographer.

  • Nachricht senden

3

Donnerstag, 10. August 2017, 03:12

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.

Beiträge: 1 117

Wohnort: Poland, Europe

Beruf: krpano developer : virtual tours : the cms4vr owner

  • Nachricht senden

4

Donnerstag, 10. August 2017, 12:05

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
Your own professional, online cloud tool for creating virtual tours - www.cms4vr.com

facebook page :: youtube :: wiki.cms4vr.com

cms4vr team *thumbsup*

publicitarios360

Fortgeschrittener

  • »publicitarios360« ist der Autor dieses Themas

Beiträge: 330

Wohnort: Habana, Cuba

Beruf: Architect, Photographer.

  • Nachricht senden

5

Donnerstag, 10. August 2017, 16:38

The simple example, check the incorrect result in the trace

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

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<krpano
debugmode="true" onstart="arranque();">

<preview type="grid(cube,128,128,512,0xCCCCCC,0xF6F6F6,0x999999);" />

<events onkeydown="keydown()"/>

<layer name="help" 
type="text"
css="text-align:left; font-size:24px;"
align="centertop"
html="
Press key 1: To Play the count[br]
Press key 2: To Pause the count[br]
Press key 3: To Restart the count[br]
Press key 4: To Compare the current count with:[br]
0 , 2 , 3 , 7 , 9 and 10 
"
/>

<action name="arranque">
set(videotime,0); 
</action>

<action name="keydown">

<!-- key 1: -->
if(keycode == 49, 
showlog();
trace('PLAY the count...');
incrementa_auto(); 
);

<!-- key 2: -->
if(keycode == 50,
trace('PAUSE the count...');
parar();
);

<!-- key 3: -->
if(keycode == 51,
trace('RESTART the count...');
set(videotime,0);
incrementa_auto();
);

<!-- key 4: -->
if(keycode == 52,
trace('CHECKING the array...');
for5();
);

</action>

<tiempos
name="ruta1"
t0="0" t1="2" t2="3" t3="7" t4="9" t5="10" 
/>

<action name="incrementa">
inc(videotime);
trace(get(videotime));
</action>

<action name="incrementa_auto">
delayedcall(conteo,1.0, incrementa();incrementa_auto(); );
</action>

<action name="parar">
stopdelayedcall(conteo);
</action>

<action name="for5" >  
 for(set(i,0),i LT 5,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),
  
trace('The Count:',videotime,' is greater or equal than ',calc('tiempos[ruta1].t'+t1),' and lower or equal than ',calc('tiempos[ruta1].t'+t2)); 
parar();,

trace('The Count:',videotime,' is NOT greater or equal than ',calc('tiempos[ruta1].t'+t1),' and is NOT lower or equal than ',calc('tiempos[ruta1].t'+t2)); 
parar();
    
  );  
 );
</action>  

</krpano>


Greets,
Fdo

Beiträge: 1 117

Wohnort: Poland, Europe

Beruf: krpano developer : virtual tours : the cms4vr owner

  • Nachricht senden

6

Donnerstag, 10. August 2017, 17:36

You must separate the code like this:


Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<action name="for5">
 for(set(i,0),i LT 5,inc(i), 
   copy(t1, i); 
   calc(t2, t1+1);
   check_result(get(videotime),calc('tiempos[ruta1].t'+t1),calc('tiempos[ruta1].t'+t2));
 );
</action>

<action name="check_result">
 if((%1 GE %2) AND (%1 LE %3),
   trace('BETWEEN: The Count: %1 is greater or equal than ',get(%2),' AND lower or equal than ',get(%3)); 
   parar();
 ,
   trace('BEYOND: The Count: %1 is NOT greater or equal than ',get(%2),' AND is NOT lower or equal than ',get(%3)); 
   parar();
 ); 
</action>



Let me know if this work

Best regards
Piotr
Your own professional, online cloud tool for creating virtual tours - www.cms4vr.com

facebook page :: youtube :: wiki.cms4vr.com

cms4vr team *thumbsup*

publicitarios360

Fortgeschrittener

  • »publicitarios360« ist der Autor dieses Themas

Beiträge: 330

Wohnort: Habana, Cuba

Beruf: Architect, Photographer.

  • Nachricht senden

7

Donnerstag, 10. August 2017, 19:00

Solved by Piotr

It works!!!!

The code is great, the ¨BEYOND¨ part, complete the example.

Thanks very much Piotr for your fast and precise help,

Greets,

Fdo

Beiträge: 1 117

Wohnort: Poland, Europe

Beruf: krpano developer : virtual tours : the cms4vr owner

  • Nachricht senden

8

Donnerstag, 10. August 2017, 19:51

Hi,

This was an interesting issue, interesting and worth solution. *thumbsup*


Regards and good luck in coding *thumbup*

Piotr
Your own professional, online cloud tool for creating virtual tours - www.cms4vr.com

facebook page :: youtube :: wiki.cms4vr.com

cms4vr team *thumbsup*