-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.js
82 lines (52 loc) · 1.62 KB
/
init.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
var lazy = require("lazy"),
fs = require("fs"),
pg = require('pg'),
xml2js = require('xml2js');
var conString = "postgres://tyler:tyler@localhost/tyler";
//this starts initializes a connection pool
//it will keep idle connections open for a (configurable) 30 seconds
//and set a limit of 20 (also configurable)
//region and timestep
//person every step from time 1 to time 2
//Trivial data storage
var parser = new xml2js.Parser();
pg.connect(conString, function(err, client, done) {
if(err) {
return console.error('error fetching client from pool', err);
}
//(id,pid,time,x,y)
var query = "INSERT INTO log VALUES (DEFAULT,$1,$2,$3,$4);"
//console.log(query)
new lazy(fs.createReadStream('initial_data/sim.xml'))
.lines
.forEach(function(line){
var line = line.toString();
parser.parseString(line, function (err, result) {
if(err){
console.log(err);
}
else {
client.query(query, [result.log.$.id,result.log.$.simstep,result.log.$.x,result.log.$.y], function(err, result) {
if(err) {
return console.error('error running query', err);
}
});
}
});
});
});
// fs.readFile('initial_data/sim.xml', function(err, data) {
// parser.parseString(data, function (err, result) {
// if(err){
// console.log(err);
// }
// else {
// var logs = result.gpsLog.log;
// //insert each log
// logs.forEach(function(entry) {
// insertRow(entry)
// });
// //console.log('Done');
// }
// });
// });