-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-variables.js
37 lines (34 loc) · 1.27 KB
/
build-variables.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
const fs = require('fs-extra')
const path = require('path')
const klawSync = require('klaw-sync')
const util = require('util')
const readFile = util.promisify(fs.readFile)
const inputFolder = 'suivi_systemes_hybrides'
const files = klawSync(path.join(__dirname, inputFolder), {nodir: true}).map(f => f.path).filter(f => f.split('.').pop() === 'evt-log');
(async function(){
const variables = {}
for (file of files){
const toks = file.split('/')
const fileName = toks.pop()
const sensor = toks.pop()
variables[sensor] = variables[sensor] || {}
const lines = (await readFile(file, 'utf-8')).split('\n')
process.stdout.write(sensor + ' - ' + fileName + ' : ')
let prevHour = ''
for (line of lines){
const toks = line.split('\t')
if(toks.length === 5){
const [date, time] = toks[0].split('-')
variables[sensor][toks[2]] = variables[sensor][toks[2]] || { unit: JSON.parse(toks[4]).unit || '', cpt: 0}
variables[sensor][toks[2]].cpt++
if(prevHour !== time.substring(0,2)){
prevHour = time.substring(0,2)
process.stdout.write('.')
}
}
}
console.log()
}
console.log(variables)
fs.writeFileSync(path.join(__dirname, 'variables.json'), JSON.stringify(variables, null, 2))
})()