Skip to content

Commit

Permalink
Merge pull request #12 from SamYuan1990/decoupleInputOutput
Browse files Browse the repository at this point in the history
decouple input and output
  • Loading branch information
SamYuan1990 committed Oct 19, 2020
2 parents fc4b7c4 + e8397a8 commit 8c39893
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 1 deletion.
Empty file added data/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion data/rs.csv
Expand Up @@ -14,4 +14,4 @@ sample,2,120,2,256, 323.526945,
sample,1.5,10,2,256, 172.745382,
sample,1.5,40,2,256, 268.041591,
sample,1.5,80,2,256, 348.150198,
sample,1.5,120,2,256, 310.915616,
sample,1.5,120,2,256, 310.915616,
18 changes: 18 additions & 0 deletions lib/libs.js
Expand Up @@ -33,4 +33,22 @@ exports.loadRs = function loadRs(lab){
}
});
return rs;
}

exports.init = function init(){
try {
fs.unlinkSync('./data/rs.csv')
fs.appendFileSync('./data/rs.csv', 'Chaincode,BatchTimeout,MaxMessageCount,AbsoluteMaxBytes,PreferredMaxBytes,TPS,');
} catch (err) {
/* 处理错误 */
console.log(err)
}
}

exports.run = function run(data){
try {
fs.appendFileSync('./data/rs.csv', '\n'+data);
} catch (err) {
/* 处理错误 */
}
}
21 changes: 21 additions & 0 deletions routes/api.js
Expand Up @@ -27,4 +27,25 @@ router.get('/getTPS', function(req, res, next) {
res.send(libs.loadRs(libs.TPS));
});

router.get('/run', function(req, res, next) {
libs.init();
libs.run('sample,0.75,10,2,256, 180.038278,');
libs.run('sample,0.75,40,2,256, 291.310916,');
libs.run('sample,0.75,80,2,256, 333.041573,');
libs.run('sample,0.75,120,2,256, 351.752320,');
libs.run('sample,1,10,2,256, 172.872861,');
libs.run('sample,1,40,2,256, 291.617799,');
libs.run('sample,1,80,2,256, 337.826232,');
libs.run('sample,1,120,2,256, 319.039588,');
libs.run('sample,2,10,2,256, 182.105577,');
libs.run('sample,2,40,2,256, 260.276446,');
libs.run('sample,2,80,2,256, 323.542760,');
libs.run('sample,2,120,2,256, 323.526945,');
libs.run('sample,1.5,10,2,256, 172.745382,');
libs.run('sample,1.5,40,2,256, 268.041591,');
libs.run('sample,1.5,80,2,256, 348.150198,');
libs.run('sample,1.5,120,2,256, 310.915616,');
res.send('success');
});

module.exports = router;
4 changes: 4 additions & 0 deletions routes/index.js
Expand Up @@ -6,4 +6,8 @@ router.get('/', function(req, res, next) {
res.render('index');
});

router.get('/result', function(req, res, next) {
res.render('result');
});

module.exports = router;
10 changes: 10 additions & 0 deletions test/app.test.js
Expand Up @@ -12,6 +12,11 @@ describe('# test app.js', function () {
.get('/api')
.expect(200, done)
});
it('GET /api/run', function (done) {
request
.get('/api/run')
.expect(200, done)
});
it('GET /api/getBatchTimeout', function (done) {
request
.get('/api/getBatchTimeout')
Expand All @@ -37,4 +42,9 @@ describe('# test app.js', function () {
.get('/api/getTPS')
.expect(200, done)
});
it('GET / 200 result', function (done) {
request
.get('/result')
.expect(200, done)
});
});
22 changes: 22 additions & 0 deletions test/lib.test.js
Expand Up @@ -2,6 +2,28 @@ const libs = require('../lib/libs');
var expect = require('chai').expect;

describe('# libs', function () {

it('run', function(done){
libs.init();
libs.run('sample,0.75,10,2,256, 180.038278,');
libs.run('sample,0.75,40,2,256, 291.310916,');
libs.run('sample,0.75,80,2,256, 333.041573,');
libs.run('sample,0.75,120,2,256, 351.752320,');
libs.run('sample,1,10,2,256, 172.872861,');
libs.run('sample,1,40,2,256, 291.617799,');
libs.run('sample,1,80,2,256, 337.826232,');
libs.run('sample,1,120,2,256, 319.039588,');
libs.run('sample,2,10,2,256, 182.105577,');
libs.run('sample,2,40,2,256, 260.276446,');
libs.run('sample,2,80,2,256, 323.542760,');
libs.run('sample,2,120,2,256, 323.526945,');
libs.run('sample,1.5,10,2,256, 172.745382,');
libs.run('sample,1.5,40,2,256, 268.041591,');
libs.run('sample,1.5,80,2,256, 348.150198,');
libs.run('sample,1.5,120,2,256, 310.915616,');
done();
})

it('get BatchTimeout', function (done) {
expect([0.75,0.75,0.75,0.75,1,1,1,1,2,2,2,2,1.5,1.5,1.5,1.5]).to.deep.equal(
libs.loadRs(libs.BatchTimeout));
Expand Down
9 changes: 9 additions & 0 deletions views/result/index.html
@@ -0,0 +1,9 @@
<head>
<!-- Load plotly.js into the DOM -->
<script src='https://cdn.plot.ly/plotly-latest.min.js'></script>
</head>

<body>
<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>
<script src='./javascripts/index.js'></script>
</body>

0 comments on commit 8c39893

Please sign in to comment.