forked from slickage/adness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js
111 lines (94 loc) · 2.67 KB
/
seed.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* jshint node: true */
'use strict';
var config = require('./config');
var db = require('./db');
var nano = require('nano')(db.getCouchUrl());
var ddoc = require('./ddoc');
var dbinit = require('./db-init');
var dbname = config.couchdb.name;
var couch;
// check for db
dbinit.validateDBExist(seed);
var seed = function() {
var start = new Date();
var end = new Date(start);
end.setHours(end.getHours() + 4);
var timeDifference = (1000 * 60 * config.antiSnipeMinutes);
var trueEnd = Math.floor(Math.random() * (timeDifference+1));
trueEnd = end.getTime() + trueEnd;
// within time and enabled
var openAuction = {
type: 'auction',
start: start.getTime(),
end: end.getTime(),
trueEnd: trueEnd,
slots: 10,
enabled: true
};
// within time and disabled
var closedAuction = {
type: 'auction',
start: start.getTime(),
end: end.getTime(),
trueEnd: trueEnd,
slots: 10,
enabled: false
};
var comingStart = new Date();
var comingEnd = new Date(start);
comingStart.setMonth(comingStart.getMonth() + 4);
comingEnd.setMonth(comingEnd.getMonth() + 4);
comingEnd.setHours(comingEnd.getHours() + 4);
timeDifference = (1000 * 60 * 30);
var comingTrueEnd = Math.floor(Math.random() * (timeDifference+1));
comingTrueEnd = comingEnd.getTime() + comingTrueEnd;
// coming auction
var comingAuction = {
type: 'auction',
start: comingStart.getTime(),
end: comingEnd.getTime(),
trueEnd: comingTrueEnd,
slots: 10,
enabled: true
};
var pastStart = new Date();
var pastEnd = new Date(start);
pastStart.setMonth(pastStart.getMonth() - 4);
pastEnd.setMonth(pastEnd.getMonth() - 4);
pastEnd.setHours(pastEnd.getHours() + 4);
timeDifference = (1000 * 60 * 30);
var pastTrueEnd = Math.floor(Math.random() * (timeDifference+1));
pastTrueEnd = pastEnd.getTime() + pastTrueEnd;
// past auction
var pastAuction = {
type: 'auction',
start: pastStart.getTime(),
end: pastEnd.getTime(),
trueEnd: pastTrueEnd,
slots: 10,
enabled: true
};
couch.insert(openAuction);
couch.insert(closedAuction);
couch.insert(comingAuction);
couch.insert(pastAuction);
// recurring auctions
var times = 0;
start = new Date();
end = new Date(start.getTime() + (1000 * 60 * 5));
while (times < 50) {
start.setTime(start.getTime() + (1000 * 60 * 5));
end.setTime(end.getTime() + (1000 * 60 * 5));
var recurringAuction = {
type: 'auction',
start: start.getTime(),
end: end.getTime(),
trueEnd: end.getTime(),
slots: 8,
enabled: true
};
couch.insert(recurringAuction);
times++;
}
console.log('Seeding data to: ' + db.getCouchUrl());
};