104 lines
2.4 KiB
TypeScript
104 lines
2.4 KiB
TypeScript
import { Data as PlotlyData, Plot } from './plot/mod.ts'
|
|
|
|
type Data = {
|
|
timestamp: string //ISO string
|
|
volume: number //mL
|
|
ipam: number //ipam
|
|
record: {
|
|
pression: number //bar
|
|
mass: number //g
|
|
timestamp: number //s
|
|
}[]
|
|
}
|
|
|
|
function parseDatas(file: string): Data {
|
|
const lines = file.split('\n')
|
|
|
|
lines.shift() //remove title
|
|
const [day, month, year, time] = lines.shift()!.split(' ')
|
|
const monthList = [
|
|
'_',
|
|
'janvier',
|
|
'fevrier',
|
|
'mars',
|
|
'avril',
|
|
'mai',
|
|
'juin',
|
|
'juillet',
|
|
'aout',
|
|
'septembre',
|
|
'decembre',
|
|
]
|
|
const timestamp = `${year}-${
|
|
monthList.indexOf(month).toString().padStart(2, '0')
|
|
}-${day.padStart(2, '0')}T${time}`
|
|
|
|
lines.shift() //remove empty line
|
|
const volume = lines.shift()!.split(';').slice(1).map(Number).at(0)!
|
|
const ipam = lines.shift()!.split(';').slice(1).map(Number).at(0)!
|
|
|
|
lines.shift() //remove empty line
|
|
lines.shift() //remove title
|
|
const record = lines
|
|
.map((line) => line.split(';').slice(1).map(Number))
|
|
.map(([pression, mass, timestamp]) => ({ pression, mass, timestamp }))
|
|
|
|
return {
|
|
timestamp,
|
|
volume,
|
|
ipam,
|
|
record,
|
|
}
|
|
}
|
|
|
|
function getDatasPlot(datas: Data): Partial<PlotlyData>[] {
|
|
const relativeTimestamp = datas.record.map((data) =>
|
|
data.timestamp - datas.record[0].timestamp
|
|
)
|
|
const meta = `${datas.volume}mL ${datas.ipam}IPAM ${
|
|
datas.timestamp.split('T')[1]
|
|
}`
|
|
|
|
const { ipam } = datas
|
|
|
|
return [
|
|
{
|
|
x: relativeTimestamp, //.map(Math.log10),
|
|
y: datas.record.map((data) => data.mass),
|
|
name: `mass (${meta})`,
|
|
line: {
|
|
color: `rgb(${50 * Math.log(ipam)}, 0, ${255 - 50 * Math.log(ipam)})`,
|
|
},
|
|
},
|
|
// {
|
|
// x: relativeTimestamp,
|
|
// y: datas.record.map((data) => data.pression),
|
|
// name: `pression (${meta})`,
|
|
// yaxis: 'y2',
|
|
// line: {
|
|
// color: `rgb(${50 * Math.log(ipam)}, 0, ${255 - 50 * Math.log(ipam)})`,
|
|
// },
|
|
// },
|
|
]
|
|
}
|
|
|
|
const plot = new Plot()
|
|
|
|
const plots: Partial<PlotlyData>[] = []
|
|
|
|
for await (const file of Deno.readDir('./datas')) {
|
|
if (!file.isFile) continue
|
|
if (!file.name.match(/Vrr3_\d{2}-\d{2}_\d{2}-\d{2}\.csv/)) continue
|
|
const path = `./datas/${file.name}`
|
|
|
|
const csv = await Deno.readTextFile(path)
|
|
const datas = parseDatas(csv)
|
|
plots.push(...getDatasPlot(datas))
|
|
}
|
|
|
|
plot.plot(plots, {
|
|
xaxis: { title: { text: 'timestamp' } },
|
|
yaxis: { title: { text: 'mass [g]' } },
|
|
yaxis2: { title: { text: 'pression [bar]' }, side: 'right' },
|
|
})
|