-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (42 loc) · 1.41 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
import input from './src/input.js';
import { error, active } from './src/theme.js';
import model from './src/model.js'
import { stringify } from 'csv/sync'
import fs from 'fs'
const App = () => {
const fileName = input('enter file name : ')
const sampleRate = +input('enter sample rate : ');
let x = [];
let shouldRepeatInput = true;
while (shouldRepeatInput) {
const enteredInput = input('enter 6 x value seperated by space : ');
x = enteredInput.split(' ');
shouldRepeatInput = x.length !== 6
if (shouldRepeatInput) console.log(error('failed, try again : '))
}
const [x1, x2, x3, x4, x5, x6] = x;
const times = { x1, x2, x3, x4, x5, x6 };
let currentTime = 0;
const result = [];
for (const [key, value] of Object.entries(times)) {
const data = model[key];
const length = value / sampleRate;
for (let i = 0; i < length; i++) {
result.push({
time: currentTime,
...data
})
currentTime += sampleRate
}
}
try {
const outputRecords = stringify(result, { header: true });
fs.writeFileSync(`./output/${fileName}.csv`, outputRecords)
console.log(active(`file has been successfully created in ./output/${fileName}.csv`))
}
catch (err) {
console.log(err);
console.log(error('something went wrong!'));
}
}
App();