-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (53 loc) · 1.83 KB
/
app.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
var app = angular.module('angularjs-starter', []);
var eegfactor = 0;
var intensity = calcintensity(eegfactor);
function calcintensity(num){
return num * 10 + 10;
}
app.controller('visualizer', function($scope, Poller) {
swirl.rotationSpeed = intensity;
swirl.colorSpeed = intensity;
swirl.circleAmount = intensity;
$scope.data = Poller.data;
$scope.swirl = swirl;
});
app.run(function(Poller) {});
app.factory('Poller', function($http, $timeout) {
var data = { response: {}, calls: 0 };
var poller = function() {
$http.get('data.json').then(function(r) {
data.response = r.data;
data.calls++;
data.intensity = getintensity(data);
swirl.rotationSpeed = data.intensity;
swirl.colorSpeed = data.intensity;
swirl.circleAmount = data.intensity;
$timeout(poller, 1000);
});
};
function getintensity(data) {
if (data != null && data.response != null && data.response.eSense != null && data.response.eSense.meditation != null) {
console.log(data.response.eSense.meditation);
if (0 < data.response.eSense.meditation && data.response.eSense.meditation <= 20) {
eegfactor = eegfactor - 2;
} else if (20 < data.response.eSense.meditation && data.response.eSense.meditation <= 40) {
eegfactor = eegfactor - 1;
} else if (40 < data.response.eSense.meditation && data.response.eSense.meditation <= 60) {
//nothing
} else if (60 < data.response.eSense.meditation && data.response.eSense.meditation <= 80) {
eegfactor = eegfactor + 1;
} else if (80 < data.response.eSense.meditation && data.response.eSense.meditation <= 100) {
eegfactor = eegfactor + 2;
}
console.log("factor: " + eegfactor);
eegfactor = Math.max(0,Math.min(10,eegfactor));
}
var visualfactor = calcintensity(eegfactor);
console.log(visualfactor);
return visualfactor;
}
poller();
return {
data: data
};
});