Guest User

Untitled

a guest
Aug 3rd, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.72 KB | None | 0 0
  1. {
  2.  
  3.     init {
  4.         xx<-c();
  5.         yy<-c();
  6.         front <-c();
  7.         gearsecs <-c();
  8.     }
  9.  
  10.     #relevant {
  11.     #    Data contains XDATA_UNITS("xdata", "GEARS");
  12.     #}
  13.  
  14.  
  15.     finalise {
  16.  
  17.         # fetch data
  18.         front <- xdata("GEARS", "FRONT");
  19.         rear <- xdata("GEARS", "REAR");
  20.         gearsecs <- xdata("GEARS", secs);
  21.  
  22.         #duration  1 5 6 8
  23.         #durationtmp 0 1 5 6 8
  24.         # secs to duration
  25.         durationtmp <- gearsecs;
  26.         append(durationtmp,0,0); # add 0 to shift indexes
  27.         remove(durationtmp, length(durationtmp) -1, 1); # remove last to have same length
  28.  
  29.         duration <- gearsecs - durationtmp;
  30.  
  31.         # remove abnormal values (ex: 255 or 0)
  32.         first <- head(duration,1);
  33.         duration <- sapply(gearsecs,front[i]<200 ? x : 0 )[x<>0];
  34.         #duration <- sapply(duration,front[i]<200 ? x : 0 );
  35.         #annotate(label,"max:",max(duration));
  36.         if(gearsecs[0]=255){
  37.             append(duration,first,0);
  38.         }
  39.         rear <- sapply(rear,front[i]<200 ? x : 0 )[x<>0];
  40.         front <- sapply(front,front[i]<200 ? x : 0 )[x<>0];  
  41.  
  42.         annotate(label,"Front:",max(front));
  43.  
  44.         # sort
  45.         #multisort(ascend, rear, front, duration);
  46.         multisort(ascend, rear, duration);
  47.        
  48.         # keep only rear when front is max
  49.         rear <- sapply(rear,front[i]=max(front) ? x : 0 )[x<>0];
  50.         duration <- sapply(duration,front[i]=max(front) ? x : 0 )[x<>0];
  51.  
  52.         yy <- aggregate(duration, rear, sum);
  53.         #annotate(label,"yy:",length(yy));
  54.         xx <- uniq(rear);
  55.         #annotate(label,"xx:",length(xx));
  56.  
  57.         multisort(descend,yy,xx);
  58.     }  
  59.  
  60.     x { xx; }
  61.     y { yy/3600; }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment