Skip to content
Snippets Groups Projects
Commit 169d72df authored by Roy de Goei's avatar Roy de Goei
Browse files

TMSS-687: some rename actions

parent 3c7a58a5
No related branches found
No related tags found
1 merge request!399Resolve TMSS-687
......@@ -33,19 +33,19 @@ NBR_DAYS_CALCULATE_AHEAD = 365 # 1 year
NBR_DAYS_BEFORE_TODAY = 1
def execute_populate_calculations(nbr_days_calculate_ahead, start_date):
def execute_populate_sunrise_and_sunset_for_all_stations(nbr_days_calculate_ahead, start_date):
"""
Execute the populate of calculations (sunrise/sunset) for given number of days stating at give date
:param nbr_days_calculate_ahead: Number of days to calculated
:param start_date: The date to start calculate
:return next_date: The next_date to process
"""
logger.info("execute_populate_calculations %s for %d days" % (start_date, nbr_days_calculate_ahead))
logger.info("execute_populate_sunrise_and_sunset_for_all_stations %s for %d days" % (start_date, nbr_days_calculate_ahead))
# Import here otherwise you get
# "django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings."
from lofar.sas.tmss.tmss.tmssapp.populate import populate_calculations
from lofar.sas.tmss.tmss.tmssapp.populate import populate_sunrise_and_sunset_for_all_stations
populate_calculations(nbr_days=nbr_days_calculate_ahead, start_date=start_date)
populate_sunrise_and_sunset_for_all_stations(nbr_days=nbr_days_calculate_ahead, start_date=start_date)
# Return the next_date to process
next_date = start_date + datetime.timedelta(days=nbr_days_calculate_ahead)
return next_date
......@@ -84,10 +84,10 @@ class TMSSPreCalculationsServiceJob(threading.Thread):
remaining_wait_time_in_sec = self.interval.total_seconds() - (time.time() - start_time)
def create_calculation_service_job(interval_time, nbr_days_calculate_ahead, nbr_days_before_today):
def create_service_job_for_sunrise_and_sunset_calculations(interval_time, nbr_days_calculate_ahead, nbr_days_before_today):
start_date = datetime.date.today() - datetime.timedelta(days=nbr_days_before_today)
return TMSSPreCalculationsServiceJob(interval=timedelta(seconds=interval_time),
execute=execute_populate_calculations,
execute=execute_populate_sunrise_and_sunset_for_all_stations,
nbr_days_calculate_ahead=nbr_days_calculate_ahead, start_date=start_date)
......@@ -119,7 +119,7 @@ def main():
from lofar.sas.tmss.tmss import setup_and_check_tmss_django_database_connection_and_exit_on_error
setup_and_check_tmss_django_database_connection_and_exit_on_error(options.dbcredentials)
job = create_calculation_service_job(options.interval_time, options.nbr_days_calculate_ahead, options.nbr_days_before_today)
job = create_service_job_for_sunrise_and_sunset_calculations(options.interval_time, options.nbr_days_calculate_ahead, options.nbr_days_before_today)
job.start()
waitForInterrupt()
job.stop()
......
......@@ -27,11 +27,8 @@ logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=loggin
from lofar.sas.tmss.test.test_utils import TMSSTestEnvironment
from lofar.sas.tmss.services.precalculations_service import create_calculation_service_job
from lofar.common.test_utils import integration_test, exit_with_skipped_code_if_skip_integration_tests
exit_with_skipped_code_if_skip_integration_tests()
from lofar.sas.tmss.services.precalculations_service import create_service_job_for_sunrise_and_sunset_calculations
from lofar.common.test_utils import integration_test
@integration_test
......@@ -79,7 +76,7 @@ class TestPreCalculationService(unittest.TestCase):
self.assertEqual(0, len(StationTimeline.objects.all()))
# Now we are going to create and start the calculation service with a wait time of 60 sec,
# nbr days to calculate ahead is 1 and nbr days before today 1 -> so only 'yesterday' should be created
job = create_calculation_service_job(60, 1, 1)
job = create_service_job_for_sunrise_and_sunset_calculations(60, 1, 1)
job.start()
job.stop()
# Check what have been created
......@@ -112,7 +109,7 @@ class TestPreCalculationService(unittest.TestCase):
# Now we are going to create and start the calculation service with a interval of 60 sec,
# nbr days to calculate ahead is 4 and nbr days before today 2 -> so 'day before yesterday, 'yesterday',
# 'today' and 'tomorrow' should be created
job = create_calculation_service_job(60, 4, 2)
job = create_service_job_for_sunrise_and_sunset_calculations(60, 4, 2)
job.start()
job.stop()
# Check what have been created
......@@ -145,7 +142,7 @@ class TestPreCalculationService(unittest.TestCase):
# Now we are going to create and start the calculation service with a interval of 10 sec (smaller will not make sense),
# nbr days to calculate ahead is 1 and nbr days before today 0 -> so it start with 'today' and after 10 seconds
# 'tomorrow' etc..,
job = create_calculation_service_job(10, 1, 0)
job = create_service_job_for_sunrise_and_sunset_calculations(10, 1, 0)
job.start()
time.sleep(25)
job.stop()
......@@ -181,7 +178,7 @@ class TestPreCalculationService(unittest.TestCase):
# Now we are going to create and start the calculation service with an interval of 2 sec
# nbr days to calculate ahead is 1 and nbr days before today 0 -> so it start with 'today' and after ~6 seconds
# 'tomorrow' etc..
job = create_calculation_service_job(2, 1, 0)
job = create_service_job_for_sunrise_and_sunset_calculations(2, 1, 0)
job.start()
time.sleep(10)
job.stop()
......@@ -199,48 +196,6 @@ class TestPreCalculationService(unittest.TestCase):
self.assertEqual(0, len(st_objects))
@integration_test
class TestPreCalculationServiceWithoutSchemas(unittest.TestCase):
"""
Tests for creation/start/stop of the TMSSPreCalculationsServiceJob when NO schemas exist
Check that no exception occur
"""
@classmethod
def setUpClass(cls) -> None:
"""
Do not populate schemas
"""
cls.tmss_test_env = TMSSTestEnvironment(populate_schemas=False)
cls.tmss_test_env.start()
cls.test_data_creator = cls.tmss_test_env.create_test_data_creator()
@classmethod
def tearDownClass(cls) -> None:
cls.tmss_test_env.stop()
def test_no_stations_calculated(self):
"""
Test when no stations exist, the StationTimeLine is empty
"""
# Import here otherwise you get
# "django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings."
from lofar.sas.tmss.tmss.tmssapp.conversions import get_all_stations
from lofar.sas.tmss.tmss.tmssapp.models.calculations import StationTimeline
nbr_stations = len(get_all_stations())
self.assertEqual(0, nbr_stations)
self.assertEqual(0, len(StationTimeline.objects.all()))
# Now we are going to create and start the calculation service with a interval time of 60 sec,
# nbr days to calculate ahead is 1 and nbr days before today 1 ->
# nothing will be created because there are no stations
job = create_calculation_service_job(60, 1, 1)
job.start()
job.stop()
nbr_stations = len(get_all_stations())
self.assertEqual(0, nbr_stations)
self.assertEqual(0, len(StationTimeline.objects.all()))
if __name__ == '__main__':
#run the unit tests
unittest.main()
\ No newline at end of file
......@@ -68,9 +68,6 @@ def populate_test_data():
from lofar.sas.tmss.tmss.tmssapp.subtasks import schedule_subtask
from lofar.common.json_utils import get_default_json_object_for_schema
# Maybe move to 'migrations populate'
#populate_calculations(nbr_days=3)
constraints_template = models.SchedulingConstraintsTemplate.objects.get(name="constraints")
constraints_spec = get_default_json_object_for_schema(constraints_template.schema)
......@@ -485,7 +482,7 @@ def populate_system_test_users():
lta_user.groups.add(Group.objects.get(name='LTA User'))
def populate_calculations(nbr_days=3, start_date=date.today()):
def populate_sunrise_and_sunset_for_all_stations(nbr_days=3, start_date=date.today()):
"""
Populate station timeline data of all stations for given number of days the starting at given date
Note: If data is not in database yet, it will take about 6 seconds to calculate it for all (51) stations
......
......@@ -456,10 +456,10 @@ class TMSSTestEnvironment:
# next service does not have a buslistener, it is just a simple time scheduler and currently rely and
# populated stations schema to retrieve all stations
if self._start_precalculations_service:
from lofar.sas.tmss.services.precalculations_service import create_calculation_service_job
from lofar.sas.tmss.services.precalculations_service import create_service_job_for_sunrise_and_sunset_calculations
# For testpurposes we can use a smaller range and higher interval frequency
self.precalculations_service = \
create_calculation_service_job(wait_time_seconds=60, nbr_days_calculate_ahead=3, nbr_days_before_today=1)
create_service_job_for_sunrise_and_sunset_calculations(wait_time_seconds=60, nbr_days_calculate_ahead=3, nbr_days_before_today=1)
self.precalculations_service.start()
def stop(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment