diff --git a/app/classes/agent.php b/app/classes/agent.php index 6c3987a..fa5aba5 100644 --- a/app/classes/agent.php +++ b/app/classes/agent.php @@ -385,8 +385,59 @@ class Agent { * @return mixed The latest stored data. */ public function getLatestData($platform_id, $agent_type, $metric_type) { - // TODO - // retrieves data already stored in db from another function (or the jilo-server to-be) + $sql = 'SELECT + jac.timestamp, + jac.response_content, + jac.agent_id, + jat.description + FROM + jilo_agent_checks jac + JOIN + jilo_agents ja ON jac.agent_id = ja.id + JOIN + jilo_agent_types jat ON ja.agent_type_id = jat.id + WHERE + ja.platform_id = :platform_id + AND jat.description = :agent_type + AND jac.status_code = 200 + ORDER BY + jac.timestamp DESC + LIMIT 1'; + + $query = $this->db->prepare($sql); + $query->execute([ + ':platform_id' => $platform_id, + ':agent_type' => $agent_type + ]); + + $result = $query->fetch(PDO::FETCH_ASSOC); + + if ($result) { + // Parse the JSON response content + $data = json_decode($result['response_content'], true); + if (json_last_error() !== JSON_ERROR_NONE) { + return null; + } + + // Extract the specific metric value from the response based on agent type + if ($agent_type === 'jvb') { + if (isset($data['jvb_api_data'][$metric_type])) { + return [ + 'value' => $data['jvb_api_data'][$metric_type], + 'timestamp' => $result['timestamp'] + ]; + } + } elseif ($agent_type === 'jicofo') { + if (isset($data['jicofo_api_data'][$metric_type])) { + return [ + 'value' => $data['jicofo_api_data'][$metric_type], + 'timestamp' => $result['timestamp'] + ]; + } + } + } + + return null; } } diff --git a/app/pages/data.php b/app/pages/data.php index e583a70..d3b1cb8 100644 --- a/app/pages/data.php +++ b/app/pages/data.php @@ -64,6 +64,7 @@ switch ($item) { break; case 'latest': + // Get latest data for both JVB and Jicofo agents $latestJvbConferences = $agentObject->getLatestData($platform_id, 'jvb', 'conferences'); $latestJvbParticipants = $agentObject->getLatestData($platform_id, 'jvb', 'participants'); $latestJicofoConferences = $agentObject->getLatestData($platform_id, 'jicofo', 'conferences'); @@ -71,6 +72,28 @@ switch ($item) { $widget['records'] = array(); + // Format data for JVB metrics + if ($latestJvbConferences !== null || $latestJvbParticipants !== null) { + $widget['records'][] = [ + 'table_headers' => 'JVB', + 'conferences' => $latestJvbConferences ? $latestJvbConferences['value'] : null, + 'participants' => $latestJvbParticipants ? $latestJvbParticipants['value'] : null, + 'from_time' => $latestJvbConferences ? $latestJvbConferences['timestamp'] : ($latestJvbParticipants ? $latestJvbParticipants['timestamp'] : null), + 'until_time' => $latestJvbConferences ? $latestJvbConferences['timestamp'] : ($latestJvbParticipants ? $latestJvbParticipants['timestamp'] : null) + ]; + } + + // Format data for Jicofo metrics + if ($latestJicofoConferences !== null || $latestJicofoParticipants !== null) { + $widget['records'][] = [ + 'table_headers' => 'Jicofo', + 'conferences' => $latestJicofoConferences ? $latestJicofoConferences['value'] : null, + 'participants' => $latestJicofoParticipants ? $latestJicofoParticipants['value'] : null, + 'from_time' => $latestJicofoConferences ? $latestJicofoConferences['timestamp'] : ($latestJicofoParticipants ? $latestJicofoParticipants['timestamp'] : null), + 'until_time' => $latestJicofoConferences ? $latestJicofoConferences['timestamp'] : ($latestJicofoParticipants ? $latestJicofoParticipants['timestamp'] : null) + ]; + } + // prepare the widget $widget['full'] = false; $widget['name'] = 'LatestData'; @@ -78,10 +101,10 @@ switch ($item) { $widget['collapsible'] = false; $widget['collapsed'] = false; $widget['filter'] = false; - if (!empty($latestJvbConferences) && !empty($latestJvbParticipants) && !empty($latestJicofoConferences) && !empty($latestJicofoParticipants)) { + if (!empty($widget['records'])) { $widget['full'] = true; } - $widget['pagination'] = true; + $widget['pagination'] = false; include '../app/templates/latest-data.php'; break; diff --git a/app/templates/latest-data.php b/app/templates/latest-data.php index 6d663da..02e7fae 100644 --- a/app/templates/latest-data.php +++ b/app/templates/latest-data.php @@ -1,16 +1,15 @@
-
+
-

NB: This functionality is still under development. The data is just an example.


- + @@ -18,27 +17,47 @@ - + - - + -
Metric
conferencesConferences - - 0 + + + + +
+ + + 0 + + + No data +
participantsParticipants - - 0 + + + + +
+ + + 0 + + + No data +
-

No records found.

+