How to use automation method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

bundle.js

Source:bundle.js Github

copy

Full Screen

1(function (global, factory) {2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/slicedToArray'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass')) :3 typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/slicedToArray', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass'], factory) :4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.automationEvents = {}, global._slicedToArray, global._classCallCheck, global._createClass));5}(this, (function (exports, _slicedToArray, _classCallCheck, _createClass) { 'use strict';6 function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }7 var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);8 var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);9 var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);10 var createExtendedExponentialRampToValueAutomationEvent = function createExtendedExponentialRampToValueAutomationEvent(value, endTime, insertTime) {11 return {12 endTime: endTime,13 insertTime: insertTime,14 type: 'exponentialRampToValue',15 value: value16 };17 };18 var createExtendedLinearRampToValueAutomationEvent = function createExtendedLinearRampToValueAutomationEvent(value, endTime, insertTime) {19 return {20 endTime: endTime,21 insertTime: insertTime,22 type: 'linearRampToValue',23 value: value24 };25 };26 var createSetValueAutomationEvent = function createSetValueAutomationEvent(value, startTime) {27 return {28 startTime: startTime,29 type: 'setValue',30 value: value31 };32 };33 var createSetValueCurveAutomationEvent = function createSetValueCurveAutomationEvent(values, startTime, duration) {34 return {35 duration: duration,36 startTime: startTime,37 type: 'setValueCurve',38 values: values39 };40 };41 var getTargetValueAtTime = function getTargetValueAtTime(time, valueAtStartTime, _ref) {42 var startTime = _ref.startTime,43 target = _ref.target,44 timeConstant = _ref.timeConstant;45 return target + (valueAtStartTime - target) * Math.exp((startTime - time) / timeConstant);46 };47 var isExponentialRampToValueAutomationEvent = function isExponentialRampToValueAutomationEvent(automationEvent) {48 return automationEvent.type === 'exponentialRampToValue';49 };50 var isLinearRampToValueAutomationEvent = function isLinearRampToValueAutomationEvent(automationEvent) {51 return automationEvent.type === 'linearRampToValue';52 };53 var isAnyRampToValueAutomationEvent = function isAnyRampToValueAutomationEvent(automationEvent) {54 return isExponentialRampToValueAutomationEvent(automationEvent) || isLinearRampToValueAutomationEvent(automationEvent);55 };56 var isSetValueAutomationEvent = function isSetValueAutomationEvent(automationEvent) {57 return automationEvent.type === 'setValue';58 };59 var isSetValueCurveAutomationEvent = function isSetValueCurveAutomationEvent(automationEvent) {60 return automationEvent.type === 'setValueCurve';61 };62 var getValueOfAutomationEventAtIndexAtTime = function getValueOfAutomationEventAtIndexAtTime(automationEvents, index, time, defaultValue) {63 var automationEvent = automationEvents[index];64 return automationEvent === undefined ? defaultValue : isAnyRampToValueAutomationEvent(automationEvent) || isSetValueAutomationEvent(automationEvent) ? automationEvent.value : isSetValueCurveAutomationEvent(automationEvent) ? automationEvent.values[automationEvent.values.length - 1] : getTargetValueAtTime(time, getValueOfAutomationEventAtIndexAtTime(automationEvents, index - 1, automationEvent.startTime, defaultValue), automationEvent);65 };66 var getEndTimeAndValueOfPreviousAutomationEvent = function getEndTimeAndValueOfPreviousAutomationEvent(automationEvents, index, currentAutomationEvent, nextAutomationEvent, defaultValue) {67 return currentAutomationEvent === undefined ? [nextAutomationEvent.insertTime, defaultValue] : isAnyRampToValueAutomationEvent(currentAutomationEvent) ? [currentAutomationEvent.endTime, currentAutomationEvent.value] : isSetValueAutomationEvent(currentAutomationEvent) ? [currentAutomationEvent.startTime, currentAutomationEvent.value] : isSetValueCurveAutomationEvent(currentAutomationEvent) ? [currentAutomationEvent.startTime + currentAutomationEvent.duration, currentAutomationEvent.values[currentAutomationEvent.values.length - 1]] : [currentAutomationEvent.startTime, getValueOfAutomationEventAtIndexAtTime(automationEvents, index - 1, currentAutomationEvent.startTime, defaultValue)];68 };69 var isCancelAndHoldAutomationEvent = function isCancelAndHoldAutomationEvent(automationEvent) {70 return automationEvent.type === 'cancelAndHold';71 };72 var isCancelScheduledValuesAutomationEvent = function isCancelScheduledValuesAutomationEvent(automationEvent) {73 return automationEvent.type === 'cancelScheduledValues';74 };75 var getEventTime = function getEventTime(automationEvent) {76 if (isCancelAndHoldAutomationEvent(automationEvent) || isCancelScheduledValuesAutomationEvent(automationEvent)) {77 return automationEvent.cancelTime;78 }79 if (isExponentialRampToValueAutomationEvent(automationEvent) || isLinearRampToValueAutomationEvent(automationEvent)) {80 return automationEvent.endTime;81 }82 return automationEvent.startTime;83 };84 var getExponentialRampValueAtTime = function getExponentialRampValueAtTime(time, startTime, valueAtStartTime, _ref) {85 var endTime = _ref.endTime,86 value = _ref.value;87 if (valueAtStartTime === value) {88 return value;89 }90 if (0 < valueAtStartTime && 0 < value || valueAtStartTime < 0 && value < 0) {91 return valueAtStartTime * Math.pow(value / valueAtStartTime, (time - startTime) / (endTime - startTime));92 }93 return 0;94 };95 var getLinearRampValueAtTime = function getLinearRampValueAtTime(time, startTime, valueAtStartTime, _ref) {96 var endTime = _ref.endTime,97 value = _ref.value;98 return valueAtStartTime + (time - startTime) / (endTime - startTime) * (value - valueAtStartTime);99 };100 var interpolateValue = function interpolateValue(values, theoreticIndex) {101 var lowerIndex = Math.floor(theoreticIndex);102 var upperIndex = Math.ceil(theoreticIndex);103 if (lowerIndex === upperIndex) {104 return values[lowerIndex];105 }106 return (1 - (theoreticIndex - lowerIndex)) * values[lowerIndex] + (1 - (upperIndex - theoreticIndex)) * values[upperIndex];107 };108 var getValueCurveValueAtTime = function getValueCurveValueAtTime(time, _ref) {109 var duration = _ref.duration,110 startTime = _ref.startTime,111 values = _ref.values;112 var theoreticIndex = (time - startTime) / duration * (values.length - 1);113 return interpolateValue(values, theoreticIndex);114 };115 var isSetTargetAutomationEvent = function isSetTargetAutomationEvent(automationEvent) {116 return automationEvent.type === 'setTarget';117 };118 var AutomationEventList = /*#__PURE__*/function () {119 function AutomationEventList(defaultValue) {120 _classCallCheck__default['default'](this, AutomationEventList);121 this._automationEvents = [];122 this._currenTime = 0;123 this._defaultValue = defaultValue;124 }125 _createClass__default['default'](AutomationEventList, [{126 key: Symbol.iterator,127 value: function value() {128 return this._automationEvents[Symbol.iterator]();129 }130 }, {131 key: "add",132 value: function add(automationEvent) {133 var eventTime = getEventTime(automationEvent);134 if (isCancelAndHoldAutomationEvent(automationEvent) || isCancelScheduledValuesAutomationEvent(automationEvent)) {135 var index = this._automationEvents.findIndex(function (currentAutomationEvent) {136 if (isCancelScheduledValuesAutomationEvent(automationEvent) && isSetValueCurveAutomationEvent(currentAutomationEvent)) {137 return currentAutomationEvent.startTime + currentAutomationEvent.duration >= eventTime;138 }139 return getEventTime(currentAutomationEvent) >= eventTime;140 });141 var removedAutomationEvent = this._automationEvents[index];142 if (index !== -1) {143 this._automationEvents = this._automationEvents.slice(0, index);144 }145 if (isCancelAndHoldAutomationEvent(automationEvent)) {146 var lastAutomationEvent = this._automationEvents[this._automationEvents.length - 1];147 if (removedAutomationEvent !== undefined && isAnyRampToValueAutomationEvent(removedAutomationEvent)) {148 if (isSetTargetAutomationEvent(lastAutomationEvent)) {149 throw new Error('The internal list is malformed.');150 }151 var startTime = isSetValueCurveAutomationEvent(lastAutomationEvent) ? lastAutomationEvent.startTime + lastAutomationEvent.duration : getEventTime(lastAutomationEvent);152 var startValue = isSetValueCurveAutomationEvent(lastAutomationEvent) ? lastAutomationEvent.values[lastAutomationEvent.values.length - 1] : lastAutomationEvent.value;153 var value = isExponentialRampToValueAutomationEvent(removedAutomationEvent) ? getExponentialRampValueAtTime(eventTime, startTime, startValue, removedAutomationEvent) : getLinearRampValueAtTime(eventTime, startTime, startValue, removedAutomationEvent);154 var truncatedAutomationEvent = isExponentialRampToValueAutomationEvent(removedAutomationEvent) ? createExtendedExponentialRampToValueAutomationEvent(value, eventTime, this._currenTime) : createExtendedLinearRampToValueAutomationEvent(value, eventTime, this._currenTime);155 this._automationEvents.push(truncatedAutomationEvent);156 }157 if (lastAutomationEvent !== undefined && isSetTargetAutomationEvent(lastAutomationEvent)) {158 this._automationEvents.push(createSetValueAutomationEvent(this.getValue(eventTime), eventTime));159 }160 if (lastAutomationEvent !== undefined && isSetValueCurveAutomationEvent(lastAutomationEvent) && lastAutomationEvent.startTime + lastAutomationEvent.duration > eventTime) {161 this._automationEvents[this._automationEvents.length - 1] = createSetValueCurveAutomationEvent(new Float32Array([6, 7]), lastAutomationEvent.startTime, eventTime - lastAutomationEvent.startTime);162 }163 }164 } else {165 var _index = this._automationEvents.findIndex(function (currentAutomationEvent) {166 return getEventTime(currentAutomationEvent) > eventTime;167 });168 var previousAutomationEvent = _index === -1 ? this._automationEvents[this._automationEvents.length - 1] : this._automationEvents[_index - 1];169 if (previousAutomationEvent !== undefined && isSetValueCurveAutomationEvent(previousAutomationEvent) && getEventTime(previousAutomationEvent) + previousAutomationEvent.duration > eventTime) {170 return false;171 }172 var persistentAutomationEvent = isExponentialRampToValueAutomationEvent(automationEvent) ? createExtendedExponentialRampToValueAutomationEvent(automationEvent.value, automationEvent.endTime, this._currenTime) : isLinearRampToValueAutomationEvent(automationEvent) ? createExtendedLinearRampToValueAutomationEvent(automationEvent.value, eventTime, this._currenTime) : automationEvent;173 if (_index === -1) {174 this._automationEvents.push(persistentAutomationEvent);175 } else {176 if (isSetValueCurveAutomationEvent(automationEvent) && eventTime + automationEvent.duration > getEventTime(this._automationEvents[_index])) {177 return false;178 }179 this._automationEvents.splice(_index, 0, persistentAutomationEvent);180 }181 }182 return true;183 }184 }, {185 key: "flush",186 value: function flush(time) {187 var index = this._automationEvents.findIndex(function (currentAutomationEvent) {188 return getEventTime(currentAutomationEvent) > time;189 });190 if (index > 1) {191 var remainingAutomationEvents = this._automationEvents.slice(index - 1);192 var firstRemainingAutomationEvent = remainingAutomationEvents[0];193 if (isSetTargetAutomationEvent(firstRemainingAutomationEvent)) {194 remainingAutomationEvents.unshift(createSetValueAutomationEvent(getValueOfAutomationEventAtIndexAtTime(this._automationEvents, index - 2, firstRemainingAutomationEvent.startTime, this._defaultValue), firstRemainingAutomationEvent.startTime));195 }196 this._automationEvents = remainingAutomationEvents;197 }198 }199 }, {200 key: "getValue",201 value: function getValue(time) {202 if (this._automationEvents.length === 0) {203 return this._defaultValue;204 }205 var indexOfNextEvent = this._automationEvents.findIndex(function (automationEvent) {206 return getEventTime(automationEvent) > time;207 });208 var nextAutomationEvent = this._automationEvents[indexOfNextEvent];209 var indexOfCurrentEvent = (indexOfNextEvent === -1 ? this._automationEvents.length : indexOfNextEvent) - 1;210 var currentAutomationEvent = this._automationEvents[indexOfCurrentEvent];211 if (currentAutomationEvent !== undefined && isSetTargetAutomationEvent(currentAutomationEvent) && (nextAutomationEvent === undefined || !isAnyRampToValueAutomationEvent(nextAutomationEvent) || nextAutomationEvent.insertTime > time)) {212 return getTargetValueAtTime(time, getValueOfAutomationEventAtIndexAtTime(this._automationEvents, indexOfCurrentEvent - 1, currentAutomationEvent.startTime, this._defaultValue), currentAutomationEvent);213 }214 if (currentAutomationEvent !== undefined && isSetValueAutomationEvent(currentAutomationEvent) && (nextAutomationEvent === undefined || !isAnyRampToValueAutomationEvent(nextAutomationEvent))) {215 return currentAutomationEvent.value;216 }217 if (currentAutomationEvent !== undefined && isSetValueCurveAutomationEvent(currentAutomationEvent) && (nextAutomationEvent === undefined || !isAnyRampToValueAutomationEvent(nextAutomationEvent) || currentAutomationEvent.startTime + currentAutomationEvent.duration > time)) {218 if (time < currentAutomationEvent.startTime + currentAutomationEvent.duration) {219 return getValueCurveValueAtTime(time, currentAutomationEvent);220 }221 return currentAutomationEvent.values[currentAutomationEvent.values.length - 1];222 }223 if (currentAutomationEvent !== undefined && isAnyRampToValueAutomationEvent(currentAutomationEvent) && (nextAutomationEvent === undefined || !isAnyRampToValueAutomationEvent(nextAutomationEvent))) {224 return currentAutomationEvent.value;225 }226 if (nextAutomationEvent !== undefined && isExponentialRampToValueAutomationEvent(nextAutomationEvent)) {227 var _getEndTimeAndValueOf = getEndTimeAndValueOfPreviousAutomationEvent(this._automationEvents, indexOfCurrentEvent, currentAutomationEvent, nextAutomationEvent, this._defaultValue),228 _getEndTimeAndValueOf2 = _slicedToArray__default['default'](_getEndTimeAndValueOf, 2),229 startTime = _getEndTimeAndValueOf2[0],230 value = _getEndTimeAndValueOf2[1];231 return getExponentialRampValueAtTime(time, startTime, value, nextAutomationEvent);232 }233 if (nextAutomationEvent !== undefined && isLinearRampToValueAutomationEvent(nextAutomationEvent)) {234 var _getEndTimeAndValueOf3 = getEndTimeAndValueOfPreviousAutomationEvent(this._automationEvents, indexOfCurrentEvent, currentAutomationEvent, nextAutomationEvent, this._defaultValue),235 _getEndTimeAndValueOf4 = _slicedToArray__default['default'](_getEndTimeAndValueOf3, 2),236 _startTime = _getEndTimeAndValueOf4[0],237 _value = _getEndTimeAndValueOf4[1];238 return getLinearRampValueAtTime(time, _startTime, _value, nextAutomationEvent);239 }240 return this._defaultValue;241 }242 }]);243 return AutomationEventList;244 }();245 var createCancelAndHoldAutomationEvent = function createCancelAndHoldAutomationEvent(cancelTime) {246 return {247 cancelTime: cancelTime,248 type: 'cancelAndHold'249 };250 };251 var createCancelScheduledValuesAutomationEvent = function createCancelScheduledValuesAutomationEvent(cancelTime) {252 return {253 cancelTime: cancelTime,254 type: 'cancelScheduledValues'255 };256 };257 var createExponentialRampToValueAutomationEvent = function createExponentialRampToValueAutomationEvent(value, endTime) {258 return {259 endTime: endTime,260 type: 'exponentialRampToValue',261 value: value262 };263 };264 var createLinearRampToValueAutomationEvent = function createLinearRampToValueAutomationEvent(value, endTime) {265 return {266 endTime: endTime,267 type: 'linearRampToValue',268 value: value269 };270 };271 var createSetTargetAutomationEvent = function createSetTargetAutomationEvent(target, startTime, timeConstant) {272 return {273 startTime: startTime,274 target: target,275 timeConstant: timeConstant,276 type: 'setTarget'277 };278 };279 exports.AutomationEventList = AutomationEventList;280 exports.createCancelAndHoldAutomationEvent = createCancelAndHoldAutomationEvent;281 exports.createCancelScheduledValuesAutomationEvent = createCancelScheduledValuesAutomationEvent;282 exports.createExponentialRampToValueAutomationEvent = createExponentialRampToValueAutomationEvent;283 exports.createLinearRampToValueAutomationEvent = createLinearRampToValueAutomationEvent;284 exports.createSetTargetAutomationEvent = createSetTargetAutomationEvent;285 exports.createSetValueAutomationEvent = createSetValueAutomationEvent;286 exports.createSetValueCurveAutomationEvent = createSetValueCurveAutomationEvent;287 Object.defineProperty(exports, '__esModule', { value: true });...

