updown = {
let updown = [];
let state = {};
let ts = null;
data.initial_state.forEach( d => {
state[ [ d[3],d[5] ] ] = d3.timeParse("%s")( d[1] )
});
updates.forEach( x => {
if( x.type == 'W' && [ x.peer_ip, x.pfx ] in state) {
updown.push({
'peer_ip': x.peer_ip,
'pfx': x.pfx,
'start_ts': state[ [x.peer_ip, x.pfx] ],
'end_ts': x.ts
});
delete state[ [ x.peer_ip, x.pfx ] ];
} else if ( x.type == 'A' && state[ x.peer_ip, x.pfx ] === undefined ) {
state[ [ x.peer_ip, x.pfx ] ] = x.ts
} else {
}
});
let end_end_ts = updates[ updates.length - 1 ].ts ;
for ( var key in state ) {
key = key.split(',');
updown.push({
'peer_ip': key[0],
'pfx': key[1],
'start_ts': state[ key ],
'end_ts': end_end_ts
});
}
return updown
};