Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
13,734 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,4 @@ TODO.txt | |
|
||
.DS_Store | ||
|
||
package-lock.json | ||
|
||
builder-output |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import * as I10nModule from "eez-studio-shared/i10n"; | ||
import { decodeDlog } from "instrument/window/waveform/dlog-file"; | ||
|
||
export function convertDlogToCsv(data: Uint8Array) { | ||
const dlog = decodeDlog(data); | ||
if (!dlog) { | ||
return undefined; | ||
} | ||
|
||
const buffer = Buffer.allocUnsafe(4); | ||
|
||
function readFloat(i: number) { | ||
buffer[0] = data[i]; | ||
buffer[1] = data[i + 1]; | ||
buffer[2] = data[i + 2]; | ||
buffer[3] = data[i + 3]; | ||
return buffer.readFloatLE(0); | ||
} | ||
|
||
const numColumns = (dlog.hasJitterColumn ? 1 : 0) + dlog.yAxes.length; | ||
|
||
const { getLocale } = require("eez-studio-shared/i10n") as typeof I10nModule; | ||
|
||
const locale = getLocale(); | ||
|
||
// determine CSV separator depending of locale usage of "," | ||
let separator; | ||
if ((0.1).toLocaleString(locale).indexOf(",") != -1) { | ||
separator = ";"; | ||
} else { | ||
separator = ","; | ||
} | ||
|
||
const numberFormat = new Intl.NumberFormat(locale, { | ||
useGrouping: false, | ||
maximumFractionDigits: 9 | ||
}); | ||
|
||
// first row contains column names | ||
let csv = ""; | ||
|
||
if (dlog.xAxis.label) { | ||
csv += dlog.xAxis.label; | ||
} else { | ||
csv += dlog.xAxis.unit.name; | ||
} | ||
|
||
for (let columnIndex = 0; columnIndex < dlog.yAxes.length; columnIndex++) { | ||
csv += separator; | ||
if (dlog.yAxes[columnIndex].label) { | ||
csv += dlog.yAxes[columnIndex].label; | ||
} else { | ||
csv += dlog.yAxes[columnIndex].unit.name; | ||
} | ||
} | ||
|
||
csv += "\n"; | ||
|
||
// | ||
for (let rowIndex = 0; rowIndex < dlog.length; rowIndex++) { | ||
csv += numberFormat.format(rowIndex * dlog.xAxis.step); | ||
for (let columnIndex = 0; columnIndex < dlog.yAxes.length; columnIndex++) { | ||
csv += separator; | ||
csv += numberFormat.format( | ||
readFloat( | ||
dlog.dataOffset + | ||
4 * (rowIndex * numColumns + (dlog.hasJitterColumn ? 1 : 0) + columnIndex) | ||
) | ||
); | ||
} | ||
csv += "\n"; | ||
} | ||
|
||
return Buffer.from(csv, "utf8"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters