Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- init {
- xx<-c();
- yy<-c();
- front <-c();
- gearsecs <-c();
- pauses_secs <-0;
- pauses_gear <-0;
- cpt <-0;
- }
- # Todo do not know how to check Data contains XDATAs
- #relevant {
- # Data contains XDATA_UNITS("xdata", "GEARS");
- #}
- finalise {
- # fetch data
- front <- xdata("GEARS", "FRONT");
- gearsecs <- xdata("GEARS", secs);
- # detect pauses in activity
- secs <- samples(SECS);
- distance <- samples(DISTANCE);
- # check same values
- while(cpt < length(distance)){
- # Same distance but secs > autopause time (10sc), flag as an activity pause
- if(distance[cpt] = distance[cpt+1] && secs[cpt] +10 < secs[cpt+1]){
- append(pauses_secs,secs[cpt],length(pauses_secs));
- append(pauses_secs,secs[cpt+1],length(pauses_secs));
- append(pauses_gear,255,length(pauses_gear));
- append(pauses_gear,255,length(pauses_gear));
- }
- cpt <- cpt + 1;
- }
- # add pauses with fake gear to be taken into account in the calculation of the duration
- append(gearsecs,pauses_secs,length(gearsecs));
- append(front,pauses_gear,length(front));
- # sort by pauses_secs
- multisort(ascend, gearsecs, front);
- # transform secs to duration
- gearsecs2 <- gearsecs;
- append(gearsecs2,gearsecs[length(gearsecs)-1],length(gearsecs2)); # repeat last at the end to shift indexes
- remove(gearsecs2, 0,1); # remove first to have same length
- duration <- gearsecs2 - gearsecs;
- # remove abnormal values (ex: 255 or 0)
- duration <- sapply(duration,front[i]=255 || front[i]=0 ? 99999 : x )[x<>99999];
- front <- sapply(front,front[i]=255 || front[i]=0 ? 99999 : x )[x<>99999];
- # sort
- multisort(ascend, front, duration);
- yy <- aggregate(duration, front, sum);
- xx <- uniq(front);
- #annotate(label,"xx:",xx);
- #annotate(label,"yy:",yy);
- multisort(descend,yy,xx);
- }
- x { xx; }
- y { yy/3600; }
- }
Advertisement
Add Comment
Please, Sign In to add comment