Skip to content
Snippets Groups Projects
Commit efeaa7b3 authored by Corné Lukken's avatar Corné Lukken
Browse files

L2SS-867: Move statistics_writer into statistics module

parent eb042fe1
No related branches found
No related tags found
1 merge request!394Resolve L2SS-868
Showing
with 28 additions and 20 deletions
...@@ -51,7 +51,7 @@ console_scripts = ...@@ -51,7 +51,7 @@ console_scripts =
l2ss-bst = tangostationcontrol.devices.sdp.bst:main l2ss-bst = tangostationcontrol.devices.sdp.bst:main
l2ss-sst = tangostationcontrol.devices.sdp.sst:main l2ss-sst = tangostationcontrol.devices.sdp.sst:main
l2ss-statistics-reader = tangostationcontrol.statistics_writer.statistics_reader:main l2ss-statistics-reader = tangostationcontrol.statistics_writer.statistics_reader:main
l2ss-statistics-writer = tangostationcontrol.statistics_writer.statistics_writer:main l2ss-statistics-writer = tangostationcontrol.statistics.writer:main
l2ss-unb2 = tangostationcontrol.devices.unb2:main l2ss-unb2 = tangostationcontrol.devices.unb2:main
l2ss-xst = tangostationcontrol.devices.sdp.xst:main l2ss-xst = tangostationcontrol.devices.sdp.xst:main
l2ss-temperature-manager = tangostationcontrol.devices.temperature_manager:main l2ss-temperature-manager = tangostationcontrol.devices.temperature_manager:main
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
from tangostationcontrol.integration_test.base import BaseIntegrationTestCase from tangostationcontrol.integration_test.base import BaseIntegrationTestCase
from tangostationcontrol.integration_test.device_proxy import TestDeviceProxy from tangostationcontrol.integration_test.device_proxy import TestDeviceProxy
from tangostationcontrol.statistics.statistics_collector import SSTCollector from tangostationcontrol.statistics.statistics_collector import SSTCollector
from tangostationcontrol.statistics_writer import statistics_writer, statistics_reader from tangostationcontrol.statistics_writer import statistics_reader
from tangostationcontrol.statistics import writer
import sys import sys
from os.path import dirname, isfile, join from os.path import dirname, isfile, join
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
...@@ -18,6 +20,7 @@ from unittest import mock ...@@ -18,6 +20,7 @@ from unittest import mock
from tango import DevState from tango import DevState
class TestStatisticsWriterSST(BaseIntegrationTestCase): class TestStatisticsWriterSST(BaseIntegrationTestCase):
def setUp(self): def setUp(self):
...@@ -51,10 +54,10 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase): ...@@ -51,10 +54,10 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase):
self.assertListEqual(collector.parameters["rcu_dth_on"].tolist(), self.recv_proxy.rcu_dth_on_r.tolist()) self.assertListEqual(collector.parameters["rcu_dth_on"].tolist(), self.recv_proxy.rcu_dth_on_r.tolist())
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
new_sys_argv = [sys.argv[0], "--mode", "SST", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir] new_sys_argv = [sys.argv[0], "--mode", "SST", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test/statistics", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir]
with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): with mock.patch.object(writer.sys, 'argv', new_sys_argv):
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
statistics_writer.main() writer.main()
# check if file was written # check if file was written
self.assertTrue(isfile(f"{tmpdir}/SST_2021-09-20-12-17-40.h5")) self.assertTrue(isfile(f"{tmpdir}/SST_2021-09-20-12-17-40.h5"))
...@@ -76,10 +79,10 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase): ...@@ -76,10 +79,10 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase):
def test_no_tango_SST_statistics(self): def test_no_tango_SST_statistics(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
new_sys_argv = [sys.argv[0], "--mode", "SST", "--no-tango", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir] new_sys_argv = [sys.argv[0], "--mode", "SST", "--no-tango", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test/statistics", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir]
with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): with mock.patch.object(writer.sys, 'argv', new_sys_argv):
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
statistics_writer.main() writer.main()
# check if file was written # check if file was written
self.assertTrue(isfile(f"{tmpdir}/SST_2021-09-20-12-17-40.h5")) self.assertTrue(isfile(f"{tmpdir}/SST_2021-09-20-12-17-40.h5"))
...@@ -104,10 +107,10 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase): ...@@ -104,10 +107,10 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase):
self.assertEqual(DevState.OFF, self.recv_proxy.state()) self.assertEqual(DevState.OFF, self.recv_proxy.state())
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
new_sys_argv = [sys.argv[0], "--mode", "SST", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir] new_sys_argv = [sys.argv[0], "--mode", "SST", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test/statistics", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir]
with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): with mock.patch.object(writer.sys, 'argv', new_sys_argv):
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
statistics_writer.main() writer.main()
# check if file was written # check if file was written
self.assertTrue(isfile(f"{tmpdir}/SST_2021-09-20-12-17-40.h5")) self.assertTrue(isfile(f"{tmpdir}/SST_2021-09-20-12-17-40.h5"))
......
...@@ -10,6 +10,7 @@ import logging ...@@ -10,6 +10,7 @@ import logging
logging.basicConfig(level=logging.INFO, format = '%(asctime)s:%(levelname)s: %(message)s') logging.basicConfig(level=logging.INFO, format = '%(asctime)s:%(levelname)s: %(message)s')
logger = logging.getLogger("statistics_writer") logger = logging.getLogger("statistics_writer")
def _create_parser(): def _create_parser():
"""Define the parser""" """Define the parser"""
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
...@@ -55,6 +56,7 @@ def _create_parser(): ...@@ -55,6 +56,7 @@ def _create_parser():
) )
return parser return parser
def _create_receiver(filename, host, port): def _create_receiver(filename, host, port):
""" creates the TCP receiver that is given to the writer """ """ creates the TCP receiver that is given to the writer """
if filename: if filename:
...@@ -65,6 +67,7 @@ def _create_receiver(filename, host, port): ...@@ -65,6 +67,7 @@ def _create_receiver(filename, host, port):
logger.fatal("Must provide either a host and port, or a file to receive input from") logger.fatal("Must provide either a host and port, or a file to receive input from")
sys.exit(1) sys.exit(1)
def _create_writer(mode, interval, output_dir, decimation): def _create_writer(mode, interval, output_dir, decimation):
"""Create the writer""" """Create the writer"""
if mode == "XST": if mode == "XST":
...@@ -77,6 +80,7 @@ def _create_writer(mode, interval, output_dir, decimation): ...@@ -77,6 +80,7 @@ def _create_writer(mode, interval, output_dir, decimation):
logger.fatal(f"Invalid mode: {mode}") logger.fatal(f"Invalid mode: {mode}")
sys.exit(1) sys.exit(1)
def _start_loop(receiver, writer, reconnect, filename, device): def _start_loop(receiver, writer, reconnect, filename, device):
"""Main loop""" """Main loop"""
try: try:
...@@ -106,6 +110,7 @@ def _start_loop(receiver, writer, reconnect, filename, device): ...@@ -106,6 +110,7 @@ def _start_loop(receiver, writer, reconnect, filename, device):
finally: finally:
writer.close_writer() writer.close_writer()
def main(): def main():
parser = _create_parser() parser = _create_parser()
......
...@@ -30,7 +30,7 @@ class UDP_Client: ...@@ -30,7 +30,7 @@ class UDP_Client:
time.sleep(1) time.sleep(1)
f = open("../../test/SDP_SST_statistics_packet.bin", "rb") f = open("../../test/statistics/SDP_SST_statistics_packet.bin", "rb")
send_data = f.read() send_data = f.read()
s.sendto(send_data, (self.server_ip, self.server_port)) s.sendto(send_data, (self.server_ip, self.server_port))
print("\n\n 1. Client Sent SST Packet at: ", datetime.now()) print("\n\n 1. Client Sent SST Packet at: ", datetime.now())
......
...@@ -144,7 +144,6 @@ class TestDelays(base.TestCase): ...@@ -144,7 +144,6 @@ class TestDelays(base.TestCase):
self.assertAlmostEqual(0.1, delays[0], 6, f"delays[0] = {delays[0]}") self.assertAlmostEqual(0.1, delays[0], 6, f"delays[0] = {delays[0]}")
def test_convert_bulk(self): def test_convert_bulk(self):
d = delay_calculator([0, 0, 0]) d = delay_calculator([0, 0, 0])
timestamp = datetime.datetime(2022, 3, 1, 0, 0, 0) # timestamp does not actually matter, but casacore doesn't know that. timestamp = datetime.datetime(2022, 3, 1, 0, 0, 0) # timestamp does not actually matter, but casacore doesn't know that.
......
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
...@@ -8,12 +8,13 @@ ...@@ -8,12 +8,13 @@
# See LICENSE.txt for more info. # See LICENSE.txt for more info.
from tangostationcontrol.test import base from tangostationcontrol.test import base
from tangostationcontrol.statistics_writer import statistics_writer from tangostationcontrol.statistics import writer
import sys import sys
from os.path import dirname, isfile from os.path import dirname, isfile
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from unittest import mock from unittest import mock
class TestStatisticsWriter(base.TestCase): class TestStatisticsWriter(base.TestCase):
# test_sst --> moved to integration_test # test_sst --> moved to integration_test
...@@ -21,9 +22,9 @@ class TestStatisticsWriter(base.TestCase): ...@@ -21,9 +22,9 @@ class TestStatisticsWriter(base.TestCase):
def test_xst(self): def test_xst(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
new_sys_argv = [sys.argv[0], "--mode", "XST", "--file", dirname(__file__) + "/SDP_XST_statistics_packets.bin", "--output_dir", tmpdir] new_sys_argv = [sys.argv[0], "--mode", "XST", "--file", dirname(__file__) + "/SDP_XST_statistics_packets.bin", "--output_dir", tmpdir]
with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): with mock.patch.object(writer.sys, 'argv', new_sys_argv):
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
statistics_writer.main() writer.main()
# check if file was written # check if file was written
self.assertTrue(isfile(f"{tmpdir}/XST_SB102_2021-09-13-13-21-32.h5")) self.assertTrue(isfile(f"{tmpdir}/XST_SB102_2021-09-13-13-21-32.h5"))
...@@ -31,9 +32,9 @@ class TestStatisticsWriter(base.TestCase): ...@@ -31,9 +32,9 @@ class TestStatisticsWriter(base.TestCase):
def test_xst_multiple_subbands(self): def test_xst_multiple_subbands(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
new_sys_argv = [sys.argv[0], "--mode", "XST", "--file", dirname(__file__) + "/SDP_XST_statistics_packets_multiple_subbands.bin", "--output_dir", tmpdir] new_sys_argv = [sys.argv[0], "--mode", "XST", "--file", dirname(__file__) + "/SDP_XST_statistics_packets_multiple_subbands.bin", "--output_dir", tmpdir]
with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): with mock.patch.object(writer.sys, 'argv', new_sys_argv):
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
statistics_writer.main() writer.main()
# check if files were written # check if files were written
self.assertTrue(isfile(f"{tmpdir}/XST_SB102_2021-09-13-13-21-32.h5")) self.assertTrue(isfile(f"{tmpdir}/XST_SB102_2021-09-13-13-21-32.h5"))
...@@ -42,9 +43,9 @@ class TestStatisticsWriter(base.TestCase): ...@@ -42,9 +43,9 @@ class TestStatisticsWriter(base.TestCase):
def test_bst(self): def test_bst(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
new_sys_argv = [sys.argv[0], "--mode", "BST", "--file", dirname(__file__) + "/SDP_BST_statistics_packets.bin", "--output_dir", tmpdir] new_sys_argv = [sys.argv[0], "--mode", "BST", "--file", dirname(__file__) + "/SDP_BST_statistics_packets.bin", "--output_dir", tmpdir]
with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): with mock.patch.object(writer.sys, 'argv', new_sys_argv):
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
statistics_writer.main() writer.main()
# check if file was written # check if file was written
self.assertTrue(isfile(f"{tmpdir}/BST_2022-05-20-11-08-44.h5")) self.assertTrue(isfile(f"{tmpdir}/BST_2022-05-20-11-08-44.h5"))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment