How to use union_type method in wpt

Best JavaScript code snippet using wpt

tag-types.jsx

Source:tag-types.jsx Github

copy

Full Screen

1/*2 * @Author: HuangQS3 * @Date: 2021-09-16 14:01:054 * @LastEditors: HuangQS5 * @LastEditTime: 2021-12-24 15:27:046 * @Description: 用户标签 - 投放类型 组合控件7 * 8 * 不传不显示下面对应的参数 不传时,获取数据也不会获取到对应参数9 * tag_name: 可更改[用户标签]字段名称 10 * delivery_name: 可更改[投放类型]字段名称11 */12import React, { Component } from 'react';13import { Form, Select, Radio, Input, Tooltip, message } from 'antd';14import './tag-types.css';15import {16 requestAdTagList, //用户设备标签17 requestNewAdTagList, //用户设备标签[新版] 用户标签18 requestDeliveryTypes, //投放类型19} from 'api';20import '@/style/base.css';21let { Option } = Select;22export default class TagTypes extends Component {23 constructor(props) {24 super(props);25 this.viewFormRef = React.createRef();26 this.state = {27 //标签判断逻辑28 dict_union_type: [29 { key: 1, value: '满足全部标签' },30 { key: 2, value: '满足部分标签' },31 ],32 dict_user_tags: [], //用户设备标签33 dict_delivery_types: [], //投放类型34 }35 }36 componentDidMount() {37 let that = this;38 that.props.onRef(that);39 that.initData();40 }41 render() {42 let that = this;43 let { dict_union_type, dict_user_tags, dict_delivery_types } = that.state;44 let { union_type, tag_name, delivery_name, desc45 , is_old_tag_resouce } = that.props;46 return (47 <div className='tag-types-wrapper'>48 <Form labelCol={{ span: 6 }} wrapperCol={{ span: 16 }} ref={that.viewFormRef}>49 {50 union_type &&51 <Tooltip title='是以按当前配置的[用户标签]为基础,进行全匹配,模糊匹配。' placement="top" color={'blue'}>52 <Form.Item label='标签逻辑' name={union_type} >53 <Radio.Group className="base-input-wrapper" >54 {dict_union_type.map((item, index) => {55 return <Radio value={item.key} key={index} onClick={(e) => that.onUnionTypeRadioClick(item.key)}>56 {item.value}57 </Radio>58 })}59 </Radio.Group>60 </Form.Item>61 </Tooltip>62 }63 {delivery_name &&64 <Tooltip title='投放类型取消或不选,都将默认为[非定向]' placement="top" color={'blue'}>65 <Form.Item label='投放类型' name={delivery_name}>66 <Radio.Group className="base-input-wrapper" >67 {dict_delivery_types.map((item, index) => {68 return <Radio value={item.key} key={index} onClick={(e) => that.onRadioClick(item.key)}>69 {item.value}70 </Radio>71 })}72 </Radio.Group>73 </Form.Item>74 </Tooltip>75 }76 {tag_name &&77 <Form.Item label='用户标签' name={tag_name} >78 <Select className="base-input-wrapper" mode={is_old_tag_resouce ? 'multiple' : true} allowClear showSearch placeholder="请选择用户设备标签"79 filterOption={(input, option) => {80 if (!input) return true;81 let children = option.children;82 if (children) {83 let key = children[2];84 let isFind = false;85 isFind = `${key}`.toLowerCase().indexOf(`${input}`.toLowerCase()) >= 0;86 if (!isFind) {87 let code = children[0];88 isFind = `${code}`.toLowerCase().indexOf(`${input}`.toLowerCase()) >= 0;89 }90 return isFind;91 }92 }}>93 {dict_user_tags.map((item, index) => (94 <Option value={item.code.toString()} key={item.code}>{item.name}-{item.code}</Option>95 ))}96 </Select>97 </Form.Item>98 }99 {desc &&100 <Form.Item label='注意' >101 <label style={{ color: 'red' }}>{desc}</label>102 </Form.Item>103 }104 </Form>105 </div>106 )107 }108 initData() {109 let that = this;110 let { is_old_tag_resouce } = that.props;111 //用户标签 根据类型获取新旧标签112 if (is_old_tag_resouce) {113 requestAdTagList().then(res => {114 that.setState({115 dict_user_tags: res.data,116 }, () => {117 that.forceUpdate();118 });119 })120 }121 //122 else {123 requestNewAdTagList({ currentPage: 1, pageSize: 999999, }).then(res => {124 that.setState({125 dict_user_tags: res.data,126 }, () => {127 that.forceUpdate();128 });129 })130 }131 //投放类型132 requestDeliveryTypes().then(res => {133 that.setState({134 dict_delivery_types: res,135 }, () => {136 that.forceUpdate();137 });138 });139 }140 /**141 * 装载数据142 * @param {*} item 143 */144 pushData(item) {145 let that = this;146 let viewFormRef = that.viewFormRef;147 let { tag_name } = that.props;148 let tags = item[tag_name];149 if (tags) {150 if (tags.constructor === String) {151 tags = tags.split(',');152 }153 // 154 else if (tags.constructor === Array) {155 if (tags.length <= 0) {156 tags = [];157 }158 }159 } else {160 tags = [];161 }162 item[tag_name] = tags;163 viewFormRef.current.resetFields();164 viewFormRef.current.setFieldsValue(item);165 }166 /**167 * 获取数据168 */169 loadData() {170 let that = this;171 let { union_type, tag_name, delivery_name } = that.props;172 let viewFormRef = that.viewFormRef;173 let value = viewFormRef.current.getFieldsValue();174 let obj = {};175 //标签判断逻辑176 if (union_type) {177 let union = value[union_type];178 if (union) {179 obj[union_type] = union;180 } else {181 if(!value[tag_name] || value[tag_name].length ==0){182 return183 }184 console.log(value[tag_name])185 message.error('请选择标签判断逻辑')186 }187 }188 //用户标签189 let tags = value[tag_name];190 if (tags) {191 if (tags.constructor === String) {192 tags = tags.split(',');193 }194 //195 else if (tags.constructor === Array) {196 if (tags.length > 0) {197 tags = tags.join(',');198 }199 }200 obj[tag_name] = tags;201 }202 //投放类型203 let delivery = value[delivery_name];204 if (delivery) {205 if (delivery !== 0) {206 obj[delivery_name] = delivery;207 }208 }209 return obj;210 }211 //标签类型逻辑212 onUnionTypeRadioClick() {213 let that = this;214 let viewFormRef = that.viewFormRef;215 let { union_type } = that.props;216 let obj = {};217 obj[union_type] = '';218 viewFormRef.current.setFieldsValue(obj);219 }220 //监听单选框 被选中的数据 再次被点击 将清除当前数据221 onRadioClick(target) {222 let that = this;223 let viewFormRef = that.viewFormRef;224 let { delivery_name } = that.props;225 let value = viewFormRef.current.getFieldValue(delivery_name);226 if (value === target) {227 let obj = {};228 obj[delivery_name] = '';229 viewFormRef.current.setFieldsValue(obj);230 }231 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1const AWS = require("aws-sdk")2const s3 = new AWS.S3()3/*4 QUERY STRING PARAMETERS5 p - Program (Show)6 --------------- GENERAL SEARCH -------------------7 q - All-purpose query parameter8 * Title9 * Character10 * Tags11 * Guest Stars12 --------------- ADVANCED SEARCH ------------------13 e - Episode index (Exact match)14 s - Season (Exact match)15 t - Title (Contains)16 d - Description aka Summary (Contains)17 c - Character (Array contains)18 g - Guest Star (Array contains)19 tags - Tags (Array contains)20 --------------------------------------------------21 dd - Date (Air date)22 mm - Month (Air date)23 yy - Year (Air date)24 --------------------------------------------------25 u - Union type ('e' = match exact combination; 'a' = match any)26*/27const PARAMS = {28 SHOW_KEY: "p",29 GENERAL_QUERY: "q",30 SEASON: "s",31 EPISODE: "e",32 TITLE: "t",33 DESCRIPTION: "d",34 CHARACTER: "c",35 GUEST_STAR: "g",36 TAG: "tt",37 DATE: "dd",38 MONTH: "mm",39 YEAR: "yy",40 UNION_TYPE: "u",41}42let resolver43let rejecter44const getS3Json = function(event, showKey) {45 s3.getObject(46 {47 Bucket: process.env.S3_BUCKET,48 Key: `data/${showKey}/${showKey}.json`,49 },50 (err, data) => {51 if (err) {52 // TODO: Extract Resolve/Reject logic from this method & use callbacks or async/await53 rejecter({54 statusCode: 500,55 body: JSON.stringify(err),56 })57 } else {58 const s3jsonString = data.Body.toString("utf-8")59 filterData(event, s3jsonString)60 }61 },62 )63}64const filterNestedArrayByKeyAndValue = function(propKey, propVal, dataArr) {65 let returnArr = []66 dataArr.forEach(item => {67 let matches = []68 item[propKey].find(val => {69 if (val.toLowerCase().indexOf(propVal.toLowerCase()) > -1) {70 matches.push(val)71 }72 })73 if (!!matches.length) {74 returnArr.push(item)75 }76 })77 return returnArr78}79const filterAllItemsByYear = function(yearValue, data) {80 return data.filter(item => String(item.broadcast.year) === yearValue)81}82const filterAllItemsByMonth = function(monthValue, data) {83 return data.filter(item => String(item.broadcast.month) === monthValue)84}85const filterAllItemsByDate = function(dateValue, data) {86 return data.filter(item => String(item.broadcast.date) === dateValue)87}88const filterAllItemsByTag = function(tagValue, data) {89 return filterNestedArrayByKeyAndValue("tags", tagValue, data)90}91const filterAllItemsByCharacter = function(characterName, data) {92 return filterNestedArrayByKeyAndValue("characters", characterName, data)93}94const filterAllItemsByGuest = function(guestName, data) {95 return filterNestedArrayByKeyAndValue("guests", guestName, data)96}97const filterBySeasonNumber = function(season, data) {98 return data.filter(item => String(item.season) === season)99}100const filterByEpisodeNumber = function(episode, data) {101 return data.filter(item => String(item.episode) === episode)102}103const filterByEpisodeTitle = function(title, data) {104 return data.filter(105 item =>106 String(item.title)107 .toLowerCase()108 .indexOf(title.toLowerCase()) > -1,109 )110}111const isQueryTermInArray = function(term, arr) {112 return Boolean(113 arr.filter(114 item =>115 String(item)116 .toLowerCase()117 .indexOf(term.toLowerCase()) > -1,118 ).length,119 )120}121const filterData = function(event, jsonDataString) {122 const queryString = event.queryStringParameters123 queryString.p = undefined124 let filtered = JSON.parse(jsonDataString).flat()125 let titleFiltered = []126 let tagFiltered = []127 let yearFiltered = []128 let monthFiltered = []129 let dateFiltered = []130 let guestFiltered = []131 let episodeFiltered = []132 let seasonFiltered = []133 let characterFiltered = []134 let blah = ""135 if (queryString[PARAMS.GENERAL_QUERY]) {136 filtered = filtered.filter(item => {137 const query = queryString[PARAMS.GENERAL_QUERY]138 return (139 String(item.title)140 .toLowerCase()141 .indexOf(query.toLowerCase()) > -1 ||142 isQueryTermInArray(query, item.tags) ||143 isQueryTermInArray(query, item.guests) ||144 isQueryTermInArray(query, item.characters)145 )146 })147 } else {148 if (!!queryString[PARAMS.TITLE]) {149 titleFiltered = filterByEpisodeTitle(queryString[PARAMS.TITLE], filtered)150 if (queryString[PARAMS.UNION_TYPE] !== "a") {151 filtered = titleFiltered152 }153 }154 if (!!queryString[PARAMS.TAG]) {155 tagFiltered = filterAllItemsByTag(PARAMS.TAG, filtered)156 if (queryString[PARAMS.UNION_TYPE] !== "a") {157 filtered = tagFiltered158 }159 }160 if (!!queryString[PARAMS.YEAR]) {161 yearFiltered = filterAllItemsByYear(queryString[PARAMS.YEAR], filtered)162 if (queryString[PARAMS.UNION_TYPE] !== "a") {163 filtered = yearFiltered164 }165 }166 if (!!queryString[PARAMS.MONTH]) {167 monthFiltered = filterAllItemsByMonth(queryString[PARAMS.MONTH], filtered)168 if (queryString[PARAMS.UNION_TYPE] !== "a") {169 filtered = monthFiltered170 }171 }172 if (!!queryString[PARAMS.DATE]) {173 dateFiltered = filterAllItemsByDate(queryString[PARAMS.DATE], filtered)174 if (queryString[PARAMS.UNION_TYPE] !== "a") {175 filtered = dateFiltered176 }177 }178 if (!!queryString[PARAMS.GUEST_STAR]) {179 guestFiltered = filterAllItemsByGuest(180 queryString[PARAMS.GUEST_STAR],181 filtered,182 )183 if (queryString[PARAMS.UNION_TYPE] !== "a") {184 filtered = guestFiltered185 }186 }187 if (!!queryString[PARAMS.EPISODE]) {188 episodeFiltered = filterByEpisodeNumber(189 queryString[PARAMS.EPISODE],190 filtered,191 )192 if (queryString[PARAMS.UNION_TYPE] !== "a") {193 filtered = episodeFiltered194 }195 }196 if (!!queryString[PARAMS.SEASON]) {197 seasonFiltered = filterBySeasonNumber(198 queryString[PARAMS.SEASON],199 filtered,200 )201 if (queryString[PARAMS.UNION_TYPE] !== "a") {202 filtered = seasonFiltered203 }204 }205 if (!!queryString[PARAMS.CHARACTER]) {206 characterFiltered = filterAllItemsByCharacter(PARAMS.CHARACTER, filtered)207 if (queryString[PARAMS.UNION_TYPE] !== "a") {208 filtered = characterFiltered209 }210 }211 if (queryString[PARAMS.UNION_TYPE] === "a") {212 const mergeArr = [].concat(213 titleFiltered,214 tagFiltered,215 guestFiltered,216 seasonFiltered,217 episodeFiltered,218 characterFiltered,219 yearFiltered,220 monthFiltered,221 dateFiltered,222 )223 mergeArr.sort((a, b) => {224 if (a.id < b.id) {225 return -1226 } else if (b.id < a.id) {227 return 1228 } else {229 return 0230 }231 })232 mergeArr.map((item, idx, arr) => {233 if (!arr[idx + 1]) {234 return true235 }236 return item.id !== arr[idx + 1].id237 })238 filtered = mergeArr239 }240 }241 resolver({242 statusCode: 200,243 body: JSON.stringify({244 count: filtered.length,245 query: queryString,246 data: filtered,247 }),248 })249}250exports.handler = event => {251 return new Promise((resolve, reject) => {252 resolver = resolve253 rejecter = reject254 const showKey = event.queryStringParameters[PARAMS.SHOW_KEY]255 getS3Json(event, showKey)256 })...

Full Screen

Full Screen

Domain.fs.js

Source:Domain.fs.js Github

copy

Full Screen

...10 return ["String", "Number", "Bool"];11 }12}13export function Value$reflection() {14 return union_type("Basic.Domain.Value", [], Value, () => [[["Item", string_type]], [["Item", class_type("System.Decimal")]], [["Item", bool_type]]]);15}16export class Expression extends Union {17 constructor(tag, ...fields) {18 super();19 this.tag = (tag | 0);20 this.fields = fields;21 }22 cases() {23 return ["Literal", "Variable", "Binary", "Function"];24 }25}26export function Expression$reflection() {27 return union_type("Basic.Domain.Expression", [], Expression, () => [[["Item", Value$reflection()]], [["Item", string_type]], [["Item1", char_type], ["Item2", Expression$reflection()], ["Item3", Expression$reflection()]], [["Item1", string_type], ["Item2", Expression$reflection()]]]);28}29export class Command extends Union {30 constructor(tag, ...fields) {31 super();32 this.tag = (tag | 0);33 this.fields = fields;34 }35 cases() {36 return ["Print", "Goto", "Run", "List", "Assign", "Input", "If"];37 }38}39export function Command$reflection() {40 return union_type("Basic.Domain.Command", [], Command, () => [[["Item", Expression$reflection()]], [["Item", int32_type]], [], [], [["Item1", string_type], ["Item2", Expression$reflection()]], [["Item", string_type]], [["Item1", Expression$reflection()], ["Item2", int32_type]]]);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 }, function(err, data) {4 if (err) return console.error(err);5 console.log('Test was run at: ' + data.data.userUrl);6 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2const fs = require('fs');3var results = [];4var results2 = [];5var results3 = [];6var results4 = [];7var results5 = [];8var results6 = [];9var results7 = [];10var results8 = [];11var results9 = [];12var results10 = [];13var results11 = [];14var results12 = [];15var results13 = [];16var results14 = [];17var results15 = [];18var results16 = [];19var results17 = [];20var results18 = [];21var results19 = [];22var results20 = [];23var results21 = [];24var results22 = [];25var results23 = [];26var results24 = [];27var results25 = [];28var results26 = [];29var results27 = [];30var results28 = [];31var results29 = [];32var results30 = [];33var results31 = [];34var results32 = [];35var results33 = [];36var results34 = [];37var results35 = [];38var results36 = [];39var results37 = [];40var results38 = [];41var results39 = [];42var results40 = [];43var results41 = [];44var results42 = [];45var results43 = [];46var results44 = [];47var results45 = [];48var results46 = [];49var results47 = [];50var results48 = [];51var results49 = [];52var results50 = [];53var results51 = [];54var results52 = [];55var results53 = [];56var results54 = [];57var results55 = [];58var results56 = [];59var results57 = [];60var results58 = [];61var results59 = [];62var results60 = [];63var results61 = [];64var results62 = [];65var results63 = [];66var results64 = [];67var results65 = [];68var results66 = [];69var results67 = [];70var results68 = [];71var results69 = [];72var results70 = [];73var results71 = [];74var results72 = [];75var results73 = [];76var results74 = [];77var results75 = [];78var results76 = [];79var results77 = [];80var results78 = [];81var results79 = [];82var results80 = [];83var results81 = [];84var results82 = [];85var results83 = [];86var results84 = [];87var results85 = [];88var results86 = [];89var results87 = [];90var results88 = [];91var results89 = [];92var results90 = [];93var results91 = [];94var results92 = [];95var results93 = [];96var results94 = [];97var results95 = [];98var results96 = [];

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Albert_Einstein');3var infobox = page.get_infobox(function(data) {4 console.log(data);5});6var wptools = require('wptools');7var page = wptools.page('Albert_Einstein');8var infobox = page.get_infobox(function(data) {9 console.log(data);10});11var wptools = require('wptools');12var page = wptools.page('Albert_Einstein');13var infobox = page.get_infobox(function(data) {14 console.log(data);15});16var wptools = require('wptools');17var page = wptools.page('Albert_Einstein');18var infobox = page.get_infobox(function(data) {19 console.log(data);20});21var wptools = require('wptools');22var page = wptools.page('Albert_Einstein');23var infobox = page.get_infobox(function(data) {24 console.log(data);25});26var wptools = require('wptools');27var page = wptools.page('Albert_Einstein');28var infobox = page.get_infobox(function(data) {29 console.log(data);30});31var wptools = require('wptools');32var page = wptools.page('Albert_Einstein');33var infobox = page.get_infobox(function(data) {34 console.log(data);35});36var wptools = require('wptools');37var page = wptools.page('Albert_Einstein');38var infobox = page.get_infobox(function(data) {39 console.log(data);40});41var wptools = require('wptools');42var page = wptools.page('Albert_Einstein');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var _ = require('underscore');4var async = require('async');5var request = require('request');6var options = {7};8var file = fs.readFileSync('data.json', 'utf8');9var data = JSON.parse(file);10var getWiki = function (wiki, callback) {11 wptools(wiki)12 .get_union(options, function (err, resp) {13 if (err) {14 console.log(err);15 }16 callback(null, resp);17 });18};19var wikis = _.pluck(data, 'wiki');20async.map(wikis, getWiki, function (err, results) {21 if (err) {22 console.log(err);23 }24 var processed = _.map(results, function (result) {25 var image = result.image[0];26 var image_url = image.url;27 var image_ext = image.ext;28 var image_name = image.name;29 var image_width = image.width;30 var image_height = image.height;31 var image_size = image.size;32 var image_mime = image.mime;33 var image_bits = image.bits;34 var image_mediatype = image.mediatype;35 var image_sha1 = image.sha1;36 var image_timestamp = image.timestamp;37 var image_user = image.user;38 var image_userid = image.userid;39 var image_metadata = image.metadata;40 var image_descriptionurl = image.descriptionurl;41 var image_descriptionshorturl = image.descriptionshorturl;42 var image_licenseurl = image.licenseurl;43 var image_licensename = image.licensename;44 var image_commonsmetadata = image.commonsmetadata;45 var image_extmetadata = image.extmetadata;46 var image_restrictiontype = image.restrictiontype;47 var image_restrictionlevels = image.restrictionlevels;48 var image_uploadwarning = image.uploadwarning;49 var image_url = image.url;50 var image_description = image.description;51 var image_descriptionsource = image.descriptionsource;52 var image_extmetadata = image.extmetadata;53 var image_descriptionurl = image.descriptionurl;54 var image_descriptionshorturl = image.descriptionshorturl;55 var image_licenseurl = image.licenseurl;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var union_type = wpt.union_type;3var test_union = union_type({4});5var test = test_union(1);6var test1 = test_union('hello');7var wpt = require('wpt');8var union_type = wpt.union_type;9var test_union = union_type({10});11var test = test_union(1);12var test1 = test_union('hello');13var wpt = require('wpt');14var union_type = wpt.union_type;15var test_union = union_type({16});17var test = test_union(1);18var test1 = test_union('hello');19var wpt = require('wpt');20var union_type = wpt.union_type;21var test_union = union_type({22});23var test = test_union(1);24var test1 = test_union('hello');25var wpt = require('wpt');26var union_type = wpt.union_type;27var test_union = union_type({28});29var test = test_union(1);30var test1 = test_union('hello');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.union_type('Q1860', function(err, resp) {3 console.log(resp);4});5var wptools = require('wptools');6wptools.union_type('Q1860', function(err, resp) {7 console.log(resp);8});9var wptools = require('wptools');10wptools.union_type('Q1860', function(err, resp) {11 console.log(resp);12});13var wptools = require('wptools');14wptools.union_type('Q1860', function(err, resp) {15 console.log(resp);16});17var wptools = require('wptools');18wptools.union_type('Q1860', function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22wptools.union_type('Q1860', function(err, resp) {23 console.log(resp);24});25var wptools = require('wptools');26wptools.union_type('Q1860', function(err, resp) {27 console.log(resp);28});29var wptools = require('wptools');30wptools.union_type('Q1860', function(err, resp) {31 console.log(resp);32});33var wptools = require('w

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 wpt 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