Best JavaScript code snippet using wpt
results_filter.ts
Source:results_filter.ts
1import { SimResult, SimResultFilter, UnitMetrics } from '../core/proto_utils/sim_result.js';2import { EventID, TypedEvent } from '../core/typed_event.js';3import { EnumPicker } from '../core/components/enum_picker.js';4import { Input } from '../core/components/input.js';5import { ResultComponent, ResultComponentConfig, SimResultData } from './result_component.js';6const ALL_UNITS = -1;7interface FilterData {8 player: number,9 target: number,10};11export class ResultsFilter extends ResultComponent {12 private readonly currentFilter: FilterData;13 readonly changeEmitter: TypedEvent<void>;14 private readonly playerFilter: PlayerFilter;15 private readonly targetFilter: TargetFilter;16 constructor(config: ResultComponentConfig) {17 config.rootCssClass = 'results-filter-root';18 super(config);19 this.currentFilter = {20 player: ALL_UNITS,21 target: ALL_UNITS,22 };23 this.changeEmitter = new TypedEvent<void>();24 this.playerFilter = new PlayerFilter(this.rootElem, this.currentFilter);25 this.playerFilter.changeEmitter.on(eventID => this.changeEmitter.emit(eventID));26 this.targetFilter = new TargetFilter(this.rootElem, this.currentFilter);27 this.targetFilter.changeEmitter.on(eventID => this.changeEmitter.emit(eventID));28 }29 getFilter(): SimResultFilter {30 return {31 player: this.currentFilter.player == ALL_UNITS ? null : this.currentFilter.player,32 target: this.currentFilter.target == ALL_UNITS ? null : this.currentFilter.target,33 };34 }35 onSimResult(resultData: SimResultData) {36 this.playerFilter.setOptions(resultData.eventID, resultData.result);37 this.targetFilter.setOptions(resultData.eventID, resultData.result);38 }39 setPlayer(eventID: EventID, newPlayer: number | null) {40 this.currentFilter.player = (newPlayer === null) ? ALL_UNITS : newPlayer;41 this.playerFilter.changeEmitter.emit(eventID);42 }43 setTarget(eventID: EventID, newTarget: number | null) {44 this.currentFilter.target = (newTarget === null) ? ALL_UNITS : newTarget;45 this.targetFilter.changeEmitter.emit(eventID);46 }47}48interface UnitFilterOption {49 iconUrl: string,50 text: string,51 color: string,52 value: number,53};54// Dropdown menu for filtering by player.55abstract class UnitGroupFilter extends Input<FilterData, number> {56 private readonly filterData: FilterData;57 readonly changeEmitter: TypedEvent<void>;58 private allUnitsOption: UnitFilterOption;59 private currentOptions: Array<UnitFilterOption>;60 private readonly buttonElem: HTMLElement;61 private readonly dropdownElem: HTMLElement;62 constructor(parent: HTMLElement, filterData: FilterData, allUnitsLabel: string) {63 const changeEmitter = new TypedEvent<void>();64 super(parent, 'unit-filter-root', filterData, {65 extraCssClasses: [66 'dropdown-root',67 ],68 changedEvent: (filterData: FilterData) => changeEmitter,69 getValue: (filterData: FilterData) => this.getFilterDataValue(filterData),70 setValue: (eventID: EventID, filterData: FilterData, newValue: number) => this.setFilterDataValue(filterData, newValue),71 });72 this.filterData = filterData;73 this.changeEmitter = changeEmitter;74 this.allUnitsOption = {75 iconUrl: '',76 text: allUnitsLabel,77 color: 'black',78 value: ALL_UNITS,79 };80 this.currentOptions = [this.allUnitsOption];81 this.rootElem.innerHTML = `82 <div class="dropdown-button unit-filter-button"></div>83 <div class="dropdown-panel unit-filter-dropdown"></div>84 `;85 this.buttonElem = this.rootElem.getElementsByClassName('unit-filter-button')[0] as HTMLElement;86 this.dropdownElem = this.rootElem.getElementsByClassName('unit-filter-dropdown')[0] as HTMLElement;87 this.buttonElem.addEventListener('click', event => {88 event.preventDefault();89 });90 this.init();91 }92 abstract getFilterDataValue(filterData: FilterData): number;93 abstract setFilterDataValue(filterData: FilterData, newValue: number): void;94 abstract getAllUnits(simResult: SimResult): Array<UnitMetrics>;95 setOptions(eventID: EventID, simResult: SimResult) {96 this.currentOptions = [this.allUnitsOption].concat(this.getAllUnits(simResult).map(unit => {97 return {98 iconUrl: unit.iconUrl || '',99 text: unit.label,100 color: unit.classColor || 'black',101 value: unit.unitIndex,102 };103 }));104 const hasSameOption = this.currentOptions.find(option => option.value == this.getInputValue()) != null;105 if (!hasSameOption) {106 this.setFilterDataValue(this.filterData, this.allUnitsOption.value);107 this.changeEmitter.emit(eventID);108 }109 this.dropdownElem.innerHTML = '';110 this.currentOptions.forEach(option => this.dropdownElem.appendChild(this.makeOption(option)));111 }112 private makeOption(data: UnitFilterOption): HTMLElement {113 const option = this.makeOptionElem(data);114 option.addEventListener('click', event => {115 event.preventDefault();116 this.setFilterDataValue(this.filterData, data.value);117 this.changeEmitter.emit(TypedEvent.nextEventID());118 });119 return option;120 }121 private makeOptionElem(data: UnitFilterOption): HTMLElement {122 const optionContainer = document.createElement('div');123 optionContainer.classList.add('dropdown-option-container');124 const option = document.createElement('div');125 option.classList.add('dropdown-option', 'unit-filter-option');126 optionContainer.appendChild(option);127 if (data.color) {128 option.style.backgroundColor = data.color;129 }130 if (data.iconUrl) {131 const icon = document.createElement('img');132 icon.src = data.iconUrl;133 icon.classList.add('unit-filter-icon');134 option.appendChild(icon);135 }136 if (data.text) {137 const label = document.createElement('span');138 label.textContent = data.text;139 label.classList.add('unit-filter-label');140 option.appendChild(label);141 }142 return optionContainer;143 }144 getInputElem(): HTMLElement {145 return this.buttonElem;146 }147 getInputValue(): number {148 return this.getFilterDataValue(this.filterData);149 }150 setInputValue(newValue: number) {151 this.setFilterDataValue(this.filterData, newValue);152 const optionData = this.currentOptions.find(optionData => optionData.value == newValue);153 if (!optionData) {154 return;155 }156 this.buttonElem.innerHTML = '';157 this.buttonElem.appendChild(this.makeOptionElem(optionData));158 }159}160class PlayerFilter extends UnitGroupFilter {161 constructor(parent: HTMLElement, filterData: FilterData) {162 super(parent, filterData, 'All Players');163 this.rootElem.classList.add('player-filter-root');164 }165 getFilterDataValue(filterData: FilterData): number {166 return filterData.player;167 }168 setFilterDataValue(filterData: FilterData, newValue: number): void {169 filterData.player = newValue;170 }171 getAllUnits(simResult: SimResult): Array<UnitMetrics> {172 return simResult.getPlayers();173 }174}175class TargetFilter extends UnitGroupFilter {176 constructor(parent: HTMLElement, filterData: FilterData) {177 super(parent, filterData, 'All Targets');178 this.rootElem.classList.add('target-filter-root');179 }180 getFilterDataValue(filterData: FilterData): number {181 return filterData.target;182 }183 setFilterDataValue(filterData: FilterData, newValue: number): void {184 filterData.target = newValue;185 }186 getAllUnits(simResult: SimResult): Array<UnitMetrics> {187 return simResult.getTargets();188 }...
searchFilter.js
Source:searchFilter.js
1const searchFilter = {2 jobsList: [],3 filterData: {4 keyword: '',5 city: 'ä¸é',6 industryCategory: 'ä¸é',7 jobCategory: 'ä¸é',8 workExp: 'ä¸é',9 education: 'ä¸é',10 workType: 'ä¸é',11 workTime: 'ä¸é',12 salaryLow: null,13 salaryHight: null,14 salaryInterView: false,15 },16 filter(jobsList, filterData) {17 this.getJobsList(jobsList);18 this.getFilterData(filterData);19 this.startFilter();20 return this.jobsList;21 },22 getJobsList(temArray) {23 this.jobsList = temArray;24 },25 sendJobsList() {26 return this.jobsList;27 },28 getFilterData(temFilter) {29 this.cleanFilter();30 this.filterData = temFilter;31 },32 cleanFilter() {33 this.filterData = {34 keyword: '',35 city: 'ä¸é',36 industryCategory: 'ä¸é',37 jobCategory: 'ä¸é',38 workExp: 'ä¸é',39 education: 'ä¸é',40 workType: 'ä¸é',41 workTime: 'ä¸é',42 salaryLow: null,43 salaryHight: null,44 salaryInterView: false,45 };46 },47 returnFilter() {48 return this.filterData;49 },50 startFilter() {51 this.filterKeyword(this.filterData);52 this.filterCity(this.filterData);53 this.filterWorkTime(this.filterData);54 this.filterWorkType(this.filterData);55 this.filterWorkExp(this.filterData);56 this.filterEducation(this.filterData);57 this.filterJobCategory(this.filterData);58 this.filterIndustryCategory(this.filterData);59 this.filterSalary(this.filterData);60 this.filterSalaryInterView(this.filterData);61 },62 filterKeyword(filterData) {63 let temData = [];64 if (filterData.keyword !== '') {65 temData = this.jobsList.filter((item) => {66 const text = item.title + item.options.company.companyName;67 const searchText = filterData.keyword.toLowerCase();68 const textResult = text.toLowerCase().includes(searchText);69 return textResult;70 });71 } else {72 temData = this.jobsList;73 }74 this.jobsList = temData;75 },76 filterCity(filterData) {77 let temData = [];78 if (filterData.city !== 'ä¸é') {79 temData = this.jobsList.filter(80 (item) => item.options.company.companyAddressCity === filterData.city,81 );82 } else {83 temData = this.jobsList;84 }85 this.jobsList = temData;86 },87 filterWorkTime(filterData) {88 let temData = [];89 if (filterData.workTime !== 'ä¸é') {90 temData = this.jobsList.filter((item) => item.options.job.workTime === filterData.workTime);91 } else {92 temData = this.jobsList;93 }94 this.jobsList = temData;95 },96 filterWorkExp(filterData) {97 let temData = [];98 if (filterData.workExp !== 'ä¸é') {99 temData = this.jobsList.filter((item) => item.options.job.workExp === filterData.workExp);100 } else {101 temData = this.jobsList;102 }103 this.jobsList = temData;104 },105 filterWorkType(filterData) {106 let temData = [];107 if (filterData.workType !== 'ä¸é') {108 temData = this.jobsList.filter((item) => item.options.job.workType === filterData.workType);109 } else {110 temData = this.jobsList;111 }112 this.jobsList = temData;113 },114 filterEducation(filterData) {115 let temData = [];116 if (filterData.education !== 'ä¸é') {117 temData = this.jobsList.filter((item) => item.options.job.education === filterData.education);118 } else {119 temData = this.jobsList;120 }121 this.jobsList = temData;122 },123 filterJobCategory(filterData) {124 let temData = [];125 if (filterData.jobCategory !== 'ä¸é') {126 temData = this.jobsList.filter((item) => item.category === filterData.jobCategory);127 } else {128 temData = this.jobsList;129 }130 this.jobsList = temData;131 },132 filterIndustryCategory(filterData) {133 let temData = [];134 if (filterData.industryCategory !== 'ä¸é') {135 temData = this.jobsList.filter(136 (item) => item.options.company.industryCategory === filterData.industryCategory,137 );138 } else {139 temData = this.jobsList;140 }141 this.jobsList = temData;142 },143 filterSalary(filterData) {144 let temData = [];145 const numLow = filterData.salaryLow;146 const numHight = filterData.salaryHight;147 if (numLow !== null && numHight !== null) {148 temData = this.jobsList.filter((item) => item.price > numLow && item.price < numHight);149 } else if (numLow !== null || numHight !== null) {150 if (numLow !== null) {151 temData = this.jobsList.filter((item) => item.price > numLow);152 } else if (numHight !== null) {153 temData = this.jobsList.filter((item) => item.price < numHight);154 }155 } else {156 temData = this.jobsList;157 }158 this.jobsList = temData;159 },160 filterSalaryInterView(filterData) {161 let temData = [];162 if (filterData.salaryInterView) {163 temData = this.jobsList.filter((item) => item.options.job.salaryInterView === true);164 } else {165 temData = this.jobsList;166 }167 this.jobsList = temData;168 },169};...
solution-filter.pipe.ts
Source:solution-filter.pipe.ts
1import { Pipe, PipeTransform } from '@angular/core';2import { FilterModel } from './solution-filter.component';3@Pipe({4 name: 'solutionFilterPipe',5 pure: false6})7export class SolutionFilterPipe implements PipeTransform {8 transform(items: any[], filter: {filterData ? :FilterModel}): any {9 if (!items || !filter) {10 return items;11 }12 // filter items array, items which match and return true will be13 // kept, false will be filtered out14 let filterItems = items;15 if( filter?.filterData?.state != undefined && filter?.filterData?.state.length != 0)16 filterItems = filterItems.filter(item => filter.filterData.state.includes(item.answerStatus));17 if(filter?.filterData?.difficulty != undefined && filter?.filterData?.difficulty.length != 0 )18 filterItems = filterItems.filter(item => filter.filterData.difficulty.includes(item.difficultyLevel ));19 if( filter?.filterData?.subject != undefined && filter?.filterData?.subject.length != 0)20 filterItems = filterItems.filter(item => filter.filterData.subject.includes(item.subject));21 if(filter?.filterData?.topic != undefined && filter?.filterData?.topic.length != 0 )22 filterItems = filterItems.filter(item => filter.filterData.topic.includes(item.topic));23 if(filter?.filterData?.subtopic != undefined && filter?.filterData?.subtopic.length != 0 )24 filterItems = filterItems.filter(item => filter.filterData.subtopic.includes(item.subTopic));25 return filterItems;26 }...
Using AI Code Generation
1var wpt = require('wpt');2var options = {3};4wpt.runTest(options, function (err, data) {5 if (err) {6 console.log(err);7 } else {8 var filteredData = wpt.filterData(data);9 console.log(filteredData);10 }11});12var wpt = require('wpt');13var options = {14};15wpt.runTest(options, function (err, data) {16 if (err) {17 console.log(err);18 } else {19 var filteredData = wpt.filterData(data);20 console.log(filteredData);21 }22});23var wpt = require('wpt');24var options = {25};26wpt.runTest(options, function (err, data) {27 if (err) {28 console.log(err);29 } else {30 var filteredData = wpt.filterData(data);31 console.log(filteredData);32 }33});34var wpt = require('wpt');35var options = {36};37wpt.runTest(options, function (err, data) {38 if (err) {39 console.log(err);40 } else {41 var filteredData = wpt.filterData(data);42 console.log(filteredData);43 }44});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.filterData('www.webpagetest.org', '201406_0D_c8b', 'pageSpeed', 'json', function(err, data) {4 console.log(data);5});6var WebPageTest = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org');8var filterData = function (url, testId, metric, format, callback) {9 var options = {10 };11 wpt.getFilterData(options, callback);12};13module.exports.filterData = filterData;
Using AI Code Generation
1var wpt = require('./wpt-api.js');2wpt.filterData({3}, function(err, data) {4 console.log(data);5});6var wpt = require('webpagetest-api');7module.exports = {8 filterData: function(options, callback) {9 wpt.getTestResults(options.key, options.url, function(err, data) {10 if (err) {11 console.log(err);12 return;13 }14 var result = data.data.median;15 callback(null, result);16 });17 }18};
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var async = require('async');4var data = fs.readFileSync('data.json');5var obj = JSON.parse(data);6var output = [];7async.eachSeries(obj, function (item, callback) {8 var page = wptools.page(item.title);9 page.get(function (err, resp) {10 if (err) {11 callback(err);12 } else {13 var infobox = resp.data['infobox'];14 if (infobox) {15 var filteredData = page.filterData(infobox);16 if (filteredData) {17 output.push(filteredData);18 }19 }20 callback();21 }22 });23}, function (err) {24 if (err) {25 console.log(err);26 } else {27 fs.writeFileSync('output.json', JSON.stringify(output, null, 2));28 }29});30[{"title":"Mumbai"},{"title":"Delhi"},{"title":"Bangalore"},{"title":"Kolkata"},{"title":"Chennai"}]31{32 "Mumbai": {
Using AI Code Generation
1var wptData = require('wpt-data');2var data = wptData.filterData( 'data.csv', 'url', 'First View', 'loadTime' );3console.log(data);4var wptData = require('wpt-data');5var data = wptData.filterData( 'data.csv', 'url', 'Repeat View', 'loadTime' );6console.log(data);7var wptData = require('wpt-data');8var data = wptData.filterData( 'data.csv', 'url', 'First View', 'TTFB' );9console.log(data);10var wptData = require('wpt-data');11var data = wptData.filterData( 'data.csv', 'url', 'Repeat View', 'TTFB' );12console.log(data);13var wptData = require('wpt-data');14var data = wptData.filterData( 'data.csv', 'url', 'First View', 'render' );15console.log(data);16var wptData = require('wpt-data');17var data = wptData.filterData( 'data.csv', 'url', 'Repeat View', 'render' );18console.log(data);
Using AI Code Generation
1var wpt = require('wpt-api');2var filterData = wpt.filterData;3var data = {4 "data": {5 "testResults": {6 "firstView": {
Using AI Code Generation
1var wpt = require('./wpt.js');2var site = 'www.google.com';3var testType = 'SpeedIndex';4var startDate = '2015-09-01';5var endDate = '2015-09-30';6wpt.filterData(site, testType, startDate, endDate, function(err, data) {7 if (err) {8 console.log(err);9 return;10 }11 console.log(data);12});13var request = require('request');14var async = require('async');15var _ = require('underscore');16module.exports = {17 filterData: function(site, testType, startDate, endDate, callback) {18 var result = [];19 if (err) {20 return callback(err);21 }22 var locations = body.split('23');24 locations = locations.slice(1, locations.length - 1);25 async.each(locations, function(location, cb) {26 var locationId = location.split(' ')[0];27 var locationUrl = url + site + '&location=' + locationId;28 request.get(locationUrl, function(err, res, body) {29 if (err) {30 return cb(err);31 }32 var data = JSON.parse(body);33 if (data.data && data.data.median && data.data.median.firstView && data.data.median.firstView[testType]) {34 result.push(data.data.median.firstView[testType]);35 }36 return cb();37 });38 }, function(err) {39 if (err) {40 return callback(err);41 }42 result = _.filter(result, function(num) {43 return num > 0;44 });45 return callback(null, result);46 });47 });48 }49};
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!!