Skip to content

Commit

Permalink
Merge pull request #27 from OpenEarable/1.3.0
Browse files Browse the repository at this point in the history
fixed faulty line break in csv generator if no values present for cer…
  • Loading branch information
TobiasRoeddiger authored Oct 7, 2023
2 parents 29c8243 + 6fb14f6 commit 02ba79b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion assets/js/AudioManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@ $(document).ready(function() {
log("Error occurred while trying to stop frequency: " + error, "ERROR");
}
}
});
});
});
40 changes: 22 additions & 18 deletions assets/js/RecordingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ $(document).ready(function () {
$("#" + btnId).click(function (e) {
e.stopPropagation();

if (btnId === "btn9") return;

if (isLocked) {
buttonIds.forEach(function (id) {
$("#" + id).css("border", "3px solid transparent");
Expand Down Expand Up @@ -104,7 +102,7 @@ $(document).ready(function () {
return $("#" + selectedButton[0]).text();
}
return null;
}
}

let recordingActive = false;
let recordingStartTime;
Expand Down Expand Up @@ -174,46 +172,52 @@ $(document).ready(function () {
"sensor_magX[µT]", "sensor_magY[µT]", "sensor_magZ[µT]",
"sensor_pressure[hPa]", "sensor_temperature[°C]"
];

for (let i = 0; i < buttonIds.length - 1; i++) {
let buttonId = buttonIds[i];
headers.push("label_OpenEarable_" + $('#' + buttonId).text());
}

let rows = [];

// Sorting the timestamps and generating the CSV lines
Object.keys(dataCache).sort().forEach(timestamp => {
let data = dataCache[timestamp];
let row = [timestamp];

// Push sensor data ensuring the correct float format
row.push(...data.acc.map(val => val.toString().replace(',', '.')));
row.push(...data.gyro.map(val => val.toString().replace(',', '.')));
row.push(...data.mag.map(val => val.toString().replace(',', '.')));
row.push(data.pressure.toString().replace(',', '.'));
row.push(data.temperature.toString().replace(',', '.'));

["acc", "gyro", "mag"].forEach(sensorType => {
if (data[sensorType] && data[sensorType].length === 3) {
row.push(...data[sensorType].map(val => val.toString().replace(',', '.')));
} else {
row.push('', '', ''); // Push empty values if sensor data isn't available or isn't valid
}
});

row.push(data.pressure ? data.pressure.toString().replace(',', '.') : '');
row.push(data.temperature ? data.temperature.toString().replace(',', '.') : '');


for (let i = 0; i < buttonIds.length - 1; i++) {
let buttonId = buttonIds[i];
let labelName = $('#' + buttonId).text();
row.push(data.labels.includes(labelName) ? "x" : "");
}

rows.push(row);
});

// Check if any columns are empty across all rows and remove them
for (let colIdx = headers.length - 1; colIdx >= 0; colIdx--) {
if (rows.every(row => !row[colIdx])) {
headers.splice(colIdx, 1);
rows.forEach(row => row.splice(colIdx, 1));
}
}

// Construct the CSV content
let csv = headers.join(",") + "\n" + rows.map(row => row.join(",")).join("\n");

// Trigger a download
const blob = new Blob([csv], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
Expand All @@ -224,7 +228,7 @@ $(document).ready(function () {
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
}


});
24 changes: 15 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@
padding: 0px 5px;
}

input[disabled], select[disabled] {
input[disabled],
select[disabled] {
opacity: 0.5 !important;
}
</style>
Expand Down Expand Up @@ -386,14 +387,19 @@ <h5 class="card-title">Audio Control </h5>
</div>


<div class="d-flex w-100 justify-content-center mt-2">
<button id="button-play-audio" class="btn btn-play btn-block is-connect-enabled"
disabled><i class="bi bi-play"></i></button>
<button id="button-pause-audio" class="btn btn-pause btn-block ms-2 is-connect-enabled"
disabled><i class="bi bi-pause"></i></button>
<button id="button-stop-audio" class="btn btn-stop btn-block ms-2 is-connect-enabled"
disabled><i class="bi bi-stop"></i></button>
<button class="btn btn-control flex-fill ms-2 is-connect-enabled">Reset</button>
<div class="d-flex w-100 justify-content-between align-items-center mt-2">
<div>
<button id="button-play-audio" class="btn btn-play btn-block is-connect-enabled"
disabled><i class="bi bi-play"></i></button>
<button id="button-pause-audio" class="btn btn-pause btn-block ms-2 is-connect-enabled"
disabled><i class="bi bi-pause"></i></button>
<button id="button-stop-audio" class="btn btn-stop btn-block ms-2 is-connect-enabled"
disabled><i class="bi bi-stop"></i></button>
</div>
<div>
<i style="color: #f27777">⚠️ Audio can be very loud. Use with caution! ⚠️</i>
</div>

</div>
</div>
</div>
Expand Down

0 comments on commit 02ba79b

Please sign in to comment.