module.exports.generateBusiness = function (amount = 100) { const businesses = []; const suffixes = ['St', 'Dr', 'Rd', 'Blvd', 'Ln', 'Ct']; const randomSuffix = () => suffixes[Math.floor(Math.random() * 6)]; for (let i = 0; i < amount; i += 1) { const entry = { name: `${faker.commerce.product()} ${faker.commerce.productMaterial()} ${faker.company.companySuffix()}`, claimed: Math.floor(Math.random() * 2), // overallRating needs future refactor to generate dynamic rating overallRating: Math.floor(Math.random() * 5) + 1, // totalReviews needs future refactor to generate dynamic count totalReviews: Math.floor(Math.random() * 225) + 10, averageCost: Math.floor(Math.random() * 4) + 1, businessTypeOne: faker.company.catchPhraseAdjective(), businessTypeTwo: faker.name.jobArea(), addressStreet: faker.address.streetAddress(), addressCityStateZip: `${faker.address.city()}, ${faker.address.stateAbbr()} ${faker.address.zipCode()}`, addressBetween: `b/t ${faker.address.streetName()} ${randomSuffix()} & ${faker.address.streetName()} ${randomSuffix()}`, addressNeighborhood: faker.address.city(), phoneNumber: faker.phone.phoneNumber(), url: `${faker.lorem.word()}${faker.internet.domainWord()}.${faker.internet.domainSuffix()}`, }; businesses.push(entry); } return businesses; };
function fakeItem(){ // trying to get a more realistic distribution here const priceMax = faker.random.number(10) > 8 ? 5000 : 100 const random = (odds, value) => faker.random.number(10) < odds ? value : "" const times = (n, func) => { let i = 0 let results = "" while(n > i){ results += func() i = i + 1 } return results } return { id: faker.random.uuid(), sku: times(16, faker.random.alphaNumeric), title: faker.commerce.product(), brand: random(8, faker.company.companyName()), color: random(8, faker.commerce.color()), size: random(8, times(2, faker.random.alphaNumeric)), description: random(8, faker.commerce.productName()), percSplit: faker.random.number(100), price: faker.commerce.price(0, priceMax), printed: faker.random.boolean() } }
export function productVariant(options = {}) { const defaults = { ancestors: [], compareAtPrice: _.random(0, 1000), weight: _.random(0, 10), inventoryManagement: faker.random.boolean(), inventoryPolicy: faker.random.boolean(), lowInventoryWarningThreshold: _.random(1, 5), inventoryQuantity: _.random(0, 100), price: _.random(10, 1000), title: faker.commerce.productName(), optionTitle: faker.commerce.productName(), shopId: getShop()._id, sku: _.random(0, 6), taxable: faker.random.boolean(), type: "variant", metafields: [ metaField(), metaField({ key: "facebook", scope: "socialMessages" }), metaField({ key: "twitter", scope: "socialMessages" }) ] }; return _.defaults(options, defaults); }
function generateProducts() { var categories = []; var products = []; for (var cid = 0; cid < 10; cid++) { categories.push({ id: cid, name: faker.commerce.productAdjective(), }); for (var id = 0; id < 50; id++) { products.push({ category: cid, id: id, name: faker.commerce.productName(), price: faker.commerce.price(), current: faker.commerce.price(), picture: 'https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2523421851,1617129705&fm=80' }); } } return { products: products, categories: categories }; }
export function metaField(options = {}) { const defaults = { key: faker.commerce.productAdjective(), value: faker.commerce.productMaterial(), scope: "detail" }; return _.defaults(options, defaults); }
const goods = _.times(1302, () => new Good( { name: faker.commerce.productName(), price: faker.commerce.price(), code: faker.random.number(), image: faker.image.abstract(120, 120), } )
(category, callback)=>{ for(var i=0; i<30; i++){ var product = new Product(); product.category = new mongoose.Types.ObjectId(category._id); product.name = faker.commerce.productName(); product.price = faker.commerce.price(); product.image = faker.image.image(); product.save(); } }
function(category,callback){ for(var i=0;i<30;i++){ var product = new Product(); product.category = category._id; product.name = faker.commerce.productName(); product.image = faker.image.image(); product.price = faker.commerce.price(); product.save(); } }
var createProduct = () => { return { name: faker.commerce.productName(), price: parseFloat(faker.commerce.price()), department: faker.commerce.department(), color: faker.commerce.color(), sales: faker.random.number({ min: 0, max: 100 }), stock: faker.random.number({ min: 0, max: 100 }) }; };
function(category, callback){ for (var i=0; i<10; i++){ var product = new Product(); product.category = category._id; product.name = faker.commerce.productName(); product.description = faker.lorem.paragraph(); product.price = faker.commerce.price(); product.image = faker.image.image(); product.save(); } }
product: (function(){ var data = []; for (var i = 0; i < 100; i++){ data.push({ id: i + 1, category: faker.random.arrayElement(categories).id, name: faker.commerce.productName(), price: faker.commerce.price(), img: faker.image.food() }); } return data; }())
function(category, callback) { for (var i = 0; i < 30; i++) { //we loop 30 times to create 30 fake products by faker in the products db in mongodb. var product = new Product(); product.category = category._id;//category.id retrieves the cat id based on the url name you typed. //all lines below will belong to the category.id retrieved in line 21 //productName, price, and image and native methods to the faker library. //faker generates massive amounts of fake data product.name = faker.commerce.productName(); product.price = faker.commerce.price(); product.image = faker.image.image(); product.save(); } }
exports.order = function(app, count) { console.info('RUN FAKER ORDER'); var helper = faker.helpers; for(var i = count; i >= 0; i--){ var order = faker.helpers.contextualCard(); var shippingAddress = faker.helpers.userCard(); order._id = (i+1).toString(); order.orderId = 100000 + i; order.account = '#'+faker.finance.account(); order.name = shippingAddress.name; order.dob = dateFormat(order.dob); order.comment = faker.lorem.sentence(); order.shippingAddress = shippingAddress.address; order.shippingAddress.name = shippingAddress.name; order.createdAt = dateFormat(faker.date.past()); order.updatedAt = dateFormat(faker.date.past()); order.items = this.product(app,faker.commerce.price(1, 6, 0, '') * 1, false); order.transaction = faker.helpers.createTransaction(); order.transaction.date = dateFormat(order.transaction.date); // order.subtotal = faker.commerce.price(5.9, 7.9, 2, '') * 1; order.subtotal = 0; order.taxRate = 19.00; for (var item = 0; item < order.items.length; item++) { order.items[item].qty = faker.commerce.price(1, 3, 0, '') * 1; order.items[item].total = order.items[item].price_euro * order.items[item].qty; order.subtotal += order.items[item].total; } order.tax = faker.commerce.price(19, 19, 2, '') * 1; order.shipping = faker.commerce.price(5.9, 7.9, 2, '') * 1; order.discount = 0; order.total = parseFloat(((order.subtotal + order.shipping) * 1.19)).toFixed(2)*1; app.service('orders').create(order, {}).then(function(data) { // console.log('Created product data', 'data'); }); if(i==1) console.log('FAKER ORDER',order); // post('http://localhost:3030/cms', prod); }; // console.log('this.product',this.product); }
function generateGenericDevice (options) { options = options || {} const templateName = options.templateName const idx = options.idx const orgIdx = options.orgIdx const organization = options.organization || {} const namePostfix = _.isNumber(idx) ? idx + 1 : '' const name = options.name || `${(NAMES[templateName] || '').replace(/\s/g, '-')}-${namePostfix}` const serialNumberPostfix = _.isNumber(orgIdx) && _.isNumber(idx) ? _.padStart(DEVICES_PER_ORGANIZATION[templateName] * orgIdx + idx + 1, 6, '0') : '' const serialNumber = options.serialNumber || `${(NAMES[templateName] || '').replace(/\s/g, '-')}-${serialNumberPostfix}` const deviceTemplateId = options.deviceTemplateId const location = getLocation() return { name, serialNumber, deviceTemplateId, deviceTemplate: NAMES[templateName], organization: organization.name, organizationId: organization.id, color: faker.commerce.color(), productionRun: 'DEC2016', hardwareVersion: faker.system.semver(), firmwareVersion: faker.system.semver(), longitude: location[0], latitude: location[1] } }
const insertProducts = function(category, count, cb) { if(count) { for (var i = 0; i < 15; i++) { const product = new Product(); product.category = category._id; product.name = faker.commerce.productName(); product.slug = slug(product.name); product.price = faker.commerce.price(); product.image = faker.image.image(); product.save(); } return cb(null, true); } }
_(count).times(function(n) { business_insert_id++; var number_of_employee = randy.randInt(1000, 100000); var department = '"' + faker.commerce.department() + '"'; var slogan = '"' + faker.company.catchPhrase() + '"'; var annual_business_cost = randy.randInt(1000, 100000); var annual_revenue = randy.randInt(1000, 100000); var annual_profit = annual_business_cost - annual_revenue; var number_of_like = randy.randInt(0, 1000000); var number_of_dislike = randy.randInt(0, 1000000); sqlQuery += '(' + number_of_employee + ',' + department + ',' + slogan + ',' + annual_business_cost + ',' + annual_revenue + ',' + annual_profit + ',' + number_of_like + ',' + number_of_dislike + ',' + business_insert_id + ',' + business_insert_id + ')'; if (n != count-1) sqlQuery += ','; });
const options = range(20).map(i => { const item = faker.commerce.productName() return { isSelected: i === 1, label: item, value: item } })
router.get('/faker/test', (req, res, next)=>{ for(i = 0; i < 20; i++){ let product = new Product(); product.category = '5b33d5eb8312572608dea5da'; product.owner = '5b323c82c5574c1770f0f3a9'; product.image = faker.image.cats(); product.title = faker.commerce.productName(); product.description = faker.lorem.words(); product.price = faker.commerce.price(); product.save(); } res.json({ message:'Succesfully added 20 pictures' }); });
product : function () { return { description: faker.commerce.productName(), bar_code: faker.random.number(100000000000), global_minimum: faker.random.number(20), global_price: faker.random.number(100000) / 100, unit_id: 1 } },
function generateData () { // Championships generation var championships = []; for (var i = 0; i < 10; i++) { championships.push({ "id": i, "name": faker.commerce.product(), "country": { "name": faker.address.country() }, "arjel": faker.random.boolean() }); } // Matches generation var matches = []; for (var j = 0; j < 50; j++) { matches.push({ "id": j, "championshipId": faker.random.arrayElement(championships).id, "home": faker.address.city(), "away": faker.address.city(), "date": faker.date.recent(), "homeOdds": generateDoubleList(10, 1.2, 1.6), "homeStatistics": { "evo": -0.4 }, "drawOdds": generateDoubleList(10, 2.8, 3.4), "drawStatistics": { "evo": 0.0 }, "awayOdds": generateDoubleList(10, 1.9, 2.5), "awayStatistics": { "evo": 0.2 }, "score": faker.random.number({min: 0, max: 10}) + " - " + faker.random.number({min: 0, max: 10}), "status": 0 }); } // Stats by championship generation var statsBychampionships = []; for (var k = 0; k < championships.length; k++) { statsBychampionships.push({ "id": k, "homeMean": faker.finance.amount(1.2, 1.6, 2), "drawMean": faker.finance.amount(2.8, 3.4, 2), "awayMean": faker.finance.amount(1.9, 2.5, 2) }); } return { "championship": championships, "soccermatch": matches, "soccermatchstats": statsBychampionships }; }
export default function () { /** * Tag Factory * @summary define tag Factory */ Factory.define("tag", Tags, { name: "Tag", slug: "tag", position: _.random(0, 100000), // relatedTagIds: [], isTopLevel: true, shopId: getShop()._id, createdAt: faker.date.past(), updatedAt: new Date() }); /** * Product factory * @summary define product Factory */ const base = { ancestors: [], shopId: getShop()._id }; const priceRange = { range: "1.00 - 12.99", min: 1.00, max: 12.99 }; let product = { title: faker.commerce.productName(), pageTitle: faker.lorem.sentence(), description: faker.lorem.paragraph(), type: "simple", vendor: faker.company.companyName(), price: priceRange, isLowQuantity: false, isSoldOut: false, isBackorder: false, metafields: [], requiresShipping: true, // parcel: ?, hashtags: [], isVisible: faker.random.boolean(), publishedAt: new Date(), createdAt: new Date(), updatedAt: new Date() }; Factory.define("product", Products, Object.assign({}, base, product)); Factory.define("variant", Products, { type: "variant" }); }
const categories = (function(){ var data = []; for(var i = 0; i < 6; i++){ data.push({ id: i + 1, name: faker.commerce.department() }) } return data; }());
products: limit => { let products = [] for (let index = 0; index < limit; index++) { products.push({ id: index, title: faker.commerce.productName(), description: faker.lorem.sentence(), price: faker.commerce.price(), user: { id: index, name: faker.name.firstName() } }) } return { products, amountOfProducts: parameters.amountOfProducts } }
function generateProduct() { var product = { name: faker.commerce.productName(), producer: faker.company.companyName(), price: Number(faker.commerce.price()) }; var properties = { size: faker.random.number(), weight: faker.random.number(), material: faker.commerce.productMaterial(), color: faker.commerce.color(), department: faker.commerce.department() }; Object.keys(properties).forEach(function (key) { if (Math.random() > 1 - PRODUCTS_SIMILARITY) { product[key] = properties[key]; } }) return product; }
/** * Generate 5 coupons * @param {[type]} req [description] * @param {[type]} res [description] * @return {[type]} [description] */ generate(req, res) { const coupon = new Coupon(); const coupons = []; for (let i = 0; i < 5; i++) { coupons.push({ name: faker.commerce.product(), description: faker.lorem.words(), price: faker.commerce.price(), code: this.generateCode(), createdAt: new Date(), }); } coupon.collection.insert(coupons, (err, raw) => { if (err) res.status(400).send(err.stack); res.json({ status: 200, message: raw.ops }); }); }
encodeImages(faker.image.image()).then(image => { var currentSubject = { subject: { name: faker.commerce.productName(), complexity: complexity[Math.floor(Math.random() * complexity.length)], characteristics: currentChars, img: image } }; postDisShit("subjects", currentSubject); });
/** * Generate 10 products using faker >:) * @param {[type]} req [description] * @param {[type]} res [description] * @return {[type]} [description] */ generate(req, res) { const product = new Product(); const products = []; for (let i = 0; i < 10; i++) { products.push({ name: faker.commerce.productName(), color: faker.commerce.color(), price: faker.commerce.price(), qty: Math.floor(Math.random() * 100 + 1), createdAt: new Date(), }); } product.collection.insert(products, (err, raw) => { if (err) res.status(400).send(err.stack); res.json({ status: 200, message: raw.ops }); }); }
.then(function(){ for(var i = 0; i < 100; i++){ promiseArray.push(Employee.create({ name: faker.name.findName() })); promiseArray.push(Product.create({ name: faker.commerce.productName() })); } return Promise.all(promiseArray); })
_(count).times(function(n) { var business_name = '"' + faker.company.companyName() + '"'; var owner_first_name = '"' + faker.name.firstName() + '"'; var owner_last_name = '"' + faker.name.lastName() + '"'; var image_link = '"' + faker.image.imageUrl() + '"'; var street_address = '"' + faker.address.streetAddress() + '"'; var city = '"' + faker.address.city() + '"'; var zipcode = '"' + faker.address.zipCode() + '"'; var country = '"' + randy.choice(countries) + '"'; var lat = randy.randInt(-20000000,20000000); var lon = randy.randInt(-20000000,20000000); var area_code = randy.randInt(101, 999); var first_three_number = randy.randInt(101, 999); var last_four_number = randy.randInt(1001, 9999); var number_of_employee = randy.randInt(1000, 100000); var department = '"' + faker.commerce.department() + '"'; var slogan = '"' + faker.company.catchPhrase() + '"'; var annual_business_cost = randy.randInt(1000, 100000); var annual_revenue = randy.randInt(1000, 100000); var annual_profit = annual_business_cost - annual_revenue; var number_of_like = randy.randInt(0, 1000000); var number_of_dislike = randy.randInt(0, 1000000); var updated_at = 'NOW()'; var created_at = 'NOW()'; sqlQuery += '(' + business_name + ',' + owner_first_name + ',' + owner_last_name + ',' + image_link + ',' + street_address + ',' + city + ',' + zipcode + ',' + country + ',' + lat + ',' + lon + ',' + area_code + ',' + first_three_number + ',' + last_four_number + ',' + number_of_employee + ',' + department + ',' + slogan + ',' + annual_business_cost + ',' + annual_revenue + ',' + annual_profit + ',' + number_of_like + ',' + number_of_dislike + ',' + updated_at + ',' + created_at + ')'; if (n != count-1) sqlQuery += ',\n'; });
export function paymentMethod(doc) { return { ...doc, processor: doc.processor ? doc.processor : randomProcessor(), storedCard: doc.storedCard ? doc.storedCard : "4242424242424242", transactionId: doc.transactionId ? doc.transactionId : Random.id(), status: doc.status ? doc.status : randomStatus(), mode: doc.mode ? doc.mode : randomMode(), authorization: "auth field", amount: doc.amount ? doc.amount : faker.commerce.price() }; }