Best JavaScript code snippet using wpt
pump.js
Source:pump.js
1'use strict';2var _ = require('lodash');3var moment = require('moment');4var levels = require('../levels');5var times = require('../times');6var ALL_STATUS_FIELDS = ['reservoir', 'battery', 'clock', 'status', 'device'];7function init (ctx) {8 var translate = ctx.language.translate;9 var timeago = require('./timeago')(ctx);10 var openaps = require('./openaps')(ctx);11 var pump = {12 name: 'pump'13 , label: 'Pump'14 , pluginType: 'pill-status'15 };16 pump.getPrefs = function getPrefs (sbx) {17 function cleanList (value) {18 return decodeURIComponent(value || '').toLowerCase().split(' ');19 }20 function isEmpty (list) {21 return _.isEmpty(list) || _.isEmpty(list[0]);22 }23 var fields = cleanList(sbx.extendedSettings.fields);24 fields = isEmpty(fields) ? ['reservoir'] : fields;25 var retroFields = cleanList(sbx.extendedSettings.retroFields);26 retroFields = isEmpty(retroFields) ? ['reservoir', 'battery'] : retroFields;27 return {28 fields: fields29 , retroFields: retroFields30 , warnClock: sbx.extendedSettings.warnClock || 3031 , urgentClock: sbx.extendedSettings.urgentClock || 6032 , warnRes: sbx.extendedSettings.warnRes || 1033 , urgentRes: sbx.extendedSettings.urgentRes || 534 , warnBattV: sbx.extendedSettings.warnBattV || 1.3535 , urgentBattV: sbx.extendedSettings.urgentBattV || 1.336 , warnBattP: sbx.extendedSettings.warnBattP || 3037 , urgentBattP: sbx.extendedSettings.urgentBattP || 2038 , warnOnSuspend: sbx.extendedSettings.warnOnSuspend || false39 , enableAlerts: sbx.extendedSettings.enableAlerts || false40 };41 };42 pump.setProperties = function setProperties (sbx) {43 sbx.offerProperty('pump', function setPump ( ) {44 var prefs = pump.getPrefs(sbx);45 var recentMills = sbx.time - times.mins(prefs.urgentClock * 2).msecs;46 var filtered = _.filter(sbx.data.devicestatus, function (status) {47 return ('pump' in status) && sbx.entryMills(status) <= sbx.time && sbx.entryMills(status) >= recentMills;48 });49 var pumpStatus = null;50 _.forEach(filtered, function each (status) {51 status.clockMills = status.pump && status.pump.clock ? moment(status.pump.clock).valueOf() : status.mills;52 if (!pumpStatus || status.clockMills > pumpStatus.clockMills) {53 pumpStatus = status;54 }55 });56 pumpStatus = pumpStatus || { };57 pumpStatus.data = prepareData(pumpStatus, prefs, sbx);58 return pumpStatus;59 });60 };61 pump.checkNotifications = function checkNotifications (sbx) {62 var prefs = pump.getPrefs(sbx);63 if (!prefs.enableAlerts) { return; }64 65 pump.warnOnSuspend = prefs.warnOnSuspend;66 var data = prepareData(sbx.properties.pump, prefs, sbx);67 if (data.level >= levels.WARN) {68 sbx.notifications.requestNotify({69 level: data.level70 , title: data.title71 , message: data.message72 , pushoverSound: 'echo'73 , group: 'Pump'74 , plugin: pump75 });76 }77 };78 pump.updateVisualisation = function updateVisualisation (sbx) {79 var prop = sbx.properties.pump;80 var prefs = pump.getPrefs(sbx);81 var result = prepareData(prop, prefs, sbx);82 var values = [ ];83 var info = [ ];84 var selectedFields = sbx.data.inRetroMode ? prefs.retroFields : prefs.fields;85 _.forEach(ALL_STATUS_FIELDS, function eachField (fieldName) {86 var field = result[fieldName];87 if (field) {88 var selected = _.indexOf(selectedFields, fieldName) > -1;89 if (selected) {90 values.push(field.display);91 } else {92 info.push({label: field.label, value: field.display});93 }94 }95 });96 97 if (result.extended) {98 info.push({label: '------------', value: ''});99 _.forOwn(result.extended, function(value, key) {100 info.push({ label: key, value: value });101 });102 }103 sbx.pluginBase.updatePillText(pump, {104 value: values.join(' ')105 , info: info106 , label: translate('Pump')107 , pillClass: statusClass(result.level)108 });109 };110 function alexaReservoirHandler (next, slots, sbx) {111 var response = translate('alexaReservoir', {112 params: [113 sbx.properties.pump.pump.reservoir114 ]115 });116 next('Remaining insulin', response);117 }118 function alexaBatteryHandler (next, slots, sbx) {119 var battery = _.get(sbx, 'properties.pump.data.battery');120 if (battery) {121 var response = translate('alexaPumpBattery', {122 params: [123 battery.value,124 battery.unit125 ]126 });127 next('Pump battery', response);128 } else {129 next();130 }131 }132 pump.alexa = {133 intentHandlers:[{134 intent: 'InsulinRemaining',135 intentHandler: alexaReservoirHandler136 }, {137 intent: 'PumpBattery',138 intentHandler: alexaBatteryHandler139 }]140 };141 function statusClass (level) {142 var cls = 'current';143 if (level === levels.WARN) {144 cls = 'warn';145 } else if (level === levels.URGENT) {146 cls = 'urgent';147 }148 return cls;149 }150 function updateClock (prefs, result, sbx) {151 if (result.clock) {152 result.clock.label = 'Last Clock';153 result.clock.display = timeFormat(result.clock.value, sbx);154 var urgent = moment(sbx.time).subtract(prefs.urgentClock, 'minutes');155 var warn = moment(sbx.time).subtract(prefs.warnClock, 'minutes');156 if (urgent.isAfter(result.clock.value)) {157 result.clock.level = levels.URGENT;158 result.clock.message = 'URGENT: Pump data stale';159 } else if (warn.isAfter(result.clock.value)) {160 result.clock.level = levels.WARN;161 result.clock.message = 'Warning, Pump data stale';162 } else {163 result.clock.level = levels.NONE;164 }165 }166 }167 function updateReservoir (prefs, result) {168 if (result.reservoir) {169 result.reservoir.label = 'Reservoir';170 result.reservoir.display = result.reservoir.value.toPrecision(3) + 'U';171 if (result.reservoir.value < prefs.urgentRes) {172 result.reservoir.level = levels.URGENT;173 result.reservoir.message = 'URGENT: Pump Reservoir Low';174 } else if (result.reservoir.value < prefs.warnRes) {175 result.reservoir.level = levels.WARN;176 result.reservoir.message = 'Warning, Pump Reservoir Low';177 } else {178 result.reservoir.level = levels.NONE;179 }180 }181 }182 function updateBattery (type, prefs, result) {183 if (result.battery) {184 result.battery.label = 'Battery';185 result.battery.display = result.battery.value + type;186 var urgent = type === 'v' ? prefs.urgentBattV : prefs.urgentBattP;187 var warn = type === 'v' ? prefs.warnBattV : prefs.warnBattP;188 if (result.battery.value < urgent) {189 result.battery.level = levels.URGENT;190 result.battery.message = 'URGENT: Pump Battery Low';191 } else if (result.battery.value < warn) {192 result.battery.level = levels.WARN;193 result.battery.message = 'Warning, Pump Battery Low';194 } else {195 result.battery.level = levels.NONE;196 }197 }198 }199 function buildMessage (result) {200 if (result.level > levels.NONE) {201 var message = [];202 if (result.battery) {203 message.push('Pump Battery: ' + result.battery.display);204 }205 if (result.reservoir) {206 message.push('Pump Reservoir: ' + result.reservoir.display);207 }208 result.message = message.join('\n');209 }210 }211 function updateStatus(pump, result) {212 if (pump.status) {213 var status = pump.status.status || 'normal';214 if (pump.status.bolusing) {215 status = 'bolusing';216 } else if (pump.status.suspended) {217 status = 'suspended';218 if (pump.warnOnSuspend && pump.status.suspended) {219 result.status.level = levels.WARN;220 result.status.message = 'Pump Suspended';221 };222 }223 result.status = { value: status, display: status, label: translate('Status') };224 }225 }226 function prepareData (prop, prefs, sbx) {227 var pump = (prop && prop.pump) || { };228 var result = {229 level: levels.NONE230 , clock: pump.clock ? { value: moment(pump.clock) } : null231 , reservoir: pump.reservoir || pump.reservoir === 0 ? { value: pump.reservoir } : null232 , extended: pump.extended || null233 };234 updateClock(prefs, result, sbx);235 updateReservoir(prefs, result);236 updateStatus(pump, result);237 if (pump.battery && pump.battery.percent) {238 result.battery = { value: pump.battery.percent, unit: 'percent' };239 updateBattery('%', prefs, result);240 } else if (pump.battery && pump.battery.voltage) {241 result.battery = { value: pump.battery.voltage, unit: 'volts'};242 updateBattery('v', prefs, result);243 }244 result.device = { label: translate('Device'), display: prop.device };245 result.title = 'Pump Status';246 result.level = levels.NONE;247 //TODO: A new Pump Offline marker? Something generic? Use something new instead of a treatment?248 if (openaps.findOfflineMarker(sbx)) {249 console.info('OpenAPS known offline, not checking for alerts');250 } else {251 _.forEach(ALL_STATUS_FIELDS, function eachField(fieldName) {252 var field = result[fieldName];253 if (field && field.level > result.level) {254 result.level = field.level;255 result.title = field.message;256 }257 });258 }259 buildMessage(result);260 return result;261 }262 function timeFormat (m, sbx) {263 var when;264 if (m && sbx.data.inRetroMode) {265 when = m.format('LT');266 } else if (m) {267 when = formatAgo(m, sbx.time);268 } else {269 when = 'unknown';270 }271 return when;272 }273 function formatAgo (m, nowMills) {274 var ago = timeago.calcDisplay({mills: m.valueOf()}, nowMills);275 return translate('%1' + ago.shortLabel + (ago.shortLabel.length === 1 ? ' ago' : ''), { params: [(ago.value ? ago.value : '')]});276 }277 return pump;278}...
pumpsKhas.service.ts
Source:pumpsKhas.service.ts
1import { IDataService, PumpKhas } from '../../../core';2import { PumpKhasFactoryService } from './pumpKhas-factory.service';3import { CreatePumpKhasDto, UpdatePumpKhasDto } from '../../../core/dtos';4export class PumpsKhasService {5 constructor(6 private dataService: IDataService,7 private pumpKhasFactoryService: PumpKhasFactoryService,8 ) {}9 async getAllPumpKhas(): Promise<PumpKhas[]> {10 return await this.dataService.pumpsKhas.getAll();11 }12 async getPumpKhasByUser(id: any): Promise<PumpKhas[]> {13 return (await this.dataService.pumpsKhas.getAll()).filter(14 (x) => x.userId == id,15 );16 }17 async getOnePumpKhas(id: any): Promise<PumpKhas> {18 return await this.dataService.pumpsKhas.get(id);19 }20 async createPumpKhas(createPumpKhasDto: CreatePumpKhasDto) {21 const newPumpKhas =22 this.pumpKhasFactoryService.createPumpKhas(createPumpKhasDto);23 return await this.dataService.pumpsKhas.create(newPumpKhas);24 }25 async updatePumpKhas(updatePumpKhasDto: UpdatePumpKhasDto, id) {26 const updatePumpKhas =27 this.pumpKhasFactoryService.updatePumpKhas(updatePumpKhasDto);28 return await this.dataService.pumpsKhas.update(id, updatePumpKhas);29 }30 async deletePumpKhas(id: any) {31 return await this.dataService.pumpsKhas.delete(id);32 }...
pumpKhas-factory.service.ts
Source:pumpKhas-factory.service.ts
1import { Injectable } from '@nestjs/common';2import {3 CreatePumpKhasDto,4 UpdateKhasDto,5 UpdatePumpKhasDto,6} from '../../../core/dtos';7import { PumpKhas } from '../../../core';8@Injectable()9export class PumpKhasFactoryService {10 createPumpKhas(createPumpKhasDto: CreatePumpKhasDto) {11 const pumpKhas = new PumpKhas();12 pumpKhas.userId = createPumpKhasDto.userId;13 pumpKhas.pumpDetail = createPumpKhasDto.pumpDetail;14 pumpKhas.isActive = createPumpKhasDto.isActive;15 return pumpKhas;16 }17 updatePumpKhas(updatePumpKhasDto: UpdatePumpKhasDto) {18 const pumpKhas = new PumpKhas();19 pumpKhas.userId = updatePumpKhasDto.userId;20 pumpKhas.pumpDetail = updatePumpKhasDto.pumpDetail;21 pumpKhas.isActive = updatePumpKhasDto.isActive;22 return pumpKhas;23 }...
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org');3 if (err) return console.log(err);4 test.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.log(err);6 console.log(data);7 });8});9var wpt = require('webpagetest');10var test = new wpt('www.webpagetest.org');11 if (err) return console.log(err);12 test.getTestResults(data.data.testId, function(err, data) {13 if (err) return console.log(err);14 console.log(data);15 });16});17var wpt = require('webpagetest');18var test = new wpt('www.webpagetest.org');19 if (err) return console.log(err);20 test.getTestResults(data.data.testId, function(err, data) {21 if (err) return console.log(err);22 console.log(data);23 });24});25var wpt = require('webpagetest');26var test = new wpt('www.webpagetest.org');27 if (err) return console.log(err);28 test.getTestResults(data.data.testId, function(err, data) {29 if (err) return console.log(err);30 console.log(data);31 });32});33var wpt = require('webpagetest');34var test = new wpt('www.webpagetest.org');35 if (err) return console.log(err);36 test.getTestResults(data.data.testId, function(err, data) {37 if (err) return console.log(err);
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt_client = wpt('www.webpagetest.org');3 if (err) return console.error(err);4 wpt_client.getTestStatus(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 wpt_client.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10 });11});12var wpt = require('webpagetest');13var wpt_client = wpt('www.webpagetest.org');14 if (err) return console.error(err);15 console.log(data);16});17var wpt = require('webpagetest');18var wpt_client = wpt('www.webpagetest.org');19wpt_client.getTestStatus('test_id', function(err, data) {20 if (err) return console.error(err);21 console.log(data);22});23var wpt = require('webpagetest');24var wpt_client = wpt('www.webpagetest.org');25wpt_client.getTestResults('test_id', function(err, data) {26 if (err) return console.error(err);27 console.log(data);28});29var wpt = require('webpagetest');30var wpt_client = wpt('www.webpagetest.org');31wpt_client.getLocations(function(err, data) {32 if (err) return console.error(err);33 console.log(data);34});
Using AI Code Generation
1var wptool = require('wptool');2var pump = wptool.pump;3var inStream = process.stdin;4var outStream = process.stdout;5pump(inStream, outStream);6var wptool = require('wptool');7var pump = wptool.pump;8var inStream = process.stdin;9var outStream = process.stdout;10pump(inStream, outStream);11var wptool = require('wptool');12var pump = wptool.pump;13var inStream = process.stdin;14var outStream = process.stdout;15pump(inStream, outStream);16var wptool = require('wptool');17var pump = wptool.pump;18var inStream = process.stdin;19var outStream = process.stdout;20pump(inStream, outStream);21var wptool = require('wptool');22var pump = wptool.pump;23var inStream = process.stdin;24var outStream = process.stdout;25pump(inStream, outStream);26var wptool = require('wptool');27var pump = wptool.pump;28var inStream = process.stdin;29var outStream = process.stdout;30pump(inStream, outStream);31var wptool = require('wptool');32var pump = wptool.pump;33var inStream = process.stdin;34var outStream = process.stdout;35pump(inStream, outStream);36var wptool = require('
Using AI Code Generation
1var wptools = require('./index.js');2var fs = require('fs');3var pump = require('pump');4var path = require('path');5var child_process = require('child_process');6var mkdirp = require('mkdirp');7var async = require('async');8var _ = require('underscore');9var argv = require('minimist')(process.argv.slice(2));10var request = require('request');11var csv = require('csv');12var csvWriter = require('csv-write-stream');13var csvReader = require('csv-parse');14var csvStream = csvWriter({headers: ['id', 'title', 'url', 'image_url', 'image_name', 'image_local_path']});15var csvStream2 = csvWriter({headers: ['id', 'title', 'url', 'image_url', 'image_name', 'image_local_path', 'image_dimensions']});16var csvStream3 = csvWriter({headers: ['id', 'title', 'url', 'image_url', 'image_name', 'image_local_path', 'image_dimensions', 'image_width', 'image_height']});17var csvStream4 = csvWriter({headers: ['id', 'title', 'url', 'image_url', 'image_name', 'image_local_path', 'image_dimensions', 'image_width', 'image_height', 'image_size']});18var csvStream5 = csvWriter({headers: ['id', 'title', 'url', 'image_url', 'image_name', 'image_local_path', 'image_dimensions', 'image_width', 'image_height', 'image_size', 'image_format']});19var csvStream6 = csvWriter({headers: ['id', 'title', 'url', 'image_url', 'image_name', 'image_local_path', 'image_dimensions', 'image_width', 'image_height', 'image_size', 'image_format', 'image_exif']});20var csvStream7 = csvWriter({headers: ['id', 'title', 'url', 'image_url', 'image_name', 'image_local_path', 'image_dimensions', 'image_width', 'image_height', 'image_size', 'image_format', 'image_exif', 'image_metadata']});21var csvStream8 = csvWriter({headers: ['id', 'title', 'url', 'image_url', 'image_name', 'image_local_path', 'image_dimensions', 'image
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var async = require('async');5var list = fs.readFileSync(path.join(__dirname, "list.txt"), "utf8");6var wikis = list.split('7');8async.each(wikis, function(wiki, callback) {9 wptools.pump({10 }, function(err, resp) {11 if (err) {12 console.log(err);13 } else {14 console.log(resp);15 }16 callback();17 });18});
Using AI Code Generation
1var fs = require('fs');2var wptools = require('wptools');3wptools.page('Barack Obama', {image: true}).then(function(page) {4 return page.pump();5}).then(function(page) {6 var images = page.images();7 var image = images[0];8 var url = image.url;9 fs.writeFile('image.txt', url, function (err) {10 if (err) return console.log(err);11 console.log('Image URL saved to file "image.txt"');12 });13});
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!!