How to use patchRow method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

coordinatePatch.js

Source:coordinatePatch.js Github

copy

Full Screen

1/* eslint-env node */2"use strict";3var fluid = require("infusion");4var hortis = fluid.registerNamespace("hortis");5// TODO: grab this from the fusion's input map6hortis.stableDatasetIds = {7 iNat: true,8 CMN: true,9 RBCM: true10};11// Also in leafletMap.js12hortis.datasetIdFromObs = function (obsId) {13 var colpos = obsId.indexOf(":");14 return obsId.substring(0, colpos);15};16hortis.equalCoordinate = function (a, b) {17 // 6 decimals is a common standard - about 10cm accuracy, e.g. RBCM truncated to this18 return Math.abs(a - b) < 1e-6;19};20hortis.equalCoordinates = function (lat1, long1, lat2, long2) {21 return hortis.equalCoordinate(lat1, lat2) && hortis.equalCoordinate(long1, long2);22};23hortis.matchOnePatchRow = function (patchRow, obsRow) {24 var score = 0;25 if (patchRow.id === obsRow.observationId) {26 var dataset = hortis.datasetIdFromObs(patchRow.id);27 score += hortis.stableDatasetIds[dataset] ? 1 : 0.5;28 }29 if (hortis.equalCoordinates(patchRow.latitude, patchRow.longitude, obsRow.latitude, obsRow.longitude)) {30 score += 1;31 }32 if (patchRow.iNaturalistTaxonName === obsRow.iNaturalistTaxonName) {33 score += 1;34 }35 return score;36};37hortis.dumpPatchRow = function (patchRow, loc) {38 return Object.values(patchRow).join(", ") + loc;39};40hortis.dumpObsMatch = function (match) {41 var obs = match.obsRow;42 return "obs of " + obs.iNaturalistTaxonName + " with coordinates " + JSON.stringify(obs.latitude) + ", " + JSON.stringify(obs.longitude) +43 " with id " + obs.observationId + " at index " + match.obsIndex;44};45/** Returns one match or null, plus some side-effects46 * @param {Object} patchRow - One row of the patch file47 * @param {ObsRow[]} obsRows - All observation rows48 * @param {String} loc - A diagnostic string indicating the location of the `patchRow`49 * @return {ObsRow|Null} The best matching observation row, or null50 */51hortis.matchCoordinatePatch = function (patchRow, obsRows, loc) {52 var matches = [];53 obsRows.forEach(function (obsRow, obsIndex) {54 var score = hortis.matchOnePatchRow(patchRow, obsRow);55 if (score > 0) {56 matches.push({57 score: score,58 obsRow: obsRow,59 obsIndex: obsIndex60 });61 }62 });63 var diag = "Warning: patch " + hortis.dumpPatchRow(patchRow, loc);64 if (matches.length === 0) {65 console.log(diag + " failed to match in any coordinate");66 return null;67 } else {68 matches.sort(function (a, b) {69 return b.score - a.score;70 });71 var topScore = matches[0].score;72 var topScoring = matches.filter(function (match) {73 return match.score === topScore;74 });75 if (topScoring.length > 1) {76 console.log(diag + " matched " + topScoring.length + " rows equally well: these were: "77 + topScoring.map(hortis.dumpObsMatch).join("\n"));78 } else if (topScore < 2.5) {79 console.log(diag + " matched " + hortis.dumpObsMatch(topScoring[0]) + " with reduced accuracy of " + topScore);80 var obsRow = topScoring[0].obsRow;81 console.log(hortis.equalCoordinates(patchRow.latitude, patchRow.longitude, obsRow.latitude, obsRow.longitude));82 }83 return topScoring[0].obsRow;84 }85};86hortis.coordinatesOutMap = {87 columns: {88 coordinatesCorrected: "Coordinates Corrected",89 coordinatesCorrectedNote: "Coordinates Corrected Note"90 }91};92hortis.parseToNumber = function (row, field) {93 var parsed = hortis.parseFloat(row[field]);94 row[field] = parsed;95};96hortis.patchNumberFields = ["latitude", "longitude", "latitudeOut", "longitudeOut"];97/**98 * Resolve a coordinate patch file against the observation list99 * @param {Object} resolved - Resolved observations containing members obsOutMap and obsRows which will be modified100 * @param {PatchFile} patch - The loaded patch structure101 * @param {String} key - Key of the patch102 */103hortis.processCoordinatePatch = function (resolved, patch, key) {104 patch.patchData.rows.forEach(function (patchRow, index) {105 var loc = " at row " + index + " of patch " + key;106 hortis.patchNumberFields.forEach(function (field) {107 hortis.parseToNumber(patchRow, field);108 });109 var match = hortis.matchCoordinatePatch(patchRow, resolved.obsRows, loc);110 var expectCoordinates = function (testEqual) {111 var equal = hortis.equalCoordinates(match.latitude, match.longitude, patchRow.latitudeOut, patchRow.longitudeOut);112 if (equal !== testEqual) {113 console.log("Error: Coordinate corrected value for patch " + hortis.dumpPatchRow(patchRow, loc) + " does not conform with original coordinates "114 + match.latitude + ", " + match.longitude + " since value of \"Corrected\" is " + patchRow.corrected);115 }116 };117 if (match) {118 if (patchRow.corrected === "yes") {119 expectCoordinates(false);120 match.coordinatesCorrected = "yes";121 } else if (patchRow.corrected === "no") {122 expectCoordinates(true);123 match.coordinatesCorrected = "no";124 } else {125 console.log("Unexpected \"Corrected\" value " + patchRow.corrected + " for patch " + hortis.dumpPatchRow(patchRow, loc));126 }127 match.latitude = patchRow.latitudeOut;128 match.longitude = patchRow.longitudeOut;129 match.coordinatesCorrectedNote = patchRow.correction;130 }131 });132 resolved.combinedObsOutMap = hortis.combineMaps([resolved.combinedObsOutMap, hortis.coordinatesOutMap]);...

