-
Notifications
You must be signed in to change notification settings - Fork 0
/
obj_test_poll2.js
112 lines (99 loc) · 2.49 KB
/
obj_test_poll2.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
112
// database setup
var mongoose = require('mongoose');
var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
// connect to the database
mongoose.connect(`mongodb://localhost/winterfell`);
// When successfully connected
mongoose.connection.on('connected', () => {
console.log('Connection to database established successfully');
});
// If the connection throws an error
mongoose.connection.on('error', (err) => {
console.log('Error connecting to database: ' + err);
});
// When the connection is disconnected
mongoose.connection.on('disconnected', () => {
console.log('Database disconnected');
});
var Poll = require('./models/pollModel.js')
var obj = new Poll();
obj.name = "Legalising Gay rights";
obj.description = "legal recognition to marriage for same-sex couples";
obj.city = "Bhubaneswar";
obj.upvotes = 110;
obj.options = [{
name: "Gay rights shouldn't be legalised",
votes: []
},
{
name: "Gay rights should be legalised",
votes: []
}
];
for (var i =0;i<70;i++){
var age = Math.floor(Math.random() * (40 - 20 + 1) + 20);
var sex = "Female"
obj.options[0].votes.push({
lat: String(age),
long: String(sex)
});
}
for (var i =0;i<65;i++){
var age = Math.floor(Math.random() * (40 - 20 + 1) + 20);
var sex = "Male"
obj.options[0].votes.push({
lat: String(age),
long: String(sex)
});
}
for (var i =0;i<20;i++){
var age = Math.floor(Math.random() * (70 - 40 + 1) + 40);
var sex = "Female"
obj.options[0].votes.push({
lat: String(age),
long: String(sex)
});
}
for (var i =0;i<20;i++){
var age = Math.floor(Math.random() * (70 - 40 + 1) + 40);
var sex = "Male"
obj.options[1].votes.push({
lat: String(age),
long: String(sex)
});
}
for (var i =0;i<15;i++){
var age = Math.floor(Math.random() * (40 - 20 + 1) + 20);
var sex = "Female"
obj.options[1].votes.push({
lat: String(age),
long: String(sex)
});
}
for (var i =0;i<18;i++){
var age = Math.floor(Math.random() * (40 - 20 + 1) + 20);
var sex = "Male"
obj.options[1].votes.push({
lat: String(age),
long: String(sex)
});
}
for (var i =0;i<50;i++){
var age = Math.floor(Math.random() * (70 - 40 + 1) + 40);
var sex = "Female"
obj.options[1].votes.push({
lat: String(age),
long: String(sex)
});
}
for (var i =0;i<55;i++){
var age = Math.floor(Math.random() * (70 - 40 + 1) + 40);
var sex = "Male"
obj.options[1].votes.push({
lat: String(age),
long: String(sex)
});
}
console.log(obj.options[0].votes);
mongoose.connection.close();