diff --git a/server_side/index.php b/server_side/index.php
index 356e5a1..3e12635 100644
--- a/server_side/index.php
+++ b/server_side/index.php
@@ -24,15 +24,38 @@ $table = isset($_GET['table']) ? $_GET['table'] : '';
+
+
-
- Datatables server side processing with PHP and MYSQL
-
+
diff --git a/server_side/stats.worker.js b/server_side/stats.worker.js
new file mode 100644
index 0000000..b251c3e
--- /dev/null
+++ b/server_side/stats.worker.js
@@ -0,0 +1,12 @@
+self.onmessage = function(e) {
+ const table = e.data.table;
+ function fetchStats() {
+ fetch(`stats_worker.php?table=${encodeURIComponent(table)}`)
+ .then(response => response.json())
+ .then(data => {
+ self.postMessage(data);
+ setTimeout(fetchStats, 5000); // Consulta cada 5 segundos
+ });
+ }
+ fetchStats();
+};
\ No newline at end of file
diff --git a/server_side/stats_worker.php b/server_side/stats_worker.php
new file mode 100644
index 0000000..038a0da
--- /dev/null
+++ b/server_side/stats_worker.php
@@ -0,0 +1,44 @@
+ ['min' => '-', 'max' => '-', 'avg' => '-'],
+ 'input' => ['min' => '-', 'max' => '-', 'avg' => '-'],
+ 'output' => ['min' => '-', 'max' => '-', 'avg' => '-']
+];
+
+if ($table && preg_match('/^[a-zA-Z0-9_]+$/', $table)) {
+ $sql = "SELECT
+ MIN(CHAR_LENGTH(instruction)) as min_instruction,
+ MAX(CHAR_LENGTH(instruction)) as max_instruction,
+ AVG(CHAR_LENGTH(instruction)) as avg_instruction,
+ MIN(CHAR_LENGTH(input)) as min_input,
+ MAX(CHAR_LENGTH(input)) as max_input,
+ AVG(CHAR_LENGTH(input)) as avg_input,
+ MIN(CHAR_LENGTH(output)) as min_output,
+ MAX(CHAR_LENGTH(output)) as max_output,
+ AVG(CHAR_LENGTH(output)) as avg_output
+ FROM `$table`";
+ $res = mysqli_query($conn, $sql);
+ if ($res && $row = mysqli_fetch_assoc($res)) {
+ $result['instruction'] = [
+ 'min' => $row['min_instruction'] !== null ? $row['min_instruction'] : '-',
+ 'max' => $row['max_instruction'] !== null ? $row['max_instruction'] : '-',
+ 'avg' => $row['avg_instruction'] !== null ? round($row['avg_instruction'], 2) : '-'
+ ];
+ $result['input'] = [
+ 'min' => $row['min_input'] !== null ? $row['min_input'] : '-',
+ 'max' => $row['max_input'] !== null ? $row['max_input'] : '-',
+ 'avg' => $row['avg_input'] !== null ? round($row['avg_input'], 2) : '-'
+ ];
+ $result['output'] = [
+ 'min' => $row['min_output'] !== null ? $row['min_output'] : '-',
+ 'max' => $row['max_output'] !== null ? $row['max_output'] : '-',
+ 'avg' => $row['avg_output'] !== null ? round($row['avg_output'], 2) : '-'
+ ];
+ }
+}
+
+header('Content-Type: application/json');
+echo json_encode($result);