CalculateAngles verpacken
This commit is contained in:
chk
2026-05-09 06:08:36 +02:00
parent 07e1378309
commit 6e8fabd230
6 changed files with 117 additions and 1 deletions

View File

@@ -0,0 +1,55 @@
const fs = require('fs');
const path = require('path');
const { calculate } = require('../public/calculateAngles.cjs');
/* -------------------------
Hilfsfunktionen
------------------------- */
function loadMarkersFromCSV(filePath) {
const text = fs.readFileSync(filePath, 'utf8');
const [header, ...lines] = text
.split('\n')
.map(l => l.trim())
.filter(Boolean);
return lines.map(line => {
const [
id,
x, y, z,
roll, pitch, yaw,
seen_by
] = line.split(',');
return {
id: Number(id),
position: [Number(x), Number(y), Number(z)],
rotation: [Number(roll), Number(pitch), Number(yaw)],
seen_by: Number(seen_by)
};
});
}
function loadJSON(filePath) {
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
}
/* -------------------------
Tests
------------------------- */
describe('calculateAngles.calculate', () => {
test('berechnet X-Durchschnitt für Base / Arm1 / Joint1', async () => {
const markersPath = path.resolve('./test/snapshots/snapshot_video0_1774805028717_two_cam.csv');
const robotPath = path.resolve('./public/robot.json');
const foundMarkers = loadMarkersFromCSV(markersPath);
const jsonRobot = loadJSON(robotPath);
const result = await calculate(foundMarkers, jsonRobot);
expect(result.status).toBe('ok');
expect(result.result).toBeDefined();
});
});