-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
117 lines (94 loc) · 3.43 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
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
113
114
115
116
117
'use strict';
const fs = require('fs');
const request = require('request');
const wsLocations = fs.createWriteStream('./olddata/locations.json');
const wsTrips = fs.createWriteStream('./olddata/trips.json');
const wsMessages = fs.createWriteStream('./olddata/messages.json');
const wsUsers = fs.createWriteStream('./olddata/users.json');
const wsConversations = fs.createWriteStream('./olddata/conversations.json');
const wsSchoenhiers = fs.createWriteStream('./olddata/schoenhiers.json');
//const wsImage = fs.createWriteStream('./image.jpeg');
let allData;
try {
allData = require('./allData.json');
} catch(e) {
console.log('pls create allData.json with all documents from couchdb first');
console.log('with VPN: http://locator.in.htwg-konstanz.de:5984/app/_all_docs?include_docs=true');
process.exit();
}
console.log('total elements', allData.total_rows);
//console.log(allData.rows[0]);
console.time('locations filter');
wsLocations.on('error', err => {
console.error(err);
});
const locations = allData.rows.filter(elem => {
let loc = elem.doc;
return loc.type === 'location' && !loc.preLocation && !loc.delete;
}).map(elem => {
return elem.doc;
});
const prelocations = allData.rows.filter(elem => {
let loc = elem.doc;
return loc.type === 'location' && loc.preLocation && !loc.delete;
}).map(elem => {
return elem.doc;
});
const trips = allData.rows.filter(elem => {
let trip = elem.doc;
return trip.type === 'trip';
}).map(elem => {
return elem.doc;
});
const messages = allData.rows.filter(elem => {
let mess = elem.doc;
return mess.type === 'message' && !mess.message.startsWith('Herzlich Willkommen im Chat von Locator') && !mess.message.startsWith('Übrigens:') && !mess.message.startsWith('Wenn du uns Feedback');
}).map(elem => {
return elem.doc;
});
const conversations = allData.rows.filter(elem => {
let conversation = elem.doc;
return conversation.type === 'conversation'
}).map(elem => {
return elem.doc;
});
const users = allData.rows.filter(elem => {
let user = elem.doc;
return user.type === 'user'
}).map(elem => {
return elem.doc;
});
const schoenhiers = allData.rows.filter(elem => {
let sh = elem.doc;
return sh.type === 'schoenhiers'
}).map(elem => {
return elem.doc;
});
const designDocs = allData.rows.filter(elem => {
let sh = elem.doc;
return sh._id.startsWith('_design');
}).map(elem => {
return elem.doc;
});
wsLocations.write(JSON.stringify(locations));
wsLocations.end();
wsTrips.write(JSON.stringify(trips));
wsTrips.end();
wsMessages.write(JSON.stringify(messages));
wsMessages.end();
wsConversations.write(JSON.stringify(conversations));
wsConversations.end();
wsUsers.write(JSON.stringify(users));
wsUsers.end();
wsSchoenhiers.write(JSON.stringify(schoenhiers));
wsSchoenhiers.end();
console.timeEnd('locations filter');
console.log('locations:', locations.length);
console.log('prelocations:', prelocations.length);
console.log('trips:', trips.length);
console.log('messages:', messages.length);
console.log('conversations:', conversations.length);
console.log('user:', users.length);
console.log('schoenhiers:', schoenhiers.length);
console.log('designDocs:', designDocs.length);
console.log('docs left:', allData.total_rows - (locations.length + prelocations.length + trips.length + messages.length + users.length + conversations.length + schoenhiers.length + designDocs.length), '(some of them might be the welcome messages)')