git ssb

1+

andrestaltz / ssb-to-graphml



Commit 0bed468ddc8682a39b1a3c0ad3d77d6cbe455b7a

add feed sequence data to export

mix irving committed on 6/28/2018, 8:59:28 AM
Parent: 14ed1d15bd344062047e7d73def69d568f4bb91f

Files changed

.gitignorechanged
index.jschanged
.gitignoreView
@@ -1,2 +1,3 @@
11 node_modules
22 shrinkwrap.yaml
3 +*.graphml
index.jsView
@@ -27,32 +27,43 @@
2727 } catch (error) {
2828 nodeLabels[key] = '';
2929 }
3030 }
31 + const nodeSeqs = {};
32 + for (let key of nodes) {
33 + try {
34 + nodeSeqs[key] = await pify(sbot.latestSequence)(key);
35 + } catch (error) {
36 + nodeSeqs[key] = 0;
37 + }
38 + }
3139 const follows = await pify(sbot.friends.get)();
3240 const edges = Object.keys(follows)
3341 .map(orig =>
3442 Object.keys(follows[orig])
3543 .filter(dest => follows[orig][dest] === true)
3644 .map(dest => [orig, dest]),
3745 )
3846 .reduce((accumulated, current) => accumulated.concat(current), []);
39- return {nodes, edges, nodeLabels};
47 + return {nodes, edges, nodeLabels, nodeSeqs};
4048 }
4149
42-function* toGraphml({nodes, edges, nodeLabels}) {
50 +function* toGraphml({nodes, edges, nodeLabels, nodeSeqs}) {
4351 yield '<?xml version="1.0" encoding="UTF-8"?>\n';
4452 yield `<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
4553 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4654 xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
4755 http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">\n`;
4856 yield ' <graph id="G" edgedefault="directed">\n';
4957 yield ' <key id="d0" for="node" attr.name="label" attr.type="string"/>\n';
58 + yield ' <key id="d1" for="node" attr.name="seq" attr.type="int"/>\n';
5059 for (let id of nodes) {
5160 const name = nodeLabels[id];
52- if (name) {
61 + const seq = nodeSeqs[id];
62 + if (name && seq) {
5363 yield ` <node id="${id}">\n`;
5464 yield ` <data key="d0">${encodeURIComponent(name)}</data>\n`;
65 + yield ` <data key="d1">${seq}</data>\n`;
5566 yield ` </node>\n`;
5667 } else {
5768 yield ` <node id="${id}"/>\n`;
5869 }

Built with git-ssb-web