You are not logged in.

publicitarios360

Intermediate

  • "publicitarios360" started this thread

Posts: 330

Location: Habana, Cuba

Occupation: Architect, Photographer.

  • Send private message

1

Wednesday, August 9th 2017, 12:35am

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

This post has been edited 1 times, last edit by "publicitarios360" (Aug 10th 2017, 7:08pm)


spacerywirtualne

Professional

Posts: 1,117

Location: Poland, Europe

Occupation: krpano developer : virtual tours : the cms4vr owner

  • Send private message

2

Wednesday, August 9th 2017, 1:28am

Hi

Try this:

Source code

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

Intermediate

  • "publicitarios360" started this thread

Posts: 330

Location: Habana, Cuba

Occupation: Architect, Photographer.

  • Send private message

3

Thursday, August 10th 2017, 3:12am

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.

spacerywirtualne

Professional

Posts: 1,117

Location: Poland, Europe

Occupation: krpano developer : virtual tours : the cms4vr owner

  • Send private message

4

Thursday, August 10th 2017, 12:05pm

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

Intermediate

  • "publicitarios360" started this thread

Posts: 330

Location: Habana, Cuba

Occupation: Architect, Photographer.

  • Send private message

5

Thursday, August 10th 2017, 4:38pm

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:

Source code

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

spacerywirtualne

Professional

Posts: 1,117

Location: Poland, Europe

Occupation: krpano developer : virtual tours : the cms4vr owner

  • Send private message

6

Thursday, August 10th 2017, 5:36pm

You must separate the code like this:


Source code

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

Intermediate

  • "publicitarios360" started this thread

Posts: 330

Location: Habana, Cuba

Occupation: Architect, Photographer.

  • Send private message

7

Thursday, August 10th 2017, 7:00pm

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

spacerywirtualne

Professional

Posts: 1,117

Location: Poland, Europe

Occupation: krpano developer : virtual tours : the cms4vr owner

  • Send private message

8

Thursday, August 10th 2017, 7:51pm

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*