Best JavaScript code snippet using wpt
polling-station-dataset.js
Source:polling-station-dataset.js
1const debug = require("debug")2const log = debug("whipple-data:polling-dataset:log")3log.log = console.log.bind(console)4function PollingStationDataset() {5 const pollingStationsMap = {}6 const distributedPollingStationsMap = {}7 this.get = (key) => pollingStationsMap[key]8 this.getPollingStations = () => {9 const pollingStation = []10 log("Ordering by zone and polling station number")11 const keys = Object.keys(pollingStationsMap).sort((pId1, pId2) => {12 const [p1Zone, p1Number] = pId113 .split("-")14 .map((item) => Number.parseInt(item))15 const [p2Zone, p2Number] = pId216 .split("-")17 .map((item) => Number.parseInt(item))18 const delta1 = p1Zone - p2Zone19 if (delta1 === 0) {20 return p1Number - p2Number21 } else {22 return delta123 }24 })25 log("Creating polling stations array")26 for (let key of keys) {27 pollingStationsMap[key].distributedPollingStationsNumbers =28 distributedPollingStationsMap[key]29 pollingStation.push(pollingStationsMap[key])30 }31 log("Polling stations array created")32 return pollingStation33 }34 this.loadTrePollingStationData = (trePollingStationData, year) => {35 log("Loading TRE data from election of %d...", year)36 for (let record of trePollingStationData) {37 const zone = Number.parseInt(record["ZONA"])38 const pollingStationNumber = Number.parseInt(record["SECAO_PRINCIPAL"])39 const key = `${zone}-${pollingStationNumber}`40 let pollingStation = pollingStationsMap[key]41 if (pollingStation === undefined) {42 pollingStation = convertTreRecordToPollingStation(record)43 pollingStationsMap[key] = pollingStation44 }45 pollingStation.elections.push(year)46 if (47 record["SECOES_DISTRIBUIDAS"] != null &&48 record["SECOES_DISTRIBUIDAS"].length > 049 ) {50 const distributedPollingStations = record["SECOES_DISTRIBUIDAS"]51 .split(",")52 .map((distrPollingStationNumber) =>53 Number.parseInt(distrPollingStationNumber.trim())54 )55 distributedPollingStations.forEach((distrPollingStationNumber) => {56 const distributedKey = `${zone}-${distrPollingStationNumber}`57 const distrPollingStation =58 distributedPollingStationsMap[distributedKey]59 if (distrPollingStation === undefined) {60 distributedPollingStationsMap[distributedKey] = [61 pollingStationNumber,62 ]63 } else {64 distrPollingStation.push(pollingStationNumber)65 }66 })67 }68 }69 log(70 "%d records loaded from election of %d",71 trePollingStationData.length,72 year73 )74 }75 this.loadTreChangedZones = (changedZonesData) => {76 for (let record of changedZonesData) {77 const key = `${Number.parseInt(record["ZONA_ORIGEM"])}-${Number.parseInt(78 record["SECAO_ORIGEM"]79 )}`80 let pollingStation = pollingStationsMap[key]81 if (pollingStation === undefined) {82 pollingStation = convertTreLinkRecordToPollingStation(record)83 pollingStationsMap[key] = pollingStation84 }85 const newPollingStation = {86 zone: Number.parseInt(record["ZONA_DESTINO"]),87 pollingStationNumber: Number.parseInt(record["SECAO_DESTINO"]),88 }89 pollingStation["changedTo"] = newPollingStation90 }91 }92 const convertTreRecordToPollingStation = (treRecord) => {93 return {94 zone: Number.parseInt(treRecord["ZONA"]),95 pollingStationNumber: Number.parseInt(treRecord["SECAO_PRINCIPAL"]),96 place: treRecord["LOCAL"],97 address: treRecord["ENDERECO"],98 neighborhood: treRecord["BAIRRO"],99 city: treRecord["MUNICIPIO"],100 groupedPollingStations: [],101 distributedPollingStationsNumbers: [],102 elections: [],103 }104 }105 const convertTreLinkRecordToPollingStation = (treRecord) => {106 return {107 zone: Number.parseInt(treRecord["ZONA_ORIGEM"]),108 pollingStationNumber: Number.parseInt(treRecord["SECAO_ORIGEM"]),109 place: treRecord["LOCAL_ORIGEM"],110 address: "",111 neighborhood: "",112 city: treRecord["MUNIC_ORIGEM"],113 groupedPollingStations: [],114 distributedPollingStationsNumbers: [],115 elections: [],116 }117 }118}...
MozartPollingPeriodDropdown.js
Source:MozartPollingPeriodDropdown.js
1import React from 'react';2import { string, func } from 'prop-types';3import { connect } from 'react-redux';4import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';5import {6 ButtonDropdown,7 DropdownToggle,8 DropdownMenu,9 DropdownItem,10} from 'reactstrap';11import { changePollingPeriod } from '../../actions/pollingPeriod.actions';12import './MozartPollingPeriodDropdown.scss';13class MozartPollingPeriodDropdown extends React.Component {14 state = {15 isDropdownOpen: false,16 };17 toggle = () =>18 this.setState(state => ({19 isDropdownOpen: !state.isDropdownOpen,20 }));21 setPollingPeriod = e => {22 // eslint-disable-next-line no-shadow23 const { changePollingPeriod } = this.props;24 const { value: pollingPeriod } = e.target;25 return changePollingPeriod(pollingPeriod);26 };27 renderPollingPeriodText = () => {28 const { pollingPeriod } = this.props;29 switch (pollingPeriod) {30 case '2':31 return '02s';32 case '5':33 return '05s';34 case '10':35 return '10s';36 case '30':37 return '30s';38 default:39 return null;40 }41 };42 render() {43 const { isDropdownOpen } = this.state;44 return (45 <div className="MozartPollingPeriodDropdown">46 <ButtonDropdown isOpen={isDropdownOpen} toggle={this.toggle}>47 <DropdownToggle caret size="md" color="dark">48 <FontAwesomeIcon icon="sync-alt" />49 <span className="mx-2">{this.renderPollingPeriodText()}</span>50 </DropdownToggle>51 <DropdownMenu right>52 <DropdownItem value={2} onClick={this.setPollingPeriod}>53 2s54 </DropdownItem>55 <DropdownItem value={5} onClick={this.setPollingPeriod}>56 5s57 </DropdownItem>58 <DropdownItem value={10} onClick={this.setPollingPeriod}>59 10s60 </DropdownItem>61 <DropdownItem value={30} onClick={this.setPollingPeriod}>62 30s63 </DropdownItem>64 </DropdownMenu>65 </ButtonDropdown>66 </div>67 );68 }69}70MozartPollingPeriodDropdown.propTypes = {71 pollingPeriod: string,72 changePollingPeriod: func,73};74const mapStateToProps = ({ global = {} }) => ({75 pollingPeriod: global.pollingPeriod,76});77export default connect(78 mapStateToProps,79 { changePollingPeriod }...
index.js
Source:index.js
1import { of, timer } from "rxjs";2import {3 map,4 catchError,5 switchMap,6 exhaustMap,7 takeUntil,8} from "rxjs/operators";9import { ofType, combineEpics } from "redux-observable";10import { getTransactionInfo, getNotificationsInfo } from "./services";11import {12 MESSAGE_POLLING,13 MESSAGE_POLLING_START,14 MESSAGE_POLLING_STOP,15 MESSAGE_POLLING_ERROR,16 STOP_NOTIFICATIONS_POLLING,17 START_NOTIFICATIONS_POLLING,18 NOTIFICATIONS_POLLING_ERROR,19 NOTIFICATIONS_POLLING,20} from "../actions/types";21export const paymentsMonitoredEpic = action$ => {22 const stopPolling$ = action$.pipe(ofType(MESSAGE_POLLING_STOP));23 return action$.pipe(24 ofType(MESSAGE_POLLING_START),25 switchMap(() =>26 timer(1000, 2000).pipe(27 takeUntil(stopPolling$),28 exhaustMap(() =>29 getTransactionInfo().pipe(30 map(data => ({31 type: MESSAGE_POLLING,32 data,33 })),34 catchError(error =>35 of({36 type: MESSAGE_POLLING_ERROR,37 error,38 })39 )40 )41 )42 )43 )44 );45};46export const notificationsMonitoredEpic = action$ => {47 const stopPolling$ = action$.pipe(ofType(STOP_NOTIFICATIONS_POLLING));48 return action$.pipe(49 ofType(START_NOTIFICATIONS_POLLING),50 switchMap(() =>51 timer(1000, 10000).pipe(52 takeUntil(stopPolling$),53 exhaustMap(() =>54 getNotificationsInfo().pipe(55 map(data => ({56 type: NOTIFICATIONS_POLLING,57 data,58 })),59 catchError(error => {60 console.error(error);61 of({62 type: NOTIFICATIONS_POLLING_ERROR,63 error,64 });65 })66 )67 )68 )69 )70 );71};72const epics = combineEpics(paymentsMonitoredEpic, notificationsMonitoredEpic);...
Using AI Code Generation
1var WebPageTest = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 if (err) return console.error(err);4 console.log(data);5});6{ statusCode: 400,
Using AI Code Generation
1var wpt = require('webpagetest');2var server = new wpt('www.webpagetest.org');3 console.log(data);4});5{statusCode: 200, statusText: 'Ok', data: {}}6{statusCode: 200, statusText: 'Ok', data: {}}7var wpt = require('webpagetest');8var server = new wpt('www.webpagetest.org');9 console.log(data);10});11{statusCode: 200, statusText: 'Ok', data: {}}12{statusCode: 200, statusText: 'Ok', data: {}}13{statusCode: 200, statusText: 'Ok', data: {}}
Using AI Code Generation
1var wptool = require('./index.js');2var wp = new wptool();3 if (err) {4 console.log('Error: ', err);5 } else {6 console.log('Data: ', data);7 }8});9var wptool = require('./index.js');10var wp = new wptool();11 if (err) {12 console.log('Error: ', err);13 } else {14 console.log('Data: ', data);15 }16});17var wptool = require('./index.js');18var wp = new wptool();19 if (err) {20 console.log('Error: ', err);21 } else {22 console.log('Data: ', data);23 }24}, {streaming: true});25var wptool = require('./index.js');26var wp = new wptool();27 if (err) {28 console.log('Error: ', err);29 } else {30 console.log('Data: ', data);31 }32}, {streaming: true, polling: true});33var wptool = require('./index.js');34var wp = new wptool();35 if (err) {36 console.log('Error: ', err);37 } else {38 console.log('Data: ', data);39 }40}, {polling: true});
Using AI Code Generation
1var wpt = require('webpagetest');2var webPageTest = new wpt('www.webpagetest.org');3var testId = '160713_7F_1T3';4webPageTest.pollResults(testId, function(error, data) {5 if(error) {6 console.log('Error: ' + error);7 } else {8 console.log(data);9 }10});11var wpt = require('webpagetest');12var webPageTest = new wpt('www.webpagetest.org');13var testId = '160713_7F_1T3';14webPageTest.pollResults(testId, function(error, data) {15 if(error) {16 console.log('Error: ' + error);17 } else {18 console.log(data);19 }20});21var wpt = require('webpagetest');22var webPageTest = new wpt('www.webpagetest.org');23var testId = '160713_7F_1T3';24webPageTest.pollResults(testId, function(error, data) {25 if(error) {26 console.log('Error: ' + error);27 } else {28 console.log(data);29 }30});31var wpt = require('webpagetest');32var webPageTest = new wpt('www.webpagetest.org');33var testId = '160713_7F_1T3';34webPageTest.pollResults(testId, function(error, data) {35 if(error) {36 console.log('Error: ' + error);37 } else {38 console.log(data);39 }40});41var wpt = require('webpagetest');42var webPageTest = new wpt('www.webpagetest.org');43var testId = '160713_7F_1T3';44webPageTest.pollResults(testId, function(error, data) {45 if(error) {46 console.log('Error: ' + error);47 } else {48 console.log(data);49 }50});51var wpt = require('webpagetest');
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.9f1f7c0c1d2e7d2f2e34e7b9f0e0f7e9');3wpt.runTest(url, {4}, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7});8var wpt = require('webpagetest');9var wpt = new WebPageTest('www.webpagetest.org', 'A.9f1f7c0c1d2e7d2f2e34e7b9f0e0f7e9');10wpt.runTest(url, {11}, function(err, data) {12 if (err) return console.error(err);13 console.log(data);14});15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org', 'A.9f1f7c0c1d2e7d2f2e34e7b9f0e0f7e9');17wpt.runTest(url, {18}, function(err, data) {19 if (err) return console.error(err);20 console.log(data);21});22var wpt = require('webpagetest');23var wpt = new WebPageTest('www.webpagetest.org', 'A.9f1f7c0c1d2e7d2f2e34e7b9f0e0f7e9');
Using AI Code Generation
1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org', 'A.0d2e7b8c0c2f7d0f2c2d7f8e8e0c7e7e');3var options = {4};5api.runTest(options, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});12var wpt = require('webpagetest');13var api = new wpt('www.webpagetest.org', 'A.0d2e7b8c0c2f7d0f2c2d7f8e8e0c7e7e');14var options = {15};16api.runTest(options, function(err, data) {17 if (err) {18 console.log(err);19 } else {20 console.log(data);21 }22});23var wpt = require('webpagetest');24var api = new wpt('www.webpagetest.org', 'A.0d2e7b8c0c2f7d0f2c2d7f8e8e0c7e7e');25var options = {26};27api.runTest(options, function(err, data) {28 if (err) {29 console.log(err);30 } else {31 console.log(data);32 }33});34var wpt = require('webpagetest');35var api = new wpt('www.webpagetest.org', 'A.0d2e7b8c0c2f7d0f2c2d7f8e8e0c7e7
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!!