-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata-export.js
More file actions
318 lines (259 loc) · 12.6 KB
/
data-export.js
File metadata and controls
318 lines (259 loc) · 12.6 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#! /usr/bin/env node
console.log('This data export is running!!!!');
const async = require('async')
const Actor = require('./models/Actor.js');
const Script = require('./models/Script.js');
const User = require('./models/User.js');
const _ = require('lodash');
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const fs = require('fs')
var UAParser = require('ua-parser-js');
const util = require('util');
// const dotenv = require("dotenv");
dotenv.config();
var csvWriter = require('csv-write-stream');
var mlm_writer = csvWriter();
//var s_writer = csvWriter();
//var summary_writer = csvWriter();
//5bb3a93ad9fd14471bf3977d
//5bb3a93ad9fd14471bf39791
//5bb3a93ad9fd14471bf39792
//5bb3a93ad9fd14471bf397c8
//var bully_messages = ["5bb3a93ad9fd14471bf3977d",
//"5bb3a93ad9fd14471bf39791",
//"5bb3a93ad9fd14471bf39792",
//"5bb3a93ad9fd14471bf397c8"];
//var bully_stats = [];
//var sur_array = [];
Array.prototype.sum = function() {
return this.reduce(function(a,b){return a+b;});
};
var mlm_array = [];
// dotenv.load({ path: '.env' });
dotenv.config({ path: '.env' });
/*
var MongoClient = require('mongodb').MongoClient
, assert = require('assert');
//var connection = mongo.connect('mongodb://127.0.0.1/test');
mongoose.connect(process.env.PRO_MONGODB_URI || process.env.PRO_MONGOLAB_URI);
var db = mongoose.connection;
mongoose.connection.on('error', (err) => {
console.error(err);
console.log('%s MongoDB connection error. Please make sure MongoDB is running.', chalk.red('✗'));
process.exit();
}); */
/**
* Connect to MongoDB.
*/
mongoose.Promise = global.Promise;
//mongoose.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI);
//mongoose.connect(process.env.MONGOLAB_TEST || process.env.PRO_MONGOLAB_URI, { useMongoClient: true });
mongoose.connect(process.env.MONGODB_URI || process.env.mongolab_uri_test, { useNewUrlParser: true });
mongoose.connection.on('error', (err) => {
console.error(err);
console.log('%s MongoDB connection error. Please make sure MongoDB is running.', chalk.red('✗'));
process.exit();
});
User.find()
// .where('active').equals(false)
.populate({
path: 'feedAction.post',
model: 'Script',
populate: {
path: 'actor',
model: 'Actor'
}
})
.exec(
function(err, users){
mlm_writer.pipe(fs.createWriteStream('results/vaping.csv'));
for (var i = users.length - 1; i >= 0; i--)
{
//console.log('print joined tables: ', users[0].feedAction[0].comments.length==0);
var mlm = {};
//var sur = {};
//var sums = {};
mlm.Participant_ID = users[i].UID;
//per feedAction
mlm.Agg_exp = 0;
mlm.Agg_com = 0;
mlm.Agg_likes = 0;
mlm.Agg_flag =0;
//var dict= {ALID1A: 209 , ALID2A: 150, ALID3A: 151, ALID1B :210, ALID2B: 152, ALID3B: 153, ALID1C: 211, ALID2C: 154, ALID3C: 155, ALID1D: 212, ALID2D: 156, ALID3D:157, RVID1A: 138, RVID2A: 139, RVID3A:144, RVID4A:145, RVID1B:140, RVID2B:141, RVID3B: 146, RVID4B: 147, RVID1C: 142, RVID2C:143, RVID3C:148, RVID4C:149, SNID1A: 213, SNID2A:214, SNID3A: 126, SNID1B:215, SNID2B:216, SNID3B:127};
var dict = {
'ALID1A': '6376e007902b88206158308b',
'ALID2A': '6376e005902b882061582fd1',
'ALID3A': '6376e005902b882061582fb7',
'ALID1B': '6376e005902b882061582fbf',
'ALID2B': '6376e005902b882061582fc9',
'ALID3B': '6376e006902b882061582ffd',
'ALID1C': '6376e007902b88206158303b',
'ALID2C': '6376e007902b88206158307b',
'ALID3C': '6376e006902b882061583003',
'ALID1D': '6376e006902b882061582fe1',
'ALID2D': '6376e006902b882061583009',
'ALID3D': '6376e007902b882061583041',
'RVID1A': '6376e005902b882061582fbb',
'RVID2A': '6376e007902b88206158308f',
'RVID3A': '6376e007902b882061583071',
'RVID4A': '6376e005902b882061582fc7',
'RVID1B': '6376e005902b882061582fcb',
'RVID2B': '6376e006902b882061582fff',
'RVID3B': '6376e005902b882061582fd5',
'RVID4B': '6376e007902b882061583095',
'RVID1C': '6376e007902b88206158303d',
'RVID2C': '6376e006902b882061582fdd',
'RVID3C': '6376e007902b88206158309d',
'RVID4C': '6376e007902b88206158307f',
'SNID1A': '6376e007902b88206158308d',
'SNID2A': '6376e007902b88206158306f',
'SNID3A': '6376e005902b882061582fb9',
'SNID1B': '6376e007902b882061583079',
'SNID2B': '6376e005902b882061582fcf'
}
// for each post
let str = "ALID1A_exp ALID1A_com ALID1A_like ALID1A_flag ALID2A_exp ALID2A_com ALID2A_like ALID2A_flag ALID3A_exp ALID3A_com ALID3A_like ALID3A_flag ALID1B_exp ALID1B_com ALID1B_like ALID1B_flag ALID2B_exp ALID2B_com ALID2B_like ALID2B_flag ALID3B_exp ALID3B_com ALID3B_like ALID3B_flag ALID1C_exp ALID1C_com ALID1C_like ALID1C_flag ALID2C_exp ALID2C_com ALID2C_like ALID2C_flag ALID3C_exp ALID3C_com ALID3C_like ALID3C_flag ALID1D_exp ALID1D_com ALID1D_like ALID1D_flag ALID2D_exp ALID2D_com ALID2D_like ALID2D_flag ALID3D_exp ALID3D_com ALID3D_like ALID3D_flag RVID1A_exp RVID1A_com RVID1A_like RVID1A_flag RVID2A_exp RVID2A_com RVID2A_like RVID2A_flag RVID3A_exp RVID3A_com RVID3A_like RVID3A_flag RVID4A_exp RVID4A_com RVID4A_like RVID4A_flag RVID1B_exp RVID1B_com RVID1B_like RVID1B_flag RVID2B_exp RVID2B_com RVID2B_like RVID2B_flag RVID3B_exp RVID3B_com RVID3B_like RVID3B_flag RVID4B_exp RVID4B_com RVID4B_like RVID4B_flag RVID1C_exp RVID1C_com RVID1C_like RVID1C_flag RVID2C_exp RVID2C_com RVID2C_like RVID2C_flag RVID3C_exp RVID3C_com RVID3C_like RVID3C_flag RVID4C_exp RVID4C_com RVID4C_like RVID4C_flag SNID1A_exp SNID1A_com SNID1A_like SNID1A_flag SNID1A_reply1_like SNID1A_reply1_flag SNID1A_reply2_like SNID1A_reply2_flag SNID1A_reply3_like SNID1A_reply3_flag SNID2A_exp SNID2A_com SNID2A_like SNID2A_flag SNID2A_reply1_like SNID2A_reply1_flag SNID2A_reply2_like SNID2A_reply2_flag SNID2A_reply3_like SNID2A_reply3_flag SNID2A_reply4_like SNID2A_reply4_flag SNID3A_exp SNID3A_com SNID3A_like SNID3A_flag SNID3A_reply1_like SNID3A_reply1_flag SNID3A_reply2_like SNID3A_reply2_flag SNID3A_reply3_like SNID3A_reply3_flag SNID3A_reply4_like SNID3A_reply4_flag SNID3A_reply5_like SNID3A_reply5_flag SNID3A_reply6_like SNID3A_reply6_flag SNID1B_exp SNID1B_com SNID1B_like SNID1B_flag SNID1B_reply1_like SNID1B_reply1_flag SNID1B_reply2_like SNID1B_reply2_flag SNID1B_reply3_like SNID1B_reply3_flag SNID2B_exp SNID2B_com SNID2B_like SNID2B_flag SNID2B_reply1_like SNID2B_reply1_flag SNID2B_reply2_like SNID2B_reply2_flag SNID2B_reply3_like SNID2B_reply3_flag SNID2B_reply4_like SNID2B_reply4_flag SNID3B_exp SNID3B_com SNID3B_like SNID3B_flag SNID3B_reply1_like SNID3B_reply1_flag SNID3B_reply2_like SNID3B_reply2_flag SNID3B_reply3_like SNID3B_reply3_flag SNID3B_reply4_like SNID3B_reply4_flag SNID3B_reply5_like SNID3B_reply5_flag SNID3B_reply6_like SNID3B_reply6_flag" ;
const myarray = str.split(" ");
//console.log("dddddd : " +myarray[0]);
for (var w=0;w<myarray.length ;w++)
{
mlm[myarray[w]]=0;
//console.log("dddddd : " +myarray[i]);
}
// console.log(users[i].posts);
//per feedAction
for (var k = users[i].feedAction.length - 1; k >= 0; k--)
{
//console.log('make sure it is running for ');
//console.log(users[i].feedAction[k].posts);
if(users[i].feedAction[k].post != null )
{
//console.log(users[i].feedAction[k].post._id);
if(users[i].feedAction[k].post.post_class == 'normal' )
{
mlm.Agg_exp++;
if(users[i].feedAction[k].comments.length!=0 )
{
for (var temp = 0 ; temp <users[i].feedAction[k].comments.length; temp++)
{
if(users[i].feedAction[k].comments[temp].new_comment)
{
mlm.Agg_com++;
}
}
}
if(users[i].feedAction[k].liked)
{
mlm.Agg_likes++;
}
if(users[i].feedAction[k].flagTime.length !=0)
{
mlm.Agg_flag++;
}
//console.log('make sure it is running for per feedAction');
}
for (var w=0;w<myarray.length ;w++)
{
//console.log("really ?");
var array = myarray[w].split("_");
//console.log(array);
//const array = myarray[0].split("_");
if(array.length==2)
{
if(users[i].feedAction[k].post._id==dict[array[0]])
{
switch(array[1]){
case "exp" :
mlm[myarray[w]]=1;
//console.log(array);
break;
case "com" :
if(users[i].feedAction[k].comments.length!=0 )
{
for (var temp = 0 ; temp <users[i].feedAction[k].comments.length; temp++)
{
if(users[i].feedAction[k].comments[temp].new_comment)
{
//console.log(array);
mlm[myarray[w]]=1;
}
}
}
break;
case "like" :
if(users[i].feedAction[k].liked)
{
//console.log(array);
mlm[myarray[w]]=1;
}
break;
case "flag" :
if(users[i].feedAction[k].flagTime.length !=0)
{
//console.log(array);
mlm[myarray[w]]=1;
}
}
}
}
else if(array.length==3)
{
//console.log("really ?");
if(users[i].feedAction[k].post._id==dict[array[0]] )
{
//console.log(users[i].feedAction[k].post);
var tempid = users[i].feedAction[k].post.comments[(array[1].replace(/[^0-9]/g, ''))-1]._id;
//console.log(typeof tempid);
//console.log("there should be one match");
//console.log(users[i].feedAction[k].post.comments[5]._id);
for(let d = 0;d<users[i].feedAction[k].comments.length;d++)
{
var tempin = users[i].feedAction[k].comments[d].comment;
//console.log("we are comparing :"+ tempid +" and " + tempin + ". The result is: " + (JSON.stringify(tempid) == JSON.stringify(tempin)));
//console.log("Go through all the comments with action: " +tempin);
if(JSON.stringify(tempid) === JSON.stringify(tempin))
{
//console.log("there should be one pinrted here");
switch(array[2]){
case "like" :
if(users[i].feedAction[k].comments[d].liked)
{
//console.log(array);
mlm[myarray[w]]=1;
}
break;
case "flag" :
if(users[i].feedAction[k].comments[d].flagged)
{
//console.log(array);
mlm[myarray[w]]=1;
}
}
}
}
//console.log("*************************************");
}
}
}
}
}//for Per FeedAction
//mlm.GeneralReplyNumber = users[i].numReplies + 1;
mlm_writer.write(mlm);
//s_writer.write(sur);
}
//for each user
/*
for (var zz = 0; zz < mlm_array.length; zz++) {
//console.log("writing user "+ mlm_array[zz].email);
//console.log("writing Bully Post "+ mlm_array[zz].BullyingPost);
mlm_writer.write(mlm_array[zz]);
}
*/
//console.log("Post Table should be "+ sur_array.length);
mlm_writer.end();
//summary_writer.end();
//s_writer.end();
console.log('Wrote MLM!');
mongoose.connection.close();
});