edit app + interface file
parent
01a5d2c238
commit
fdf7b1b117
|
|
@ -145,10 +145,10 @@ function saveDataToCSV() {
|
||||||
|
|
||||||
// Write data to the CSV file
|
// Write data to the CSV file
|
||||||
let fileName = "heart_rate_data.csv"; // Use consistent file name
|
let fileName = "heart_rate_data.csv"; // Use consistent file name
|
||||||
require("Storage").write(fileName, csvContent);
|
var file = require("Storage").open(fileName,"a"); // Open file in append mode
|
||||||
|
file.write(csvContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
setWatch(function() {
|
setWatch(function() {
|
||||||
if (!isMeasuring) {
|
if (!isMeasuring) {
|
||||||
startMeasure();
|
startMeasure();
|
||||||
|
|
|
||||||
|
|
@ -4,39 +4,60 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="data"></div>
|
<div id="data"></div>
|
||||||
|
<button class="btn btn-default" id="btnSave">Save</button>
|
||||||
|
<button class="btn btn-default" id="btnDelete">Delete</button>
|
||||||
|
|
||||||
<script src="../../core/lib/interface.js"></script>
|
<script src="../../core/lib/interface.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var dataElement = document.getElementById("data");
|
var dataElement = document.getElementById("data");
|
||||||
|
var csvData = "";
|
||||||
|
|
||||||
function displayOptions() {
|
function getData() {
|
||||||
// Display options to save the heart rate data file
|
// show loading window
|
||||||
dataElement.innerHTML = `
|
Util.showModal("Loading...");
|
||||||
<button class="btn btn-primary" onclick="saveHeartRateData()">Save</button>
|
// get the data
|
||||||
`;
|
dataElement.innerHTML = "";
|
||||||
}
|
Util.readStorageFile(`heart_rate_data.csv`,data=>{
|
||||||
|
csvData = data.trim();
|
||||||
function saveHeartRateData() {
|
// remove window
|
||||||
Util.showModal("Saving...");
|
|
||||||
var fileName = "heart_rate_data.csv"; // Set the file name to save
|
|
||||||
// Read the heart rate data from the watch's storage
|
|
||||||
Util.readStorageFile(fileName, function(data) {
|
|
||||||
// Save the data to the device through app loader
|
|
||||||
Util.saveFileToDevice(fileName, data, function(success) {
|
|
||||||
if (success) {
|
|
||||||
dataElement.innerHTML = "<p>Heart rate data saved successfully</p>";
|
|
||||||
} else {
|
|
||||||
dataElement.innerHTML = "<p>Error saving heart rate data</p>";
|
|
||||||
}
|
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
});
|
// If no data, report it and exit
|
||||||
|
if (data.length==0) {
|
||||||
|
dataElement.innerHTML = "<b>No data found</b>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Otherwise parse the data and output it as a table
|
||||||
|
dataElement.innerHTML = `<table>
|
||||||
|
<tr>
|
||||||
|
<th>Timestamp</th>
|
||||||
|
<th>Heart Rate (bpm)</th>
|
||||||
|
<th>HRV (ms)</th>
|
||||||
|
</tr>`+data.trim().split("\n").map(l=>{
|
||||||
|
l = l.split(",");
|
||||||
|
return `<tr>
|
||||||
|
<td>${l[0]}</td>
|
||||||
|
<td>${l[1]}</td>
|
||||||
|
<td>${l[2]}</td>
|
||||||
|
</tr>`
|
||||||
|
}).join("\n")+"</table>";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// You can call a utility function to save the data
|
||||||
|
document.getElementById("btnSave").addEventListener("click", function() {
|
||||||
|
Util.saveCSV("heart_rate_data.csv", csvData);
|
||||||
|
});
|
||||||
|
// Or you can also delete the file
|
||||||
|
document.getElementById("btnDelete").addEventListener("click", function() {
|
||||||
|
Util.showModal("Deleting...");
|
||||||
|
Util.eraseStorageFile("heart_rate_data.csv", function() {
|
||||||
|
Util.hideModal();
|
||||||
|
getData();
|
||||||
|
});
|
||||||
|
});
|
||||||
// Called when app starts
|
// Called when app starts
|
||||||
function onInit() {
|
function onInit() {
|
||||||
// Display option to save data
|
getData();
|
||||||
displayOptions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue