forked from devleague/omnimood
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbSetup.js
More file actions
67 lines (60 loc) · 1.55 KB
/
dbSetup.js
File metadata and controls
67 lines (60 loc) · 1.55 KB
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
const mongoose = require('mongoose');
const MONGO_URL = 'mongodb://localhost/omnimood';
const connection = mongoose.connect(MONGO_URL);
const data = require('./json/newCountryList.json');
const Country = require('./models/countries');
const Timeline = require('./models/timeline');
const emojiData = require('./json/emoji.json');
const bluebird = require('bluebird');
const emojiCode = require('./json/codeEmoji.json');
var sendData = [];
var countryName = {}
data.forEach((element)=>{
countryName[element.codeNum] = [];
sendData.push({name: element.name, code: element.code, codeNum: parseInt(element.codeNum)});
});
var list = {};
var emojiNames = {};
var totalCount = {};
for(var face in emojiData){
var inFace = emojiData[face];
var nameFace = inFace.name;
list[nameFace] = 0;
emojiNames[nameFace] = '';
}
for(var code in emojiCode){
var codeCode = emojiCode[code].code;
totalCount[codeCode] = {
count: 0,
percentage: 0
};
}
totalCount.total = 0;
list.amount = 0;
list.negativeEmojis = 0;
list.neutralEmojis = 0;
list.positiveEmojis = 0;
var timeSave = new Timeline({
countries: countryName,
times: [],
topEmojis: emojiNames,
totalCount: totalCount
})
mongoose.connection.once('open', function() {
Promise.all([
Country.insertMany(sendData.map((element, index, array) =>{
return {
countryId: element.codeNum,
name: element.name,
code: element.code,
GPS: '0,0',
mood: 0,
emoji: list
}
})),
timeSave.save()
])
.then(function() {
mongoose.connection.close();
});
});