Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: blockchain-lab/ScaleOutDistributedLedger
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: blockchain-lab/ScaleOutDistributedLedger
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 4 commits
  • 7 files changed
  • 3 contributors

Commits on Feb 15, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    67d66b5 View commit details

Commits on Feb 19, 2018

  1. added data writing

    bart-de-jonge committed Feb 19, 2018
    Copy the full SHA
    189a62c View commit details
  2. Merge pull request #79 from bartdejonge1996/more-data-points

    added data writing
    Bart de Jonge authored Feb 19, 2018
    Copy the full SHA
    a021804 View commit details
  3. Merge pull request #78 from bartdejonge1996/fix-rounding

    Fix rounding for demo
    Bart de Jonge authored Feb 19, 2018
    Copy the full SHA
    1bb03b7 View commit details
5 changes: 4 additions & 1 deletion tracker-server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules/*
.idea/*
dist/*
dist/*
data.csv
nodelist.json
transactionlist.json
19 changes: 19 additions & 0 deletions tracker-server/model/TransactionList.js
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ class TransactionList {
this.numberOfTransactions = 0;
this.numberOfChains = 0;
this.numberOfBlocks = 0;
this.numbersArray = [];
}

/**
@@ -91,6 +92,24 @@ class TransactionList {
averageNumberOfChains: averageNumberOfChains
};
}

/**
* Adds numbers data point to the array.
*/
addNumbersToArray() {
const numbers = this.getNumbers();
if(numbers.numberOfTransactions !== 0 || numbers.averageNumberOfBlocks !== 0 || numbers.averageNumberOfChains !== 0) {
this.numbersArray.push(numbers);
}
}

/**
* Gets the numbers array.
* @returns {Array}
*/
getNumbersArray() {
return this.numbersArray;
}
}

module.exports = TransactionList;
10 changes: 10 additions & 0 deletions tracker-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tracker-server/package.json
Original file line number Diff line number Diff line change
@@ -19,9 +19,11 @@
"dependencies": {
"body-parser": "latest",
"cookie-parser": "^1.4.3",
"csv-writer": "0.0.3",
"debug": "latest",
"ejs": "^2.5.7",
"express": "^4.16.2",
"fs": "0.0.1-security",
"jsnetworkx": "^0.3.4",
"morgan": "^1.9.0"
}
17 changes: 8 additions & 9 deletions tracker-server/public/javascripts/demo.js
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ $(document).ready(function() {
network.setData({nodes: data.nodes, edges: data.edges});
network.redraw();
$(".transactions").text(data.numbers.numberOfTransactions);
$(".chains").text(data.numbers.averageNumberOfChains);
$(".blocks").text(data.numbers.averageNumberOfBlocks);
$(".chains").text(Math.round(data.numbers.averageNumberOfChains * 100) / 100);
$(".blocks").text(Math.round(data.numbers.averageNumberOfBlocks * 100) / 100);
};

window.odometerOptions = {
@@ -74,11 +74,10 @@ $(document).ready(function() {

var counter = 12;

$("#graph_button").on('click', function() {
edges[0].value += 1;
counter += 1;
$(".odometer").text(counter);
network.setData({nodes: nodes, edges: edges});
network.redraw();
$("#saveButton").on("click", function() {
$.ajax({
method: 'POST',
url: '/write-data'
});
});
});
});
29 changes: 29 additions & 0 deletions tracker-server/routes/index.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ const router = express.Router();
import app from '../app';
import NodeList from '../model/NodeList';
const sseMW = require('./../helpers/sse');
const fs = require('fs');
import Transaction from '../model/Transaction';
import TransactionList from '../model/TransactionList';

@@ -113,6 +114,7 @@ router.post('/reset', (req, res) => {
app.nodeList = new NodeList();
app.transactionList = new TransactionList();
res.json({success: true});
initDataHeartbeat();
});

/**
@@ -146,6 +148,33 @@ function updateSseClients() {
{nodes: nodes, edges: edges, numbers: app.transactionList.getNumbers()}));
}

function initDataHeartbeat() {
setInterval(() => {
app.transactionList.addNumbersToArray();
}, 5000);
}

/**
* Write all data.
*/
router.post('/write-data', (req, res) => {
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const csvWriter = createCsvWriter({
path: './data.csv',
header: [
{id: 'numberOfTransactions', title:'numberOfTransactions'},
{id: 'averageNumberOfBlocks', title:'averageNumberOfBlocks'},
{id: 'averageNumberOfChains', title:'averageNumberOfChains'}
]
});
fs.writeFile('./nodelist.json', JSON.stringify(app.nodeList, null, 2) , 'utf-8');
fs.writeFile('./transactionlist.json', JSON.stringify(app.transactionList, null, 2) , 'utf-8');
csvWriter.writeRecords(app.transactionList.getNumbersArray()).then(() => {
console.log("Writing to csv done!");
res.json(app.transactionList.getNumbersArray());
});
});

/**
* send a heartbeat signal to all SSE clients, once every interval seconds (or every 3 seconds if no interval is specified)
* @param interval - interval in seconds
2 changes: 1 addition & 1 deletion tracker-server/views/demo.ejs
Original file line number Diff line number Diff line change
@@ -41,6 +41,6 @@
</body>

<footer>

<button id="saveButton">Save data</button>
</footer>
</main>