-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
86 lines (73 loc) · 3.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const MIN = 2;
const MAX = 10;
let FakerPlaces = require('./src/faker/Locations');
let FakerOrders = require('./src/faker/Orders');
let FakerIsochrones = require('./src/faker/Isochrones');
let utils = require('./src/lib/utils');
let pouchdb = require('pouchdb');
pouchdb.plugin(require('pouchdb-erase'));
function logAllErrors() {
console.log(arguments);
}
function init() {
let db = utils.setDatabase("testing");
return db.erase()
.catch(logAllErrors)
.then(() => {
return db.get('_design/extract').catch(function (err) {
if (err.name === 'not_found') {
return db.put({
"_id": "_design/extract",
"language": "javascript",
"views": {
"Isochrones": {
"map": "function(doc) { if(doc.properties.type === 'isochrone') emit(doc._id, null); };"
},
"Customers": {
"map": "function(doc) { if(doc.properties.type === 'customer') emit(doc._id, null); };"
},
"Drivers": {
"map": "function(doc) { if(doc.properties.type === 'driver') emit(doc._id, null); };"
},
"Restaurants": {
"map": "function(doc) { if(doc.properties.type === 'restaurant') emit(doc._id, null); };"
},
"Orders": {
"map": "function(doc) { if(doc.properties.type === 'order') emit(doc._id, null); };"
},
"Locations": {
"map": "function(doc) { if(doc.geometry.type === 'Point') emit(doc._id, null); };"
}
}
});
} else { // hm, some other error
throw err;
}
}).then(()=>{
return new FakerPlaces(MIN, MAX);
});
})
}
function run(){
return init().catch(logAllErrors).then((faker) => {
return new FakerOrders(2, 10, faker.data.customers, faker.data.restaurants, faker.data.drivers);
}).then((faker) => {
return new FakerIsochrones(
faker.data.customers,
faker.data.restaurants,
faker.data.drivers,
faker.data.orders
);
}).then((faker) => {
console.log(`Created:
${faker.data.customers.length} Customers
${faker.data.drivers.length} Drivers
${faker.data.restaurants.length} Restaurants
${faker.data.orders.length} Orders
${faker.data.isochrones.length} Isochrones`);
// require('./test/Generate_Customer_Features');
return faker;
});
}
// run();
module.exports = run;