Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- init {
- xx<-c();
- yy<-c();
- front <-c();
- gearsecs <-c();
- }
- #relevant {
- # Data contains XDATA_UNITS("xdata", "GEARS");
- #}
- finalise {
- # fetch data
- front <- xdata("GEARS", "FRONT");
- rear <- xdata("GEARS", "REAR");
- gearsecs <- xdata("GEARS", secs);
- #duration 1 5 6 8
- #durationtmp 0 1 5 6 8
- # secs to duration
- durationtmp <- gearsecs;
- append(durationtmp,0,0); # add 0 to shift indexes
- remove(durationtmp, length(durationtmp) -1, 1); # remove last to have same length
- duration <- gearsecs - durationtmp;
- # remove abnormal values (ex: 255 or 0)
- first <- head(duration,1);
- duration <- sapply(gearsecs,front[i]<200 ? x : 0 )[x<>0];
- #duration <- sapply(duration,front[i]<200 ? x : 0 );
- #annotate(label,"max:",max(duration));
- if(gearsecs[0]=255){
- append(duration,first,0);
- }
- rear <- sapply(rear,front[i]<200 ? x : 0 )[x<>0];
- front <- sapply(front,front[i]<200 ? x : 0 )[x<>0];
- annotate(label,"Front:",max(front));
- # sort
- #multisort(ascend, rear, front, duration);
- multisort(ascend, rear, duration);
- # keep only rear when front is max
- rear <- sapply(rear,front[i]=max(front) ? x : 0 )[x<>0];
- duration <- sapply(duration,front[i]=max(front) ? x : 0 )[x<>0];
- yy <- aggregate(duration, rear, sum);
- #annotate(label,"yy:",length(yy));
- xx <- uniq(rear);
- #annotate(label,"xx:",length(xx));
- multisort(descend,yy,xx);
- }
- x { xx; }
- y { yy/3600; }
- }
Advertisement
Add Comment
Please, Sign In to add comment