diff --git a/LCS/Messaging/python/messaging/messagebus.py b/LCS/Messaging/python/messaging/messagebus.py index 7bc94c6719b6a51193969591d8b8e9c39a5deea9..2e3e510dc06b7ad270a24bae73b1f849cebbb566 100644 --- a/LCS/Messaging/python/messaging/messagebus.py +++ b/LCS/Messaging/python/messaging/messagebus.py @@ -1136,7 +1136,7 @@ class TemporaryQueue: """ return ToBus(broker=self.broker, exchange=self._bound_exchange, connection_log_level=logging.DEBUG) -class AbstractMessageHandler: +class AbstractMessageHandler: """ The AbstractMessageHandler is the base class which defines the following message handling pattern: - the method start_handling is called at startup diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/conversions.py b/SAS/TMSS/backend/src/tmss/tmssapp/conversions.py index d6b6b91a8d9e03b107b364e3362589259c50dd7d..142c1635f1cc1207c7700f525593b635de6eb939 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/conversions.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/conversions.py @@ -6,6 +6,8 @@ from astropy.coordinates import Angle, get_body import astropy.time from functools import lru_cache from lofar.sas.tmss.tmss.tmssapp.models.calculations import StationTimeline +from lofar.sas.tmss.tmss.tmssapp.models.specification import CommonSchemaTemplate + from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned import logging @@ -34,7 +36,7 @@ SUN_SET_RISE_PRECISION = 30 @lru_cache(maxsize=256, typed=False) # does not like lists, so use tuples to allow caching def timestamps_and_stations_to_sun_rise_and_set(timestamps: tuple, stations: tuple, angle_to_horizon: Angle=SUN_SET_RISE_ANGLE_TO_HORIZON, - create_when_not_found=True) -> dict: + create_when_not_found=False) -> dict: """ Retrieve for given stations and given timestamps the sunrise/sunset/day/night data as dictionary If station/timestamp is already calculated it will be retrieved from database otherwise it will be calculated @@ -42,6 +44,7 @@ def timestamps_and_stations_to_sun_rise_and_set(timestamps: tuple, stations: tup Storing the pre-calculated data into a database makes retrieval faster. TODO make a service to pre-calculate e.g. 1 year in advanced, currently only one week for all stations during populate of testenvironment + TODO about the night.... when using a time in the timestamp :param timestamps: tuple of datetimes, e.g. datetime(2020, 1, 1) :param stations: tuple of station names, e.g. ("CS002") :param angle_to_horizon: the angle between horizon and given coordinates for which rise and set times are returned @@ -284,14 +287,23 @@ def antennafields_for_antennaset_and_station(antennaset:str, station:str) -> lis def get_all_stations(): """ returns all possible stations. - TODO: should retrieved from the eneum values in common_schema_template-stations-1.json - or getting it the default values of station_groups of Core, Remote and International - """ - lst_stations = ["CS001", "CS002", "CS003", "CS004", "CS005", "CS006", "CS007", "CS011", "CS013", "CS017", "CS021", + Retrieve station names from station template by getting the Dutch and International stations, + then you should have it all. + lst_stations = ["CS001", "CS002", "CS003", "CS004", "CS005", "CS006", "CS007", "CS011", "CS013", "CS017", "CS021", "CS024", "CS026", "CS028", "CS030", "CS031", "CS032", "CS101", "CS103", "CS201", "CS301", "CS302", "CS401", "CS501", "RS106", "RS205", "RS208", "RS210", "RS305", "RS306", "RS307", "RS310", "RS406", "RS407", "RS409", "RS503", "RS508", "RS509", "DE601", "DE602", "DE603", "DE604", "DE605", "FR606", "SE607", "UK608", "DE609", "PL610", "PL611", "PL612", "IE613", "LV614"] - return lst_stations \ No newline at end of file + """ + lst_stations = [] + for station_group in ["Dutch", "International"]: + station_schema_template = CommonSchemaTemplate.objects.get(name="stations", version=1) + groups = station_schema_template.schema['definitions']['station_group']['anyOf'] + try: + selected_group = next(g for g in groups if g['title'].lower() == station_group.lower()) + except StopIteration: + raise ValueError('No station_group with name "%s" found in the JSON schema.' % station_group) + lst_stations.extend(selected_group['properties']['stations']['enum'][0]) + return lst_stations diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py index 2ce55e6e96abc66eaa668730b65a080de65b0418..18046daac1d7c76c09c8ab8e05341b0758a39b93 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py @@ -489,7 +489,7 @@ def populate_calculations(nbr_days=3): """ Calculate a week of station timeline data of all stations will take about a minute - TODO create a service which will do this continiously ? + TODO create a service which will do this continuously ? """ starttime = datetime.utcnow() logger.info("Populate sunrise, sunset, day, night for ALL stations from today up to %d days" % nbr_days) @@ -498,6 +498,5 @@ def populate_calculations(nbr_days=3): dt = datetime.combine(date.today(), datetime.min.time()) + timedelta(days=i) lst_timestamps.append(dt) - # retrieving will create in db timestamps_and_stations_to_sun_rise_and_set(tuple(lst_timestamps), tuple(get_all_stations()), create_when_not_found=True) logger.info("Done in %.1fs", (datetime.utcnow()-starttime).total_seconds()) diff --git a/SAS/TMSS/backend/test/t_conversions.py b/SAS/TMSS/backend/test/t_conversions.py index 7f8d66d6e4b8758b3cf13bf04bf3d8488deb89ad..132ccfde9dbd0676e17aeb427dd26312c73b9c1e 100755 --- a/SAS/TMSS/backend/test/t_conversions.py +++ b/SAS/TMSS/backend/test/t_conversions.py @@ -30,7 +30,6 @@ import json logger = logging.getLogger(__name__) logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO) -from lofar.sas.tmss.tmss.tmssapp.conversions import local_sidereal_time_for_utc_and_station, local_sidereal_time_for_utc_and_longitude from lofar.common.test_utils import exit_with_skipped_code_if_skip_integration_tests exit_with_skipped_code_if_skip_integration_tests() @@ -40,6 +39,10 @@ exit_with_skipped_code_if_skip_integration_tests() # (ignore pycharm unused import statement, python unittests does use at RunTime the tmss_test_environment_unittest_setup module) from lofar.sas.tmss.test.tmss_test_environment_unittest_setup import * +# The next import should be done after the 'tmss_test_environment_unittest_setup' magic !!! +from lofar.sas.tmss.tmss.tmssapp.conversions import local_sidereal_time_for_utc_and_station, local_sidereal_time_for_utc_and_longitude + + class SiderealTime(unittest.TestCase): def test_local_sidereal_time_for_utc_and_longitude_returns_correct_result(self):