mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
split Javascript code over multiple files
This commit is contained in:
parent
1056ad3b4e
commit
0a270c7aad
4 changed files with 54 additions and 40 deletions
|
@ -216,44 +216,4 @@ function wsUrl(endpoint) {
|
|||
return url;
|
||||
}
|
||||
|
||||
function fileStart(e) {
|
||||
var file = e.target.files[0];
|
||||
var reader = new FileReader();
|
||||
|
||||
var start;
|
||||
var msgs = [ ]
|
||||
var position = 0;
|
||||
|
||||
reader.onload = function(e) {
|
||||
var lines = e.target.result.split(/[\r\n]+/g); // tolerate both Windows and Unix linebreaks
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var msg = new Msg();
|
||||
msg.parse(lines[i]);
|
||||
msgs.push(msg);
|
||||
}
|
||||
|
||||
console.log("Read " + msgs.length + " samples from file");
|
||||
|
||||
if (msgs.length > 0) {
|
||||
var offset = Date.now() - msgs[0].ts;
|
||||
var data = [];
|
||||
|
||||
for (var i = 0; i < msgs.length; i++)
|
||||
data.push(msgs[i].ts + offset, msgs[i].data[0]);
|
||||
|
||||
plotData.push(data);
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
}
|
||||
|
||||
/* Some helpers */
|
||||
function getParameterByName(name) {
|
||||
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
|
||||
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
|
||||
}
|
||||
|
|
36
web/socket/file.js
Normal file
36
web/socket/file.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
function fileStart(e)
|
||||
{
|
||||
var file = e.target.files[0];
|
||||
var reader = new FileReader();
|
||||
|
||||
var start;
|
||||
var msgs = [ ]
|
||||
var position = 0;
|
||||
|
||||
reader.onload = function(e) {
|
||||
var lines = e.target.result.split(/[\r\n]+/g); // tolerate both Windows and Unix linebreaks
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var msg = new Msg();
|
||||
msg.parse(lines[i]);
|
||||
msgs.push(msg);
|
||||
}
|
||||
|
||||
console.log('Read ' + msgs.length + ' samples from file');
|
||||
|
||||
if (msgs.length > 0) {
|
||||
var offset = Date.now() - msgs[0].ts;
|
||||
var data = [];
|
||||
|
||||
for (var i = 0; i < msgs.length; i++)
|
||||
data.push(msgs[i].ts + offset, msgs[i].data[0]);
|
||||
|
||||
plotData.push(data);
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
}
|
|
@ -13,6 +13,7 @@
|
|||
<script src="flot/jquery.flot.time.js"></script>
|
||||
<script src="msg.js"></script>
|
||||
<script src="app.js"></script>
|
||||
<script src="utils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
|
|
17
web/socket/utils.js
Normal file
17
web/socket/utils.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
function getParameterByName(name)
|
||||
{
|
||||
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
|
||||
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
|
||||
}
|
||||
|
||||
function guid()
|
||||
{
|
||||
function s4()
|
||||
{
|
||||
return Math.floor((1 + Math.random()) * 0x10000)
|
||||
.toString(16)
|
||||
.substring(1);
|
||||
}
|
||||
|
||||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
|
||||
}
|
Loading…
Add table
Reference in a new issue