Best JavaScript code snippet using devicefarmer-stf
group-list-controller.js
Source:group-list-controller.js
...41 $scope.pendingGroups += incr42 }43 $scope.readyGroups = $scope.groups.length - $scope.activeGroups - $scope.pendingGroups44 }45 function updateStateStats(oldGroup, newGroup) {46 if (oldGroup === null) {47 incrStateStats(newGroup, 1)48 }49 else if (newGroup === null) {50 incrStateStats(oldGroup, -1)51 }52 else {53 if (newGroup.isActive && !oldGroup.isActive) {54 incrStateStats(newGroup, 1)55 }56 else if (!newGroup.isActive && oldGroup.isActive) {57 incrStateStats(oldGroup, -1)58 }59 else if (newGroup.state === 'ready' && oldGroup.state === 'pending') {60 incrStateStats(oldGroup, -1)61 }62 }63 }64 function updateGroupExtraProperties(group) {65 const status = {pending: 'Pending', waiting: 'Waiting', ready: 'Ready'}66 group.status = group.isActive ? 'Active' : status[group.state]67 group.startTime = $filter('date')(group.dates[0].start, SettingsService.get('dateFormat'))68 group.stopTime = $filter('date')(group.dates[0].stop, SettingsService.get('dateFormat'))69 }70 function updateQuotaBar(bar, consumed, allocated) {71 bar.value = (consumed / allocated) * 100 | 072 if (bar.value < 25) {73 bar.type = 'success'74 }75 else if (bar.value < 50) {76 bar.type = 'info'77 }78 else if (bar.value < 75) {79 bar.type = 'warning'80 }81 else {82 bar.type = 'danger'83 }84 }85 function updateQuotaBars() {86 updateQuotaBar(87 $scope.numberBar88 , $scope.user.groups.quotas.consumed.number89 , $scope.user.groups.quotas.allocated.number90 )91 updateQuotaBar(92 $scope.durationBar93 , $scope.user.groups.quotas.consumed.duration94 , $scope.user.groups.quotas.allocated.duration95 )96 }97 function addGroup(group, timeStamp) {98 if (CommonService.add(99 $scope.groups100 , groupsById101 , group102 , 'id'103 , timeStamp)) {104 $scope.groupsEnv[group.id] = {105 devices: []106 , users: []107 }108 groupsEnv[group.id] = {109 devicesBySerial: {}110 , usersByEmail: {}111 }112 updateStateStats(null, group)113 updateGroupExtraProperties(group)114 return group115 }116 return null117 }118 function updateGroup(group, timeStamp) {119 return CommonService.update(120 $scope.groups121 , groupsById122 , group123 , 'id'124 , timeStamp)125 }126 function deleteGroup(id, timeStamp) {127 const group = CommonService.delete(128 $scope.groups129 , groupsById130 , id131 , timeStamp)132 if (group) {133 updateStateStats(group, null)134 delete $scope.groupsEnv[group.id]135 delete groupsEnv[group.id]136 }137 return group138 }139 function addUser(user, timeStamp) {140 if (CommonService.add(141 users142 , usersByEmail143 , user144 , 'email'145 , timeStamp146 ) && typeof groupUserToAdd[user.email] !== 'undefined') {147 addGroupUser(148 groupUserToAdd[user.email].id149 , user.email150 , groupUserToAdd[user.email].timeStamp)151 delete groupUserToAdd[user.email]152 }153 }154 function deleteUser(email, timeStamp) {155 return CommonService.delete(156 users157 , usersByEmail158 , email159 , timeStamp)160 }161 function addDevice(device, timeStamp) {162 return CommonService.add(163 devices164 , devicesBySerial165 , device166 , 'serial'167 , timeStamp)168 }169 function updateDevice(device, timeStamp) {170 return CommonService.update(171 devices172 , devicesBySerial173 , device174 , 'serial'175 , timeStamp)176 }177 function deleteDevice(serial, timeStamp) {178 return CommonService.delete(179 devices180 , devicesBySerial181 , serial182 , timeStamp)183 }184 function addGroupUser(id, email, timeStamp) {185 if (CommonService.isExisting(usersByEmail[email])) {186 CommonService.add(187 $scope.groupsEnv[id].users188 , groupsEnv[id].usersByEmail189 , users[usersByEmail[email].index]190 , 'email'191 , timeStamp)192 }193 else {194 groupUserToAdd[email] = {id: id, timeStamp: timeStamp}195 }196 }197 function deleteGroupUser(id, email, timeStamp) {198 CommonService.delete(199 $scope.groupsEnv[id].users200 , groupsEnv[id].usersByEmail201 , email202 , timeStamp)203 }204 function addGroupDevice(id, serial, timeStamp) {205 if (CommonService.isExisting(devicesBySerial[serial])) {206 CommonService.add(207 $scope.groupsEnv[id].devices208 , groupsEnv[id].devicesBySerial209 , devices[devicesBySerial[serial].index]210 , 'serial'211 , timeStamp)212 }213 else {214 GroupsService.getGroupDevice(id, serial, deviceFields)215 .then(function(response) {216 if (addDevice(response.data.device, timeStamp)) {217 CommonService.add(218 $scope.groupsEnv[id].devices219 , groupsEnv[id].devicesBySerial220 , devices[devicesBySerial[serial].index]221 , 'serial'222 , timeStamp)223 }224 })225 }226 }227 function deleteGroupDevice(id, serial, timeStamp) {228 CommonService.delete(229 $scope.groupsEnv[id].devices230 , groupsEnv[id].devicesBySerial231 , serial232 , timeStamp)233 }234 function updateGroupDevices(group, isAddedDevice, devices, timeStamp) {235 if (devices.length) {236 if (isAddedDevice) {237 devices.forEach(function(serial) {238 addGroupDevice(group.id, serial, timeStamp)239 })240 }241 else {242 devices.forEach(function(serial) {243 deleteGroupDevice(group.id, serial, timeStamp)244 })245 }246 }247 }248 function updateGroupUsers(group, isAddedUser, users, timeStamp) {249 if (users.length) {250 if (isAddedUser) {251 users.forEach(function(email) {252 addGroupUser(group.id, email, timeStamp)253 })254 }255 else {256 users.forEach(function(email) {257 deleteGroupUser(group.id, email, timeStamp)258 })259 }260 }261 }262 function initScope() {263 GroupsService.getOboeGroups(function(group) {264 addGroup(group, -1)265 })266 .done(function() {267 $scope.$digest()268 })269 UserService.getUser().then(function(response) {270 $scope.user = response.data.user271 updateQuotaBars()272 })273 UsersService.getOboeUsers(userFields, function(user) {274 addUser(user, -1)275 })276 }277 $scope.scopeGroupListCtrl = $scope278 $scope.sortBy = CommonService.sortBy279 $scope.getDuration = CommonService.getDuration280 $scope.getClassName = CommonService.getClassName281 $scope.user = UserService.currentUser282 $scope.numberBar = {}283 $scope.durationBar = {}284 $scope.groupsEnv = {}285 $scope.groups = []286 $scope.activeGroups = $scope.readyGroups = $scope.pendingGroups = 0287 $scope.itemsPerPageOptions = ItemsPerPageOptionsService288 SettingsService.bind($scope, {289 target: 'groupItemsPerPage'290 , source: 'groupViewItemsPerPage'291 , defaultValue: $scope.itemsPerPageOptions[2]292 })293 $scope.groupColumns = [294 {name: 'Status', property: 'status'}295 , {name: 'Name', property: 'name'}296 , {name: 'Identifier', property: 'id'}297 , {name: 'Owner', property: 'owner.name'}298 , {name: 'Devices', property: 'devices.length'}299 , {name: 'Users', property: 'users.length'}300 , {name: 'Class', property: 'class'}301 , {name: 'Repetitions', property: 'repetitions'}302 , {name: 'Duration', property: 'duration'}303 , {name: 'Starting Date', property: 'startTime'}304 , {name: 'Expiration Date', property: 'stopTime'}305 ]306 $scope.defaultGroupData = {307 columns: [308 {name: 'Status', selected: true, sort: 'none'}309 , {name: 'Name', selected: true, sort: 'sort-asc'}310 , {name: 'Identifier', selected: false, sort: 'none'}311 , {name: 'Owner', selected: true, sort: 'none'}312 , {name: 'Devices', selected: true, sort: 'none'}313 , {name: 'Users', selected: true, sort: 'none'}314 , {name: 'Class', selected: true, sort: 'none'}315 , {name: 'Repetitions', selected: true, sort: 'none'}316 , {name: 'Duration', selected: true, sort: 'none'}317 , {name: 'Starting Date', selected: true, sort: 'none'}318 , {name: 'Expiration Date', selected: true, sort: 'none'}319 ]320 , sort: {index: 1, reverse: false}321 }322 SettingsService.bind($scope, {323 target: 'groupData'324 , source: 'groupData'325 , defaultValue: $scope.defaultGroupData326 })327 $scope.mailToGroupOwners = function(groups) {328 CommonService.copyToClipboard(_.uniq(groups.map(function(group) {329 return group.owner.email330 }))331 .join(SettingsService.get('emailSeparator')))332 .url('mailto:?body=*** Paste the email addresses from the clipboard! ***')333 }334 $scope.mailToGroupUsers = function(group, users) {335 // group unused actually..336 CommonService.copyToClipboard(users.map(function(user) {337 return user.email338 })339 .join(SettingsService.get('emailSeparator')))340 .url('mailto:?body=*** Paste the email addresses from the clipboard! ***')341 }342 $scope.getTooltip = function(objects) {343 var tooltip = ''344 objects.forEach(function(object) {345 tooltip += object + '\n'346 })347 return tooltip348 }349 $scope.resetData = function() {350 $scope.groupData = JSON.parse(JSON.stringify($scope.defaultGroupData))351 }352 $scope.initGroupUsers = function(group) {353 if (typeof $scope.groupsEnv[group.id].userCurrentPage === 'undefined') {354 $scope.groupsEnv[group.id].userCurrentPage = 1355 $scope.groupsEnv[group.id].userItemsPerPage = $scope.itemsPerPageOptions[1]356 }357 group.users.forEach(function(email) {358 addGroupUser(group.id, email, -1)359 })360 }361 $scope.initGroupDevices = function(group) {362 if (typeof $scope.groupsEnv[group.id].deviceCurrentPage === 'undefined') {363 $scope.groupsEnv[group.id].deviceCurrentPage = 1364 $scope.groupsEnv[group.id].deviceItemsPerPage = $scope.itemsPerPageOptions[1]365 }366 GroupsService.getOboeGroupDevices(group.id, false, deviceFields, function(device) {367 addDevice(device, -1)368 addGroupDevice(group.id, device.serial, -1)369 })370 .done(function() {371 $scope.$digest()372 })373 }374 $scope.$on('user.view.groups.created', function(event, message) {375 addGroup(message.group, message.timeStamp)376 })377 $scope.$on('user.view.groups.deleted', function(event, message) {378 deleteGroup(message.group.id, message.timeStamp)379 })380 $scope.$on('user.view.groups.updated', function(event, message) {381 if (CommonService.isExisting(groupsById[message.group.id])) {382 if (message.group.users.indexOf(UserService.currentUser.email) < 0) {383 deleteGroup(message.group.id, message.timeStamp)384 }385 else {386 updateStateStats($scope.groups[groupsById[message.group.id].index], message.group)387 updateGroupDevices(message.group, message.isAddedDevice, message.devices, message.timeStamp)388 updateGroupUsers(message.group, message.isAddedUser, message.users, message.timeStamp)389 updateGroup(message.group, message.timeStamp)390 updateGroupExtraProperties($scope.groups[groupsById[message.group.id].index])391 }392 }393 else {394 addGroup(message.group, message.timeStamp)395 }396 })397 $scope.$on('user.settings.users.created', function(event, message) {398 addUser(message.user, message.timeStamp)399 })400 $scope.$on('user.settings.users.deleted', function(event, message) {...
index.ts
Source:index.ts
...48 covidData.location = geo.point(covidData.location.lat, covidData.location.lng);49 return covidDataIdRef50 .create(covidData)51 .then(() => {52 const statsToUpdate: any = updateStateStats(covidData.metadata.state, {53 isIncrement: true54 });55 statsToUpdate.register = admin.firestore.FieldValue.increment(1);56 return admin57 .firestore()58 .collection(`stats`)59 .doc(`ecuador`)60 .update(statsToUpdate)61 .then(() => res.status(200).json({ message: `Covid data was created` }));62 })63 .catch((error: any) => res.status(400).json({ message: `error: ${error}` }));64 })65 .catch((error: any) => res.status(400).json({ message: `error: ${error}` }));66 });67});68exports.updateCovidData = functions.https.onRequest(async (req, res) => {69 cors(req, res, () => {70 const covidData: CovidData = req.body;71 if (!covidData.id) {72 return res.status(400).json({ message: `id is required` });73 }74 const covidDataIdRef = admin.firestore().doc(`tracker-id/${covidData.id}`);75 return covidDataIdRef76 .get()77 .then((response: any) => {78 const oldCovidData = response.data();79 if (!oldCovidData) {80 return res.status(400).json({ message: 'Covid user incorrect' });81 }82 delete covidData['id'];83 delete covidData['location'];84 delete covidData['createdAt'];85 covidData.updatedAt = new Date().getTime();86 return covidDataIdRef87 .update(covidData)88 .then(() => {89 let statsToUpdate: any = {};90 if (oldCovidData.metadata.state !== covidData.metadata.state) {91 statsToUpdate = {92 ...updateStateStats(oldCovidData.metadata.state, { isIncrement: false }),93 ...updateStateStats(covidData.metadata.state, { isIncrement: true })94 };95 return admin96 .firestore()97 .collection(`stats`)98 .doc(`ecuador`)99 .update(statsToUpdate)100 .then(() => res.status(200).json({ message: `Covid data was updated` }));101 }102 return res.status(200).json({ message: `Covid data was updated` });103 })104 .catch((error: any) => res.status(400).json({ message: `error: ${error}` }));105 })106 .catch((error: any) => res.status(400).json({ message: `error: ${error}` }));107 });108});109exports.checkProximity = functions.https.onRequest(async (req, res) => {110 cors(req, res, async () => {111 const queryLocation: any = req.query;112 const covidLocation = JSON.parse(queryLocation.location);113 if (!covidLocation || !covidLocation.lat && !covidLocation.lng) {114 return res.status(400).json({ message: `location is required` });115 }116 const position = geo.point(covidLocation.lat, covidLocation.lng);117 const radius = 10;118 const field = 'location';119 const query = geo.query(locations).within(position, radius, field);120 const proximity = await get(query);121 let proximityId = 'far';122 if (proximity.length > 0 && proximity.length < 5) {123 proximityId = 'warning';124 } else if (proximity.length >= 5) {125 proximityId = 'near';126 }127 return res.status(200).json({ proximity: proximityId });128 });129});130function updateStateStats(131 state: CovidState,132 opt: { isIncrement: boolean } = { isIncrement: false }133): any {134 const statsToUpdate: any = {};135 switch (state) {136 case CovidState.false:137 statsToUpdate.false = admin.firestore.FieldValue.increment(opt.isIncrement ? 1 : -1);138 break;139 case CovidState.negative:140 statsToUpdate.negative = admin.firestore.FieldValue.increment(opt.isIncrement ? 1 : -1);141 break;142 case CovidState.positive:143 statsToUpdate.positive = admin.firestore.FieldValue.increment(opt.isIncrement ? 1 : -1);144 break;...
Stats.js
Source:Stats.js
2 constructor() {3 // debugger4 this.usStatsDiv = this.createUSStatsDiv();5 this.stateStatsDiv = this.createStatesStatsDiv();6 this.updateStateStats('California')7 }8 createUSStatsDiv() {9 let usStats = stats.append('div')10 .attr('id', 'us-stats')11 .attr('class', 'status')12 // .style('height', '200px')13 usStats14 .append('div')15 .html('Latest US Stats:')16 usStats17 .append('div')18 .html(`7-Day New Case Average: ${numberWithCommas(parseInt(organizedData.aggregateAvgNewCases))}`)19 usStats20 .append('div')21 .html(`7-Day Recovered Average: ${numberWithCommas(parseInt(organizedData.aggregateAvgRecovered))}`)22 return usStats23 }24 createStatesStatsDiv() {25 let stateStats = stats.append('div')26 .attr('id', 'state-stats')27 .attr('class', 'status')28 // .style('height', '200px')29 30 stateStats31 .append('div')32 .attr('id', 'state-stat-div')33 .append('div')34 .html('Latest State Stats: ')35 .style('padding-right', '5px')36 d3.select('#state-stat-div')37 .append('div')38 .attr('id', 'state-stat-name')39 // .html('California')40 stateStats41 .append('div')42 .attr('id', 'state-stat-new-div')43 .append('div')44 .html(`7-Day New Case Average: `)45 .style('padding-right', '5px')46 d3.select('#state-stat-new-div')47 .append('div')48 .attr('id','state-stat-new-number')49 // .html(numberWithCommas(parseInt(organizedData.aggregateAvgNewCases)))50 stateStats51 .append('div')52 .attr('id', 'state-stat-recovered-div')53 .append('div')54 .html(`7-Day Recovered Average: `)55 .style('padding-right', '5px')56 d3.select('#state-stat-recovered-div')57 .append('div')58 .attr('id','state-stat-recovered-number')59 // .html(numberWithCommas(parseInt(organizedData.aggregateAvgRecovered)))60 61 stateStats62 .append('div')63 .attr('id', 'state-stat-info')64 .html(`NOTE: Hover Over State`)65 .style('padding-right', '5px')66 .style('font-weight', 'bold')67 }68 updateStateStats(stateName) {69 d3.select('#state-stat-name').html(stateName.replace('_', ' '))70 d3.select('#state-stat-new-number').html(numberWithCommas(parseInt(organizedData.lastSevenDayStats[stateName].Confirmed)))71 d3.select('#state-stat-recovered-number').html(numberWithCommas(parseInt(organizedData.lastSevenDayStats[stateName].Recovered)))72 }...
Using AI Code Generation
1var stf = require('devicefarmer-stf');2stf.updateStateStats(function(err, res){3 if(err){4 console.log("Error: " + err);5 }else{6 console.log("Success: " + res);7 }8});9var stf = require('devicefarmer-stf');10stf.updateStateStats(function(err, res){11 if(err){12 console.log("Error: " + err);13 }else{14 console.log("Success: " + res);15 }16});17var stf = require('devicefarmer-stf');18stf.updateStateStats(function(err, res){19 if(err){20 console.log("Error: " + err);21 }else{22 console.log("Success: " + res);23 }24});25var stf = require('devicefarmer-stf');26stf.updateStateStats(function(err, res){27 if(err){28 console.log("Error: " + err);29 }else{30 console.log("Success: " + res);31 }32});33var stf = require('devicefarmer-stf');34stf.updateStateStats(function(err, res){35 if(err){36 console.log("Error: " + err);37 }else{38 console.log("Success: " + res);39 }40});41var stf = require('devicefarmer-stf');42stf.updateStateStats(function(err, res){43 if(err){44 console.log("Error: " + err);45 }else{46 console.log("Success: " + res);47 }48});49var stf = require('devicefarmer-stf');50stf.updateStateStats(function(err, res){51 if(err){52 console.log("Error: " + err);53 }else{54 console.log("Success: "
Using AI Code Generation
1var DeviceFarmer = require('devicefarmer-stf');2df.updateStateStats(function(err, data){3 if(err){4 console.log(err);5 }6 else{7 console.log(data);8 }9});10{ online: 1, offline: 1, broken: 0 }11var DeviceFarmer = require('devicefarmer-stf');12df.updateStateStats(function(err, data){13 if(err){14 console.log(err);15 }16 else{17 console.log(data);18 }19});20{ online: 1, offline: 1, broken: 0 }21var DeviceFarmer = require('devicefarmer-stf');22df.updateStateStats(function(err, data){23 if(err){24 console.log(err);25 }26 else{27 console.log(data);28 }29});30{ online: 1, offline: 1, broken: 0 }31var DeviceFarmer = require('devicefarmer-stf');32df.updateStateStats(function(err, data){33 if(err){34 console.log(err);35 }36 else{37 console.log(data);38 }39});40{ online: 1, offline: 1, broken: 0 }41var DeviceFarmer = require('devicefarmer-stf');42df.updateStateStats(function(err, data){43 if(err){44 console.log(err);45 }46 else{47 console.log(data);48 }49});50{ online: 1, offline: 1, broken: 0 }51var DeviceFarmer = require('devicefarmer-stf');
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var test = new stf();3test.updateStateStats("device1","available");4var stf = require('devicefarmer-stf');5var test = new stf();6test.updateStateStats("device1","present");7var stf = require('devicefarmer-stf');8var test = new stf();9test.updateStateStats("device1","using");10var stf = require('devicefarmer-stf');11var test = new stf();12test.updateStateStats("device1","unauthorized");13var stf = require('devicefarmer-stf');14var test = new stf();15test.updateStateStats("device1","offline");16var stf = require('devicefarmer-stf');17var test = new stf();18test.updateStateStats("device1","broken");19var stf = require('devicefarmer-stf');20var test = new stf();21test.updateStateStats("device1","other");22var stf = require('devicefarmer-stf');23var test = new stf();24test.updateStateStats("device1","unknown");25var stf = require('devicefarmer-stf');26var test = new stf();27test.updateStateStats("device1","recovery");28var stf = require('devicefarmer-stf');29var test = new stf();30test.updateStateStats("device1","bootloader");31var stf = require('devicefarmer-stf');32var test = new stf();33test.updateStateStats("device1","device");
Using AI Code Generation
1const stf = require('devicefarmer-stf');2stf.updateStateStats({3});4stf.updateStateStats({5});6stf.updateStateStats({7});8stf.updateStateStats({9});10stf.updateStateStats({11});12stf.updateStateStats({13});14stf.updateStateStats({15});16stf.updateStateStats({17});18stf.updateStateStats({19});20stf.updateStateStats({21});22stf.updateStateStats({23});24stf.updateStateStats({25});26stf.updateStateStats({27});28stf.updateStateStats({29});30stf.updateStateStats({31});32stf.updateStateStats({33});34stf.updateStateStats({35});
Using AI Code Generation
1var updateStateStats = require('devicefarmer-stf/updateStateStats.js');2var stats = {3};4updateStateStats(stats);5module.exports = function updateStateStats(stats) {6 console.log(stats);7};8{9 "dependencies": {
Using AI Code Generation
1const deviceDb = require('devicefarmer-stf-device-db');2const db = deviceDb.open('test.db');3db.updateStateStats('deviceState', 'present', 1);4const deviceDb = require('devicefarmer-stf-device-db');5const db = deviceDb.open('test.db');6db.updateStateStats('deviceState', 'present', 1);7const deviceDb = require('devicefarmer-stf-device-db');8const db = deviceDb.open('test.db');9db.updateStateStats('deviceState', 'present', 1);10const deviceDb = require('devicefarmer-stf-device-db');11const db = deviceDb.open('test.db');12db.updateStateStats('deviceState', 'present', 1);13const deviceDb = require('devicefarmer-stf-device-db');14const db = deviceDb.open('test.db');15db.updateStateStats('deviceState', 'present', 1);
Using AI Code Generation
1var device = require('devicefarmer-stf-device');2var deviceState = device.DeviceState;3var deviceStats = device.DeviceStats;4var deviceState = new deviceState('device-uuid', 'device-name');5deviceState.updateStateStats(deviceStats);6var DeviceState = function (uuid, name) {7 this.stats = {8 }9 this.updateStateStats = function (deviceStats) {10 }11}12{13 network: {14 },15 battery: {16 },17 display: {18 },19 phone: {20 },21 storage: {22 internal: {23 },24 external: {25 }26 },27 cpu: {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!