This commit is contained in:
PaulVua
2025-02-10 17:25:34 +01:00
parent e609c38ca0
commit 62c729b63b
8 changed files with 223 additions and 41 deletions

View File

@@ -58,8 +58,21 @@
<div class="card text-dark bg-light">
<div class="card-body">
<h5 class="card-title">Consulter la base de donnée</h5>
<button class="btn btn-primary" onclick="get_data_sqlite('data_NPM',10,false)">Mesures PM</button>
<button class="btn btn-primary" onclick="get_data_sqlite('data_BME280',10,false)">Mesures Temp/Hum</button>
<!-- Dropdown to select number of records -->
<div class="d-flex align-items-center mb-3">
<label for="records_limit" class="form-label me-2">Nombre de mesures:</label>
<select id="records_limit" class="form-select w-auto">
<option value="10" selected>10 dernières</option>
<option value="20">20 dernières</option>
<option value="30">30 dernières</option>
</select>
</div>
<button class="btn btn-primary" onclick="get_data_sqlite('data_NPM',getSelectedLimit(),false)">Mesures PM</button>
<button class="btn btn-primary" onclick="get_data_sqlite('data_BME280',getSelectedLimit(),false)">Mesures Temp/Hum</button>
<button class="btn btn-primary" onclick="get_data_sqlite('data_NPM_5channels',getSelectedLimit(),false)">Mesures PM (5 canaux)</button>
</div>
</div>
</div>
@@ -68,8 +81,18 @@
<div class="card text-dark bg-light">
<div class="card-body">
<h5 class="card-title">Télécharger les données</h5>
<button class="btn btn-primary" onclick="get_data_sqlite('data_NPM',10,true)">Mesures PM</button>
<button class="btn btn-primary" onclick="get_data_sqlite('data_BME280',10,true)">Mesures Temp/Hum</button>
<!-- Date selection for download -->
<div class="d-flex align-items-center gap-3 mb-3">
<label for="start_date" class="form-label">Date de début:</label>
<input type="date" id="start_date" class="form-control w-auto">
<label for="end_date" class="form-label">Date de fin:</label>
<input type="date" id="end_date" class="form-control w-auto">
</div>
<button class="btn btn-primary" onclick="get_data_sqlite('data_NPM',10,true, getStartDate(), getEndDate())">Mesures PM</button>
<button class="btn btn-primary" onclick="get_data_sqlite('data_BME280',10,true, getStartDate(), getEndDate())">Mesures Temp/Hum</button>
<button class="btn btn-primary" onclick="get_data_sqlite('data_NPM_5channels',10,true, getStartDate(), getEndDate())">Mesures PM (5 canaux)</button>
</table>
</div>
@@ -123,11 +146,6 @@
window.onload = function() {
fetch('../config.json') // Replace 'deviceID.txt' with 'config.json'
.then(response => response.json()) // Parse response as JSON
@@ -168,11 +186,21 @@
// TABLE PM
function get_data_sqlite(table, limit, download) {
console.log("Getting data for table mesure PM");
function get_data_sqlite(table, limit, download , startDate = "", endDate = "") {
console.log(`Getting data for table: ${table}, limit: ${limit}, download: ${download}, start: ${startDate}, end: ${endDate}`);
// Construct URL parameters dynamically
let url = `launcher.php?type=table_mesure&table=${table}&limit=${limit}&download=${download}`;
// Add date parameters if downloading
if (download) {
url += `&start_date=${startDate}&end_date=${endDate}`;
}
console.log(url);
$.ajax({
url: 'launcher.php?type=table_mesurePM&table='+table+'&limit='+limit+'&download='+download,
url: url,
dataType: 'text', // Specify that you expect a JSON response
method: 'GET', // Use GET or POST depending on your needs
success: function(response) {
@@ -207,6 +235,16 @@ function get_data_sqlite(table, limit, download) {
<th>Humidity (%)</th>
<th>Pressure (hPa)</th>
`;
} else if (table === "data_NPM_5channels") {
tableHTML += `
<th>Timestamp</th>
<th>PM_ch1 (nb/L)</th>
<th>PM_ch2 (nb/L)</th>
<th>PM_ch3 (nb/L)</th>
<th>PM_ch4 (nb/L)</th>
<th>PM_ch5 (nb/L)</th>
`;
}
tableHTML += `</tr></thead><tbody>`;
@@ -233,6 +271,17 @@ function get_data_sqlite(table, limit, download) {
<td>${columns[3]}</td>
`;
}
else if (table === "data_NPM_5channels") {
tableHTML += `
<td>${columns[0]}</td>
<td>${columns[1]}</td>
<td>${columns[2]}</td>
<td>${columns[3]}</td>
<td>${columns[4]}</td>
<td>${columns[5]}</td>
`;
}
tableHTML += "</tr>";
});
@@ -250,6 +299,19 @@ function get_data_sqlite(table, limit, download) {
}
function getSelectedLimit() {
return document.getElementById("records_limit").value;
}
function getStartDate() {
return document.getElementById("start_date").value || "2025-01-01"; // Default to a safe date
}
function getEndDate() {
return document.getElementById("end_date").value || "2025-12-31"; // Default to a safe date
}
function downloadCSV(response, table) {
let rows = response.trim().split("\n");
@@ -257,9 +319,12 @@ function downloadCSV(response, table) {
// Add headers based on table type
if (table === "data_NPM") {
csvContent += "Timestamp,PM1,PM2.5,PM10,Temperature (°C),Humidity (%)\n";
csvContent += "TimestampUTC,PM1,PM2.5,PM10,Temperature_sensor,Humidity_sensor\n";
} else if (table === "data_BME280") {
csvContent += "Timestamp,Temperature (°C),Humidity (%),Pressure (hPa)\n";
csvContent += "TimestampUTC,Temperature (°C),Humidity (%),Pressure (hPa)\n";
}
else if (table === "data_NPM_5channels") {
csvContent += "TimestampUTC,PM_ch1,PM_ch2,PM_ch3,PM_ch4,PM_ch5\n";
}
// Format rows as CSV

View File

@@ -203,14 +203,23 @@ if ($type == "BME280") {
}
if ($type == "table_mesurePM") {
if ($type == "table_mesure") {
$table=$_GET['table'];
$limit=$_GET['limit'];
$download=$_GET['download'];
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/read.py '.$table.' '.$limit;
$output = shell_exec($command);
echo $output;
if ($download==="false") {
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/read.py '.$table.' '.$limit;
$output = shell_exec($command);
echo $output;
} else{
$start_date=$_GET['start_date'];
$end_date=$_GET['end_date'];
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/read_select_date.py '.$table.' '.$start_date.' '.$end_date;
$output = shell_exec($command);
echo $output;
}
}
# SARA R4 COMMANDS