Guest User

Untitled

a guest
Aug 4th, 2021
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.16 KB | None | 0 0
  1. {
  2.  
  3.     init {
  4.         xx<-c();
  5.         yy<-c();
  6.         front <-c();
  7.         gearsecs <-c();
  8.         pauses_secs <-0;
  9.         pauses_gear <-0;
  10.         cpt <-0;
  11.     }
  12.  
  13.     # Todo do not know how to check Data contains XDATAs
  14.     #relevant {
  15.     #    Data contains XDATA_UNITS("xdata", "GEARS");
  16.     #}
  17.  
  18.  
  19.     finalise {
  20.  
  21.         # fetch data
  22.         front <- xdata("GEARS", "FRONT");
  23.         gearsecs <- xdata("GEARS", secs);
  24.        
  25.         # detect pauses in activity
  26.         secs <- samples(SECS);
  27.         distance <- samples(DISTANCE);
  28.         # check same values
  29.         while(cpt < length(distance)){
  30.           # Same distance but secs > autopause time (10sc), flag as an activity pause
  31.           if(distance[cpt] = distance[cpt+1] && secs[cpt] +10 < secs[cpt+1]){
  32.             append(pauses_secs,secs[cpt],length(pauses_secs));
  33.             append(pauses_secs,secs[cpt+1],length(pauses_secs));
  34.             append(pauses_gear,255,length(pauses_gear));
  35.             append(pauses_gear,255,length(pauses_gear));
  36.           }
  37.           cpt <- cpt + 1;
  38.         }
  39.         # add pauses with fake gear to be taken into account in the calculation of the duration
  40.         append(gearsecs,pauses_secs,length(gearsecs));
  41.         append(front,pauses_gear,length(front));
  42.  
  43.         # sort by pauses_secs
  44.         multisort(ascend, gearsecs, front);
  45.  
  46.         # transform secs to duration
  47.         gearsecs2 <- gearsecs;
  48.         append(gearsecs2,gearsecs[length(gearsecs)-1],length(gearsecs2)); # repeat last at the end to shift indexes
  49.         remove(gearsecs2, 0,1); # remove first to have same length
  50.  
  51.         duration <- gearsecs2 - gearsecs;
  52.  
  53.         # remove abnormal values (ex: 255 or 0)
  54.         duration <- sapply(duration,front[i]=255 || front[i]=0 ? 99999 : x )[x<>99999];
  55.         front <- sapply(front,front[i]=255 || front[i]=0 ? 99999 : x )[x<>99999];  
  56.  
  57.         # sort
  58.         multisort(ascend, front, duration);
  59.  
  60.         yy <- aggregate(duration, front, sum);
  61.         xx <- uniq(front);
  62.         #annotate(label,"xx:",xx);
  63.         #annotate(label,"yy:",yy);
  64.  
  65.         multisort(descend,yy,xx);
  66.     }  
  67.  
  68.     x { xx; }
  69.     y { yy/3600; }
  70.  
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment