How to use addEvent method in fMBT

Best Python code snippet using fMBT_python

controllers(tab-timetable).js

Source:controllers(tab-timetable).js Github

copy

Full Screen

1angular.module('timetable.controllers', [])2.controller('TimetableCtrl', function($scope, $state, $http, $filter, $ionicPopup, detailedEventService, eventDateStorageService, editEventService) {3 //var below is used for weekDaysList option4 var resultDate = $filter('date')(eventDateStorageService.getDate(), "yyyy-MM-dd");5 ionic.Platform.ready(function() {6 $http.get('http://unicomhk.net/fyp/www/php/actionTimetable.php?inputDate=' + resultDate + '&action=getData')7 .then(function(response) {8 if (response.data.length > 0) {9 console.log("Data Received");10 $scope.recData = response.data;11 } else {12 $scope.recData = {};13 }14 });15 });16 $scope.datepickerObject = {17 titleLabel: 'Calendar - Select Date', //Optional18 inputDate: eventDateStorageService.getDate(), //Optional19 mondayFirst: false, //Optional20 weekDaysList: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], //Optional21 templateType: 'modal', //Optional can be popup22 showTodayButton: 'true', //Optional23 modalHeaderColor: 'bar-assertive', //Optional24 modalFooterColor: 'bar-assertive', //Optional25 callback: function(val) { //Mandatory26 if (val === undefined || val === 'undefined') {27 } else {28 this.inputDate = val;29 resultDate = $filter('date')(val, "yyyy-MM-dd");30 $http.get('http://unicomhk.net/fyp/www/php/actionTimetable.php?inputDate=' + resultDate + '&action=getData')31 .then(function(response) {32 if (response.data.length > 0) {33 console.log("Data Received");34 $scope.recData = response.data;35 } else {36 $scope.recData = {};37 }38 });39 };40 },41 dateFormat: 'YYYY-MM-DD', //Optional42 };43 $scope.deleteEventTypeList = [44 {45 text: "Delete all occurences",46 value: "deleteAll"47 },48 {49 text: "Delete this only event entry",50 value: "deleteSingle"51 }];52 $scope.deleteEventType = {type: "deleteAll"};53 $scope.deleteEvent = function(EventID, EventRepeatID, event) {54 var choices = $ionicPopup.show({55 title: 'Delete',56 template: '<ion-radio ng-repeat="type in deleteEventTypeList" ng-model="deleteEventType.type" ng-value="type.value">{{ type.text }}</ion-radio>',57 scope: $scope,58 buttons: [59 {60 text: 'Cancel'61 },62 {63 text: 'Delete',64 type: 'button-assertive',65 onTap: function() {66 console.log(EventID, EventRepeatID, $scope.deleteEventType.type);67 $http.get('http://unicomhk.net/fyp/www/php/actionTimetable.php?action=deleteEvent&eventID=' + EventID + '&deleteEventType=' + $scope.deleteEventType.type + '&deleteEventRepeatID=' + EventRepeatID);68 var index = $scope.recData.indexOf(event);69 $scope.recData.splice(index, 1); 70 return $scope.deleteEventType.type;71 }72 }]73 })74 choices.then(function(result) {75 console.log($scope.deleteEventType.type, result);76 })77 }78 $scope.editEvent = function(event) {79 editEventService.data(event);80 //$scope.addEvent = editEventService.get();81 $scope.addEvent.isEditEventCtrl = 1;82 $state.go('editEvent');83 }84 $scope.showDetailedEvent = function(event, date) {85 detailedEventService.pass(event);86 eventDateStorageService.date(new Date(date));87 $state.go('showDetailedEvent');88 };89 $scope.addEvent = function(date) {90 eventDateStorageService.date(new Date(date));91 $state.go('addEvent');92 };93})94.controller('ShowDetailsCtrl', function($scope, $state, detailedEventService, $rootScope, $ionicPopup, $http, editEventService) {95 ionic.Platform.ready(function() {96 $scope.data = detailedEventService.all();97 })98 $rootScope.$on('$stateChangeSuccess', function(event, next) {99 $scope.data = detailedEventService.all();100 })101 $scope.backToPrevPage = function() {102 $state.go('tab.timetable');103 };104 $scope.deleteEventTypeList = [105 {106 text: "Delete all occurences",107 value: "deleteAll"108 },109 {110 text: "Delete this only event entry",111 value: "deleteSingle"112 }];113 $scope.repeatListChoices = [{114 text: "None",115 value: "none"116 }, {117 text: "Everyday",118 value: "daily"119 }, {120 text: "Every Week",121 value: "weekly"122 }, {123 text: "Every 2 Weeks",124 value: "biweekly"125 }, {126 text: "Every Month",127 value: "monthly"128 }, {129 text: "Every Year",130 value: "yearly"131 }];132 $scope.data.repeatTypeText = function(val) {133 for (var i = 0; i < $scope.repeatListChoices.length; i++) {134 if ($scope.repeatListChoices[i].value == val) {135 return $scope.repeatListChoices[i].text;136 }137 }138 }139 $scope.deleteEventType = {type: "deleteAll"};140 $scope.deleteEvent = function(EventID, EventRepeatID, event) {141 var choices = $ionicPopup.show({142 title: 'Delete',143 template: '<ion-radio ng-repeat="type in deleteEventTypeList" ng-model="deleteEventType.type" ng-value="type.value"></ion-radio>',144 scope: $scope,145 buttons: [146 {147 text: 'Cancel'148 },149 {150 text: 'Delete',151 type: 'button-assertive',152 onTap: function() {153 console.log(EventID, EventRepeatID, $scope.deleteEventType.type);154 $http.get('http://unicomhk.net/fyp/www/php/actionTimetable.php?action=deleteEvent&eventID=' + EventID + '&deleteEventType=' + $scope.deleteEventType.type + '&deleteEventRepeatID=' + EventRepeatID);155 $state.go('tab.timetable');156 return $scope.deleteEventType.type;157 }158 }]159 })160 choices.then(function(result) {161 console.log($scope.deleteEventType.type, result);162 })163 }164 $scope.editEvent = function() {165 editEventService.data($scope.data);166 //$scope.addEvent = editEventService.get();167 $state.go('editEvent');168 }169})170.controller('AddEventCtrl', function($scope, $state, $http, $ionicPopup, $filter, eventDateStorageService, editEventService, $sanitize) {171 if ($scope.isEditEventCtrl == 1) {172 $scope.addEvent = editEventService.get();173 ionic.Platform.ready(function() {174 $scope.addEvent = editEventService.get();175 });176 $rootScope.$on('$stateChangeSuccess', function(event, next) {177 $scope.addEvent = editEventService.get();178 });179 }180 181 $scope.timetable = {182 from: $filter('date')(moment("10:30 am"), 'shortTime', "+0800"),183 to: $filter('date')(moment("10:30 am"), 'shortTime', "+0800"),184 // to: new Date(moment("10:30 am", "hh:mm a")),185 };186 $scope.$on('$destroy', function() {187 console.log('destroy');188 });189 $scope.addEvent = {190 fromTime: new Date(moment("08:30 am", "hh:mm a")),191 toTime: new Date(moment("10:30 am", "hh:mm a")),192 repeatType: "none",193 fromDate: $filter('date')(new Date(), "yyyy-MM-dd"),194 toDate: $filter('date')(new Date(), "yyyy-MM-dd"),195 isPersonal: 0,196 isAllDay: 0197 };198 $scope.fromDatePickerObject = {199 titleLabel: 'Calendar - Select Start Date', //Optional200 inputDate: new Date(), //Optional201 mondayFirst: false, //Optional202 weekDaysList: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], //Optional203 templateType: 'popup', //Optional can be popup204 showTodayButton: 'true', //Optional205 modalHeaderColor: 'bar-assertive', //Optional206 modalFooterColor: 'bar-assertive', //Optional207 callback: function(val) { //Mandatory208 if (val === undefined || val === 'undefined') {209 } else {210 this.inputDate = val;211 $scope.toDatePickerObject.inputDate = val;212 $scope.addEvent.fromDate = $filter('date')(val, "yyyy-MM-dd");213 };214 },215 dateFormat: 'YYYY-MM-DD', //Optional216 };217 $scope.toDatePickerObject = {218 titleLabel: 'Calendar - Select the End Date', //Optional219 inputDate: $scope.fromDatePickerObject.inputDate, //Optional220 mondayFirst: false, //Optional221 weekDaysList: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], //Optional222 templateType: 'popup', //Optional can be popup223 showTodayButton: 'true', //Optional224 callback: function(val) { //Mandatory225 if (val === undefined || val === 'undefined') {226 } else {227 if ($scope.fromDatePickerObject.inputDate > val) {228 var alertPopup = $ionicPopup.alert({229 title: 'Review inputs again',230 template: "The date must be in the future of the beginning date"231 });232 this.inputDate = $scope.fromDatePickerObject.inputDate;233 } else {234 this.inputDate = val;235 $scope.addEvent.toDate = $filter('date')(val, "yyyy-MM-dd"); 236 }237 238 };239 },240 };241 $scope.repeatUntilDatePickerObject = {242 titleLabel: 'Repeat Until', //Optional243 inputDate: $scope.toDatePickerObject.inputDate, //Optional244 mondayFirst: false, //Optional245 weekDaysList: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], //Optional246 templateType: 'popup', //Optional can be popup247 showTodayButton: 'false', //Optional248 callback: function(val) { //Mandatory249 if (val === undefined || val === 'undefined') {250 } else {251 this.inputDate = val;252 $scope.addEvent.repeatUntil = $filter('date')(val, "yyyy-MM-dd");253 };254 }255 };256 $scope.repeatListChoices = [{257 text: "None",258 value: "none"259 }, {260 text: "Everyday",261 value: "daily"262 }, {263 text: "Every Week",264 value: "weekly"265 }, {266 text: "Every 2 Weeks",267 value: "biweekly"268 }, {269 text: "Every Month",270 value: "monthly"271 }, {272 text: "Every Year",273 value: "yearly"274 }];275 $scope.takeText = function(value) {276 for (var i = 0; i < $scope.repeatListChoices.length; i++) {277 if ($scope.repeatListChoices[i].value == value) {278 return $scope.repeatListChoices[i].text;279 }280 }281 };282 $scope.repeatPopup = function() {283 var choices = $ionicPopup.show({284 title: 'Repeat',285 template: '<ion-radio ng-repeat="type in repeatListChoices" ng-model="addEvent.repeatType" ng-value="type.value">{{ type.text }}</ion-radio>',286 scope: $scope,287 buttons: [{288 text: 'Save',289 type: 'button-assertive',290 onTap: function() {291 return $scope.addEvent.repeatType;292 }293 }]294 });295 choices.then(function(result) {296 console.log($scope.addEvent.repeatType);297 })298 }299 $scope.backToPrevPage = function() {300 $state.go('tab.timetable');301 };302 var checkToRemoveTime = function() {303 if ($scope.addEvent.isAllDay == 1 || $scope.addEvent.isAllDay == true) {304 $scope.addEvent.fromTime = null;305 $scope.addEvent.toTime = null;306 return 1;307 }308 return 0;309 };310 var checkFromDateWithRepeatDate = function() {311 // compare if not sameday AND repeated, show error312 if (!(angular.equals($scope.addEvent.fromDate, $scope.addEvent.toDate)) && (!(angular.equals($scope.addEvent.repeatType, 'none')))) {313 console.log("error: cannot remove because repeat date is set while end date is different from beginning date"); 314 return false;315 } else {316 // check if either not same day or same day but not repeated317 if (!(angular.equals($scope.addEvent.toDate, $scope.addEvent.fromDate)) || 318 (angular.equals($scope.addEvent.toDate, $scope.addEvent.fromDate) && (angular.equals($scope.addEvent.repeatType, 'none'))))319 {320 $scope.addEvent.repeatUntil = $scope.addEvent.toDate;321 }322 return true;323 };324 };325 var toTimeCheck = function() {326 if ($filter('date')($scope.addEvent.fromTime, "shortTime", "+0800") > $filter('date')($scope.addEvent.toTime, "shortTime", "+0800")) {327 if ($scope.addEvent.toDate > $scope.addEvent.fromDate) {328 return true;329 } else {330 $scope.addEvent.toTime = $scope.addEvent.fromTime;331 var alertPopup = $ionicPopup.alert({332 title: 'Review time again',333 template: "End time should be ahead of beginning time."334 });335 return false;336 }337 } else {338 return true;339 }340 }341 $scope.endAddEventCheck = function(val) {342 if (val)343 // if (val && toTimeCheck())344 endAddEvent();345 else{346 var alertPopup = $ionicPopup.alert({347 title: 'Review inputs again',348 template: "Please revise the required fields."349 });350 }351 }352 var endAddEvent = function() {353 console.log($scope.addEvent.fromDate);354 console.log($scope.addEvent.repeatUntil);355 checkToRemoveTime();356 var checker = checkFromDateWithRepeatDate();357 if (checker) {358 // var post = {};359 // if($scope.addEvent.isEditEventCtrl == 1) {360 // post.url = 'http://unicomhk.net/fyp/www/php/actionAddEvent.php';361 // }362 var post = {363 url: 'http://unicomhk.net/fyp/www/php/actionAddEvent.php',364 method: 'POST',365 headers: {366 'Content-Type': 'application/json',367 },368 data: {369 eventTitle: $sanitize($scope.addEvent.eventTitle),370 eventDescription: $sanitize($scope.addEvent.eventDescription),371 eventLocation: $sanitize($scope.addEvent.eventLocation),372 fromTime: $filter('date')($scope.addEvent.fromTime,'shortTime','+0800'),373 toTime: $filter('date')($scope.addEvent.toTime,'shortTime','+0800'),374 fromDate: $scope.addEvent.fromDate,375 toDate: $scope.addEvent.toDate,376 repeatUntil: $scope.addEvent.repeatUntil,377 personal: $scope.addEvent.isPersonal,378 repeatType: $scope.addEvent.repeatType,379 allDay: $scope.addEvent.isAllDay380 }381 }382 $http(post).then(function(response) {383 $state.go('tab.timetable');384 });385 } else {386 var alertPopup = $ionicPopup.alert({387 title: 'Date Mismatch!',388 template: "Setting a different End date while repeating the event is not possible. Either set the end date to be the same as beginning date or choose repeat to 'None' !"389 });390 }391 }392})393.controller('EditEventCtrl', function($scope, $state, $http, $ionicPopup, $sanitize, $filter, $rootScope, eventDateStorageService, editEventService) {394 ionic.Platform.ready(function() {395 $scope.addEvent = editEventService.get();396 })397 $rootScope.$on('$stateChangeSuccess', function(event, next) {398 $scope.addEvent = editEventService.get();399 })400 $scope.backToPrevPage = function() {401 $state.go('tab.timetable');402 };403 $scope.$on('$destroy', function() {404 console.log('destroy');405 });406 $scope.fromDatePickerObject = {407 titleLabel: 'Calendar - Edit Start Date', //Optional408 inputDate: $filter('date')($scope.addEvent.fromDate, "yyyy-MM-dd"), //Optional409 mondayFirst: false, //Optional410 weekDaysList: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], //Optional411 templateType: 'popup', //Optional can be popup412 showTodayButton: 'true', //Optional413 modalHeaderColor: 'bar-assertive', //Optional414 modalFooterColor: 'bar-assertive', //Optional415 callback: function(val) { //Mandatory416 if (val === undefined || val === 'undefined') {417 } else {418 this.inputDate = val;419 $scope.addEvent.fromDate = $filter('date')(val, "yyyy-MM-dd");420 };421 },422 dateFormat: 'YYYY-MM-DD', //Optional423 };424 $scope.toDatePickerObject = {425 titleLabel: 'Calendar - Edit End Date', //Optional426 inputDate: $filter('date')($scope.addEvent.toDate, "yyyy-MM-dd"), //Optional427 mondayFirst: false, //Optional428 weekDaysList: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], //Optional429 templateType: 'popup', //Optional can be popup430 showTodayButton: 'true', //Optional431 callback: function(val) { //Mandatory432 if (val === undefined || val === 'undefined') {433 } else {434 if ($scope.fromDatePickerObject.inputDate > val) {435 var alertPopup = $ionicPopup.alert({436 title: 'Review inputs again',437 template: "The date must be in the future of the beginning date"438 });439 this.inputDate = $scope.fromDatePickerObject.inputDate;440 } else {441 this.inputDate = val;442 $scope.addEvent.toDate = $filter('date')(val, "yyyy-MM-dd"); 443 }444 };445 },446 };447 $scope.repeatUntilDatePickerObject = {448 titleLabel: 'Repeat Until', //Optional449 inputDate: $filter('date')($scope.addEvent.toDate, "yyyy-MM-dd"), //Optional450 mondayFirst: false, //Optional451 weekDaysList: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], //Optional452 templateType: 'popup', //Optional can be popup453 showTodayButton: 'false', //Optional454 callback: function(val) { //Mandatory455 if (val === undefined || val === 'undefined') {456 } else {457 this.inputDate = val;458 $scope.addEvent.repeatUntil = $filter('date')(val, "yyyy-MM-dd");459 };460 }461 };462 $scope.repeatListChoices = [{463 text: "None",464 value: "none"465 }, {466 text: "Everyday",467 value: "daily"468 }, {469 text: "Every Week",470 value: "weekly"471 }, {472 text: "Every 2 Weeks",473 value: "biweekly"474 }, {475 text: "Every Month",476 value: "monthly"477 }, {478 text: "Every Year",479 value: "yearly"480 }];481 $scope.takeText = function(value) {482 for (var i = 0; i < $scope.repeatListChoices.length; i++) {483 if ($scope.repeatListChoices[i].value == value) {484 return $scope.repeatListChoices[i].text;485 }486 }487 };488 $scope.repeatPopup = function() {489 var choices = $ionicPopup.show({490 title: 'Repeat',491 template: '<ion-radio ng-repeat="type in repeatListChoices" ng-model="addEvent.repeatType" ng-value="type.value">{{ type.text }}</ion-radio>',492 scope: $scope,493 buttons: [{494 text: 'Save',495 type: 'button-assertive',496 onTap: function() {497 return $scope.addEvent.repeatType;498 }499 }]500 });501 choices.then(function(result) {502 console.log($scope.addEvent.repeatType);503 })504 }505 var checkToRemoveTime = function() {506 if ($scope.addEvent.isAllDay == 1 || $scope.addEvent.isAllDay == true) {507 $scope.addEvent.fromTime = null;508 $scope.addEvent.toTime = null;509 return 1;510 }511 return 0;512 };513 var checkFromDateWithRepeatDate = function() {514 // compare if not sameday AND repeated, show error515 if (!(angular.equals($scope.addEvent.fromDate, $scope.addEvent.toDate)) && (!(angular.equals($scope.addEvent.repeatType, 'none')))) {516 console.log("error: cannot remove because repeat date is set while end date is different from beginning date"); 517 return false;518 } else {519 // check if either not same day or same day but not repeated520 if (!(angular.equals($scope.addEvent.toDate, $scope.addEvent.fromDate)) || 521 (angular.equals($scope.addEvent.toDate, $scope.addEvent.fromDate) && (angular.equals($scope.addEvent.repeatType, 'none'))))522 {523 $scope.addEvent.repeatUntil = $scope.addEvent.toDate;524 }525 return true;526 };527 };528 var toTimeCheck = function() {529 if ($filter('date')($scope.addEvent.fromTime, "shortTime", "+0800") > $filter('date')($scope.addEvent.toTime, "shortTime", "+0800")) {530 if ($scope.addEvent.toDate > $scope.addEvent.fromDate) {531 return true;532 } else {533 $scope.addEvent.toTime = $scope.addEvent.fromTime;534 var alertPopup = $ionicPopup.alert({535 title: 'Review time again',536 template: "Time should be ahead of beginning time."537 });538 return false;539 }540 } else {541 return true;542 }543 }544 $scope.editEventTypeList = [545 {546 text: "Edit all occurences",547 value: "editAll"548 },549 {550 text: "Edit this only event entry",551 value: "editSingle"552 }];553 $scope.editEventType = {type: "editSingle"};554 // $scope.chooseEventEditType = function() {555 // var choices = $ionicPopup.show({556 // title: 'Edit',557 // template: '<ion-radio ng-repeat="type in editEventTypeList" ng-model="editEventType.type" ng-value="type.value"></ion-radio>',558 // scope: $scope,559 // buttons: [560 // {561 // text: 'Cancel'562 // },563 // {564 // text: 'Edit',565 // type: 'button-assertive',566 // onTap: function() {567 // return $scope.editEventType.type;568 // }569 // }]570 // })571 // }572 $scope.endAddEventCheck = function(val) {573 if (val && toTimeCheck()) {574 //endAddEvent($scope.chooseEventEditType());575 endAddEvent();576 }577 else{578 var alertPopup = $ionicPopup.alert({579 title: 'Review inputs again',580 template: "Please revise the required fields."581 });582 }583 }584 var endAddEvent = function() {585 console.log($scope.addEvent.fromDate);586 console.log($scope.addEvent.repeatUntil);587 checkToRemoveTime();588 var checker = checkFromDateWithRepeatDate();589 if (checker) {590 var post = {591 url: 'http://unicomhk.net/fyp/www/php/actionEditEvent.php',592 method: 'POST',593 headers: {594 'Content-Type': 'application/json',595 },596 data: {597 eventID: $scope.addEvent.eventID,598 eventRepeatID: $scope.addEvent.eventRepeatID,599// editType: editType,600 eventTitle: $sanitize($scope.addEvent.eventTitle),601 eventDescription: $sanitize($scope.addEvent.eventDescription),602 eventLocation: $sanitize($scope.addEvent.eventLocation),603 fromTime: $filter('date')($scope.addEvent.fromTime,'shortTime','+0800'),604 toTime: $filter('date')($scope.addEvent.toTime,'shortTime','+0800'),605 fromDate: $scope.addEvent.fromDate,606 toDate: $scope.addEvent.toDate,607 repeatUntil: $scope.addEvent.repeatUntil,608 personal: $scope.addEvent.isPersonal,609 repeatType: $scope.addEvent.repeatType,610 allDay: $scope.addEvent.isAllDay611 }612 }613 $http(post).then(function(response) {614 $state.go('tab.timetable');615 });616 } else {617 var alertPopup = $ionicPopup.alert({618 title: 'Date Mismatch!',619 template: "Setting a different End date while repeating the event is not possible. Either set the end date to be the same as beginning date or choose repeat to 'None' !"620 });621 }622 }623 /* All the code below are from past tests that might have worked and buggy. It's kept to be a 624 basis and backup incase new code underneath does not work. */625 // $scope.endAddEvent = function() {626 // console.log($scope.addEvent.fromDate);627 // console.log($scope.addEvent.repeatUntil);628 // checkToRemoveTime();629 // var checker = checkFromDateWithRepeatDate();630 // if (checker) {631 // // var post = {};632 // // if($scope.addEvent.isEditEventCtrl == 1) {633 // // post.url = 'http://unicomhk.net/fyp/www/php/actionAddEvent.php';634 // // }635 // var post = {636 // url: 'http://unicomhk.net/fyp/www/php/actionAddEvent.php',637 // method: 'POST',638 // headers: {639 // 'Content-Type': 'application/json',640 // },641 // data: {642 // eventTitle: $scope.addEvent.eventTitle,643 // eventDescription: $scope.addEvent.eventDescription,644 // eventLocation: $scope.addEvent.eventLocation,645 // fromTime: $filter('date')($scope.addEvent.fromTime,'shortTime','+0800'),646 // toTime: $filter('date')($scope.addEvent.toTime,'shortTime','+0800'),647 // fromDate: $scope.addEvent.fromDate,648 // toDate: $scope.addEvent.toDate,649 // repeatUntil: $scope.addEvent.repeatUntil,650 // personal: $scope.addEvent.isPersonal,651 // repeatType: $scope.addEvent.repeatType,652 // allDay: $scope.addEvent.isAllDay653 // }654 // }655 // $http(post).then(function(response) {656 // $state.go('tab.timetable');657 // });658 // } else {659 // var alertPopup = $ionicPopup.alert({660 // title: 'Date Mismatch!',661 // template: "Setting a different End date while repeating the event is not possible. Either set the end date to be the same as beginning date or choose repeat to 'None' !"662 // });663 // }664 //}...

Full Screen

Full Screen

groundTruth.py

Source:groundTruth.py Github

copy

Full Screen

...13 14 def setEvents(self, events):15 pass16 17 def addEvent(self, event):18 self.events.append(event)19 20 def addClear(self, clear):21 self.clears.append(clear)22 23 def simulationBGP_CLEAR(self):24 eventRecord = {25 'name': 'event1',26 'startTime': 1498754415519000000,27 'startIndex': 76,28 'endTime': 1498754521434000000,29 'endIndex': 100,30 'node': 'leaf1',31 'type': 'single'32 }33 34 self.addEvent(eventRecord)35 36 eventRecord = {37 'name': 'event2',38 'startTime': 1498754656637000000,39 'startIndex': 129,40 'endTime': 1498754760063000000,41 'endIndex': 154,42 'node': 'spine4',43 'type': 'single'44 }45 46 self.addEvent(eventRecord)47 48 eventRecord = {49 'name': 'event3',50 'startTime': 1498754885121000000,51 'startIndex': 183,52 'endTime': 1498755000770000000,53 'endIndex': 208,54 'node': 'leaf8',55 'type': 'single'56 }57 58 self.addEvent(eventRecord)59 60 eventRecord = {61 'name': 'event4',62 'startTime': 1498755124567000000,63 'startIndex': 232,64 'endTime': 1498755304432000000,65 'endIndex': 276,66 'node': 'spine2',67 'type': 'single'68 }69 70 self.addEvent(eventRecord)71 72 eventRecord = {73 'name': 'event5',74 'startTime': 1498755424734000000,75 'startIndex': 303,76 'endTime': 1498755601181000000,77 'endIndex': 343,78 'node': 'leaf2',79 'type': 'single'80 }81 82 self.addEvent(eventRecord)83 84 eventRecord = {85 'name': 'event5',86 'startTime': 1498755419850000000,87 'startIndex': 304,88 'endTime': 1498755601181000000,89 'endIndex': 343,90 'node': 'leaf6',91 'type': 'multiple'92 }93 94 self.addEvent(eventRecord)95 96 eventRecord = {97 'name': 'event6',98 'startTime': 1498755721694000000,99 'startIndex': 366,100 'endTime': 1498755900264000000,101 'endIndex': 410,102 'node': 'spine1',103 'type': 'single'104 }105 self.addEvent(eventRecord)106 107 eventRecord = {108 'name': 'event6',109 'startTime': 1498755722500000000,110 'startIndex': 366,111 'endTime': 1498755900264000000,112 'endIndex': 410,113 'node': 'spine3',114 'type': 'multiple'115 }116 self.addEvent(eventRecord)117 118 eventRecord = {119 'name': 'event7',120 'startTime': 1498756020858000000,121 'startIndex': 437,122 'endTime': 1498756199112000000,123 'endIndex': 477,124 'node': 'spine1',125 'type': 'single'126 }127 128 self.addEvent(eventRecord)129 130 eventRecord = {131 'name': 'event7',132 'startTime': 1498756020858000000,133 'startIndex': 438,134 'endTime': 1498756199112000000,135 'endIndex': 477,136 'node': 'spine2',137 'type': 'multiple'138 }139 140 self.addEvent(eventRecord)141 142 eventRecord = {143 'name': 'event7',144 'startTime': 1498756044535000000,145 'startIndex': 438,146 'endTime': 1498756199112000000,147 'endIndex': 477,148 'node': 'spine3',149 'type': 'multiple'150 }151 self.addEvent(eventRecord)152 def simulationBGP_CLEAR2(self):153 eventRecord = {154 'name': 'event1',155 'startTime': 1498754400000,156 'endTime': 1498754520000,157 'node': 'leaf1',158 'type': 'single'159 }160 161 self.addEvent(eventRecord)162 163 eventRecord = {164 'name': 'event2',165 'startTime': 1498754640000,166 'endTime': 1498754760000,167 'node': 'spine4',168 'type': 'single'169 }170 171 self.addEvent(eventRecord)172 173 eventRecord = {174 'name': 'event3',175 'startTime': 1498754880000,176 'endTime': 1498755000000,177 'node': 'leaf8',178 'type': 'single'179 }180 181 self.addEvent(eventRecord)182 183 eventRecord = {184 'name': 'event4',185 'startTime': 1498755120000,186 'endTime': 1498755300000,187 'node': 'spine2',188 'type': 'single'189 }190 191 self.addEvent(eventRecord)192 193 eventRecord = {194 'name': 'event5',195 'startTime': 1498755420000,196 'endTime': 1498755600000,197 'node': 'leaf2',198 'type': 'single'199 }200 201 self.addEvent(eventRecord)202 203 eventRecord = {204 'name': 'event5',205 'startTime': 1498755420000,206 'endTime': 1498755600000,207 'node': 'leaf6',208 'type': 'multiple'209 }210 211 self.addEvent(eventRecord)212 213 eventRecord = {214 'name': 'event6',215 'startTime': 1498755720000,216 'endTime': 1498755900000,217 'node': 'spine1',218 'type': 'single'219 }220 self.addEvent(eventRecord)221 222 eventRecord = {223 'name': 'event6',224 'startTime': 1498755720000,225 'endTime': 1498755900000,226 'node': 'spine3',227 'type': 'multiple'228 }229 self.addEvent(eventRecord)230 231 eventRecord = {232 'name': 'event7',233 'startTime': 1498756020000,234 'endTime': 1498756200000,235 'node': 'spine1',236 'type': 'single'237 }238 239 self.addEvent(eventRecord)240 241 eventRecord = {242 'name': 'event7',243 'startTime': 1498756020000,244 'endTime': 1498756200000,245 'node': 'spine2',246 'type': 'multiple'247 }248 249 self.addEvent(eventRecord)250 251 eventRecord = {252 'name': 'event7',253 'startTime': 1498756020000,254 'endTime': 1498756200000,255 'node': 'spine3',256 'type': 'multiple'257 }258 259 self.addEvent(eventRecord)260 261 262 def simulationBGP_CLEAR3(self):263 264 ##indexStart : 76265 eventRecord = {266 'name': 'event1',267 'startTime': 1498754415519,268 'endTime': 1498754580441,269 'startidx': 76,270 'endidx': 100,271 'node': 'leaf1',272 'type': 'single',273 'entity': 'single'274 }275 276 self.addEvent(eventRecord)277 278 ### indexStart : 129279 eventRecord = {280 'name': 'event2',281 'startTime': 1498754656637,282 'endTime': 1498754820000,283 'node': 'spine4',284 'type': 'single',285 'entity': 'single'286 }287 self.addEvent(eventRecord)288 289 ### indexStart : 183290 eventRecord = {291 'name': 'event3',292 'startTime': 1498754885121,293 'endTime': 1498755060000,294 'node': 'leaf8',295 'type': 'single',296 'entity': 'single'297 }298 self.addEvent(eventRecord)299 300 ### indexStart : 232301 eventRecord = {302 'name': 'event4',303 'startTime': 1498755124567,304 'endTime': 1498755300000,305 'node': 'spine2',306 'type': 'single',307 'entity': 'single'308 }309 self.addEvent(eventRecord)310 311 ### indexStart : 303 312 eventRecord = {313 'name': 'event5leaf2',314 'startTime': 1498755424540,315 'endTime': 1498755600000,316 'node': 'leaf2',317 'type': 'single',318 'entity': 'multiple'319 }320 self.addEvent(eventRecord)321 322 ### indexStart : 304323 eventRecord = {324 'name': 'event5leaf6',325 'startTime': 1498755429032,326 'endTime': 1498755600000,327 'node': 'leaf6',328 'type': 'multiple',329 'entity': 'multiple'330 }331 self.addEvent(eventRecord)332 333 ### indexStart : 366334 eventRecord = {335 'name': 'event6spine1',336 'startTime': 1498755727878,337 'endTime': 1498755900000,338 'node': 'spine1',339 'type': 'single',340 'entity': 'multiple'341 }342 self.addEvent(eventRecord)343 344 ### indexStart : 368345 eventRecord = {346 'name': 'event6spine3',347 'startTime': 1498755731460,348 'endTime': 1498755900000,349 'node': 'spine3',350 'type': 'multiple',351 'entity': 'multiple'352 }353 self.addEvent(eventRecord)354 ### indexStart : 437 355 eventRecord = {356 'name': 'event7spine1',357 'startTime': 1498756046457,358 'endTime': 1498756200000,359 'node': 'spine1',360 'type': 'single',361 'entity': 'multiple'362 }363 self.addEvent(eventRecord)364 365 ### indexStart : 437366 eventRecord = {367 'name': 'event7spine2',368 'startTime': 1498756045516,369 'endTime': 1498756200000,370 'node': 'spine2',371 'type': 'multiple',372 'entity': 'multiple'373 }374 self.addEvent(eventRecord)375 376 ### indexStart : 439377 eventRecord = {378 'name': 'event7spine3',379 'startTime': 1498756044535,380 'endTime': 1498756200000,381 'node': 'spine3',382 'type': 'multiple',383 'entity': 'multiple'384 }385 386 self.addEvent(eventRecord)387 388 def simulationBGP_CLEAR3_TwoMin(self):389 390 ##indexStart : 76391 eventRecord = {392 'name': 'event1',393 'startTime': 1498754415519,394 'endTime': 1498754535519,395 'startidx': 76,396 'endidx': 100,397 'node': 'leaf1',398 'type': 'single',399 'entity': 'single'400 }401 402 self.addEvent(eventRecord)403 404 ### indexStart : 129405 eventRecord = {406 'name': 'event2',407 'startTime': 1498754656637,408 'endTime': 1498754776637,409 'node': 'spine4',410 'type': 'single',411 'entity': 'single'412 }413 self.addEvent(eventRecord)414 415 ### indexStart : 183416 eventRecord = {417 'name': 'event3',418 'startTime': 1498754885121,419 'endTime': 1498755005121,420 'node': 'leaf8',421 'type': 'single',422 'entity': 'single'423 }424 self.addEvent(eventRecord)425 426 ### indexStart : 232427 eventRecord = {428 'name': 'event4',429 'startTime': 1498755124567,430 'endTime': 1498755244567,431 'node': 'spine2',432 'type': 'single',433 'entity': 'single'434 }435 self.addEvent(eventRecord)436 437 ### indexStart : 303 438 eventRecord = {439 'name': 'event5leaf2',440 'startTime': 1498755424540,441 'endTime': 1498755600000,442 'node': 'leaf2',443 'type': 'single',444 'entity': 'multiple'445 }446 self.addEvent(eventRecord)447 448 ### indexStart : 304449 eventRecord = {450 'name': 'event5leaf6',451 'startTime': 1498755429032,452 'endTime': 1498755600000,453 'node': 'leaf6',454 'type': 'multiple',455 'entity': 'multiple'456 }457 self.addEvent(eventRecord)458 459 ### indexStart : 366460 eventRecord = {461 'name': 'event6spine1',462 'startTime': 1498755727878,463 'endTime': 1498755900000,464 'node': 'spine1',465 'type': 'single',466 'entity': 'multiple'467 }468 self.addEvent(eventRecord)469 470 ### indexStart : 368471 eventRecord = {472 'name': 'event6spine3',473 'startTime': 1498755731460,474 'endTime': 1498755900000,475 'node': 'spine3',476 'type': 'multiple',477 'entity': 'multiple'478 }479 self.addEvent(eventRecord)480 ### indexStart : 437 481 eventRecord = {482 'name': 'event7spine1',483 'startTime': 1498756046457,484 'endTime': 1498756200000,485 'node': 'spine1',486 'type': 'single',487 'entity': 'multiple'488 }489 self.addEvent(eventRecord)490 491 ### indexStart : 437492 eventRecord = {493 'name': 'event7spine2',494 'startTime': 1498756045516,495 'endTime': 1498756200000,496 'node': 'spine2',497 'type': 'multiple',498 'entity': 'multiple'499 }500 self.addEvent(eventRecord)501 502 ### indexStart : 439503 eventRecord = {504 'name': 'event7spine3',505 'startTime': 1498756044535,506 'endTime': 1498756200000,507 'node': 'spine3',508 'type': 'multiple',509 'entity': 'multiple'510 }511 512 self.addEvent(eventRecord)513 514 def simulationBGP_CLEAR_CLEAR(self):515 516 ##indexStart : 76517 eventRecord = {518 'name': 'clear1',519 'startTime': 1498754580442,520 'endTime': 1498754645636521 }522 523 self.addClear(eventRecord)524 ### OK525 526 ##indexStart : 76527 eventRecord = {528 'name': 'clear2',529 'startTime': 1498754820001,530 'endTime': 1498754885122531 }532 533 self.addClear(eventRecord)534 ### OK535 536 eventRecord = {537 'name': 'clear3',538 'startTime': 1498755060001,539 'endTime': 1498755124566540 }541 542 self.addClear(eventRecord)543 ###OK544 545 eventRecord = {546 'name': 'clear4',547 'startTime': 1498755300001,548 'endTime': 1498755424530549 }550 551 self.addClear(eventRecord)552 ### OK553 554 eventRecord = {555 'name': 'clear5',556 'startTime': 1498755600001,557 'endTime': 1498755727877558 }559 self.addClear(eventRecord)560 ### OK561 562 eventRecord = {563 'name': 'clear6',564 'startTime': 1498755900001,565 'endTime': 1498756044534566 }567 self.addClear(eventRecord)568 ### OK569# eventRecord = {570# 'name': 'clear7',571# 'startTime': 1498756200000,572# 'endTime': 1598756200000573# }574# self.addClear(eventRecord)575# ### OK576 577 def simulationPORT_FLAP(self):578 579 ##indexStart : 64580 eventRecord = {581 'name': 'event1',582 'startTime': 1504286090625,583 'endTime': 1504286362296,584 'node': 'spine2',585 'interface': 8,586 'neighbor': 'leaf3',587 'type': 'single',588 'entity': 'single'589 }590 591 self.addEvent(eventRecord)592 593 ##indexStart : 130594 eventRecord = {595 'name': 'event2',596 'startTime': 1504286455946,597 'endTime': 1504286753902,598 'node': 'leaf3',599 'interface': 8,600 'neighbor': 'spine2',601 'type': 'single',602 'entity': 'single'603 }604 605 self.addEvent(eventRecord)606 607 ##indexStart : 212608 eventRecord = {609 'name': 'event3',610 'startTime': 1504286868536,611 'endTime': 1504287184286,612 'node': 'spine2',613 'interface': 8,614 'neighbor': 'leaf3',615 'type': 'single',616 'entity': 'single'617 }618 619 self.addEvent(eventRecord)620 ##indexStart : 274621 eventRecord = {622 'name': 'event4',623 'startTime': 1504287248681,624 'endTime': 1504287531916,625 'node': 'leaf3',626 'interface': 8,627 'neighbor': 'spine2',628 'type': 'single',629 'entity': 'single'630 }631 632 self.addEvent(eventRecord) 633 634 ##indexStart : 380635 eventRecord = {636 'name': 'event5',637 'startTime': 1504287831774,638 'endTime': 1504288112632,639 'node': 'leaf3',640 'interface': 8,641 'neighbor': 'rswA5',642 'type': 'single',643 'entity': 'single'644 }645 646 self.addEvent(eventRecord) 647 648 ##indexStart : 461649 eventRecord = {650 'name': 'event6',651 'startTime': 1504288281689,652 'endTime': 1504288718480,653 'node': 'rswA5',654 'interface': 8,655 'neighbor': 'leaf3',656 'type': 'single',657 'entity': 'single'658 }659 660 self.addEvent(eventRecord) 661 662 def simulationPORT_FLAP_CLEAR(self):663 664 eventRecord = {665 'name': 'clear1',666 'startTime': 1504286362297,667 'endTime': 1504286455945668 }669 670 self.addClear(eventRecord)671 672 ##indexStart : 76673 eventRecord = {674 'name': 'clear2',675 'startTime': 1504286753903,676 'endTime': 1504286868535677 }678 self.addClear(eventRecord)679 680 eventRecord = {681 'name': 'clear3',682 'startTime': 1504287184287,683 'endTime': 1504287248680684 }685 686 self.addClear(eventRecord)687 688 eventRecord = {689 'name': 'clear4',690 'startTime': 1504287531918,691 'endTime': 1504287831775692 }693 694 self.addClear(eventRecord)695 696 eventRecord = {697 'name': 'clear5',698 'startTime': 1504288112633,699 'endTime': 1504288281690700 }701 self.addClear(eventRecord)702 703# eventRecord = {704# 'name': 'clear6',705# 'startTime': 1504288718480,706# 'endTime': 1550000000000707# }708# self.addClear(eventRecord)709 def simulationBGP_CLEAR_Second_DATASET(self):710 711 ##indexStart : 76712 eventRecord = {713 'name': 'event1',714 'startTime': 1501867182617,715 'endTime': 1501867403375,716 'startidx': 39,717 'endidx': 39+50,718 'node': 'leaf1',719 'type': 'single',720 'entity': 'single',721 'ONLINE' : False,722 'endSent': False723 }724 725 self.addEvent(eventRecord)726 727 ### indexStart : 129728 eventRecord = {729 'name': 'event2',730 'startTime': 1501867481598,731 'endTime': 1501867701677,732 'node': 'leaf6',733 'type': 'single',734 'entity': 'single',735 'ONLINE' : False,736 'endSent': False737 }738 self.addEvent(eventRecord)739 740 ### indexStart : 183741 eventRecord = {742 'name': 'event3',743 'startTime': 1501867783946,744 'endTime': 1501868006351,745 'node': 'spine2',746 'type': 'single',747 'entity': 'single',748 'ONLINE' : False,749 'endSent': False750 }751 self.addEvent(eventRecord)752# 753 ### indexStart : 232754 eventRecord = {755 'name': 'event4',756 'startTime': 1501868091453,757 'endTime': 1501868312576,758 'node': 'leaf2',759 'type': 'single',760 'entity': 'single',761 'ONLINE' : False,762 'endSent': False763 }764 self.addEvent(eventRecord)765# 766 ### indexStart : 303 767 eventRecord = {768 'name': 'event5leaf2',769 'startTime': 1501868124311,770 'endTime': 1501868343454,771 'node': 'leaf8',772 'type': 'single',773 'entity': 'single',774 'ONLINE' : False,775 'endSent': False776 }777 self.addEvent(eventRecord)778# 779 ### indexStart : 304780 eventRecord = {781 'name': 'event5leaf6',782 'startTime': 1501868384250,783 'endTime': 1501868606662,784 'node': 'spine1',785 'type': 'single',786 'entity': 'single',787 'ONLINE' : False,788 'endSent': False789 }790 self.addEvent(eventRecord)791# 792 ### indexStart : 366793 eventRecord = {794 'name': 'event6spine1',795 'startTime': 1501868428974,796 'endTime': 1501868650995,797 'node': 'spine2',798 'type': 'single',799 'entity': 'single',800 'ONLINE' : False,801 'endSent': False802 }803 self.addEvent(eventRecord)804# 805 ### indexStart : 368806 eventRecord = {807 'name': 'event6spine3',808 'startTime': 1501868492556,809 'endTime': 1501868714299,810 'node': 'spine3',811 'type': 'single',812 'entity': 'single',813 'ONLINE' : False,814 'endSent': False815 }816 self.addEvent(eventRecord)817 def simulationBGP_CLEAR2_CLEAR(self):818 819 eventRecord = {820 'name': 'clear1',821 'startTime': 1501867403376,822 'endTime': 1501867481597823 }824 825 self.addClear(eventRecord)826 827 ##indexStart : 76828 eventRecord = {829 'name': 'clear2',830 'startTime': 1501867701677,...

Full Screen

Full Screen

IntervalTimeline.js

Source:IntervalTimeline.js Github

copy

Full Screen

...3 Basic(IntervalTimeline);4 context("inserting/deleting events", function(){5 it ("accepts events into the timeline", function(){6 var sched = new IntervalTimeline();7 sched.addEvent({8 "state" : "A",9 "duration" : 0.2,10 "time" : 011 });12 sched.addEvent({13 "state" : "B",14 "duration" : 0.4,15 "time" : 116 });17 sched.addEvent({18 "state" : "C",19 "duration" : 12,20 "time" : 221 });22 sched.dispose();23 });24 it ("computes the lenght of the timeline correctly after adding events", function(){25 var sched = new IntervalTimeline();26 sched.addEvent({27 "state" : "A",28 "duration" : 0.2,29 "time" : 030 });31 sched.addEvent({32 "state" : "B",33 "duration" : 0.4,34 "time" : 135 });36 sched.addEvent({37 "state" : "C",38 "duration" : 12,39 "time" : 240 });41 expect(sched.length).to.equal(3);42 sched.dispose();43 });44 it ("can remove events from the timeline", function(){45 var sched = new IntervalTimeline();46 var ev0 = {47 "duration" : 0.2,48 "time" : 049 };50 var ev1 = {51 "duration" : 0.2,52 "time" : 053 };54 var ev2 = {55 "duration" : 0.2,56 "time" : 057 };58 sched.addEvent(ev0);59 sched.addEvent(ev1);60 sched.addEvent(ev2);61 expect(sched.length).to.equal(3);62 sched.removeEvent(ev0);63 sched.removeEvent(ev1);64 expect(sched.length).to.equal(1);65 sched.dispose();66 });67 it ("can add and remove and add again events from the timeline", function(){68 var sched = new IntervalTimeline();69 var ev0 = {70 "duration" : 0.2,71 "time" : 072 };73 var ev1 = {74 "duration" : 0.2,75 "time" : 076 };77 var ev2 = {78 "duration" : 0.2,79 "time" : 080 };81 sched.addEvent(ev0);82 sched.addEvent(ev1);83 sched.addEvent(ev2);84 expect(sched.length).to.equal(3);85 sched.removeEvent(ev0);86 sched.removeEvent(ev1);87 expect(sched.length).to.equal(1);88 sched.addEvent(ev0);89 sched.addEvent(ev1);90 expect(sched.length).to.equal(3);91 sched.dispose();92 });93 it ("throws an error if events do not have both time and duration attributes", function(){94 var sched = new IntervalTimeline();95 expect(function(){96 sched.addEvent({97 "time" : 098 });99 }).to.throw(Error);100 expect(function(){101 sched.addEvent({102 "duration" : 0103 });104 }).to.throw(Error);105 sched.dispose();106 });107 });108 context("getting events", function(){109 it ("returns null when no events are in the timeline", function(){110 var sched = new IntervalTimeline();111 expect(sched.getEvent(3)).to.equal(null);112 sched.dispose();113 });114 it ("returns the event which overlaps the given time", function(){115 var sched = new IntervalTimeline();116 sched.addEvent({117 "state" : "A",118 "duration" : Infinity,119 "time" : 0120 });121 sched.addEvent({122 "state" : "B",123 "duration" : 0.4,124 "time" : 1125 });126 sched.addEvent({127 "state" : "C",128 "duration" : 12,129 "time" : 2130 });131 expect(sched.getEvent(0.2).state).to.equal("A");132 sched.dispose();133 });134 it ("returns events exclusive of the end time", function(){135 var sched = new IntervalTimeline();136 sched.addEvent({137 "state" : "A",138 "duration" : 1,139 "time" : 0140 });141 expect(sched.getEvent(0.99).state).to.equal("A");142 expect(sched.getEvent(1)).to.equal(null);143 sched.dispose();144 });145 it ("factors in start position and duration when checking for overlaps", function(){146 var sched = new IntervalTimeline();147 sched.addEvent({148 "duration" : 0.4,149 "time" : 0150 });151 expect(sched.getEvent(0.5)).to.be.null;152 expect(sched.getEvent(-1)).to.be.null;153 expect(sched.getEvent(0)).to.not.be.null;154 expect(sched.getEvent(0.39)).to.not.be.null;155 sched.dispose();156 });157 it ("returns the event whose start is closest to the given time", function(){158 var sched = new IntervalTimeline();159 sched.addEvent({160 "state" : "A",161 "duration" : Infinity,162 "time" : 0163 });164 sched.addEvent({165 "state" : "B",166 "duration" : 0.4,167 "time" : 0.2168 });169 sched.addEvent({170 "state" : "C",171 "duration" : 12,172 "time" : 2173 });174 expect(sched.getEvent(0.2).state).to.equal("B");175 sched.dispose();176 });177 it ("returns the events correctly after some events are removed", function(){178 var sched = new IntervalTimeline();179 var ev0 = {180 "state" : "A",181 "duration" : 0.2,182 "time" : 0.1183 };184 var ev1 = {185 "state" : "B",186 "duration" : 0.3,187 "time" : 0.2188 };189 var ev2 = {190 "state" : "C",191 "duration" : Infinity,192 "time" : 0193 };194 sched.addEvent(ev0);195 sched.addEvent(ev1);196 sched.addEvent(ev2);197 sched.removeEvent(ev0);198 sched.removeEvent(ev1);199 expect(sched.getEvent(0.2)).to.not.be.null;200 expect(sched.getEvent(0.2).state).to.equal("C");201 sched.dispose();202 });203 it ("can handle many items", function(){204 var sched = new IntervalTimeline();205 for (var i = 0; i < 10000; i++){206 sched.addEvent({207 "time" : i,208 "duration" : 1209 });210 }211 for (var j = 0; j < 10000; j++){212 expect(sched.getEvent(j).time).to.equal(j);213 }214 sched.dispose();215 });216 });217 context("cancelling", function(){218 it ("can cancel items after the given time", function(){219 var sched = new IntervalTimeline();220 for (var i = 5; i < 100; i++){221 sched.addEvent({222 "time" : i,223 "duration" : 10224 });225 }226 sched.cancel(10);227 expect(sched.length).to.equal(5);228 sched.cancel(0);229 expect(sched.length).to.equal(0);230 sched.dispose();231 });232 });233 context("Iterators", function(){234 it("iterates over all items and returns and item", function(){235 var sched = new IntervalTimeline();236 sched.addEvent({"time" : 0, "duration" : 5});237 sched.addEvent({"time" : 0.1, "duration" : 5});238 sched.addEvent({"time" : 0.2, "duration" : 5});239 sched.addEvent({"time" : 0.3, "duration" : 5});240 sched.addEvent({"time" : 0.4, "duration" : 5});241 var count = 0;242 sched.forEach(function(event){243 expect(event).to.be.an.object;244 count++;245 });246 expect(count).to.equal(5);247 sched.dispose();248 });249 it("iterates over all items overlapping the given time", function(){250 var sched = new IntervalTimeline();251 sched.addEvent({"time" : 0, "duration" : 5});252 sched.addEvent({"time" : 0.1, "duration" : 5});253 sched.addEvent({"time" : 0.2, "duration" : 5});254 sched.addEvent({"time" : 0.3, "duration" : 5});255 sched.addEvent({"time" : 0.4, "duration" : 5});256 var count = 0;257 sched.forEachAtTime(0.3, function(event){258 expect(event).to.be.an.object;259 expect(event.time).to.be.at.most(0.3);260 count++;261 });262 expect(count).to.equal(4);263 sched.dispose();264 });265 it("handles time ranges before the available objects", function(){266 var sched = new IntervalTimeline();267 sched.addEvent({"time" : 0.1, "duration" : 5});268 sched.addEvent({"time" : 0.2, "duration" : 5});269 sched.addEvent({"time" : 0.3, "duration" : 5});270 sched.addEvent({"time" : 0.4, "duration" : 5});271 var count = 0;272 sched.forEachAtTime(0, function(){273 count++;274 });275 expect(count).to.equal(0);276 sched.dispose();277 });278 it("handles time ranges after the available objects", function(){279 var sched = new IntervalTimeline();280 sched.addEvent({"time" : 0.1, "duration" : 5});281 sched.addEvent({"time" : 0.2, "duration" : 5});282 sched.addEvent({"time" : 0.3, "duration" : 5});283 sched.addEvent({"time" : 0.4, "duration" : 5});284 var count = 0;285 sched.forEachAtTime(5.5, function(){286 count++;287 });288 expect(count).to.equal(0);289 sched.dispose();290 });291 it("iterates over all items after the given time", function(){292 var sched = new IntervalTimeline();293 sched.addEvent({"time" : 0.1, "duration" : 5});294 sched.addEvent({"time" : 0.2, "duration" : 5});295 sched.addEvent({"time" : 0.3, "duration" : 5});296 sched.addEvent({"time" : 0.4, "duration" : 5});297 var count = 0;298 sched.forEachAfter(0.2, function(event){299 expect(event).to.be.an.object;300 expect(event.time).to.be.gte(0.2);301 count++;302 });303 expect(count).to.equal(3);304 count = 0;305 sched.forEachAfter(0.35, function(event){306 expect(event.time).to.be.gte(0.35);307 count++;308 });309 expect(count).to.equal(1);310 sched.dispose();311 });312 it("handles time ranges after the available objects", function(){313 var sched = new IntervalTimeline();314 sched.addEvent({"time" : 0.1, "duration" : 5});315 sched.addEvent({"time" : 0.2, "duration" : 5});316 sched.addEvent({"time" : 0.3, "duration" : 5});317 sched.addEvent({"time" : 0.4, "duration" : 5});318 var count = 0;319 sched.forEachAfter(0.5, function(){320 count++;321 });322 expect(count).to.equal(0);323 sched.dispose();324 });325 it("iterates over all items", function(){326 var sched = new IntervalTimeline();327 sched.addEvent({"time" : 0.1, "duration" : 5});328 sched.addEvent({"time" : 0.2, "duration" : 5});329 sched.addEvent({"time" : 0.3, "duration" : 5});330 sched.addEvent({"time" : 0.4, "duration" : 5});331 var count = 0;332 sched.forEach(function(){333 count++;334 });335 expect(count).to.equal(4);336 sched.dispose();337 });338 it("can remove items during forEach iterations", function(){339 var sched = new IntervalTimeline();340 for (var i = 0; i < 1000; i++){341 sched.addEvent({"time" : i, "duration" : 0.01});342 }343 sched.forEach(function(event){344 sched.cancel(event.time);345 });346 expect(sched.length).to.equal(0);347 sched.dispose();348 });349 it("can remove items during forEachAtTime iterations", function(){350 var sched = new IntervalTimeline();351 for (var i = 0; i < 1000; i++){352 sched.addEvent({"time" : i, "duration" : Infinity});353 }354 sched.forEachAtTime(1000, function(event){355 sched.cancel(event.time);356 });357 expect(sched.length).to.equal(0);358 sched.dispose();359 });360 it("can remove items during forEachAfter iterations", function(){361 var sched = new IntervalTimeline();362 for (var i = 0; i < 1000; i++){363 sched.addEvent({"time" : i, "duration" : Infinity});364 }365 sched.forEachAfter(0, function(event){366 sched.removeEvent(event);367 });368 expect(sched.length).to.equal(0);369 sched.dispose();370 });371 });372 });...