Full Screen

Full Screen

grid_remote_model.js

Source:grid_remote_model.js Github

copy

Full Screen

1(function($) {2 $.extend(true, window, {3 "Dirigible": {4 "GridRemoteModel": GridRemoteModel5 }6 });7 function GridRemoteModel(urls) {8 var self = this;9 self.data = [];10 self.url = urls.getJSONGridData;11 self.patches = {};12 self.pending = {};13 self.patchWidth = 26;14 self.patchHeight = 100;15 16 self.getLength = function() {17 return self.data.length;18 };19 20 self.getItem = function(index) {21 return self.data[index];22 };23 self.cellToPatch = function(col, row) {24 return {25 patchCol: Math.floor( Math.max((col - 1), 0) / self.patchWidth ),26 patchRow: Math.floor( Math.max((row - 1), 0) / self.patchHeight )27 };28 };29 self.patchToCells = function(patch) {30 return {31 left: patch.patchCol * self.patchWidth + 1,32 topmost: patch.patchRow * self.patchHeight + 1,33 right: patch.patchCol * self.patchWidth + self.patchWidth,34 bottom: patch.patchRow * self.patchHeight + self.patchHeight35 };36 };37 self.choosePatchesToLoad = function(left, topmost, right, bottom) {38 var patchesToLoad = [];39 var nw = self.cellToPatch(left, topmost);40 var se = self.cellToPatch(right, bottom);41 for (var patchCol = nw.patchCol; patchCol <= se.patchCol; patchCol++) {42 for (var patchRow = nw.patchRow; patchRow <= se.patchRow; patchRow++) {43 patchesToLoad.push( { patchCol: patchCol, patchRow: patchRow } );44 }45 }46 return patchesToLoad;47 };48 self.isPatchLoadedOrPending = function(patch) {49 if (self.patches[patch.patchCol] !== undefined) {50 if(self.patches[patch.patchCol][patch.patchRow] !== undefined){51 return true;52 }53 }54 if (self.pending[patch.patchCol] !== undefined) {55 if(self.pending[patch.patchCol][patch.patchRow] !== undefined){56 return true;57 }58 }59 return false;60 };61 self.loadPatchIfNecessary = function(patch) {62 if (!self.isPatchLoadedOrPending(patch)) {63 var range = self.patchToCells(patch);64 if (self.pending[patch.patchCol] === undefined){65 self.pending[patch.patchCol] = {};66 }67 self.pending[patch.patchCol][patch.patchRow] = true;68 self.onDataLoading.notify();69 self.getData(range.left, range.topmost, range.right, range.bottom, patch);70 }71 };72 self.getData = function (left, topmost, right, bottom, patch) {73 var range = left + ', ' + topmost + ', ' + right + ', ' + bottom;74 $.getJSON(self.url, {'range' : range}, self.getSuccessHandlerForPatch(patch) );75 };76 self.ensureData = function(left, topmost, right, bottom) {77 var patchesToLoad = self.choosePatchesToLoad(left, topmost, right, bottom);78 for (var patch=0; patch<patchesToLoad.length; patch++) {79 self.loadPatchIfNecessary(patchesToLoad[patch]);80 }81 };82 self.onDataLoading = new Slick.Event();83 self.onDataLoaded = new Slick.Event();84 self.onError = function(fromPage,toPage) {85 console.log("error loading pages " + fromPage + " to " + toPage);86 };87 self.addData = function(jsonData) {88 for (var row=jsonData.topmost; row <= jsonData.bottom; row++ ) {89 if (self.data[row - 1] === undefined) {90 self.data[row - 1] = { header: row };91 }92 for (93 var column=jsonData.left;94 column <= jsonData.right;95 column++)96 {97 if (98 jsonData[row] !== undefined &&99 jsonData[row][column] !== undefined)100 {101 self.data[row - 1][column] = jsonData[row][column];102 } else {103 delete self.data[row - 1][column];104 }105 }106 }107 };108 self.getSuccessHandlerForPatch = function(patch) {109 return function(jsonData) {110 self.onSuccess(jsonData);111 var expectedArea = self.patchToCells(patch);112 if (jsonData.left > expectedArea.left 113 || jsonData.topmost > expectedArea.topmost 114 || jsonData.right < expectedArea.right 115 || jsonData.bottom < expectedArea.bottom){116 return117 }118 if (self.patches[patch.patchCol] === undefined){119 self.patches[patch.patchCol] = {};120 }121 self.patches[patch.patchCol][patch.patchRow] = true;122 if (self.pending[patch.patchCol] !== undefined) {123 delete self.pending[patch.patchCol][patch.patchRow];124 }125 };126 };127 self.onSuccess = function(jsonData) {128 self.addData(jsonData);129 self.onDataLoaded.notify({130 left: jsonData.left,131 topmost: jsonData.topmost,132 right: jsonData.right,133 bottom: jsonData.bottom134 });135 };136 self.reset = function(newData) {137 self.data = newData;138 self.patches = {};139 self.pending = {};140 };141 }...

Full Screen

Full Screen

crud.js

Source:crud.js Github

copy

Full Screen

...15 const data = {16 id: patchID,17 quantity: patchQuantity + quantity,18 }19 await patchRow(data, patchMessage)20 const deleteMessage = `delete(${rowData.id}: ${rowData.title}) success:`21 22 await deleteRow(rowData, deleteMessage)23}24async function updateLessThanExpected(25 todoModel, rowData, newStatus, quantity, expected26) {27 const { patchID, patchQuantity } = 28 getPatchInfo(todoModel, newStatus, rowData)29 const nextStatusMessage = 30 `update new task [${patchID}] with status += 1 to be it.quantity ` +31 `[${patchQuantity}] + this.quantity [${quantity}]`32 const nextStatusData = {33 id: patchID,34 quantity: patchQuantity + quantity,35 }36 await patchRow(nextStatusData, nextStatusMessage)37 const currentStatusMessage = "current task expected -= quantity"38 const currentStatusData = {39 ...rowData,40 quantity: expected - quantity,41 }42 await patchRow(currentStatusData, currentStatusMessage)43}44async function updateGreaterThanExpected(45 todoModel, rowData, newStatus, quantity 46) {47 const { patchID, patchQuantity } = 48 getPatchInfo(todoModel, newStatus, rowData)49 const message = 50 `task expected += extra (or rather expected <- quantity), ` +51 `and add it to task in the next status list [${patchID}]`52 const data = {53 id: patchID,54 quantity: patchQuantity + quantity,55 }56 await patchRow(data, message)57 await deleteRow({id: rowData.id}, "clean up old row")58}59/************************************************************60 * Shift Todo Form 61 * (Same as update, but no identical task in next status section)62 ************************************************************/63async function shiftNormal(rowData, newStatus) {64 const message = "update task status += 1 (and ++1 if skipping oil)"65 const data = {66 ...rowData,67 status: newStatus,68 }69 await patchRow(data, message)70}71async function shiftLessThanExpected(rowData, newStatus, quantity, expected) {72 const postMessage = "new task of quantity with status += 1 (++ if no oil)"73 const postData = {74 ...rowData,75 id: undefined, // let django model assign new id for the ect76 quantity: quantity,77 status: newStatus,78 }79 await postRow(postData, postMessage)80 const patchMessage = "current task expected -= quantity"81 const patchData = {82 ...rowData,83 quantity: expected - quantity,84 }85 await patchRow(patchData, patchMessage)86}87async function shiftGreaterThanExpected(rowData, quantity) {88 const message = 89 "task expected += extra (or rather expected <- quantity)," +90 "and status += 1"91 const data = {92 ...rowData,93 quantity: quantity, // new quantity94 status: rowData.status + 1,95 }96 await patchRow(data, message)97}98export async function onCreate(newStatus, rowData, numVal) {99 if (!(newStatus && rowData && numVal)) throw Error("Undefined Parameters")100 const quantity = parseInt(numVal)101 const expected = parseInt(rowData.quantity)102 103 if (quantity === expected)104 shiftNormal(rowData, newStatus)105 106 else if (quantity < expected)107 shiftLessThanExpected(rowData, newStatus, quantity, expected)108 109 else if (quantity > expected)110 shiftGreaterThanExpected(rowData, quantity) 111}112export async function onUpdate(todoModel, rowData, numVal) {113 114 try {115 // define116 const quantity = parseInt(numVal)117 const expected = parseInt(rowData.quantity)118 let newStatus = rowData.status + 1119 if (!rowData.toOil && (rowData.status + 1) === 3) newStatus++120 if (newStatus > 5) // abort121 throw new Error("cannot update status above 5")122 // if item with same title/new status not found, create new123 const statusFound = r => r.status === newStatus124 const titleFound = r => r.title === rowData.title125 console.log({126 "item with same title/new status not found":127 todoModel.filter(statusFound).filter(titleFound).length <= 0128 })129 if (todoModel.filter(statusFound).filter(titleFound).length <= 0) {130 console.log("no matching task found to merge")131 onCreate(newStatus, rowData, numVal)132 return133 }134 // else update135 if (quantity === expected)136 await updateNormal(todoModel, rowData, newStatus, quantity)137 if (quantity < expected)138 await updateLessThanExpected(139 todoModel, rowData, newStatus, quantity, expected140 )141 if (quantity > expected)142 await updateGreaterThanExpected(143 todoModel, rowData, newStatus, quantity144 )145 }146 catch (error) {147 console.error(error)148 }149}150export async function onDiscard(rowData) {151 try {152 const message = `discarding ${rowData.id}:${rowData.title}`153 154 const data = {155 ...rowData,156 discarded: true157 }158 await patchRow(data, message)159 }160 161 catch(error) {162 console.error(error)163 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stfAppium = require('devicefarmer-stf-appium');2var device = stf.getDevice('1234567890');3var appium = device.getAppium();4appium.patchRow(1, 'text', 'new text');5var stfAppium = require('devicefarmer-stf-appium');6var device = stf.getDevice('1234567890');7var appium = device.getAppium();8appium.patchRow(1, 'text', 'new text');9var stfAppium = require('devicefarmer-stf-appium');10var device = stf.getDevice('1234567890');11var appium = device.getAppium();12appium.patchRow(1, 'text', 'new text');13var stfAppium = require('devicefarmer-stf-appium');

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var device = new stf.Device({serial:'0123456789ABCDEF'});3device.patchRow({present:true}).then(function(result) {4 console.log(result);5});6var stf = require('devicefarmer-stf');7var device = new stf.Device({serial:'0123456789ABCDEF'});8device.patchRow({present:false}).then(function(result) {9 console.log(result);10});11var stf = require('devicefarmer-stf');12var device = new stf.Device({serial:'0123456789ABCDEF'});13device.patchRow({present:null}).then(function(result) {14 console.log(result);15});16var stf = require('devicefarmer-stf');17var device = new stf.Device({serial:'0123456789ABCDEF'});18device.patchRow({present:undefined}).then(function(result) {19 console.log(result);20});21var stf = require('devicefarmer-stf');22var device = new stf.Device({serial:'0123456789ABCDEF'});23device.patchRow({present:0}).then(function(result) {24 console.log(result);25});26var stf = require('devicefarmer-stf');27var device = new stf.Device({serial:'0123456789ABCDEF'});28device.patchRow({present:1}).then(function(result) {29 console.log(result);30});31var stf = require('devicefarmer-stf');32var device = new stf.Device({serial:'0123456789ABCDEF'});33device.patchRow({present:2}).then(function(result) {34 console.log(result);35});36var stf = require('devicefarmer-stf');37var device = new stf.Device({serial:'012345678

Full Screen

Using AI Code Generation

copy

Full Screen

1var Client = require('devicefarmer-stf-client');2client.patchRow('2c0f5f5d', {present: true}, function(err, result) {3 if (err) {4 console.log('ERROR: ' + err);5 }6 console.log(result);7});8var Client = require('devicefarmer-stf-client');9client.getDevice('2c0f5f5d', function(err, result) {10 if (err) {11 console.log('ERROR: ' + err);12 }13 console.log(result);14});15var Client = require('devicefarmer-stf-client');16client.getDevices(function(err, result) {17 if (err) {18 console.log('ERROR: ' + err);19 }20 console.log(result);21});22var Client = require('devicefarmer-stf-client');23client.getDevicesByUser('2c0f5f5d', function(err, result) {24 if (err) {25 console.log('ERROR: ' + err);26 }27 console.log(result);28});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = client.getDevice('4d004c0d0f4b0e00');3device.patchRow('battery', 50);4device.patchRow('battery', 100);5var stf = require('devicefarmer-stf-client');6var device = client.getDevice('4d004c0d0f4b0e00');7device.patchRow('battery', 50);8device.patchRow('battery', 100);9var stf = require('devicefarmer-stf-client');10var device = client.getDevice('4d004c0d0f4b0e00');11device.patchRow('battery', 50);12device.patchRow('battery', 100);13var stf = require('devicefarmer-stf-client');14var device = client.getDevice('4d004c0d0f4b0e00');15device.patchRow('battery', 50);16device.patchRow('battery', 100);17var stf = require('devicefarmer-stf-client');18var device = client.getDevice('4d004c0d0f4b0e00');19device.patchRow('battery', 50);20device.patchRow('battery', 100);21var stf = require('devicefarmer-stf-client');22var device = client.getDevice('4d004c0d0f4b0e00');23device.patchRow('battery', 50);24device.patchRow('battery

Full Screen

Using AI Code Generation

copy

Full Screen

1var device = require('devicefarmer-stf-android-provider/lib/adb/device');2device.patchRow('5b5c5e9b', {owner: '5b5c5e9b'});3var device = require('devicefarmer-stf-android-provider/lib/adb/device');4device.patchRow('5b5c5e9b', {owner: '5b5c5e9b'});5var device = require('devicefarmer-stf-android-provider/lib/adb/device');6device.patchRow('5b5c5e9b', {owner: '5b5c5e9b'});7var device = require('devicefarmer-stf-android-provider/lib/adb/device');8device.patchRow('5b5c5e9b', {owner: '5b5c5e9b'});9var device = require('devicefarmer-stf-android-provider/lib/adb/device');10device.patchRow('5b5c5e9b', {owner: '5b5c5e9b'});11var device = require('devicefarmer-stf-android-provider/lib/adb/device');12device.patchRow('5b5c5e9

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