diff options
| author | Jules Laplace <jules@okfoc.us> | 2017-03-20 00:54:41 +0100 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2017-03-20 00:54:41 +0100 |
| commit | 29c18b202b291304ee8b08c2387b25542f76c414 (patch) | |
| tree | 39448f3bc02db693903c2b84ea780a9283259e2a /mock | |
| parent | dc8baa6109b7cc8eac33ba32fdf0f52cfbabd0db (diff) | |
mock data
Diffstat (limited to 'mock')
| -rw-r--r-- | mock/dish.js | 38 | ||||
| -rw-r--r-- | mock/index.js | 81 |
2 files changed, 119 insertions, 0 deletions
diff --git a/mock/dish.js b/mock/dish.js new file mode 100644 index 0000000..5fc998a --- /dev/null +++ b/mock/dish.js @@ -0,0 +1,38 @@ + +const fs = require('fs') +const path = require('path') + +const products = fs.readFileSync('./mock/data/products.default.txt').toString().split('\n') +const techniques = fs.readFileSync('./mock/data/techniques.txt').toString().split('\n') +const preparations = fs.readFileSync('./mock/data/preparations.txt').toString().split('\n') + +function choice(a){ return a[ randint(a.length) ]} +function randint(n){ return Math.floor(Math.random()*n) } + +module.exports = function dish(n){ + var pcount = randint(2) + 1; + var ps = []; + while (pcount-- > 0) ps.push(product()); + if (randint(100) < 90) { + var d = ps.join(" and ") + " " + choice(preparations); + } + else { + var d = ps.join(", "); + } + return d; +} +function product(){ + var result; + if (randint(100) > 1) { + var technique = choice(techniques); + if (technique[0] == '-') { + result = choice(products) + technique + " " + choice(products); + } else { + result = technique + " " + choice(products) + } + } + else { + result = choice(products) + } + return result; +} diff --git a/mock/index.js b/mock/index.js new file mode 100644 index 0000000..ee04bff --- /dev/null +++ b/mock/index.js @@ -0,0 +1,81 @@ +'use strict'; + +const app = require('../src/app') +const dish = require('./dish') + +const User = app.service('users') +const Meal = app.service('meals') + +console.log('hey') + +User.create({ + email: 'admin@toptal', + password: 'admin', + role: 'admin', + goal: 5000, +}).then((user) => { + let userid = user.id + populateMeals(userid) +}) + +User.create({ + email: 'manager@toptal', + password: 'manager', + role: 'manager', + goal: 3000, +}).then((user) => { + let userid = user.id + populateMeals(userid) +}) + +User.create({ + email: 'user@toptal', + password: 'manager', + role: 'user', + goal: 3000, +}).then((user) => { + let userid = user.id + populateMeals(userid) +}) + +function randrange(a,b){ return Math.floor((b-a) * Math.random() + a) } +function quantize(a,n){ return Math.floor(a/n)*n } +function choice(a){ return a[ Math.floor(Math.random()*a.length) ]} + +function populateMeals (userid) { + console.log(userid) + let date = null + for (let i = 0; i < 30; i++) { + date = new Date () + date.setDate( date.getDate() - i ) + for (let j = 0, count = randrange(3,5); j < count; j++) { + switch (j) { + case 0: + date.setHours(randrange(6,11)) + break + case 1: + date.setHours(randrange(12,15)) + break + case 2: + date.setHours(randrange(17,23)) + break + case 3: + date.setHours(randrange(6,23)) + break + case 4: + date.setHours(randrange(0,2)) + break + } + date.setMinutes(randrange(0,60)) + let name = dish() + Meal.create({ + name: name, + calories: quantize(randrange(500,1200), 50), + userid: userid, + date: date, + }).then(function(){ + console.log(name) + }) + } + } +} |
