Guest User

Untitled

a guest
Aug 3rd, 2021
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.62 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:",min(front));
  43.  
  44.         # sort
  45.         multisort(ascend, rear, duration);
  46.        
  47.         # keep only rear when front is min
  48.         rear <- sapply(rear,front[i]=min(front) ? x : 0 )[x<>0];
  49.         duration <- sapply(duration,front[i]=min(front) ? x : 0 )[x<>0];
  50.  
  51.         yy <- aggregate(duration, rear, sum);
  52.         #annotate(label,"yy:",yy);
  53.         xx <- uniq(rear);
  54.  
  55.         multisort(descend,yy,xx);
  56.     }  
  57.  
  58.     x { xx; }
  59.     y { yy/3600; }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment