Comparar commits
108 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| c28e6e8080 | |||
| 723eb8c533 | |||
| aa7a5c78f2 | |||
| ff0b0192bb | |||
| 2803c3b829 | |||
| 6e1fc861e7 | |||
| d96fbabef8 | |||
| ed260da6ee | |||
| 4cd9a641ce | |||
| 9601ff89a1 | |||
| 2942d8a3d0 | |||
| b3f41b00de | |||
| 8b7e60ca35 | |||
| 7661dad72e | |||
| cc3eaf834b | |||
| 8351474fbc | |||
| 005950b173 | |||
| 847c1ff511 | |||
| 44ed5c8fa5 | |||
| 44f7a035c8 | |||
| ef761dd32b | |||
| c2bad61f92 | |||
| 74c8fb1a68 | |||
| 36986b66a6 | |||
| 98ebbd83fd | |||
| 118b480690 | |||
| e3e9974888 | |||
| 0c237e0116 | |||
| bd534b3216 | |||
| 7393c0603b | |||
| 17ef476a32 | |||
| ef5857e3a2 | |||
| 92f27fb400 | |||
| 1e4401c68b | |||
| 64460c3fe6 | |||
| 4de6d83bf4 | |||
| efe6fe2829 | |||
| 7810048145 | |||
| 77d62d797f | |||
| a0fc9925d9 | |||
| b1fa763845 | |||
| 0329ea5703 | |||
| 1640a96e95 | |||
| 60c0ab004c | |||
| 5e4ea5b750 | |||
| 3fece01fd4 | |||
| 39de35ea28 | |||
| 6f9a5a260c | |||
| 29777e0770 | |||
| 3ff08885f3 | |||
| f76ac21401 | |||
| 5e41f2328b | |||
| 8041e70ac3 | |||
| 1c9682351c | |||
| f41b60515f | |||
| 544dec0433 | |||
| 29382c8369 | |||
| 29903ceabf | |||
| 03312d6f14 | |||
| 474965a679 | |||
| abc3631d06 | |||
| ba9b5cbd04 | |||
| f53868166b | |||
| bcd225a5fb | |||
| 33e9dad276 | |||
| f9b1e50ebe | |||
| dc3deb6bf9 | |||
| 580e3fc93e | |||
| c6d5c0e210 | |||
| 8cef10d64a | |||
| 28114d108a | |||
| b63405d3b3 | |||
| d6fac735cb | |||
| 1ee9de08c8 | |||
| 6d0859579a | |||
| 782af8c06a | |||
| be7b68acb1 | |||
| ead11736ca | |||
| 4c851dd637 | |||
| 0b6bec2ef0 | |||
| eb6a072964 | |||
| 3c79f2e3b0 | |||
| a09fa51221 | |||
| 1da42774a4 | |||
| 93ae6b5627 | |||
| 46c45645df | |||
| 1725f2d0b8 | |||
| 89705f9e64 | |||
| 9294f853c3 | |||
| 56f9d91560 | |||
| b7e694f62b | |||
| 8cfffd2577 | |||
| 75c262f1f3 | |||
| 901b472ea1 | |||
| 84c199b0db | |||
| 1571d22e9b | |||
| 538bb08632 | |||
| a604e4943c | |||
| f61c0c2637 | |||
| 1e9ddf63e5 | |||
| d0536238b5 | |||
| 43fb52bb88 | |||
| b0102288cd | |||
| 7e1a2ecd5e | |||
| c7250e5932 | |||
| 1ff37171e7 | |||
| 5a102f5f28 | |||
| 96ca12aaf0 |
@@ -0,0 +1,14 @@
|
||||
# Editor configuration, see http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
max_line_length = 0
|
||||
trim_trailing_whitespace = false
|
||||
@@ -1,2 +1,33 @@
|
||||
.idea
|
||||
node_modules
|
||||
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# compiled output
|
||||
/dist
|
||||
/tmp
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/bower_components
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
*.launch
|
||||
.settings/
|
||||
|
||||
# misc
|
||||
/.sass-cache
|
||||
/connect.lock
|
||||
/coverage/*
|
||||
/libpeerconnection.log
|
||||
npm-debug.log
|
||||
testem.log
|
||||
/typings
|
||||
|
||||
# e2e
|
||||
/e2e/*.js
|
||||
/e2e/*.map
|
||||
|
||||
#System Files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# OpenBCI Visualizer
|
||||
# OpenBCI Dashboard
|
||||
|
||||
A fullstack javascript app for capturing and visualizing OpenBCI EEG data
|
||||

|
||||
|
||||
A fullstack JavaScript app for reading and visualizing OpenBCI EEG data.
|
||||
|
||||
This project is under development, this is just a first draft.
|
||||
|
||||
@@ -10,18 +12,30 @@ This project is under development, this is just a first draft.
|
||||
* Turn on OpenBCI board
|
||||
|
||||
```bash
|
||||
npm install -g angular-cli concurrently
|
||||
npm install
|
||||
node visualizer
|
||||
npm run visualize
|
||||
```
|
||||
|
||||
* Go to: http://localhost:3036
|
||||
* Go to: http://localhost:4200
|
||||
|
||||
## Simulating data
|
||||
|
||||
```bash
|
||||
node visualizer simulate
|
||||
npm run simulate
|
||||
```
|
||||
|
||||
## Technologies
|
||||
|
||||
* Node.js
|
||||
* Angular 2
|
||||
* Socket.io
|
||||
* Data Visualization
|
||||
- Plotly.js
|
||||
- Chart.js
|
||||
- Smoothie
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
Pull requests are welcomed!
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"project": {
|
||||
"version": "1.0.0-beta.11-webpack.8",
|
||||
"name": "openbci-dashboard"
|
||||
},
|
||||
"apps": [
|
||||
{
|
||||
"root": "src",
|
||||
"outDir": "dist",
|
||||
"assets": "assets",
|
||||
"index": "index.html",
|
||||
"main": "main.ts",
|
||||
"test": "test.ts",
|
||||
"tsconfig": "tsconfig.json",
|
||||
"prefix": "app",
|
||||
"mobile": false,
|
||||
"styles": [
|
||||
"styles.css"
|
||||
],
|
||||
"scripts": [],
|
||||
"environments": {
|
||||
"source": "environments/environment.ts",
|
||||
"prod": "environments/environment.prod.ts",
|
||||
"dev": "environments/environment.dev.ts"
|
||||
}
|
||||
}
|
||||
],
|
||||
"addons": [],
|
||||
"packages": [],
|
||||
"e2e": {
|
||||
"protractor": {
|
||||
"config": "./protractor.conf.js"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"karma": {
|
||||
"config": "./karma.conf.js"
|
||||
}
|
||||
},
|
||||
"defaults": {
|
||||
"styleExt": "css",
|
||||
"prefixInterfaces": false,
|
||||
"lazyRoutePrefix": "+"
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<section>
|
||||
<h2>Alpha</h2>
|
||||
<canvas id="alpha"
|
||||
class="chart chart-bar"
|
||||
chart-data="$ctrl.data"
|
||||
chart-labels="$ctrl.series"
|
||||
chart-series="$ctrl.series">
|
||||
</canvas>
|
||||
</section>
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
angular.module('openbciVisualizer')
|
||||
.component('bciAlpha', {
|
||||
templateUrl: 'components/alpha/alpha.html',
|
||||
controller: function ($timeout) {
|
||||
var $ctrl = this;
|
||||
var socket = io();
|
||||
$ctrl.series = ['Channel 1','Channel 2','Channel 3','Channel 4','Channel 5','Channel 6','Channel 7','Channel 8'];
|
||||
socket.on('openBCIData', function (data) {
|
||||
var alphaRange = EEGSpectrumUtils.filterBand(data.spectrums.data, data.spectrums.labels, [8, 12]);
|
||||
$timeout(function () {
|
||||
$ctrl.labels = alphaRange.labels;
|
||||
$ctrl.data = alphaRange.spectrums;
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
<section>
|
||||
<h2>Beta</h2>
|
||||
<canvas id="beta"
|
||||
class="chart chart-bar"
|
||||
chart-data="$ctrl.data"
|
||||
chart-labels="$ctrl.series"
|
||||
chart-series="$ctrl.series">
|
||||
</canvas>
|
||||
</section>
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
angular.module('openbciVisualizer')
|
||||
.component('bciBeta', {
|
||||
templateUrl: 'components/beta/beta.html',
|
||||
controller: function ($timeout) {
|
||||
var $ctrl = this;
|
||||
var socket = io();
|
||||
$ctrl.series = ['Channel 1','Channel 2','Channel 3','Channel 4','Channel 5','Channel 6','Channel 7','Channel 8'];
|
||||
socket.on('openBCIData', function (data) {
|
||||
var betaRange = EEGSpectrumUtils.filterBand(data.spectrums.data, data.spectrums.labels, [12, 40]);
|
||||
$timeout(function () {
|
||||
$ctrl.labels = betaRange.labels;
|
||||
$ctrl.data = betaRange.spectrums;
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
<section>
|
||||
<h2>Delta</h2>
|
||||
<canvas id="delta"
|
||||
class="chart chart-bar"
|
||||
chart-data="$ctrl.data"
|
||||
chart-labels="$ctrl.series"
|
||||
chart-series="$ctrl.series">
|
||||
</canvas>
|
||||
</section>
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
angular.module('openbciVisualizer')
|
||||
.component('bciDelta', {
|
||||
templateUrl: 'components/delta/delta.html',
|
||||
controller: function ($timeout) {
|
||||
var $ctrl = this;
|
||||
var socket = io();
|
||||
$ctrl.series = ['Channel 1','Channel 2','Channel 3','Channel 4','Channel 5','Channel 6','Channel 7','Channel 8'];
|
||||
socket.on('openBCIData', function (data) {
|
||||
var deltaRange = EEGSpectrumUtils.filterBand(data.spectrums.data, data.spectrums.labels, [0.5, 4]);
|
||||
$timeout(function () {
|
||||
$ctrl.labels = deltaRange.labels;
|
||||
$ctrl.data = deltaRange.spectrums;
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,10 +0,0 @@
|
||||
<section>
|
||||
<h2>Frequency</h2>
|
||||
<canvas id="frequency"
|
||||
class="chart chart-line"
|
||||
chart-data="$ctrl.data"
|
||||
chart-labels="$ctrl.labels"
|
||||
chart-series="$ctrl.series"
|
||||
chart-options="{ responsive: true }">
|
||||
</canvas>
|
||||
</section>
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
angular.module('openbciVisualizer')
|
||||
.component('bciFrequency', {
|
||||
templateUrl: 'components/frequency/frequency.html',
|
||||
controller: function ($timeout) {
|
||||
var $ctrl = this;
|
||||
var socket = io();
|
||||
$ctrl.series = ['Channel 1','Channel 2','Channel 3','Channel 4','Channel 5','Channel 6','Channel 7','Channel 8'];
|
||||
socket.on('openBCIData', function (data) {
|
||||
$timeout(function () {
|
||||
$ctrl.data = data.spectrums.data;
|
||||
$ctrl.labels = data.spectrums.labels;
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
<section>
|
||||
<h2>Theta</h2>
|
||||
<canvas id="theta"
|
||||
class="chart chart-bar"
|
||||
chart-data="$ctrl.data"
|
||||
chart-labels="$ctrl.series"
|
||||
chart-series="$ctrl.series">
|
||||
</canvas>
|
||||
</section>
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
angular.module('openbciVisualizer')
|
||||
.component('bciTheta', {
|
||||
templateUrl: 'components/theta/theta.html',
|
||||
controller: function ($timeout) {
|
||||
var $ctrl = this;
|
||||
var socket = io();
|
||||
$ctrl.series = ['Channel 1','Channel 2','Channel 3','Channel 4','Channel 5','Channel 6','Channel 7','Channel 8'];
|
||||
socket.on('openBCIData', function (data) {
|
||||
var thetaRange = EEGSpectrumUtils.filterBand(data.spectrums.data, data.spectrums.labels, [4, 8]);
|
||||
$timeout(function () {
|
||||
$ctrl.labels = thetaRange.labels;
|
||||
$ctrl.data = thetaRange.spectrums;
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,10 +0,0 @@
|
||||
<section>
|
||||
<h2>Time</h2>
|
||||
<canvas id="time"
|
||||
class="chart chart-line"
|
||||
chart-data="$ctrl.data"
|
||||
chart-labels="$ctrl.labels"
|
||||
chart-series="$ctrl.series"
|
||||
chart-options="{ responsive: true, scaleOverride: false }">
|
||||
</canvas>
|
||||
</section>
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
angular.module('openbciVisualizer')
|
||||
.component('bciTime', {
|
||||
templateUrl: 'components/time/time.html',
|
||||
controller: function ($timeout) {
|
||||
var $ctrl = this;
|
||||
var socket = io();
|
||||
$ctrl.series = ['Channel 1','Channel 2','Channel 3','Channel 4','Channel 5','Channel 6','Channel 7','Channel 8'];
|
||||
socket.on('openBCIData', function (data) {
|
||||
$timeout(function () {
|
||||
console.log(data.timeSeries);
|
||||
$ctrl.labels = data.timeSeries.labels;
|
||||
$ctrl.data = data.timeSeries.data;
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,55 +0,0 @@
|
||||
<!doctype html>
|
||||
<html ng-app="openbciVisualizer">
|
||||
<head>
|
||||
<title>OpenBCI Visualizer</title>
|
||||
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/angular.chartjs/latest/angular-chart.css">
|
||||
|
||||
<script src="node_modules/socket.io-client/socket.io.js"></script>
|
||||
|
||||
<script src="/node_modules/angular/angular.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.1.1/Chart.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/angular.chartjs/latest/angular-chart.min.js"></script>
|
||||
|
||||
<script src="visualizer.js"></script>
|
||||
|
||||
<script src="lib/EEGSpectrumUtils.js"></script>
|
||||
|
||||
<script src="components/frequency/frequency.js"></script>
|
||||
<script src="components/time/time.js"></script>
|
||||
<script src="components/alpha/alpha.js"></script>
|
||||
<script src="components/delta/delta.js"></script>
|
||||
<script src="components/beta/beta.js"></script>
|
||||
<script src="components/theta/theta.js"></script>
|
||||
|
||||
<style>
|
||||
@import url(https://fonts.googleapis.com/css?family=Roboto:400,700,300);
|
||||
body {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
}
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<main>
|
||||
|
||||
<h1>OpenBCI Visualizer</h1>
|
||||
|
||||
<bci-time></bci-time>
|
||||
<bci-frequency></bci-frequency>
|
||||
|
||||
<section class="flex">
|
||||
<bci-alpha></bci-alpha>
|
||||
<bci-delta></bci-delta>
|
||||
<bci-beta></bci-beta>
|
||||
<bci-theta></bci-theta>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,28 +0,0 @@
|
||||
|
||||
var EEGSpectrumUtils = {
|
||||
|
||||
/**
|
||||
* filterBand: Give spectrums and labels, it filters the spectrums based on the labels within the range
|
||||
* @param spectrums
|
||||
* @param labels
|
||||
* @param range
|
||||
* @returns {{spectrums: Array, labels: *}}
|
||||
*/
|
||||
filterBand: function (spectrums, labels, range) {
|
||||
//if (!spectrums ) return console.log();
|
||||
spectrums = spectrums.map(function (channel) {
|
||||
return channel.filter(function (spectrum, index) {
|
||||
return labels[index] >= range[0] && labels[index] <= range[1];
|
||||
});
|
||||
});
|
||||
spectrums = [spectrums.map(function (channel) {
|
||||
return channel.reduce(function (a, b) {
|
||||
return a + b;
|
||||
}) / channel.length;
|
||||
})];
|
||||
return {
|
||||
spectrums: spectrums,
|
||||
labels: labels
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
|
||||
angular.module('openbciVisualizer', ['chart.js'])
|
||||
.config(function (ChartJsProvider) {
|
||||
ChartJsProvider.setOptions({
|
||||
chartColors: ['#F7464A', '#46BFBD','#FDB45C', '#949FB1','#4D5360', '#803690','#00ADF9', '#FF0000'],
|
||||
responsive: false,
|
||||
pointDot: false,
|
||||
datasetFill: false,
|
||||
scaleOverride: true,
|
||||
scaleStartValue: -2,
|
||||
scaleStepWidth: 1,
|
||||
scaleSteps: 6
|
||||
});
|
||||
});
|
||||
|
Depois Largura: | Altura: | Tamanho: 356 KiB |
|
Depois Largura: | Altura: | Tamanho: 3.6 MiB |
|
Depois Largura: | Altura: | Tamanho: 1.9 MiB |
|
Depois Largura: | Altura: | Tamanho: 3.6 MiB |
|
Depois Largura: | Altura: | Tamanho: 120 KiB |
|
Depois Largura: | Altura: | Tamanho: 123 KiB |
|
Depois Largura: | Altura: | Tamanho: 76 KiB |
@@ -0,0 +1,3 @@
|
||||
export const environment = {
|
||||
production: false
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export const environment = {
|
||||
production: true
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
/*global jasmine, __karma__, window*/
|
||||
Error.stackTraceLimit = Infinity;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
|
||||
|
||||
__karma__.loaded = function () {
|
||||
};
|
||||
|
||||
var distPath = '/base/dist/';
|
||||
var appPath = distPath + 'app/';
|
||||
|
||||
function isJsFile(path) {
|
||||
return path.slice(-3) == '.js';
|
||||
}
|
||||
|
||||
function isSpecFile(path) {
|
||||
return path.slice(-8) == '.spec.js';
|
||||
}
|
||||
|
||||
function isAppFile(path) {
|
||||
return isJsFile(path) && (path.substr(0, appPath.length) == appPath);
|
||||
}
|
||||
|
||||
var allSpecFiles = Object.keys(window.__karma__.files)
|
||||
.filter(isSpecFile)
|
||||
.filter(isAppFile);
|
||||
|
||||
// Load our SystemJS configuration.
|
||||
System.config({
|
||||
baseURL: distPath
|
||||
});
|
||||
|
||||
System.import('system-config.js').then(function() {
|
||||
// Load and configure the TestComponentBuilder.
|
||||
return Promise.all([
|
||||
System.import('@angular/core/testing'),
|
||||
System.import('@angular/platform-browser-dynamic/testing')
|
||||
]).then(function (providers) {
|
||||
var testing = providers[0];
|
||||
var testingBrowser = providers[1];
|
||||
|
||||
testing.setBaseTestProviders(testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
|
||||
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
|
||||
});
|
||||
}).then(function() {
|
||||
// Finally, load all spec files.
|
||||
// This will run the tests directly.
|
||||
return Promise.all(
|
||||
allSpecFiles.map(function (moduleName) {
|
||||
return System.import(moduleName);
|
||||
}));
|
||||
}).then(__karma__.start, __karma__.error);
|
||||
@@ -0,0 +1,29 @@
|
||||
/*global jasmine */
|
||||
var SpecReporter = require('jasmine-spec-reporter');
|
||||
|
||||
exports.config = {
|
||||
allScriptsTimeout: 11000,
|
||||
specs: [
|
||||
'../e2e/**/*.e2e.ts'
|
||||
],
|
||||
capabilities: {
|
||||
'browserName': 'chrome'
|
||||
},
|
||||
directConnect: true,
|
||||
baseUrl: 'http://localhost:4200/',
|
||||
framework: 'jasmine',
|
||||
jasmineNodeOpts: {
|
||||
showColors: true,
|
||||
defaultTimeoutInterval: 30000,
|
||||
print: function() {}
|
||||
},
|
||||
useAllAngular2AppRoots: true,
|
||||
beforeLaunch: function() {
|
||||
require('ts-node').register({
|
||||
project: 'e2e'
|
||||
});
|
||||
},
|
||||
onPrepare: function() {
|
||||
jasmine.getEnv().addReporter(new SpecReporter());
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
import { OpenbciDashboardPage } from './app.po';
|
||||
|
||||
describe('openbci-dashboard App', function() {
|
||||
let page: OpenbciDashboardPage;
|
||||
|
||||
beforeEach(() => {
|
||||
page = new OpenbciDashboardPage();
|
||||
});
|
||||
|
||||
it('should display message saying app works', () => {
|
||||
page.navigateTo();
|
||||
expect(page.getParagraphText()).toEqual('app works!');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { ClitestPage } from './app.po';
|
||||
|
||||
describe('clitest App', function() {
|
||||
let page: ClitestPage;
|
||||
|
||||
beforeEach(() => {
|
||||
page = new ClitestPage();
|
||||
})
|
||||
|
||||
it('should display message saying app works', () => {
|
||||
page.navigateTo();
|
||||
expect(page.getParagraphText()).toEqual('clitest works!');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { browser, element, by } from 'protractor/globals';
|
||||
|
||||
export class OpenbciDashboardPage {
|
||||
navigateTo() {
|
||||
return browser.get('/');
|
||||
}
|
||||
|
||||
getParagraphText() {
|
||||
return element(by.css('app-root h1')).getText();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"declaration": false,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../dist/out-tsc-e2e",
|
||||
"sourceMap": true,
|
||||
"target": "es5",
|
||||
"typeRoots": [
|
||||
"../node_modules/@types"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
/// <reference path="../typings/main.d.ts" />
|
||||
@@ -0,0 +1,35 @@
|
||||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/0.13/config/configuration-file.html
|
||||
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
basePath: './',
|
||||
frameworks: ['jasmine', 'angular-cli'],
|
||||
plugins: [
|
||||
require('karma-jasmine'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-remap-istanbul'),
|
||||
require('angular-cli/plugins/karma')
|
||||
],
|
||||
files: [
|
||||
{ pattern: './src/test.ts', watched: false }
|
||||
],
|
||||
preprocessors: {
|
||||
'./src/test.ts': ['angular-cli']
|
||||
},
|
||||
remapIstanbulReporter: {
|
||||
reports: {
|
||||
html: 'coverage',
|
||||
lcovonly: './coverage/coverage.lcov'
|
||||
}
|
||||
},
|
||||
angularCliConfig: './angular-cli.json',
|
||||
reporters: ['progress', 'karma-remap-istanbul'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: config.LOG_INFO,
|
||||
autoWatch: true,
|
||||
browsers: ['Chrome'],
|
||||
singleRun: false
|
||||
});
|
||||
};
|
||||
@@ -1,27 +1,62 @@
|
||||
{
|
||||
"name": "openbci-visualizer",
|
||||
"private": false,
|
||||
"version": "0.0.1",
|
||||
"description": "A fullstack javascript app for capturing and visualizing OpenBCI EEG data",
|
||||
"main": "visualizer.js",
|
||||
"name": "openbci-dashboard",
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"openbci",
|
||||
"fft",
|
||||
"chartjs"
|
||||
],
|
||||
"author": "Alex Castillo",
|
||||
"scripts": {},
|
||||
"angular-cli": {},
|
||||
"scripts": {
|
||||
"start": "ng serve",
|
||||
"lint": "tslint \"src/**/*.ts\"",
|
||||
"test": "ng test",
|
||||
"pree2e": "webdriver-manager update",
|
||||
"e2e": "protractor"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"angular": "^1.5.3",
|
||||
"angular-chartjs": "0.0.5",
|
||||
"chart.js": "^2.0.0",
|
||||
"@angular/common": "2.0.0-rc.5",
|
||||
"@angular/compiler": "2.0.0-rc.5",
|
||||
"@angular/core": "2.0.0-rc.5",
|
||||
"@angular/forms": "0.3.0",
|
||||
"@angular/http": "2.0.0-rc.5",
|
||||
"@angular/platform-browser": "2.0.0-rc.5",
|
||||
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
|
||||
"@angular/router": "3.0.0-rc.1",
|
||||
"brainbrowser": "^2.3.0",
|
||||
"chart.js": "^2.1.4",
|
||||
"chroma-js": "^1.1.1",
|
||||
"dsp.js": "neurojs/dsp.js",
|
||||
"es6-shim": "^0.35.0",
|
||||
"express": "^4.13.4",
|
||||
"fili": "^1.2.1",
|
||||
"jstat": "^1.5.2",
|
||||
"ng2-charts": "^1.1.0",
|
||||
"nodemon": "^1.9.1",
|
||||
"openbci-sdk": "^0.2.0",
|
||||
"socket.io": "^1.4.5",
|
||||
"socket.io-client": "^1.4.5",
|
||||
"yargs": "^4.3.2"
|
||||
"openbci-sdk": "^0.3.4",
|
||||
"plotly.js": "^1.10.2",
|
||||
"reflect-metadata": "^0.1.3",
|
||||
"smoothie": "^1.27.0",
|
||||
"socket.io": "^1.4.6",
|
||||
"socket.io-client": "^1.4.6",
|
||||
"systemjs": "0.19.27",
|
||||
"topogrid": "^1.0.6",
|
||||
"yargs": "^4.3.2",
|
||||
"core-js": "^2.4.1",
|
||||
"zone.js": "^0.6.17"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jasmine": "^2.2.30",
|
||||
"@types/smoothie": "^1.25.27",
|
||||
"@types/socket.io-client": "^1.4.26",
|
||||
"angular-cli": "1.0.0-beta.11-webpack.8",
|
||||
"codelyzer": "~0.0.26",
|
||||
"jasmine-core": "2.4.1",
|
||||
"jasmine-spec-reporter": "2.5.0",
|
||||
"karma": "0.13.22",
|
||||
"karma-chrome-launcher": "0.2.3",
|
||||
"karma-jasmine": "0.3.8",
|
||||
"karma-remap-istanbul": "^0.2.1",
|
||||
"protractor": "4.0.3",
|
||||
"ts-node": "1.2.1",
|
||||
"tslint": "3.13.0",
|
||||
"typescript": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Protractor configuration file, see link for more information
|
||||
// https://github.com/angular/protractor/blob/master/docs/referenceConf.js
|
||||
|
||||
/*global jasmine */
|
||||
var SpecReporter = require('jasmine-spec-reporter');
|
||||
|
||||
exports.config = {
|
||||
allScriptsTimeout: 11000,
|
||||
specs: [
|
||||
'./e2e/**/*.e2e-spec.ts'
|
||||
],
|
||||
capabilities: {
|
||||
'browserName': 'chrome'
|
||||
},
|
||||
directConnect: true,
|
||||
baseUrl: 'http://localhost:4200/',
|
||||
framework: 'jasmine',
|
||||
jasmineNodeOpts: {
|
||||
showColors: true,
|
||||
defaultTimeoutInterval: 30000,
|
||||
print: function() {}
|
||||
},
|
||||
useAllAngular2AppRoots: true,
|
||||
beforeLaunch: function() {
|
||||
require('ts-node').register({
|
||||
project: 'e2e'
|
||||
});
|
||||
},
|
||||
onPrepare: function() {
|
||||
jasmine.getEnv().addReporter(new SpecReporter());
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,143 @@
|
||||
@import url(https://fonts.googleapis.com/css?family=Roboto:400,700,300);
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:host {
|
||||
display: block;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
main {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
h1 {
|
||||
padding: 20px;
|
||||
font-weight: 300;
|
||||
margin: 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.capitalize {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.loading:after {
|
||||
content: 'Loading...';
|
||||
text-transform: uppercase;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin: -10px 0 0 -40px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.block {
|
||||
display: block;
|
||||
margin: 20px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 0 5px rgba(0,0,0,0.3);
|
||||
background-color: #333333;
|
||||
position: relative;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.block h2 {
|
||||
position: absolute;
|
||||
margin: 0;
|
||||
top: 10px;
|
||||
right: 20px;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.block-25 {
|
||||
width: 25%;
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
.block-33 {
|
||||
width: 33%;
|
||||
min-height: 260px;
|
||||
}
|
||||
|
||||
.block-50 {
|
||||
width: 50%;
|
||||
min-height: 400px;
|
||||
}
|
||||
|
||||
.block-75 {
|
||||
width: 75%;
|
||||
min-height: 580px;
|
||||
}
|
||||
|
||||
.block-100 {
|
||||
width: 100%;
|
||||
min-height: 580px;
|
||||
}
|
||||
|
||||
|
||||
nav {
|
||||
margin-left: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
|
||||
nav a {
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #ffffff;
|
||||
padding: 8px 20px;
|
||||
text-transform: uppercase;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
font-weight: 300;
|
||||
font-size: 12px;
|
||||
letter-spacing: 1px;
|
||||
margin-right: 2px;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
nav a:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
nav a:nth-child(1) {
|
||||
background-color: rgba(112,185,252,1);
|
||||
}
|
||||
|
||||
nav a:nth-child(2) {
|
||||
background-color: rgba(138,219,229,1);
|
||||
}
|
||||
|
||||
nav a:nth-child(3) {
|
||||
background-color: rgba(162,86,178,1);
|
||||
}
|
||||
|
||||
nav a:nth-child(4) {
|
||||
background-color: rgba(144,132,246,1);
|
||||
}
|
||||
|
||||
nav a:nth-child(5) {
|
||||
background-color: rgba(232,223,133,1);
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
nav a:nth-child(6) {
|
||||
background-color: rgba(148,159,177,1);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<main>
|
||||
<bci-filters></bci-filters>
|
||||
<section class="content">
|
||||
<h1>{{ title }}</h1>
|
||||
<nav>
|
||||
<a [routerLink]="['/time-series']">Time Series</a>
|
||||
<a [routerLink]="['/frequency/line', { type: 'line' }]">Frequency Line</a>
|
||||
<a [routerLink]="['/frequency/radar', { type: 'radar' }]">Frequency Radar</a>
|
||||
<a [routerLink]="['/frequency/bands']">Frequency Bands</a>
|
||||
<a [routerLink]="['/motion']">Motion</a>
|
||||
<a [routerLink]="['/topo']">Topo</a>
|
||||
</nav>
|
||||
<router-outlet></router-outlet>
|
||||
</section>
|
||||
</main>
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'bci-dashboard',
|
||||
templateUrl: 'dashboard.component.html',
|
||||
styleUrls: ['dashboard.component.css'],
|
||||
})
|
||||
|
||||
export class DashboardComponent implements OnInit {
|
||||
title = 'BCI Dashboard';
|
||||
|
||||
constructor () {
|
||||
}
|
||||
|
||||
ngOnInit () {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
|
||||
import { routing, appRoutingProviders } from './dashboard.routing';
|
||||
|
||||
import { DashboardComponent } from './dashboard.component';
|
||||
import { FiltersComponent } from './filters';
|
||||
import { TimeSeriesComponent } from './time-series';
|
||||
import { FrequencyComponent } from './frequency';
|
||||
import { FrequencyBandsComponent } from './frequency-bands';
|
||||
import { TopoComponent } from './topo';
|
||||
import { MotionComponent } from './motion';
|
||||
|
||||
import { CHART_DIRECTIVES } from './shared/ng2-charts';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
BrowserModule,
|
||||
routing
|
||||
],
|
||||
declarations: [
|
||||
DashboardComponent,
|
||||
FiltersComponent,
|
||||
TimeSeriesComponent,
|
||||
FrequencyComponent,
|
||||
FrequencyBandsComponent,
|
||||
TopoComponent,
|
||||
MotionComponent,
|
||||
CHART_DIRECTIVES
|
||||
],
|
||||
providers: [
|
||||
appRoutingProviders
|
||||
],
|
||||
bootstrap: [
|
||||
DashboardComponent
|
||||
]
|
||||
})
|
||||
export class DashboardModule { }
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
|
||||
import { TimeSeriesComponent } from './time-series';
|
||||
import { FrequencyComponent } from './frequency';
|
||||
import { FrequencyBandsComponent } from './frequency-bands';
|
||||
import { TopoComponent } from './topo';
|
||||
import { MotionComponent } from './motion';
|
||||
|
||||
const dashboardRoutes: Routes = [
|
||||
{ path: '', redirectTo: '/time-series', pathMatch: 'full' },
|
||||
{ path: 'time-series', component: TimeSeriesComponent },
|
||||
{ path: 'frequency/line', component: FrequencyComponent },
|
||||
{ path: 'frequency/radar', component: FrequencyComponent },
|
||||
{ path: 'frequency/bands', component: FrequencyBandsComponent },
|
||||
{ path: 'motion', component: MotionComponent },
|
||||
{ path: 'topo', component: TopoComponent }
|
||||
];
|
||||
|
||||
export const appRoutingProviders: any[] = [
|
||||
|
||||
];
|
||||
|
||||
export const routing = RouterModule.forRoot(dashboardRoutes);
|
||||
@@ -0,0 +1,7 @@
|
||||
// The file for the current environment will overwrite this one during build
|
||||
// Different environments can be found in config/environment.{dev|prod}.ts
|
||||
// The build system defaults to the dev environment
|
||||
|
||||
export const environment = {
|
||||
production: false
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.filters {
|
||||
width: 120px;
|
||||
height: 100vh;
|
||||
padding: 14px;
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
.filters h3 {
|
||||
font-weight: 500;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.filters article {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.filters nav {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.filters label {
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.filters .select {
|
||||
position: relative;
|
||||
border: 2px solid rgba(255,255,255, 0.6);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.filters .select:after {
|
||||
content: "▼";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
font-size: 6px;
|
||||
line-height: 27px;
|
||||
padding: 0 8px;
|
||||
color: rgba(255,255,255,0.2);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.filters select {
|
||||
width: 100%;
|
||||
-webkit-appearance: none;
|
||||
color: rgba(255,255,255,0.4);
|
||||
font-weight: 300;
|
||||
letter-spacing: 1px;
|
||||
background: transparent;
|
||||
padding: 6px;
|
||||
outline: none;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.filters .disabled {
|
||||
opacity: 0.2;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<aside class="filters">
|
||||
<h3>Filters</h3>
|
||||
<nav>
|
||||
<article *ngFor="let filter of filters"
|
||||
[ngClass]="{ disabled: !filter.enabled }">
|
||||
<label>{{ filter.label }}</label>
|
||||
<div class="select">
|
||||
<select
|
||||
[multiple]="filter.type === 'multiple'"
|
||||
[disabled]="!filter.enabled"
|
||||
(change)="applyFilter($event.target.value)">
|
||||
<option *ngFor="let option of filter.options"
|
||||
[value]="option.id">
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</article>
|
||||
</nav>
|
||||
</aside>
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import * as io from 'socket.io-client';
|
||||
import { Constants } from '../shared/constants';
|
||||
|
||||
@Component({
|
||||
selector: 'bci-filters',
|
||||
templateUrl: 'filters.component.html',
|
||||
styleUrls: ['filters.component.css'],
|
||||
providers: [Constants]
|
||||
})
|
||||
|
||||
export class FiltersComponent {
|
||||
|
||||
socket: any;
|
||||
constructor(private constants: Constants) {
|
||||
this.socket = io(this.constants.socket.url);
|
||||
}
|
||||
|
||||
private filters: Array<any> = this.constants.filters;
|
||||
|
||||
applyFilter (filter) {
|
||||
this.socket.emit(this.constants.socket.events.filter, filter)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { FiltersComponent } from './filters.component';
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
.chart {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
:host {
|
||||
display: inline-block;
|
||||
margin: 0 0 20px 20px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 0 5px rgba(0,0,0,0.3);
|
||||
background-color: #333333;
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: 47%;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
h2 {
|
||||
position: absolute;
|
||||
margin: 0;
|
||||
top: 10px;
|
||||
right: 20px;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.capitalize {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.frequency-band {
|
||||
height: 100%;
|
||||
padding-top: 40px;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<section class="frequency-band" [ngClass]="{ 'loading': !data }">
|
||||
<h2 class="capitalize">{{ band }} {{ type }}</h2>
|
||||
<base-chart class="chart"
|
||||
[datasets]="data"
|
||||
[labels]="channels"
|
||||
[options]="options"
|
||||
[colors]="colors"
|
||||
[legend]="false"
|
||||
[series]="channels"
|
||||
[chartType]="type">
|
||||
</base-chart>
|
||||
</section>
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Component, OnInit, OnDestroy, Input } from '@angular/core';
|
||||
import * as io from 'socket.io-client';
|
||||
import { ChartService } from '../shared';
|
||||
import { CHART_DIRECTIVES } from '../shared/ng2-charts';
|
||||
import { Constants } from '../shared/constants';
|
||||
|
||||
@Component({
|
||||
selector: 'bci-frequency-band',
|
||||
templateUrl: 'frequency-band.component.html',
|
||||
styleUrls: ['frequency-band.component.css'],
|
||||
providers: [ChartService, Constants]
|
||||
})
|
||||
|
||||
export class FrequencyBandComponent implements OnInit {
|
||||
|
||||
socket: any;
|
||||
constructor(private chartService: ChartService, private constants: Constants) {
|
||||
this.socket = io(constants.socket.url);
|
||||
}
|
||||
|
||||
@Input() public type:string;
|
||||
@Input() public band:string;
|
||||
@Input() public color:number;
|
||||
|
||||
private data:Array<any> = [{ data: [], label: [] }];
|
||||
private colors:Array<any>;
|
||||
private channels:Array<string> = this.chartService.getChannels();
|
||||
private options:any = this.chartService.getChartJSBarDefaults();
|
||||
|
||||
ngOnInit() {
|
||||
this.colors = this.chartService.getColorByIndex(this.color);
|
||||
this.socket.on(this.constants.socket.events.fft, (data) => {
|
||||
this.data = [];
|
||||
data[this.band || 'data'].forEach((dataset, index) => {
|
||||
this.data.push({
|
||||
data: dataset
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy () {
|
||||
this.socket.removeListener(this.constants.socket.events.fft);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { FrequencyBandComponent } from './frequency-band.component';
|
||||
@@ -0,0 +1,11 @@
|
||||
<div>
|
||||
<!--<section>
|
||||
<bci-frequency-band type="bar" band="delta" [color]="1"></bci-frequency-band>
|
||||
<bci-frequency-band type="bar" band="theta" [color]="2"></bci-frequency-band>
|
||||
</section>
|
||||
<section>
|
||||
<bci-frequency-band type="bar" band="alpha" [color]="3"></bci-frequency-band>
|
||||
<bci-frequency-band type="bar" band="beta" [color]="4"></bci-frequency-band>
|
||||
<bci-frequency-band type="bar" band="gamma" [color]="5"></bci-frequency-band>
|
||||
</section>-->
|
||||
</div>
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'bci-frequency-bands',
|
||||
templateUrl: 'frequency-bands.component.html',
|
||||
styleUrls: ['frequency-bands.component.css']
|
||||
})
|
||||
|
||||
export class FrequencyBandsComponent implements OnInit {
|
||||
|
||||
constructor() {}
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { FrequencyBandsComponent } from './frequency-bands.component';
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
.chart {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
:host {
|
||||
display: block;
|
||||
margin: 20px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 0 5px rgba(0,0,0,0.3);
|
||||
background-color: #333333;
|
||||
position: relative;
|
||||
height: 600px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
h2 {
|
||||
position: absolute;
|
||||
margin: 0;
|
||||
top: 10px;
|
||||
right: 20px;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.frequency {
|
||||
height: 100%;
|
||||
padding-top: 40px;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<section class="frequency" [ngClass]="{ 'loading': !data }">
|
||||
<h2>Frequency {{ type }}</h2>
|
||||
<base-chart class="chart"
|
||||
[datasets]="data"
|
||||
[labels]="labels"
|
||||
[options]="options"
|
||||
[colors]="colors"
|
||||
[series]="channels"
|
||||
[chartType]="type">
|
||||
</base-chart>
|
||||
</section>
|
||||
@@ -0,0 +1,63 @@
|
||||
import { Component, ElementRef, OnInit, OnDestroy, Input } from '@angular/core';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import * as io from 'socket.io-client';
|
||||
import { ChartService } from '../shared';
|
||||
import { Constants } from '../shared/constants';
|
||||
|
||||
@Component({
|
||||
selector: 'bci-frequency',
|
||||
templateUrl: 'frequency.component.html',
|
||||
styleUrls: ['frequency.component.css'],
|
||||
providers: [ChartService, Constants]
|
||||
})
|
||||
|
||||
export class FrequencyComponent implements OnInit {
|
||||
|
||||
socket: any;
|
||||
constructor(private chartService: ChartService,
|
||||
private route: ActivatedRoute,
|
||||
private constants: Constants) {
|
||||
this.socket = io(constants.socket.url);
|
||||
this.type = this.route.snapshot.params['type'] || 'line';
|
||||
|
||||
this.setOptions(this.type);
|
||||
}
|
||||
|
||||
@Input() type:string;
|
||||
|
||||
private data:Array<any> = [{ data: [], label: [] }];
|
||||
private labels:Array<any> = [];
|
||||
private colors:Array<any> = this.chartService.getColors();
|
||||
private channels:Array<string> = this.chartService.getChannels();
|
||||
private options:any;
|
||||
|
||||
setOptions (type) {
|
||||
if (type === 'line') {
|
||||
this.options = this.chartService.getChartJSLineDefaults();
|
||||
}
|
||||
if (type === 'radar') {
|
||||
this.options = this.chartService.getChartJSRadarDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.socket.on(this.constants.socket.events.fft, (data) => {
|
||||
this.data = [];
|
||||
data.data.forEach((dataset, index) => {
|
||||
this.data.push({
|
||||
data: dataset,
|
||||
label: this.channels[index],
|
||||
borderWidth: 1,
|
||||
pointRadius: 0,
|
||||
fill: false
|
||||
});
|
||||
});
|
||||
this.labels = data.labels;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy () {
|
||||
this.socket.removeListener(this.constants.socket.events.fft);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { FrequencyComponent } from './frequency.component';
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './app.component';
|
||||
export * from './app.module';
|
||||
@@ -0,0 +1 @@
|
||||
export { MotionComponent } from './motion.component';
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
:host {
|
||||
display: block;
|
||||
margin: 20px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 0 5px rgba(0,0,0,0.3);
|
||||
background-color: #333333;
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: 768px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
h2 {
|
||||
position: absolute;
|
||||
margin: 0;
|
||||
top: 10px;
|
||||
right: 20px;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
#brainbrowser {
|
||||
width: 100%;
|
||||
height: 500px;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<section class="motion" [ngClass]="{ 'loading': !model }">
|
||||
<h2>Motion</h2>
|
||||
<article id="brainbrowser"></article>
|
||||
</section>
|
||||
@@ -0,0 +1,52 @@
|
||||
import { Component, OnInit, ElementRef } from '@angular/core';
|
||||
import * as io from 'socket.io-client';
|
||||
import { Constants } from '../shared/constants';
|
||||
|
||||
declare var BrainBrowser;
|
||||
|
||||
@Component({
|
||||
selector: 'bci-motion',
|
||||
templateUrl: 'motion.component.html',
|
||||
styleUrls: ['motion.component.css'],
|
||||
providers: [Constants]
|
||||
})
|
||||
|
||||
export class MotionComponent implements OnInit {
|
||||
|
||||
socket: any;
|
||||
viewer: any;
|
||||
model: any;
|
||||
constructor(private view: ElementRef, private constants: Constants) {
|
||||
this.socket = io(constants.socket.url);
|
||||
}
|
||||
|
||||
private rotation = [];
|
||||
|
||||
ngOnInit() {
|
||||
BrainBrowser.config.set('worker_dir', 'vendor/brainbrowser/build/brainbrowser-2.3.0/workers');
|
||||
|
||||
this.socket.on(this.constants.socket.events.motion, (data) => {
|
||||
this.rotation = data.data;
|
||||
|
||||
if (this.model) {
|
||||
this.viewer.resetView();
|
||||
this.viewer.model.rotation.set(...this.rotation);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit () {
|
||||
this.viewer = BrainBrowser.SurfaceViewer.start('brainbrowser', (viewer) => {
|
||||
this.viewer = viewer;
|
||||
this.viewer.render();
|
||||
this.viewer.setWireframe(true);
|
||||
this.viewer.loadModelFromURL('app/motion/models/brain-surface.obj');
|
||||
this.viewer.setClearColor(0x333333);
|
||||
|
||||
this.viewer.addEventListener('displaymodel', (data) => {
|
||||
this.model = data.model;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class ChartService {
|
||||
|
||||
constructor() {}
|
||||
|
||||
getPlotlyContourLayout (overrides: any = {}): any {
|
||||
return Object.assign({
|
||||
bargap: 0,
|
||||
autosize: true,
|
||||
paper_bgcolor: 'rgba(0,0,0,0)',
|
||||
plot_bgcolor: 'rgba(0,0,0,0)',
|
||||
margin: { l: 0, r: 0, b: 0, t: 0 },
|
||||
xaxis: {
|
||||
autorange: true,
|
||||
showgrid: false,
|
||||
zeroline: false,
|
||||
showline: false,
|
||||
autotick: true,
|
||||
ticks: '',
|
||||
showticklabels: false
|
||||
},
|
||||
yaxis: {
|
||||
autorange: true,
|
||||
showgrid: false,
|
||||
zeroline: false,
|
||||
showline: false,
|
||||
autotick: true,
|
||||
ticks: '',
|
||||
showticklabels: false
|
||||
}
|
||||
}, overrides);
|
||||
}
|
||||
|
||||
getPlotlyContourData (overrides: any = {}): any {
|
||||
return Object.assign({
|
||||
z: [],
|
||||
x: [],
|
||||
y: [],
|
||||
type: 'contour',
|
||||
colorscale: 'Jet',
|
||||
showscale: false
|
||||
}, overrides);
|
||||
}
|
||||
|
||||
getChartJSGlobalDefaults (overrides: any = {}): any {
|
||||
return Object.assign({
|
||||
responsive: true,
|
||||
animation: false,
|
||||
legend: {
|
||||
display: true,
|
||||
position: 'bottom'
|
||||
},
|
||||
}, overrides);
|
||||
}
|
||||
|
||||
getChartJSLineDefaults (overrides: any = {}): any {
|
||||
return Object.assign({
|
||||
scales: {
|
||||
xAxes: [{
|
||||
gridLines: {
|
||||
display: true
|
||||
},
|
||||
ticks: {
|
||||
max: 4,
|
||||
min: -2,
|
||||
stepSize: 0.5
|
||||
}
|
||||
}],
|
||||
yAxes: [{
|
||||
gridLines: {
|
||||
display: true
|
||||
},
|
||||
ticks: {
|
||||
max: 4,
|
||||
min: -2,
|
||||
stepSize: 0.5
|
||||
}
|
||||
}]
|
||||
}
|
||||
}, this.getChartJSGlobalDefaults());
|
||||
}
|
||||
|
||||
getChartJSBarDefaults (overrides: any = {}): any {
|
||||
return Object.assign({
|
||||
scales: {
|
||||
xAxes: [{
|
||||
gridLines: {
|
||||
display: false
|
||||
},
|
||||
ticks: {
|
||||
max: 4,
|
||||
min: 0,
|
||||
stepSize: 0.5
|
||||
}
|
||||
}],
|
||||
yAxes: [{
|
||||
gridLines: {
|
||||
display: false
|
||||
},
|
||||
ticks: {
|
||||
max: 4,
|
||||
min: 0,
|
||||
stepSize: 0.5
|
||||
}
|
||||
}]
|
||||
}
|
||||
}, this.getChartJSGlobalDefaults({
|
||||
legend: {
|
||||
display: false
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
getChartJSRadarDefaults (overrides: any = {}): any {
|
||||
return Object.assign({
|
||||
scale: {
|
||||
lineArc: false,
|
||||
angleLines: {
|
||||
display: true
|
||||
},
|
||||
ticks: {
|
||||
max: 4,
|
||||
min: -2,
|
||||
stepSize: 0.5,
|
||||
showLabelBackdrop: false
|
||||
}
|
||||
}
|
||||
}, this.getChartJSGlobalDefaults());
|
||||
}
|
||||
|
||||
getChartSmoothieDefaults (overrides: any = {}): any {
|
||||
return Object.assign({
|
||||
millisPerLine: 3000,
|
||||
grid: {
|
||||
fillStyle: '#333333',
|
||||
strokeStyle: 'rgba(0,0,0,0.1)',
|
||||
sharpLines: false,
|
||||
verticalSections: this.getChannels().length,
|
||||
borderVisible: true
|
||||
},
|
||||
labels: {
|
||||
disabled: true
|
||||
},
|
||||
maxValue: this.getChannels().length * 2,
|
||||
minValue: 0
|
||||
}, overrides);
|
||||
}
|
||||
|
||||
getChannels (): Array<string> {
|
||||
return Array(8).fill('CH').map((item, index) => item + (index + 1));
|
||||
}
|
||||
|
||||
getColors (): Array<any> {
|
||||
return [
|
||||
{ borderColor: 'rgba(112,185,252,1)', backgroundColor: 'rgba(112,185,252,1)' },
|
||||
{ borderColor: 'rgba(116,150,161,1)', backgroundColor: 'rgba(116,150,161,1)' },
|
||||
{ borderColor: 'rgba(162,86,178,1)', backgroundColor: 'rgba(162,86,178,1)' },
|
||||
{ borderColor: 'rgba(144,132,246,1)', backgroundColor: 'rgba(144,132,246,1)' },
|
||||
{ borderColor: 'rgba(138,219,229,1)', backgroundColor: 'rgba(138,219,229,1)' },
|
||||
{ borderColor: 'rgba(232,223,133,1)', backgroundColor: 'rgba(232,223,133,1)' },
|
||||
{ borderColor: 'rgba(148,159,177,1)', backgroundColor: 'rgba(148,159,177,1)' },
|
||||
{ borderColor: 'rgba(77,83,96,1)', backgroundColor: 'rgba(77,83,96,1)' }
|
||||
];
|
||||
}
|
||||
|
||||
getColorByIndex (index:number): Array<any> {
|
||||
return this.getColors().filter((c, i) => index === i);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class Constants {
|
||||
|
||||
socket: any = {
|
||||
url: 'http://localhost:8080',
|
||||
events: {
|
||||
fft: 'bci:fft',
|
||||
time: 'bci:time',
|
||||
topo: 'bci:topo',
|
||||
filter: 'bci:filter',
|
||||
motion: 'bci:motion'
|
||||
}
|
||||
};
|
||||
|
||||
filters: Array<any> = [
|
||||
{
|
||||
id: 'NOTCH',
|
||||
label: 'Notch',
|
||||
type: 'single',
|
||||
enabled: true,
|
||||
options: [
|
||||
{
|
||||
id: 'NOTCH:60',
|
||||
label: '60 Hz'
|
||||
},
|
||||
{
|
||||
id: 'NOTCH:50',
|
||||
label: '50 Hz'
|
||||
},
|
||||
{
|
||||
id: 'NOTCH:NONE',
|
||||
label: 'None'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'BANDPASS',
|
||||
label: 'Band Pass',
|
||||
type: 'single',
|
||||
enabled: false,
|
||||
options: [
|
||||
{
|
||||
id: 'BANDPASS:1-50',
|
||||
label: '1-50 Hz'
|
||||
},
|
||||
{
|
||||
id: 'BANDPASS:7-13',
|
||||
label: '7-13 Hz'
|
||||
},
|
||||
{
|
||||
id: 'BANDPASS:15-50',
|
||||
label: '15-50 Hz'
|
||||
},
|
||||
{
|
||||
id: 'BANDPASS:5-50',
|
||||
label: '5-50 Hz'
|
||||
},
|
||||
{
|
||||
id: 'BANDPASS:NONE',
|
||||
label: 'None'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'VERTSCALE',
|
||||
label: 'Vert Scale',
|
||||
type: 'single',
|
||||
enabled: false,
|
||||
options: [
|
||||
{
|
||||
id: 'VERTSCALE:50',
|
||||
label: '50uV'
|
||||
},
|
||||
{
|
||||
id: 'VERTSCALE:100',
|
||||
label: '100uV'
|
||||
},
|
||||
{
|
||||
id: 'VERTSCALE:200',
|
||||
label: '200uV'
|
||||
},
|
||||
{
|
||||
id: 'VERTSCALE:400',
|
||||
label: '400uV'
|
||||
},
|
||||
{
|
||||
id: 'VERTSCALE:1000',
|
||||
label: '1000uV'
|
||||
},
|
||||
{
|
||||
id: 'VERTSCALE:10000',
|
||||
label: '10,000uV'
|
||||
},
|
||||
{
|
||||
id: 'VERTSCALE:NONE',
|
||||
label: 'None'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'VERTALGO',
|
||||
label: 'Vert Algo',
|
||||
type: 'single',
|
||||
enabled: false,
|
||||
options: [
|
||||
{
|
||||
id: 'VERTALGO:50',
|
||||
label: 'Log'
|
||||
},
|
||||
{
|
||||
id: 'VERTALGO:Linear',
|
||||
label: 'Linear'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'SMOOTH',
|
||||
label: 'Smooth',
|
||||
type: 'single',
|
||||
enabled: false,
|
||||
options: [
|
||||
{
|
||||
id: 'SMOOTH:0-75',
|
||||
label: '0 75'
|
||||
},
|
||||
{
|
||||
id: 'SMOOTH:0-9',
|
||||
label: '0 9'
|
||||
},
|
||||
{
|
||||
id: 'SMOOTH:0-95',
|
||||
label: '0 95'
|
||||
},
|
||||
{
|
||||
id: 'SMOOTH:0-98',
|
||||
label: '0 98'
|
||||
},
|
||||
{
|
||||
id: 'SMOOTH:0-0',
|
||||
label: '0 0'
|
||||
},
|
||||
{
|
||||
id: 'SMOOTH:0-5',
|
||||
label: '0 5'
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'POLARITY',
|
||||
label: 'Polarity',
|
||||
type: 'single',
|
||||
enabled: false,
|
||||
options: [
|
||||
{
|
||||
id: 'POLARITY:Yes',
|
||||
label: 'Yes'
|
||||
},
|
||||
{
|
||||
id: 'POLARITY:NO',
|
||||
label: 'No'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'MAXFREQUENCY',
|
||||
label: 'Max Frequency',
|
||||
type: 'single',
|
||||
enabled: false,
|
||||
options: [
|
||||
{
|
||||
id: 'MAXFREQUENCY:60',
|
||||
label: '60 Hz'
|
||||
},
|
||||
{
|
||||
id: 'MAXFREQUENCY:120',
|
||||
label: '120 Hz'
|
||||
},
|
||||
{
|
||||
id: 'MAXFREQUENCY:20',
|
||||
label: '20 Hz'
|
||||
},
|
||||
{
|
||||
id: 'MAXFREQUENCY:40',
|
||||
label: '40 Hz'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './chart.service';
|
||||
export * from './ng2-charts';
|
||||
@@ -0,0 +1,287 @@
|
||||
import {
|
||||
Component, OnDestroy, OnInit, OnChanges, EventEmitter, ElementRef, Input,
|
||||
Output
|
||||
} from '@angular/core';
|
||||
|
||||
declare var Chart:any;
|
||||
|
||||
@Component({
|
||||
selector: 'base-chart',
|
||||
template: `<canvas style="width: 100%; height: 100%;"></canvas>`,
|
||||
})
|
||||
export class BaseChartComponent implements OnDestroy, OnChanges, OnInit {
|
||||
public static defaultColors:Array<number[]> = [
|
||||
[255, 99, 132],
|
||||
[54, 162, 235],
|
||||
[255, 206, 86],
|
||||
[231, 233, 237],
|
||||
[75, 192, 192],
|
||||
[151, 187, 205],
|
||||
[220, 220, 220],
|
||||
[247, 70, 74],
|
||||
[70, 191, 189],
|
||||
[253, 180, 92],
|
||||
[148, 159, 177],
|
||||
[77, 83, 96]
|
||||
];
|
||||
|
||||
@Input() public data:number[] | Array<number[]>;
|
||||
@Input() public datasets:any[];
|
||||
@Input() public labels:Array<any> = [];
|
||||
@Input() public options:any = {responsive: true};
|
||||
@Input() public chartType:string;
|
||||
@Input() public colors:Array<any>;
|
||||
@Input() public legend:boolean;
|
||||
@Input() public series:any;
|
||||
|
||||
@Output() public chartClick:EventEmitter<any> = new EventEmitter();
|
||||
@Output() public chartHover:EventEmitter<any> = new EventEmitter();
|
||||
|
||||
private ctx:any;
|
||||
private cvs:any;
|
||||
private parent:any;
|
||||
private chart:any;
|
||||
private initFlag:boolean = false;
|
||||
|
||||
private element:ElementRef;
|
||||
|
||||
public constructor(element:ElementRef) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public ngOnInit():any {
|
||||
this.ctx = this.element.nativeElement.children[0].getContext('2d');
|
||||
this.cvs = this.element.nativeElement.children[0];
|
||||
this.parent = this.element.nativeElement;
|
||||
this.initFlag = true;
|
||||
if (this.data || this.datasets) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public ngOnChanges():any {
|
||||
if (this.initFlag) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public ngOnDestroy():any {
|
||||
if (this.chart) {
|
||||
this.chart.destroy();
|
||||
this.chart = void 0;
|
||||
}
|
||||
}
|
||||
|
||||
public getChartBuilder(ctx:any/*, data:Array<any>, options:any*/):any {
|
||||
let datasets:any = void 0;
|
||||
|
||||
// in case if datasets is not provided, but data is present
|
||||
if (!this.datasets || !this.datasets.length && (this.data && this.data.length)) {
|
||||
if (Array.isArray(this.data[0])) {
|
||||
datasets = (this.data as Array<number[]>).map((data:number[], index:number) => {
|
||||
return {data, label: this.labels[index] || `Label ${index}`};
|
||||
});
|
||||
} else {
|
||||
datasets = [{data: this.data, label: `Label 0`}];
|
||||
}
|
||||
}
|
||||
|
||||
if (this.datasets && this.datasets.length ||
|
||||
(datasets && datasets.length)) {
|
||||
datasets = (this.datasets || datasets)
|
||||
.map((elm:number, index:number) => {
|
||||
let newElm:any = Object.assign({}, elm);
|
||||
if (this.colors && this.colors.length) {
|
||||
Object.assign(newElm, this.colors[index]);
|
||||
} else {
|
||||
Object.assign(newElm, getColors(this.chartType, index, newElm.data.length));
|
||||
}
|
||||
return newElm;
|
||||
});
|
||||
}
|
||||
|
||||
if (!datasets) {
|
||||
throw new Error(`ng-charts configuration error,
|
||||
data or datasets field are required to render char ${this.chartType}`);
|
||||
}
|
||||
|
||||
let options:any = Object.assign({}, this.options);
|
||||
// hock for onHover and onClick events
|
||||
options.hover = options.hover || {};
|
||||
if (!options.hover.onHover) {
|
||||
options.hover.onHover = (active:Array<any>) => {
|
||||
if (active && !active.length) {
|
||||
return;
|
||||
}
|
||||
this.chartHover.emit({active});
|
||||
};
|
||||
}
|
||||
|
||||
if (!options.onClick) {
|
||||
options.onClick = (event:any, active:Array<any>) => {
|
||||
this.chartClick.emit({event, active});
|
||||
};
|
||||
}
|
||||
|
||||
let opts = {
|
||||
type: this.chartType,
|
||||
data: {
|
||||
labels: this.labels,
|
||||
datasets: datasets
|
||||
},
|
||||
options: options
|
||||
};
|
||||
|
||||
if (typeof Chart === 'undefined') {
|
||||
throw new Error('ng2-charts configuration issue: Embedding Chart.js lib is mandatory');
|
||||
}
|
||||
|
||||
return new Chart(ctx, opts);
|
||||
}
|
||||
|
||||
private refresh():any {
|
||||
if (this.options && this.options.responsive && this.parent.clientHeight === 0) {
|
||||
return setTimeout(() => this.refresh(), 50);
|
||||
}
|
||||
|
||||
// todo: remove this line, it is producing flickering
|
||||
this.ngOnDestroy();
|
||||
this.chart = this.getChartBuilder(this.ctx/*, data, this.options*/);
|
||||
}
|
||||
}
|
||||
|
||||
// private helper functions
|
||||
export interface Color {
|
||||
backgroundColor?:string | string[];
|
||||
borderWidth?:number | number[];
|
||||
borderColor?:string | string[];
|
||||
borderCapStyle?:string;
|
||||
borderDash?:number[];
|
||||
borderDashOffset?:number;
|
||||
borderJoinStyle?:string;
|
||||
|
||||
pointBorderColor?:string | string[];
|
||||
pointBackgroundColor?:string | string[];
|
||||
pointBorderWidth?:number | number[];
|
||||
|
||||
pointRadius?:number | number[];
|
||||
pointHoverRadius?:number | number[];
|
||||
pointHitRadius?:number | number[];
|
||||
|
||||
pointHoverBackgroundColor?:string | string[];
|
||||
pointHoverBorderColor?:string | string[];
|
||||
pointHoverBorderWidth?:number | number[];
|
||||
pointStyle?:string | string[];
|
||||
|
||||
hoverBackgroundColor?:string | string[];
|
||||
hoverBorderColor?:string | string[];
|
||||
hoverBorderWidth?:number;
|
||||
}
|
||||
|
||||
// pie | doughnut
|
||||
export interface Colors extends Color {
|
||||
data?:number[];
|
||||
label?:string;
|
||||
}
|
||||
|
||||
function rgba(colour:Array<number>, alpha:number):string {
|
||||
return 'rgba(' + colour.concat(alpha).join(',') + ')';
|
||||
}
|
||||
|
||||
function getRandomInt(min:number, max:number):number {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
function formatLineColor(colors:Array<number>):Color {
|
||||
return {
|
||||
backgroundColor: rgba(colors, 0.4),
|
||||
borderColor: rgba(colors, 1),
|
||||
pointBackgroundColor: rgba(colors, 1),
|
||||
pointBorderColor: '#fff',
|
||||
pointHoverBackgroundColor: '#fff',
|
||||
pointHoverBorderColor: rgba(colors, 0.8)
|
||||
};
|
||||
}
|
||||
|
||||
function formatBarColor(colors:Array<number>):Color {
|
||||
return {
|
||||
backgroundColor: rgba(colors, 0.6),
|
||||
borderColor: rgba(colors, 1),
|
||||
hoverBackgroundColor: rgba(colors, 0.8),
|
||||
hoverBorderColor: rgba(colors, 1)
|
||||
};
|
||||
}
|
||||
|
||||
function formatPieColors(colors:Array<number[]>):Colors {
|
||||
return {
|
||||
backgroundColor: colors.map((color:number[]) => rgba(color, 0.6)),
|
||||
borderColor: colors.map(() => '#fff'),
|
||||
pointBackgroundColor: colors.map((color:number[]) => rgba(color, 1)),
|
||||
pointBorderColor: colors.map(() => '#fff'),
|
||||
pointHoverBackgroundColor: colors.map((color:number[]) => rgba(color, 1)),
|
||||
pointHoverBorderColor: colors.map((color:number[]) => rgba(color, 1))
|
||||
};
|
||||
}
|
||||
|
||||
function formatPolarAreaColors(colors:Array<number[]>):Color {
|
||||
return {
|
||||
backgroundColor: colors.map((color:number[]) => rgba(color, 0.6)),
|
||||
borderColor: colors.map((color:number[]) => rgba(color, 1)),
|
||||
hoverBackgroundColor: colors.map((color:number[]) => rgba(color, 0.8)),
|
||||
hoverBorderColor: colors.map((color:number[]) => rgba(color, 1))
|
||||
};
|
||||
}
|
||||
|
||||
function getRandomColor():number[] {
|
||||
return [getRandomInt(0, 255), getRandomInt(0, 255), getRandomInt(0, 255)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate colors for line|bar charts
|
||||
* @param index
|
||||
* @returns {number[]|Color}
|
||||
*/
|
||||
function generateColor(index:number):number[] {
|
||||
return BaseChartComponent.defaultColors[index] || getRandomColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate colors for pie|doughnut charts
|
||||
* @param count
|
||||
* @returns {Colors}
|
||||
*/
|
||||
function generateColors(count:number):Array<number[]> {
|
||||
let colorsArr:Array<number[]> = new Array(count);
|
||||
for (let i = 0; i < count; i++) {
|
||||
colorsArr[i] = BaseChartComponent.defaultColors[i] || getRandomColor();
|
||||
}
|
||||
return colorsArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate colors by chart type
|
||||
* @param chartType
|
||||
* @param index
|
||||
* @param count
|
||||
* @returns {Color}
|
||||
*/
|
||||
function getColors(chartType:string, index:number, count:number):Color {
|
||||
if (chartType === 'pie' || chartType === 'doughnut') {
|
||||
return formatPieColors(generateColors(count));
|
||||
}
|
||||
|
||||
if (chartType === 'polarArea') {
|
||||
return formatPolarAreaColors(generateColors(count));
|
||||
}
|
||||
|
||||
if (chartType === 'line' || chartType === 'radar') {
|
||||
return formatLineColor(generateColor(index));
|
||||
}
|
||||
|
||||
if (chartType === 'bar') {
|
||||
return formatBarColor(generateColor(index));
|
||||
}
|
||||
return generateColor(index);
|
||||
}
|
||||
|
||||
export const CHART_DIRECTIVES:Array<any> = [BaseChartComponent];
|
||||
@@ -0,0 +1 @@
|
||||
export { TimeSeriesComponent } from './time-series.component';
|
||||
@@ -0,0 +1,82 @@
|
||||
|
||||
:host {
|
||||
display: block;
|
||||
margin: 20px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 0 5px rgba(0,0,0,0.3);
|
||||
background-color: #333333;
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: 1060px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
h2 {
|
||||
position: absolute;
|
||||
margin: 0;
|
||||
top: 10px;
|
||||
right: 20px;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.time-series canvas {
|
||||
margin: 40px 80px 40px 40px;
|
||||
}
|
||||
|
||||
.time-series-channels,
|
||||
.time-series-amplitudes {
|
||||
position: absolute;
|
||||
top: 60px;
|
||||
height: 450px;
|
||||
color: rgba(102,102,102,1);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.time-series-channels {
|
||||
width: 40px;
|
||||
left: 20px;
|
||||
text-align: left;
|
||||
color: #000000;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.time-series-amplitudes {
|
||||
right: 20px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.time-series-channels ul {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.time-series-channels li {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.time-series-channels ul,
|
||||
.time-series-amplitudes ul {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: space-around;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.time-series-duration {
|
||||
position: absolute;
|
||||
left: 50px;
|
||||
width: 98%;
|
||||
bottom: 22px;
|
||||
display: flex;
|
||||
color: rgba(102,102,102,1);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.time-series-duration time {
|
||||
width: 20%;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<section class="time-series" [ngClass]="{ 'loading': !amplitudes }">
|
||||
<h2>Time Series</h2>
|
||||
<aside class="time-series-channels">
|
||||
<ul>
|
||||
<li *ngFor="let channel of channels, let i = index"
|
||||
[ngStyle]="{ 'color': colors[i].borderColor }">
|
||||
{{ channel }}
|
||||
</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<canvas id="timeSeries" width="950" height="450"></canvas>
|
||||
<aside class="time-series-amplitudes">
|
||||
<ul>
|
||||
<li *ngFor="let amplitude of amplitudes, let i = index"
|
||||
[ngStyle]="{ 'color': colors[i].borderColor }">
|
||||
{{ amplitude }}
|
||||
</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<footer class="time-series-duration">
|
||||
<time *ngFor="let time of timeline"
|
||||
datetime="P1M">
|
||||
{{ time }}
|
||||
</time>
|
||||
</footer>
|
||||
</section>
|
||||
@@ -0,0 +1,68 @@
|
||||
import { Component, ElementRef, OnInit, OnDestroy } from '@angular/core';
|
||||
import { SmoothieChart, TimeSeries } from 'smoothie';
|
||||
import * as io from 'socket.io-client';
|
||||
import { ChartService } from '../shared';
|
||||
|
||||
import { Constants } from '../shared/constants';
|
||||
|
||||
@Component({
|
||||
selector: 'bci-time-series',
|
||||
templateUrl: 'time-series.component.html',
|
||||
styleUrls: ['time-series.component.css'],
|
||||
providers: [ChartService, Constants]
|
||||
})
|
||||
|
||||
export class TimeSeriesComponent implements OnInit {
|
||||
|
||||
socket: any;
|
||||
constructor(private view: ElementRef,
|
||||
private chartService: ChartService,
|
||||
private constants: Constants) {
|
||||
this.socket = io(constants.socket.url);
|
||||
this.chartService = chartService;
|
||||
}
|
||||
|
||||
private options = this.chartService.getChartSmoothieDefaults();
|
||||
|
||||
private timeSeries = new SmoothieChart(this.options);
|
||||
private amplitudes = [];
|
||||
private timeline = [];
|
||||
private lines = Array(8).fill(0).map(() => new TimeSeries());
|
||||
private channels = this.chartService.getChannels();
|
||||
private colors = this.chartService.getColors();
|
||||
|
||||
ngOnInit() {
|
||||
this.addTimeSeriesLines();
|
||||
|
||||
this.socket.on(this.constants.socket.events.time, (data) => {
|
||||
this.amplitudes = data.amplitudes;
|
||||
this.timeline = data.timeline;
|
||||
this.appendTimeSeriesLines(data.data);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy () {
|
||||
this.socket.removeListener(this.constants.socket.events.time);
|
||||
}
|
||||
|
||||
ngAfterViewInit () {
|
||||
this.timeSeries.streamTo(this.view.nativeElement.querySelector('canvas'), 40);
|
||||
}
|
||||
|
||||
addTimeSeriesLines () {
|
||||
this.lines.forEach((line, index) => {
|
||||
this.timeSeries.addTimeSeries(line, {
|
||||
strokeStyle: this.colors[index].borderColor
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
appendTimeSeriesLines (data) {
|
||||
this.lines.forEach((line, index) => {
|
||||
data[index].forEach((amplitude) => {
|
||||
line.append(new Date().getTime(), amplitude);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { TopoComponent } from './topo.component';
|
||||
@@ -0,0 +1,101 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:host {
|
||||
display: block;
|
||||
margin: 20px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 0 5px rgba(0,0,0,0.3);
|
||||
background-color: #333333;
|
||||
position: relative;
|
||||
height: 40vw;
|
||||
width: 40vw;
|
||||
}
|
||||
|
||||
h2 {
|
||||
position: absolute;
|
||||
margin: 0;
|
||||
top: 10px;
|
||||
right: 20px;
|
||||
font-weight: 300;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.topoplot {
|
||||
-webkit-clip-path: circle(50%);
|
||||
border-radius: 50%;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
[class*='topoplot-c'] {
|
||||
z-index: 2;
|
||||
background-color: black;
|
||||
border: 1px solid black;
|
||||
width: 5%;
|
||||
height: 5%;
|
||||
border-radius: 50%;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.top {
|
||||
top: 2%
|
||||
}
|
||||
.middle {
|
||||
top: calc(50% - 50px);
|
||||
}
|
||||
.third {
|
||||
top: 70%;
|
||||
}
|
||||
.bottom {
|
||||
bottom: 2%;
|
||||
}
|
||||
|
||||
.top.left,
|
||||
.bottom.left {
|
||||
left: 32%;
|
||||
}
|
||||
|
||||
.top.right,
|
||||
.bottom.right {
|
||||
right: 32%;
|
||||
}
|
||||
|
||||
.middle.left {
|
||||
left: 25%;
|
||||
}
|
||||
|
||||
.middle.right {
|
||||
right: 25%;
|
||||
}
|
||||
|
||||
.third.left {
|
||||
left: 8%;
|
||||
}
|
||||
|
||||
.third.right {
|
||||
right: 8%;
|
||||
}
|
||||
|
||||
|
||||
/* Grid */
|
||||
|
||||
.topoplot-grid {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
-webkit-clip-path: circle(50%);
|
||||
border-radius: 50%;
|
||||
-webkit-filter: blur(10px);
|
||||
}
|
||||
|
||||
[class*='topoplot-u'] {
|
||||
float: left;
|
||||
/*border: 1px solid lightgray;*/
|
||||
width: 9.09%;
|
||||
height: 9.09%;
|
||||
/*background: lightblue;*/
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<section [ngClass]="{ loading: !data }">
|
||||
<h2>Topo</h2>
|
||||
<section class="topoplot">
|
||||
<div id="topo"></div>
|
||||
</section>
|
||||
</section>
|
||||
@@ -0,0 +1,55 @@
|
||||
import { Component, OnInit, OnDestroy, ElementRef } from '@angular/core';
|
||||
import * as io from 'socket.io-client';
|
||||
import { Constants } from '../shared/constants';
|
||||
import { ChartService } from '../shared';
|
||||
|
||||
declare var chroma: any;
|
||||
declare var Plotly: any;
|
||||
|
||||
@Component({
|
||||
selector: 'bci-topo',
|
||||
templateUrl: 'topo.component.html',
|
||||
styleUrls: ['topo.component.css'],
|
||||
providers: [Constants, ChartService]
|
||||
})
|
||||
|
||||
export class TopoComponent implements OnInit {
|
||||
|
||||
socket: any;
|
||||
plotElement: any;
|
||||
|
||||
constructor(private view: ElementRef, private chartService: ChartService, private constants: Constants) {
|
||||
this.socket = io(constants.socket.url);
|
||||
}
|
||||
|
||||
private data: any = this.chartService.getPlotlyContourData({
|
||||
x: this.getGrid(11),
|
||||
y: this.getGrid(11)
|
||||
});
|
||||
|
||||
private layout: any = this.chartService.getPlotlyContourLayout();
|
||||
|
||||
private options: any = {
|
||||
staticPlot: true
|
||||
};
|
||||
|
||||
ngOnInit(): void {
|
||||
this.plotElement = this.view.nativeElement.querySelector('#topo');
|
||||
Plotly.newPlot(this.plotElement.id, [this.data], this.layout, this.options);
|
||||
|
||||
this.socket.on(this.constants.socket.events.topo, (data) => {
|
||||
this.data.z = data.data;
|
||||
Plotly.redraw(this.plotElement);
|
||||
Plotly.Plots.resize(this.plotElement);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy (): void {
|
||||
this.socket.removeListener(this.constants.socket.events.topo);
|
||||
}
|
||||
|
||||
getGrid (n) {
|
||||
return Array(n).fill(0).map((v, i) => i).reverse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export const environment = {
|
||||
production: false
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export const environment = {
|
||||
production: true
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
// The file for the current environment will overwrite this one during build.
|
||||
// Different environments can be found in ./environment.{dev|prod}.ts, and
|
||||
// you can create your own and use it with the --env flag.
|
||||
// The build system defaults to the dev environment.
|
||||
|
||||
export const environment = {
|
||||
production: false
|
||||
};
|
||||
|
Depois Largura: | Altura: | Tamanho: 5.3 KiB |
@@ -0,0 +1,25 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>BCI Dashboard</title>
|
||||
<base href="/">
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
<style>
|
||||
@import url(https://fonts.googleapis.com/css?family=Roboto:400,700,300);
|
||||
body {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
font-weight: 300;
|
||||
color: #ffffff;
|
||||
background-color: #222222;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<bci-dashboard>Loading...</bci-dashboard>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
import './polyfills.ts';
|
||||
import 'chart.js';
|
||||
import 'chroma-js';
|
||||
import 'plotly.js';
|
||||
import 'brainbrowser/build/brainbrowser-2.3.0/brainbrowser.surface-viewer.min';
|
||||
|
||||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||
import { enableProdMode } from '@angular/core';
|
||||
import { environment } from './environments/environment';
|
||||
import { DashboardModule } from './app/dashboard.module';
|
||||
|
||||
if (environment.production) {
|
||||
enableProdMode();
|
||||
}
|
||||
|
||||
platformBrowserDynamic().bootstrapModule(DashboardModule);
|
||||
@@ -0,0 +1,19 @@
|
||||
// This file includes polyfills needed by Angular 2 and is loaded before
|
||||
// the app. You can add your own extra polyfills to this file.
|
||||
import 'core-js/es6/symbol';
|
||||
import 'core-js/es6/object';
|
||||
import 'core-js/es6/function';
|
||||
import 'core-js/es6/parse-int';
|
||||
import 'core-js/es6/parse-float';
|
||||
import 'core-js/es6/number';
|
||||
import 'core-js/es6/math';
|
||||
import 'core-js/es6/string';
|
||||
import 'core-js/es6/date';
|
||||
import 'core-js/es6/array';
|
||||
import 'core-js/es6/regexp';
|
||||
import 'core-js/es6/map';
|
||||
import 'core-js/es6/set';
|
||||
import 'core-js/es6/reflect';
|
||||
|
||||
import 'core-js/es7/reflect';
|
||||
import 'zone.js/dist/zone';
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const constants = require('./constants');
|
||||
const io = require('socket.io')(process.env.app_port || constants.sockets.port);
|
||||
|
||||
const Connectors = require('./connectors');
|
||||
const Providers = require('./providers');
|
||||
const Modules = require('./modules');
|
||||
|
||||
const Connector = new Connectors.Serialport({
|
||||
verbose: true
|
||||
});
|
||||
|
||||
const Signal = new Providers.Signal({ io });
|
||||
const Motion = new Providers.Motion({ io });
|
||||
|
||||
Connector.start().then(() => {
|
||||
const FFT = new Modules.FFT({ Signal });
|
||||
const Topo = new Modules.Topo({ Signal });
|
||||
const TimeSeries = new Modules.TimeSeries({ Signal });
|
||||
});
|
||||
|
||||
Connector.stream((data) => {
|
||||
Signal.buffer(data);
|
||||
Motion.capture(data);
|
||||
});
|
||||
|
||||
process.on(constants.events.terminate, Connector.stop);
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
module.exports = class Bluetooth {
|
||||
/**
|
||||
* The future!
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const Serialport = require('./serialport.connector');
|
||||
const Bluetooth = require('./bluetooth.connector');
|
||||
|
||||
module.exports = {
|
||||
Serialport,
|
||||
Bluetooth
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
const Utils = require('../utils');
|
||||
const OpenBCI = require('openbci-sdk');
|
||||
const OpenBCIBoard = OpenBCI.OpenBCIBoard;
|
||||
const constants = require('../constants');
|
||||
|
||||
module.exports = class Serialport extends OpenBCIBoard {
|
||||
|
||||
constructor (options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
start () {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
var onConnect = () => {
|
||||
this.on(constants.connector.readyEvent, () => {
|
||||
this.streamStart();
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
|
||||
this.autoFindOpenBCIBoard()
|
||||
.then((portName) => {
|
||||
if (portName) {
|
||||
this.connect(portName).then(onConnect);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
if (Utils.signal.isSimulated()) {
|
||||
this.connect(OpenBCI.OpenBCIConstants.OBCISimulatorPortName)
|
||||
.then(onConnect);
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
stop () {
|
||||
this.streamStop().then(() => {
|
||||
this.disconnect().then(() => {
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
stream (callback) {
|
||||
this.on(constants.connector.sampleEvent, callback);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
connector: {
|
||||
channels: 8,
|
||||
simulateFlag: 'simulate',
|
||||
readyEvent: 'ready',
|
||||
sampleEvent: 'sample'
|
||||
},
|
||||
signal: {
|
||||
bufferSize: 512,
|
||||
sampleRate: 250,
|
||||
windowSize: 32 // data has a moving window of 32 samples = 128 milliseconds (250Hz)
|
||||
},
|
||||
fft: {
|
||||
bins: 512
|
||||
},
|
||||
scale: {
|
||||
global: 1.5,
|
||||
simulated: 4,
|
||||
skipLabels: 4
|
||||
},
|
||||
units: {
|
||||
hertz: 'Hz',
|
||||
microvolts: 'uV',
|
||||
seconds: 's'
|
||||
},
|
||||
bands: { // frequency
|
||||
delta: [1, 3],
|
||||
theta: [4, 8],
|
||||
alpha: [8, 12],
|
||||
beta: [13, 30],
|
||||
gamma: [30, 100]
|
||||
},
|
||||
time: {
|
||||
windowSize: 5, // seconds
|
||||
timeline: 20, // seconds
|
||||
skip: 2 //
|
||||
},
|
||||
events: {
|
||||
fft: 'bci:fft',
|
||||
topo: 'bci:topo',
|
||||
time: 'bci:time',
|
||||
signal: 'bci:signal',
|
||||
filter: 'bci:filter',
|
||||
motion: 'bci:motion',
|
||||
terminate: 'SIGINT'
|
||||
},
|
||||
topo: {
|
||||
params: [0,10,11],
|
||||
x: [3,7,2,8,0,10,3,7],
|
||||
y: [0,0,3,3,8,8,10,10]
|
||||
},
|
||||
sockets: {
|
||||
port: 8080
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,76 @@
|
||||
'use strict';
|
||||
|
||||
const dsp = require('dsp.js');
|
||||
const Utils = require('../utils');
|
||||
const constants = require('../constants');
|
||||
|
||||
module.exports = class FFT {
|
||||
|
||||
constructor ({ Signal }) {
|
||||
this.signal = Signal;
|
||||
this.bins = constants.fft.bins;
|
||||
this.bufferSize = constants.signal.bufferSize;
|
||||
this.sampleRate = constants.signal.sampleRate;
|
||||
this.bands = constants.bands;
|
||||
this.spectrums = [[],[],[],[],[],[],[],[]];
|
||||
this.byBand = [];
|
||||
this.labels = [];
|
||||
this.subscribe();
|
||||
}
|
||||
|
||||
subscribe () {
|
||||
this.signal.emitter.on(constants.events.signal, (signals) => {
|
||||
this.signalsToFFT(signals);
|
||||
this.scaleLabels();
|
||||
this.filterBands();
|
||||
this.filterLabels();
|
||||
this.emit();
|
||||
});
|
||||
}
|
||||
|
||||
signalsToFFT (signals) {
|
||||
signals.forEach((signal, index) => {
|
||||
signal = Utils.filter.process(signal);
|
||||
let fft = new dsp.FFT(this.bufferSize, this.sampleRate);
|
||||
fft.forward(signal);
|
||||
this.spectrums[index] = Utils.data.parseObjectAsArray(fft.spectrum);
|
||||
this.spectrums[index] = Utils.signal.voltsToMicrovolts(this.spectrums[index], true);
|
||||
});
|
||||
}
|
||||
|
||||
scaleLabels () {
|
||||
this.labels = new Array(this.bins / 2).fill()
|
||||
.map((label, index) => {
|
||||
return Math.ceil(index * (this.sampleRate / this.bins));
|
||||
});
|
||||
}
|
||||
|
||||
filterBands () {
|
||||
for (let band in this.bands) {
|
||||
this.byBand[band] = Utils.filter.filterBand(this.spectrums, this.labels, this.bands[band]);
|
||||
}
|
||||
}
|
||||
|
||||
filterLabels () {
|
||||
// Skip every 8, add uni (too many labels issue)
|
||||
this.labels = this.labels.map((label, index, labels) => {
|
||||
let eighth = index % constants.scale.skipLabels === 0;
|
||||
let last = index === (labels.length - 1);
|
||||
return eighth || last ? `${label} ${constants.units.hertz}` : ``;
|
||||
});
|
||||
}
|
||||
|
||||
emit () {
|
||||
this.signal.io.emit(constants.events.fft, {
|
||||
data: this.spectrums,
|
||||
labels: this.labels,
|
||||
theta: this.byBand.theta.spectrums,
|
||||
delta: this.byBand.delta.spectrums,
|
||||
alpha: this.byBand.alpha.spectrums,
|
||||
beta: this.byBand.beta.spectrums,
|
||||
gamma: this.byBand.gamma.spectrums
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const FFT = require('./fft.module');
|
||||
const TimeSeries = require('./time-series.module');
|
||||
const Topo = require('./topo.module');
|
||||
|
||||
module.exports = {
|
||||
FFT,
|
||||
TimeSeries,
|
||||
Topo
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
|
||||
const Utils = require('../utils');
|
||||
const constants = require('../constants');
|
||||
|
||||
module.exports = class TimeSeries {
|
||||
|
||||
constructor ({ Signal }) {
|
||||
this.signal = Signal;
|
||||
this.sampleRate = constants.signal.sampleRate;
|
||||
this.bufferSize = constants.signal.bufferSize;
|
||||
this.windowSize = constants.signal.windowSize;
|
||||
this.timeline = Utils.data.generateTimeline(constants.time.timeline, constants.time.skip, constants.units.seconds);
|
||||
this.timeSeries = [];
|
||||
this.amplitudes = [];
|
||||
this.subscribe();
|
||||
}
|
||||
|
||||
subscribe () {
|
||||
this.signal.emitter.on(constants.events.signal, (signal) => {
|
||||
this.timeSeries = signal;
|
||||
this.filter();
|
||||
this.offset();
|
||||
this.trim();
|
||||
this.signalToAmplitudes(signal);
|
||||
this.emit();
|
||||
});
|
||||
}
|
||||
|
||||
offset () {
|
||||
this.timeSeries = this.timeSeries.map((channel, channelIndex) => {
|
||||
return channel.map((amplitude) => {
|
||||
return Utils.signal.offsetForGrid(amplitude, channelIndex, constants.connector.channels, this.signal.scale);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
filter () {
|
||||
this.timeSeries.forEach((signal) => {
|
||||
signal = Utils.filter.highpass(signal);
|
||||
});
|
||||
}
|
||||
|
||||
trim () {
|
||||
this.timeSeries.forEach((channel) => {
|
||||
channel = channel.splice(0, this.bufferSize - this.windowSize);
|
||||
});
|
||||
}
|
||||
|
||||
signalToAmplitudes (signal) {
|
||||
this.amplitudes = signal.map((channel) => {
|
||||
let microvolts = Utils.signal.voltsToMicrovolts(channel[channel.length - 1])[0];
|
||||
return `${Math.round(microvolts)} ${constants.units.microvolts}`;
|
||||
});
|
||||
}
|
||||
|
||||
emit () {
|
||||
this.signal.io.emit(constants.events.time, {
|
||||
data: this.timeSeries,
|
||||
amplitudes: this.amplitudes,
|
||||
timeline: this.timeline
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
const topogrid = require('topogrid');
|
||||
const Utils = require('../utils');
|
||||
const constants = require('../constants');
|
||||
|
||||
module.exports = class Topo {
|
||||
|
||||
constructor ({ Signal }) {
|
||||
this.signal = Signal;
|
||||
this.sampleRate = constants.signal.sampleRate;
|
||||
this.grid = [];
|
||||
this.subscribe();
|
||||
}
|
||||
|
||||
subscribe () {
|
||||
this.signal.emitter.on(constants.events.signal, (signal) => {
|
||||
this.signalToGrid(signal);
|
||||
this.emit();
|
||||
});
|
||||
}
|
||||
|
||||
signalToGrid (signal) {
|
||||
|
||||
let grid = [];
|
||||
|
||||
signal.forEach((channel) => {
|
||||
grid.push(channel[channel.length - 1]);
|
||||
});
|
||||
|
||||
/**
|
||||
* params: Parameters for the grid [x,y,z] where x is the min
|
||||
* of the grid, y is the Max of the grid and z is the number of points
|
||||
* x: coordinates of the data
|
||||
* y: coordinates of the data
|
||||
* grid: data = [10,0,0,0,0,0,-10,30,25]; // the data values
|
||||
*/
|
||||
this.grid = topogrid.create(
|
||||
constants.topo.x,
|
||||
constants.topo.y,
|
||||
grid,
|
||||
constants.topo.params
|
||||
);
|
||||
}
|
||||
|
||||
emit () {
|
||||
this.signal.io.emit(constants.events.topo, {
|
||||
data: this.grid
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const Signal = require('./signal.provider');
|
||||
const Motion = require('./motion.provider');
|
||||
|
||||
module.exports = {
|
||||
Signal,
|
||||
Motion
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
const constants = require('../constants');
|
||||
const Utils = require('../utils');
|
||||
|
||||
module.exports = class Motion {
|
||||
|
||||
constructor ({ io }) {
|
||||
this.io = io;
|
||||
this.auxData = [];
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
capture ({ auxData }) {
|
||||
|
||||
if (Utils.signal.isSimulated()) {
|
||||
this.simulate();
|
||||
} else {
|
||||
if (this.hasMotion(auxData)) {
|
||||
this.auxData = this.amplify(auxData);
|
||||
this.emit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
hasMotion (auxData) {
|
||||
return auxData.reduce((a, b) => a + b, 0);
|
||||
}
|
||||
|
||||
amplify (auxData) {
|
||||
return auxData.map(axis => Math.round(axis));
|
||||
}
|
||||
|
||||
simulate () {
|
||||
this.count++;
|
||||
|
||||
if (this.count === 10) {
|
||||
this.auxData = [
|
||||
Math.round(Math.random() * 180),
|
||||
Math.round(Math.random() * 180),
|
||||
Math.round(Math.random() * 180)
|
||||
];
|
||||
this.count = 0;
|
||||
|
||||
|
||||
this.emit();
|
||||
}
|
||||
}
|
||||
|
||||
emit () {
|
||||
this.io.emit(constants.events.motion, {
|
||||
data: this.auxData
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const Utils = require('../utils');
|
||||
const constants = require('../constants');
|
||||
|
||||
class SignalEmitter extends EventEmitter {}
|
||||
|
||||
module.exports = class Signal {
|
||||
|
||||
constructor ({ io }) {
|
||||
this.io = io;
|
||||
this.emitter = new SignalEmitter();
|
||||
this.bufferSize = constants.signal.bufferSize;
|
||||
this.windowSize = constants.signal.windowSize;
|
||||
this.sampleRate = constants.signal.sampleRate;
|
||||
this.signals = [[],[],[],[],[],[],[],[]];
|
||||
this.sampleNumber = 0;
|
||||
this.init();
|
||||
}
|
||||
|
||||
init () {
|
||||
this.io.on('connection', (socket) => {
|
||||
socket.on(constants.events.filter, (filter) => {
|
||||
Utils.filter.apply(filter);
|
||||
});
|
||||
});
|
||||
|
||||
this.setScale();
|
||||
}
|
||||
|
||||
buffer (sample) {
|
||||
this.sampleNumber++;
|
||||
this.add(sample);
|
||||
|
||||
if (this.sampleNumber === this.bufferSize) {
|
||||
this.emitter.emit(constants.events.signal, [...this.signals]);
|
||||
this.window();
|
||||
}
|
||||
}
|
||||
|
||||
add (sample) {
|
||||
//console.log('sample', sample);
|
||||
Object.keys(sample.channelData).forEach((channel, i) => {
|
||||
this.signals[i].push(sample.channelData[channel]);
|
||||
});
|
||||
}
|
||||
|
||||
window () {
|
||||
this.signals = this.signals.map((channel) => {
|
||||
return channel.filter((signal, index) => {
|
||||
return index > (this.windowSize - 1);
|
||||
});
|
||||
});
|
||||
this.sampleNumber = this.bufferSize - this.windowSize;
|
||||
}
|
||||
|
||||
setScale () {
|
||||
if (Utils.signal.isSimulated()) {
|
||||
this.scale = constants.scale.simulated;
|
||||
} else {
|
||||
this.scale = constants.scale.global;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||