This repository has been archived by the owner on May 10, 2018. It is now read-only.
forked from jackymallett/Threadneedle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chartserver.js
81 lines (61 loc) · 2.02 KB
/
chartserver.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
// Node.js server to provide browser view of simulation charts generated
// in batch mode.
//
// node chartserver <directory with output dirs>
//
// Todo: Implement rotate through directories
// (c) jacky mallett
var express = require('express')
var glob = require('globule')
var os = require('os');
var fs = require('fs');
var masterdir = process.argv[2]
var app = express();
var index = 0;
var data = "";
app.use(express.static(__dirname + '/'));
app.get('/', function(req, res)
{
dirs = glob.find([masterdir + '/*']);
res.writeHead(200, {'Content-Type' : 'text/html'});
res.write('<!DOCTYPE html>');
res.write('<html><head><title>' + dirs[index] + '</title></head></html>');
res.write('<link rel="stylesheet" type="text/css" href="styles.css" media="screen" />');
res.write('<h1>' + dirs[index] + '</h1>');
res.write('<div id="wrapper">');
res.write('<section id="charts">');
var files = glob.find([dirs[index] + '/' + '*.png']);
for(var i = 0; i < files.length; i++)
{
res.write('<img src=' + files[i] + '></a>\n');
}
res.write('</section>')
res.write('<section id="model">');
data = fs.readFileSync(dirs[index] + '/test_config', 'utf8', function(err, data) {});
rows = data.split(os.EOL);
cols = 0;
for(var i = 0; i < rows.length; i++)
{
cols = cols < rows[i].length ? rows[i].length + 1 : cols;
}
res.write('<textarea cols='+ cols + ' rows=' + (rows.length + 1) + '>');
res.write(data);
res.write('</textarea>');
res.write('</section>')
index === dirs.length - 1? index = 0 : index++;
res.end('');
});
var server = app.listen(1234,function()
{
console.log('listening at http://%s:%s', os.hostname(), server.address().port);
if(process.argv.length < 2)
console.log("Error: must specify directory with results");
else
console.log("Displaying charts in: " + process.argv[2]);
}).on('error', function(err)
{
if(err.errno == 'EADDRINUSE')
console.log('Port busy/already running');
else
console.log(err);
});