Full Screen

Full Screen

automation-event-list.ts

Source:automation-event-list.ts Github

copy

Full Screen

1import { createExtendedExponentialRampToValueAutomationEvent } from '../functions/create-extended-exponential-ramp-to-value-automation-event';2import { createExtendedLinearRampToValueAutomationEvent } from '../functions/create-extended-linear-ramp-to-value-automation-event';3import { createSetValueAutomationEvent } from '../functions/create-set-value-automation-event';4import { createSetValueCurveAutomationEvent } from '../functions/create-set-value-curve-automation-event';5import { getEndTimeAndValueOfPreviousAutomationEvent } from '../functions/get-end-time-and-value-of-previous-automation-event';6import { getEventTime } from '../functions/get-event-time';7import { getExponentialRampValueAtTime } from '../functions/get-exponential-ramp-value-at-time';8import { getLinearRampValueAtTime } from '../functions/get-linear-ramp-value-at-time';9import { getTargetValueAtTime } from '../functions/get-target-value-at-time';10import { getValueCurveValueAtTime } from '../functions/get-value-curve-value-at-time';11import { getValueOfAutomationEventAtIndexAtTime } from '../functions/get-value-of-automation-event-at-index-at-time';12import { isAnyRampToValueAutomationEvent } from '../guards/any-ramp-to-value-automation-event';13import { isCancelAndHoldAutomationEvent } from '../guards/cancel-and-hold-automation-event';14import { isCancelScheduledValuesAutomationEvent } from '../guards/cancel-scheduled-values-automation-event';15import { isExponentialRampToValueAutomationEvent } from '../guards/exponential-ramp-to-value-automation-event';16import { isLinearRampToValueAutomationEvent } from '../guards/linear-ramp-to-value-automation-event';17import { isSetTargetAutomationEvent } from '../guards/set-target-automation-event';18import { isSetValueAutomationEvent } from '../guards/set-value-automation-event';19import { isSetValueCurveAutomationEvent } from '../guards/set-value-curve-automation-event';20import { TAutomationEvent, TPersistentAutomationEvent } from '../types';21export class AutomationEventList {22 private _automationEvents: TPersistentAutomationEvent[];23 private _currenTime: number;24 private _defaultValue: number;25 constructor(defaultValue: number) {26 this._automationEvents = [];27 this._currenTime = 0;28 this._defaultValue = defaultValue;29 }30 public [Symbol.iterator](): Iterator<TPersistentAutomationEvent> {31 return this._automationEvents[Symbol.iterator]();32 }33 public add(automationEvent: TAutomationEvent): boolean {34 const eventTime = getEventTime(automationEvent);35 if (isCancelAndHoldAutomationEvent(automationEvent) || isCancelScheduledValuesAutomationEvent(automationEvent)) {36 const index = this._automationEvents.findIndex((currentAutomationEvent) => {37 if (isCancelScheduledValuesAutomationEvent(automationEvent) && isSetValueCurveAutomationEvent(currentAutomationEvent)) {38 return currentAutomationEvent.startTime + currentAutomationEvent.duration >= eventTime;39 }40 return getEventTime(currentAutomationEvent) >= eventTime;41 });42 const removedAutomationEvent = this._automationEvents[index];43 if (index !== -1) {44 this._automationEvents = this._automationEvents.slice(0, index);45 }46 if (isCancelAndHoldAutomationEvent(automationEvent)) {47 const lastAutomationEvent = this._automationEvents[this._automationEvents.length - 1];48 if (removedAutomationEvent !== undefined && isAnyRampToValueAutomationEvent(removedAutomationEvent)) {49 if (isSetTargetAutomationEvent(lastAutomationEvent)) {50 throw new Error('The internal list is malformed.');51 }52 const startTime = isSetValueCurveAutomationEvent(lastAutomationEvent)53 ? lastAutomationEvent.startTime + lastAutomationEvent.duration54 : getEventTime(lastAutomationEvent);55 const startValue = isSetValueCurveAutomationEvent(lastAutomationEvent)56 ? lastAutomationEvent.values[lastAutomationEvent.values.length - 1]57 : lastAutomationEvent.value;58 const value = isExponentialRampToValueAutomationEvent(removedAutomationEvent)59 ? getExponentialRampValueAtTime(eventTime, startTime, startValue, removedAutomationEvent)60 : getLinearRampValueAtTime(eventTime, startTime, startValue, removedAutomationEvent);61 const truncatedAutomationEvent = isExponentialRampToValueAutomationEvent(removedAutomationEvent)62 ? createExtendedExponentialRampToValueAutomationEvent(value, eventTime, this._currenTime)63 : createExtendedLinearRampToValueAutomationEvent(value, eventTime, this._currenTime);64 this._automationEvents.push(truncatedAutomationEvent);65 }66 if (lastAutomationEvent !== undefined && isSetTargetAutomationEvent(lastAutomationEvent)) {67 this._automationEvents.push(createSetValueAutomationEvent(this.getValue(eventTime), eventTime));68 }69 if (70 lastAutomationEvent !== undefined &&71 isSetValueCurveAutomationEvent(lastAutomationEvent) &&72 lastAutomationEvent.startTime + lastAutomationEvent.duration > eventTime73 ) {74 this._automationEvents[this._automationEvents.length - 1] = createSetValueCurveAutomationEvent(75 new Float32Array([6, 7]),76 lastAutomationEvent.startTime,77 eventTime - lastAutomationEvent.startTime78 );79 }80 }81 } else {82 const index = this._automationEvents.findIndex((currentAutomationEvent) => getEventTime(currentAutomationEvent) > eventTime);83 const previousAutomationEvent =84 index === -1 ? this._automationEvents[this._automationEvents.length - 1] : this._automationEvents[index - 1];85 if (86 previousAutomationEvent !== undefined &&87 isSetValueCurveAutomationEvent(previousAutomationEvent) &&88 getEventTime(previousAutomationEvent) + previousAutomationEvent.duration > eventTime89 ) {90 return false;91 }92 const persistentAutomationEvent = isExponentialRampToValueAutomationEvent(automationEvent)93 ? createExtendedExponentialRampToValueAutomationEvent(automationEvent.value, automationEvent.endTime, this._currenTime)94 : isLinearRampToValueAutomationEvent(automationEvent)95 ? createExtendedLinearRampToValueAutomationEvent(automationEvent.value, eventTime, this._currenTime)96 : automationEvent;97 if (index === -1) {98 this._automationEvents.push(persistentAutomationEvent);99 } else {100 if (101 isSetValueCurveAutomationEvent(automationEvent) &&102 eventTime + automationEvent.duration > getEventTime(this._automationEvents[index])103 ) {104 return false;105 }106 this._automationEvents.splice(index, 0, persistentAutomationEvent);107 }108 }109 return true;110 }111 public flush(time: number): void {112 const index = this._automationEvents.findIndex((currentAutomationEvent) => getEventTime(currentAutomationEvent) > time);113 if (index > 1) {114 const remainingAutomationEvents = this._automationEvents.slice(index - 1);115 const firstRemainingAutomationEvent = remainingAutomationEvents[0];116 if (isSetTargetAutomationEvent(firstRemainingAutomationEvent)) {117 remainingAutomationEvents.unshift(118 createSetValueAutomationEvent(119 getValueOfAutomationEventAtIndexAtTime(120 this._automationEvents,121 index - 2,122 firstRemainingAutomationEvent.startTime,123 this._defaultValue124 ),125 firstRemainingAutomationEvent.startTime126 )127 );128 }129 this._automationEvents = remainingAutomationEvents;130 }131 }132 public getValue(time: number): number {133 if (this._automationEvents.length === 0) {134 return this._defaultValue;135 }136 const indexOfNextEvent = this._automationEvents.findIndex((automationEvent) => getEventTime(automationEvent) > time);137 const nextAutomationEvent = this._automationEvents[indexOfNextEvent];138 const indexOfCurrentEvent = (indexOfNextEvent === -1 ? this._automationEvents.length : indexOfNextEvent) - 1;139 const currentAutomationEvent = this._automationEvents[indexOfCurrentEvent];140 if (141 currentAutomationEvent !== undefined &&142 isSetTargetAutomationEvent(currentAutomationEvent) &&143 (nextAutomationEvent === undefined ||144 !isAnyRampToValueAutomationEvent(nextAutomationEvent) ||145 nextAutomationEvent.insertTime > time)146 ) {147 return getTargetValueAtTime(148 time,149 getValueOfAutomationEventAtIndexAtTime(150 this._automationEvents,151 indexOfCurrentEvent - 1,152 currentAutomationEvent.startTime,153 this._defaultValue154 ),155 currentAutomationEvent156 );157 }158 if (159 currentAutomationEvent !== undefined &&160 isSetValueAutomationEvent(currentAutomationEvent) &&161 (nextAutomationEvent === undefined || !isAnyRampToValueAutomationEvent(nextAutomationEvent))162 ) {163 return currentAutomationEvent.value;164 }165 if (166 currentAutomationEvent !== undefined &&167 isSetValueCurveAutomationEvent(currentAutomationEvent) &&168 (nextAutomationEvent === undefined ||169 !isAnyRampToValueAutomationEvent(nextAutomationEvent) ||170 currentAutomationEvent.startTime + currentAutomationEvent.duration > time)171 ) {172 if (time < currentAutomationEvent.startTime + currentAutomationEvent.duration) {173 return getValueCurveValueAtTime(time, currentAutomationEvent);174 }175 return currentAutomationEvent.values[currentAutomationEvent.values.length - 1];176 }177 if (178 currentAutomationEvent !== undefined &&179 isAnyRampToValueAutomationEvent(currentAutomationEvent) &&180 (nextAutomationEvent === undefined || !isAnyRampToValueAutomationEvent(nextAutomationEvent))181 ) {182 return currentAutomationEvent.value;183 }184 if (nextAutomationEvent !== undefined && isExponentialRampToValueAutomationEvent(nextAutomationEvent)) {185 const [startTime, value] = getEndTimeAndValueOfPreviousAutomationEvent(186 this._automationEvents,187 indexOfCurrentEvent,188 currentAutomationEvent,189 nextAutomationEvent,190 this._defaultValue191 );192 return getExponentialRampValueAtTime(time, startTime, value, nextAutomationEvent);193 }194 if (nextAutomationEvent !== undefined && isLinearRampToValueAutomationEvent(nextAutomationEvent)) {195 const [startTime, value] = getEndTimeAndValueOfPreviousAutomationEvent(196 this._automationEvents,197 indexOfCurrentEvent,198 currentAutomationEvent,199 nextAutomationEvent,200 this._defaultValue201 );202 return getLinearRampValueAtTime(time, startTime, value, nextAutomationEvent);203 }204 return this._defaultValue;205 }...

Full Screen

Full Screen

automation-event-list.js

Source:automation-event-list.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", {3 value: true4});5exports.AutomationEventList = void 0;6var _createExtendedExponentialRampToValueAutomationEvent = require("../functions/create-extended-exponential-ramp-to-value-automation-event");7var _createExtendedLinearRampToValueAutomationEvent = require("../functions/create-extended-linear-ramp-to-value-automation-event");8var _createSetValueAutomationEvent = require("../functions/create-set-value-automation-event");9var _createSetValueCurveAutomationEvent = require("../functions/create-set-value-curve-automation-event");10var _getEndTimeAndValueOfPreviousAutomationEvent = require("../functions/get-end-time-and-value-of-previous-automation-event");11var _getEventTime = require("../functions/get-event-time");12var _getExponentialRampValueAtTime = require("../functions/get-exponential-ramp-value-at-time");13var _getLinearRampValueAtTime = require("../functions/get-linear-ramp-value-at-time");14var _getTargetValueAtTime = require("../functions/get-target-value-at-time");15var _getValueCurveValueAtTime = require("../functions/get-value-curve-value-at-time");16var _getValueOfAutomationEventAtIndexAtTime = require("../functions/get-value-of-automation-event-at-index-at-time");17var _anyRampToValueAutomationEvent = require("../guards/any-ramp-to-value-automation-event");18var _cancelAndHoldAutomationEvent = require("../guards/cancel-and-hold-automation-event");19var _cancelScheduledValuesAutomationEvent = require("../guards/cancel-scheduled-values-automation-event");20var _exponentialRampToValueAutomationEvent = require("../guards/exponential-ramp-to-value-automation-event");21var _linearRampToValueAutomationEvent = require("../guards/linear-ramp-to-value-automation-event");22var _setTargetAutomationEvent = require("../guards/set-target-automation-event");23var _setValueAutomationEvent = require("../guards/set-value-automation-event");24var _setValueCurveAutomationEvent = require("../guards/set-value-curve-automation-event");25class AutomationEventList {26 constructor(defaultValue) {27 this._automationEvents = [];28 this._currenTime = 0;29 this._defaultValue = defaultValue;30 }31 [Symbol.iterator]() {32 return this._automationEvents[Symbol.iterator]();33 }34 add(automationEvent) {35 const eventTime = (0, _getEventTime.getEventTime)(automationEvent);36 if ((0, _cancelAndHoldAutomationEvent.isCancelAndHoldAutomationEvent)(automationEvent) || (0, _cancelScheduledValuesAutomationEvent.isCancelScheduledValuesAutomationEvent)(automationEvent)) {37 const index = this._automationEvents.findIndex(currentAutomationEvent => {38 if ((0, _cancelScheduledValuesAutomationEvent.isCancelScheduledValuesAutomationEvent)(automationEvent) && (0, _setValueCurveAutomationEvent.isSetValueCurveAutomationEvent)(currentAutomationEvent)) {39 return currentAutomationEvent.startTime + currentAutomationEvent.duration >= eventTime;40 }41 return (0, _getEventTime.getEventTime)(currentAutomationEvent) >= eventTime;42 });43 const removedAutomationEvent = this._automationEvents[index];44 if (index !== -1) {45 this._automationEvents = this._automationEvents.slice(0, index);46 }47 if ((0, _cancelAndHoldAutomationEvent.isCancelAndHoldAutomationEvent)(automationEvent)) {48 const lastAutomationEvent = this._automationEvents[this._automationEvents.length - 1];49 if (removedAutomationEvent !== undefined && (0, _anyRampToValueAutomationEvent.isAnyRampToValueAutomationEvent)(removedAutomationEvent)) {50 if ((0, _setTargetAutomationEvent.isSetTargetAutomationEvent)(lastAutomationEvent)) {51 throw new Error('The internal list is malformed.');52 }53 const startTime = (0, _setValueCurveAutomationEvent.isSetValueCurveAutomationEvent)(lastAutomationEvent) ? lastAutomationEvent.startTime + lastAutomationEvent.duration : (0, _getEventTime.getEventTime)(lastAutomationEvent);54 const startValue = (0, _setValueCurveAutomationEvent.isSetValueCurveAutomationEvent)(lastAutomationEvent) ? lastAutomationEvent.values[lastAutomationEvent.values.length - 1] : lastAutomationEvent.value;55 const value = (0, _exponentialRampToValueAutomationEvent.isExponentialRampToValueAutomationEvent)(removedAutomationEvent) ? (0, _getExponentialRampValueAtTime.getExponentialRampValueAtTime)(eventTime, startTime, startValue, removedAutomationEvent) : (0, _getLinearRampValueAtTime.getLinearRampValueAtTime)(eventTime, startTime, startValue, removedAutomationEvent);56 const truncatedAutomationEvent = (0, _exponentialRampToValueAutomationEvent.isExponentialRampToValueAutomationEvent)(removedAutomationEvent) ? (0, _createExtendedExponentialRampToValueAutomationEvent.createExtendedExponentialRampToValueAutomationEvent)(value, eventTime, this._currenTime) : (0, _createExtendedLinearRampToValueAutomationEvent.createExtendedLinearRampToValueAutomationEvent)(value, eventTime, this._currenTime);57 this._automationEvents.push(truncatedAutomationEvent);58 }59 if (lastAutomationEvent !== undefined && (0, _setTargetAutomationEvent.isSetTargetAutomationEvent)(lastAutomationEvent)) {60 this._automationEvents.push((0, _createSetValueAutomationEvent.createSetValueAutomationEvent)(this.getValue(eventTime), eventTime));61 }62 if (lastAutomationEvent !== undefined && (0, _setValueCurveAutomationEvent.isSetValueCurveAutomationEvent)(lastAutomationEvent) && lastAutomationEvent.startTime + lastAutomationEvent.duration > eventTime) {63 this._automationEvents[this._automationEvents.length - 1] = (0, _createSetValueCurveAutomationEvent.createSetValueCurveAutomationEvent)(new Float32Array([6, 7]), lastAutomationEvent.startTime, eventTime - lastAutomationEvent.startTime);64 }65 }66 } else {67 const index = this._automationEvents.findIndex(currentAutomationEvent => (0, _getEventTime.getEventTime)(currentAutomationEvent) > eventTime);68 const previousAutomationEvent = index === -1 ? this._automationEvents[this._automationEvents.length - 1] : this._automationEvents[index - 1];69 if (previousAutomationEvent !== undefined && (0, _setValueCurveAutomationEvent.isSetValueCurveAutomationEvent)(previousAutomationEvent) && (0, _getEventTime.getEventTime)(previousAutomationEvent) + previousAutomationEvent.duration > eventTime) {70 return false;71 }72 const persistentAutomationEvent = (0, _exponentialRampToValueAutomationEvent.isExponentialRampToValueAutomationEvent)(automationEvent) ? (0, _createExtendedExponentialRampToValueAutomationEvent.createExtendedExponentialRampToValueAutomationEvent)(automationEvent.value, automationEvent.endTime, this._currenTime) : (0, _linearRampToValueAutomationEvent.isLinearRampToValueAutomationEvent)(automationEvent) ? (0, _createExtendedLinearRampToValueAutomationEvent.createExtendedLinearRampToValueAutomationEvent)(automationEvent.value, eventTime, this._currenTime) : automationEvent;73 if (index === -1) {74 this._automationEvents.push(persistentAutomationEvent);75 } else {76 if ((0, _setValueCurveAutomationEvent.isSetValueCurveAutomationEvent)(automationEvent) && eventTime + automationEvent.duration > (0, _getEventTime.getEventTime)(this._automationEvents[index])) {77 return false;78 }79 this._automationEvents.splice(index, 0, persistentAutomationEvent);80 }81 }82 return true;83 }84 flush(time) {85 const index = this._automationEvents.findIndex(currentAutomationEvent => (0, _getEventTime.getEventTime)(currentAutomationEvent) > time);86 if (index > 1) {87 const remainingAutomationEvents = this._automationEvents.slice(index - 1);88 const firstRemainingAutomationEvent = remainingAutomationEvents[0];89 if ((0, _setTargetAutomationEvent.isSetTargetAutomationEvent)(firstRemainingAutomationEvent)) {90 remainingAutomationEvents.unshift((0, _createSetValueAutomationEvent.createSetValueAutomationEvent)((0, _getValueOfAutomationEventAtIndexAtTime.getValueOfAutomationEventAtIndexAtTime)(this._automationEvents, index - 2, firstRemainingAutomationEvent.startTime, this._defaultValue), firstRemainingAutomationEvent.startTime));91 }92 this._automationEvents = remainingAutomationEvents;93 }94 }95 getValue(time) {96 if (this._automationEvents.length === 0) {97 return this._defaultValue;98 }99 const indexOfNextEvent = this._automationEvents.findIndex(automationEvent => (0, _getEventTime.getEventTime)(automationEvent) > time);100 const nextAutomationEvent = this._automationEvents[indexOfNextEvent];101 const indexOfCurrentEvent = (indexOfNextEvent === -1 ? this._automationEvents.length : indexOfNextEvent) - 1;102 const currentAutomationEvent = this._automationEvents[indexOfCurrentEvent];103 if (currentAutomationEvent !== undefined && (0, _setTargetAutomationEvent.isSetTargetAutomationEvent)(currentAutomationEvent) && (nextAutomationEvent === undefined || !(0, _anyRampToValueAutomationEvent.isAnyRampToValueAutomationEvent)(nextAutomationEvent) || nextAutomationEvent.insertTime > time)) {104 return (0, _getTargetValueAtTime.getTargetValueAtTime)(time, (0, _getValueOfAutomationEventAtIndexAtTime.getValueOfAutomationEventAtIndexAtTime)(this._automationEvents, indexOfCurrentEvent - 1, currentAutomationEvent.startTime, this._defaultValue), currentAutomationEvent);105 }106 if (currentAutomationEvent !== undefined && (0, _setValueAutomationEvent.isSetValueAutomationEvent)(currentAutomationEvent) && (nextAutomationEvent === undefined || !(0, _anyRampToValueAutomationEvent.isAnyRampToValueAutomationEvent)(nextAutomationEvent))) {107 return currentAutomationEvent.value;108 }109 if (currentAutomationEvent !== undefined && (0, _setValueCurveAutomationEvent.isSetValueCurveAutomationEvent)(currentAutomationEvent) && (nextAutomationEvent === undefined || !(0, _anyRampToValueAutomationEvent.isAnyRampToValueAutomationEvent)(nextAutomationEvent) || currentAutomationEvent.startTime + currentAutomationEvent.duration > time)) {110 if (time < currentAutomationEvent.startTime + currentAutomationEvent.duration) {111 return (0, _getValueCurveValueAtTime.getValueCurveValueAtTime)(time, currentAutomationEvent);112 }113 return currentAutomationEvent.values[currentAutomationEvent.values.length - 1];114 }115 if (currentAutomationEvent !== undefined && (0, _anyRampToValueAutomationEvent.isAnyRampToValueAutomationEvent)(currentAutomationEvent) && (nextAutomationEvent === undefined || !(0, _anyRampToValueAutomationEvent.isAnyRampToValueAutomationEvent)(nextAutomationEvent))) {116 return currentAutomationEvent.value;117 }118 if (nextAutomationEvent !== undefined && (0, _exponentialRampToValueAutomationEvent.isExponentialRampToValueAutomationEvent)(nextAutomationEvent)) {119 const [startTime, value] = (0, _getEndTimeAndValueOfPreviousAutomationEvent.getEndTimeAndValueOfPreviousAutomationEvent)(this._automationEvents, indexOfCurrentEvent, currentAutomationEvent, nextAutomationEvent, this._defaultValue);120 return (0, _getExponentialRampValueAtTime.getExponentialRampValueAtTime)(time, startTime, value, nextAutomationEvent);121 }122 if (nextAutomationEvent !== undefined && (0, _linearRampToValueAutomationEvent.isLinearRampToValueAutomationEvent)(nextAutomationEvent)) {123 const [startTime, value] = (0, _getEndTimeAndValueOfPreviousAutomationEvent.getEndTimeAndValueOfPreviousAutomationEvent)(this._automationEvents, indexOfCurrentEvent, currentAutomationEvent, nextAutomationEvent, this._defaultValue);124 return (0, _getLinearRampValueAtTime.getLinearRampValueAtTime)(time, startTime, value, nextAutomationEvent);125 }126 return this._defaultValue;127 }128}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var automation = new stf.Automation(device);3automation.connect(function(err) {4 if (err) {5 console.error('Could not connect to device', err);6 return;7 }8 automation.tap(100, 100);9 automation.swipe(100, 100, 200, 200);10 automation.input('Hello World!');11 automation.shell('am start -n com.example.foo/.MainActivity');12 automation.disconnect();13});14var stf = require('devicefarmer-stf');15var minicap = new stf.Minicap(device);16minicap.connect(function(err) {17 if (err) {18 console.error('Could not connect to device', err);19 return;20 }21 minicap.on('frame', function(frame) {22 console.log('Got frame', frame);23 });24 minicap.disconnect();25});26var stf = require('devicefarmer-stf');27var minitouch = new stf.Minitouch(device);28minitouch.connect(function(err) {29 if (err) {30 console.error('Could not connect to device', err);31 return;32 }33 minitouch.on('touch', function(touch) {34 console.log('Got touch', touch);35 });36 minitouch.disconnect();37});38var stf = require('devicefarmer-stf');39var minitouch = new stf.Minitouch(device);40minitouch.connect(function(err) {41 if (err) {42 console.error('Could not connect to device', err);43 return;44 }45 minitouch.on('touch', function(touch) {46 console.log('Got touch', touch);47 });48 minitouch.disconnect();49});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require("devicefarmer-stf");2var automation = new stf.Automation();3automation.connect(function(err, api) {4 if (err) {5 console.log("Error connecting to STF: " + err);6 process.exit(1);7 }8 console.log("Connected to STF");9 api.getDevices(function(err, devices) {10 if (err) {11 console.log("Error getting devices: " + err);12 process.exit(1);13 }14 console.log("Devices: " + JSON.stringify(devices, null, 4));15 });16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var device = client.getDevice('device id');3device.use(function(err, device) {4 if (err) {5 console.log(err);6 } else {7 device.shell('monkey -p com.android.settings -c android.intent.category.LAUNCHER 1');8 device.shell('input keyevent 3');9 device.shell('input keyevent 82');10 device.shell('input text "devicefarmer"');11 device.shell('input keyevent 66');12 device.shell('input keyevent 4');13 }14});15var stf = require('devicefarmer-stf');16var device = client.getDevice('device id');17device.use(function(err, device) {18 if (err) {19 console.log(err);20 } else {21 device.shell('monkey -p com.android.settings -c android.intent.category.LAUNCHER 1');22 device.shell('input keyevent 3');23 device.shell('input keyevent 82');24 device.shell('input text "devicefarmer"');25 device.shell('input keyevent 66');26 device.shell('input keyevent 4');27 }28});29var stf = require('devicefarmer-stf');30var device = client.getDevice('device id');31device.use(function(err, device) {32 if (err) {33 console.log(err);34 } else {35 device.shell('monkey -p com.android.settings -c android.intent.category.LAUNCHER 1');36 device.shell('input keyevent 3');37 device.shell('input keyevent 82');38 device.shell('input text "devicefarmer"');39 device.shell('input keyevent 66');40 device.shell('input keyevent 4');41 }42});43var stf = require('devicefarmer-stf');44var device = client.getDevice('device id');

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('automation');2var adb = require('adbkit');3var client = adb.createClient();4var stf = require('automation');5var util = require('util');6var device = require('automation');

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 devicefarmer-stf 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