From 94945a285e9145bd9f30c96fee913334cd87b22e Mon Sep 17 00:00:00 2001
From: Thijs <snijder@astron.nl>
Date: Wed, 9 Jun 2021 16:20:30 +0200
Subject: [PATCH] changed back to put_nowait and added queue percentage MP

---
 devices/Statistics.py               |  1 +
 devices/clients/sst_client.py       |  7 ++++++-
 jupyter-notebooks/test_device.ipynb | 17 +++++++++--------
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/devices/Statistics.py b/devices/Statistics.py
index 6b56b1aaa..b397898e5 100644
--- a/devices/Statistics.py
+++ b/devices/Statistics.py
@@ -49,6 +49,7 @@ class SST(hardware_device):
     # Example: comms_annotation={"parameter": "this_value_R"}
     packet_count_R = attribute_wrapper(comms_annotation={"parameter": "packet_count_R"}, datatype=numpy.int64)
     last_packet_timestamp_R = attribute_wrapper(comms_annotation={"parameter": "last_packet_timestamp_R"}, datatype=numpy.int64)
+    queue_percentage_used_R = attribute_wrapper(comms_annotation={"parameter": "queue_percentage_used_R"}, datatype=numpy.double)
 
     # --------
     # overloaded functions
diff --git a/devices/clients/sst_client.py b/devices/clients/sst_client.py
index 4692b5d07..407dabde3 100644
--- a/devices/clients/sst_client.py
+++ b/devices/clients/sst_client.py
@@ -1,3 +1,4 @@
+import queue
 from threading import Thread
 import socket
 from util.comms_client import CommClient
@@ -134,6 +135,8 @@ class UDP_Receiver(Thread):
 
             except socket.timeout:
                 pass
+            except queue.Full:
+                pass
 
     def __del__(self):
         self.stream_on = False
@@ -149,7 +152,8 @@ class SST(Thread):
 
         self.parameters = {
             "packet_count_R": numpy.int64(0),
-            "last_packet_timestamp_R": numpy.int64(0)
+            "last_packet_timestamp_R": numpy.int64(0),
+            "queue_percentage_used_R": numpy.double(100 * self.queue.qsize() / self.queue.maxsize)
         }
 
         super().__init__()
@@ -174,3 +178,4 @@ class SST(Thread):
     def process_packet(self, packet):
         self.parameters["packet_count_R"] += 1
         self.parameters["last_packet_timestamp_R"] = numpy.int64(int(time.time()))
+        self.parameters["queue_percentage_used_R"] = numpy.double(100 * self.queue.qsize() / self.queue.maxsize)
\ No newline at end of file
diff --git a/jupyter-notebooks/test_device.ipynb b/jupyter-notebooks/test_device.ipynb
index b404b04c7..69a441862 100644
--- a/jupyter-notebooks/test_device.ipynb
+++ b/jupyter-notebooks/test_device.ipynb
@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": 30,
    "id": "waiting-chance",
    "metadata": {},
    "outputs": [],
@@ -13,7 +13,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": 31,
    "id": "moving-alexandria",
    "metadata": {},
    "outputs": [],
@@ -23,7 +23,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": 32,
    "id": "ranking-aluminum",
    "metadata": {},
    "outputs": [
@@ -51,7 +51,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": 60,
    "id": "beneficial-evidence",
    "metadata": {},
    "outputs": [
@@ -59,10 +59,11 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "packet_count_R [80]\n",
-      "last_packet_timestamp_R [1623239037]\n",
-      "State <function __get_command_func.<locals>.f at 0x7fcb20e510d0>\n",
-      "Status <function __get_command_func.<locals>.f at 0x7fcb20e510d0>\n"
+      "packet_count_R [139917203]\n",
+      "last_packet_timestamp_R [1623248251]\n",
+      "queue_percentage_used_R [100.]\n",
+      "State <function __get_command_func.<locals>.f at 0x7fcb20e68bf8>\n",
+      "Status <function __get_command_func.<locals>.f at 0x7fcb20e68bf8>\n"
      ]
     }
    ],
-- 
GitLab