Full Screen

Full Screen

Timeline.js

Source:Timeline.js Github

copy

Full Screen

...6 Test.wasDisposed(sched);7 });8 it ("accepts events into the timeline", function(){9 var sched = new Timeline();10 sched.addEvent({11 "state" : "A",12 "time" : 013 });14 sched.addEvent({15 "state" : "B",16 "time" : 117 });18 sched.addEvent({19 "state" : "C",20 "time" : 221 });22 sched.dispose();23 });24 it ("can insert events in the timeline in the right order", function(){25 var sched = new Timeline();26 sched.addEvent({27 "time" : 028 });29 sched.addEvent({30 "time" : 231 });32 sched.addEvent({33 "time" : 134 });35 expect(sched._timeline[0].time).to.equal(0);36 expect(sched._timeline[1].time).to.equal(1);37 expect(sched._timeline[2].time).to.equal(2);38 sched.dispose();39 });40 it ("can get the length of the timeline", function(){41 var sched = new Timeline();42 expect(sched.length).to.equal(0);43 sched.addEvent({44 "time" : 045 });46 expect(sched.length).to.equal(1);47 sched.dispose();48 });49 it ("can remove items from the timeline", function(){50 var sched = new Timeline();51 var obj = {"time" : 0};52 sched.addEvent(obj);53 sched.addEvent({54 "time" : 255 });56 expect(sched.length).to.equal(2);57 sched.removeEvent(obj);58 expect(sched.length).to.equal(1);59 sched.dispose();60 });61 it ("can search for events in the timeline by time", function(){62 var sched = new Timeline();63 sched.addEvent({64 "time" : 065 });66 sched.addEvent({67 "time" : 268 });69 sched.addEvent({70 "time" : 171 });72 expect(sched._search(0)).to.equal(0);73 expect(sched._search(0.01)).to.equal(0);74 expect(sched._search(1)).to.equal(1);75 expect(sched._search(1.01)).to.equal(1);76 expect(sched._search(2)).to.equal(2);77 expect(sched._search(20000)).to.equal(2);78 expect(sched._search(-1)).to.equal(-1);79 sched.dispose();80 });81 82 it ("can get the scheduled event at the given time", function(){83 var sched = new Timeline();84 sched.addEvent({85 "state" : "A",86 "time" : 287 });88 sched.addEvent({89 "state" : "C",90 "time" : 9.491 });92 sched.addEvent({93 "state" : "B",94 "time" : 695 });96 expect(sched.getEvent(0)).is.null97 expect(sched.getEvent(2).state).is.equal("A");98 expect(sched.getEvent(5.9).state).is.equal("A");99 expect(sched.getEvent(6.1).state).is.equal("B");100 expect(sched.getEvent(12).state).is.equal("C");101 sched.dispose();102 });103 it ("puts the second scheduled event after if two events are scheduled at the same time", function(){104 var sched = new Timeline();105 sched.addEvent({106 "name" : "A",107 "time" : 0108 });109 sched.addEvent({110 "name" : "B",111 "time" : 0112 });113 expect(sched.getEvent(0).name).is.equal("B");114 sched.addEvent({115 "name" : "C",116 "time" : 0117 });118 expect(sched.getEvent(0).name).is.equal("C");119 sched.dispose();120 });121 it ("can the next event after the given time", function(){122 var sched = new Timeline();123 expect(sched.getEventAfter(0)).is.null;124 sched.addEvent({125 "state" : "A",126 "time" : 0.1127 });128 sched.addEvent({129 "state" : "B",130 "time" : 1.1131 });132 sched.addEvent({133 "state" : "C",134 "time" : 2.1135 });136 expect(sched.getEventAfter(0).state).is.equal("A");137 expect(sched.getEventAfter(1).state).is.equal("B");138 expect(sched.getEventAfter(3)).is.null;139 sched.dispose();140 });141 it ("can the event before the event before the given time", function(){142 var sched = new Timeline();143 expect(sched.getEventBefore(0)).is.null;144 sched.addEvent({145 "state" : "A",146 "time" : 0.1147 });148 sched.addEvent({149 "state" : "B",150 "time" : 1.1151 });152 sched.addEvent({153 "state" : "C",154 "time" : 2.1155 });156 expect(sched.getEventBefore(0)).is.null;157 expect(sched.getEventBefore(1.1).state).is.equal("A");158 expect(sched.getEventBefore(2.1).state).is.equal("B");159 expect(sched.getEventBefore(3).state).is.equal("C");160 sched.dispose();161 });162 it ("can cancel an item", function(){163 var sched = new Timeline();164 sched.addEvent({"time" : 3});165 sched.addEvent({"time" : 5});166 sched.addEvent({"time" : 4});167 sched.addEvent({"time" : 8});168 sched.addEvent({"time" : 5});169 expect(sched.length).to.equal(5);170 sched.cancel(10);171 expect(sched.length).to.equal(5);172 sched.cancel(5);173 expect(sched.length).to.equal(2);174 sched.cancel(3);175 expect(sched.length).to.equal(0);176 sched.dispose();177 });178 it ("can cancel items after the given time", function(){179 var sched = new Timeline();180 for (var i = 0; i < 100; i++){181 sched.addEvent({"time" : 100 - i});182 }183 sched.cancel(10);184 expect(sched.length).to.equal(9);185 sched.cancel(5);186 expect(sched.length).to.equal(4);187 sched.cancel(0);188 expect(sched.length).to.equal(0);189 sched.dispose();190 });191 it ("can cancel items before the given time", function(){192 var sched = new Timeline();193 for (var i = 0; i < 100; i++){194 sched.addEvent({"time" : i});195 }196 sched.cancelBefore(9);197 expect(sched.length).to.equal(90);198 sched.cancelBefore(10.1);199 expect(sched.length).to.equal(89);200 sched.cancelBefore(100);201 expect(sched.length).to.equal(0);202 sched.dispose();203 });204 205 it ("has no problem with many items", function(){206 var sched = new Timeline();207 for (var i = 0; i < 10000; i++){208 sched.addEvent({209 "time" : i210 });211 }212 for (var j = 0; j < 10000; j++){213 expect(sched.getEvent(j).time).to.equal(j);214 }215 sched.dispose();216 });217 it ("can constrain the length of the timeline", function(){218 var sched = new Timeline(4);219 for (var i = 0; i < 10000; i++){220 sched.addEvent({221 "time" : i222 });223 }224 expect(sched.length).to.equal(4);225 sched.dispose();226 });227 context("Iterators", function(){228 it("iterates over all items and returns and item", function(){229 var sched = new Timeline();230 sched.addEvent({"time" : 0});231 sched.addEvent({"time" : 0.1});232 sched.addEvent({"time" : 0.2});233 sched.addEvent({"time" : 0.3});234 sched.addEvent({"time" : 0.4});235 var count = 0;236 sched.forEach(function(event){237 expect(event).to.be.an.object;238 count++;239 });240 expect(count).to.equal(5);241 sched.dispose();242 });243 it("iterates over all items before the given time", function(){244 var sched = new Timeline();245 sched.addEvent({"time" : 0});246 sched.addEvent({"time" : 0.1});247 sched.addEvent({"time" : 0.2});248 sched.addEvent({"time" : 0.3});249 sched.addEvent({"time" : 0.4});250 var count = 0;251 sched.forEachBefore(0.3, function(event){252 expect(event).to.be.an.object;253 expect(event.time).to.be.at.most(0.3);254 count++;255 });256 expect(count).to.equal(4);257 sched.dispose();258 });259 it("handles time ranges before the available objects", function(){260 var sched = new Timeline();261 sched.addEvent({"time" : 0.1});262 sched.addEvent({"time" : 0.2});263 sched.addEvent({"time" : 0.3});264 sched.addEvent({"time" : 0.4});265 var count = 0;266 sched.forEachBefore(0, function(){267 count++;268 });269 expect(count).to.equal(0);270 sched.dispose();271 });272 it("iterates over all items after the given time", function(){273 var sched = new Timeline();274 sched.addEvent({"time" : 0});275 sched.addEvent({"time" : 0.1});276 sched.addEvent({"time" : 0.2});277 sched.addEvent({"time" : 0.3});278 sched.addEvent({"time" : 0.4});279 var count = 0;280 sched.forEachAfter(0.1, function(event){281 expect(event).to.be.an.object;282 expect(event.time).to.be.above(0.1);283 count++;284 });285 expect(count).to.equal(3);286 sched.dispose();287 });288 it("handles time ranges after the available objects", function(){289 var sched = new Timeline();290 sched.addEvent({"time" : 0.1});291 sched.addEvent({"time" : 0.2});292 sched.addEvent({"time" : 0.3});293 sched.addEvent({"time" : 0.4});294 var count = 0;295 sched.forEachAfter(0.5, function(){296 count++;297 });298 expect(count).to.equal(0);299 sched.dispose();300 });301 it("handles time ranges before the first object", function(){302 var sched = new Timeline();303 sched.addEvent({"time" : 0.1});304 sched.addEvent({"time" : 0.2});305 sched.addEvent({"time" : 0.3});306 sched.addEvent({"time" : 0.4});307 var count = 0;308 sched.forEachAfter(-Infinity, function(){309 count++;310 });311 expect(count).to.equal(4);312 sched.dispose();313 });314 it("can iterate after inclusive of the item at the given time", function(){315 var sched = new Timeline();316 sched.addEvent({"time" : 0.1});317 sched.addEvent({"time" : 0.2});318 sched.addEvent({"time" : 0.2});319 sched.addEvent({"time" : 0.3});320 sched.addEvent({"time" : 0.4});321 var count = 0;322 sched.forEachFrom(0.2, function(){323 count++;324 });325 expect(count).to.equal(4);326 count = 0;327 sched.forEachFrom(0.21, function(){328 count++;329 });330 expect(count).to.equal(2);331 count = 0;332 sched.forEachFrom(0, function(){333 count++;334 });335 expect(count).to.equal(5);336 sched.dispose();337 });338 it("iterates over all items at the given time", function(){339 var sched = new Timeline();340 sched.addEvent({"time" : 0});341 sched.addEvent({"time" : 0});342 sched.addEvent({"time" : 0.2});343 sched.addEvent({"time" : 0.2});344 sched.addEvent({"time" : 0.4});345 var count = 0;346 sched.forEachAtTime(0.1, function(event){347 count++;348 });349 expect(count).to.equal(0);350 //and with an actual time351 sched.forEachAtTime(0.2, function(event){352 expect(event.time).to.equal(0.2);353 count++;354 });355 expect(count).to.equal(2);356 sched.dispose();357 });358 it("can remove items during iterations", function(){359 var sched = new Timeline();360 for (var i = 0; i < 1000; i++){361 sched.addEvent({"time" : i});362 }363 sched.forEach(function(event){364 sched.removeEvent(event);365 });366 expect(sched.length).to.equal(0);367 sched.dispose();368 });369 });370 });...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful