-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
89 lines (73 loc) · 2.39 KB
/
index.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
80
81
82
83
84
85
86
87
88
89
const { Notion } = require("@neurosity/notion");
require("dotenv").config();
const deviceId = process.env.DEVICE_ID || "";
const email = process.env.NEUROSITY_EMAIL || "";
const password = process.env.NEUROSITY_PASSWORD || "";
const verifyEnvs = (email, password, deviceId) => {
const invalidEnv = (env) => {
return env === "" || env === 0;
};
if (
invalidEnv(email) ||
invalidEnv(password) ||
invalidEnv(deviceId)
) {
console.error(
"Please verify deviceId, email and password are in .env file, quitting..."
);
process.exit(0);
}
};
verifyEnvs(email, password, deviceId);
console.log(`${email} attempting to authenticate to ${deviceId}`);
const notion = new Notion({
timesync: true
});
main();
async function main() {
console.log(`Logging in`);
await notion.login({
email: process.env.NEUROSITY_EMAIL,
password: process.env.NEUROSITY_PASSWORD
})
.catch(error => {
console.log(error);
throw new Error(error)
});
console.log(`Logged in`);
const metric = "kinesis";
const label = "leftArm";
const trainingOptions = {
metric,
label,
experimentId: "-experiment-123"
};
// Subscribe to Kinesis
notion.kinesis(label).subscribe((kinesis) => {
console.log("leftArm kinesis detection", kinesis);
});
// Subscribe to raw predictions
notion.predictions(label).subscribe((prediction) => {
console.log("leftArm prediction", prediction);
});
// Tell the user to clear their mind
console.log("Clear you mind and relax");
// Tag baseline after a couple seconds
setTimeout(() => {
// Note: using the spread operator to bring all properties from trainingOptions into the current object plus adding the new baseline tag. Learn about spread operators here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
notion.training.record({
...trainingOptions,
baseline: true
});
// Now tell the user to imagine an active thought
console.log("Imagine a baseball with your left arm");
}, 4000);
// Tell the user to imagine active thought and fit
setTimeout(() => {
// Note: You must call fit after a baseline and an active have been recorded.
notion.training.record({
...trainingOptions,
fit: true
});
}, 8000);
}