From 22a16f794317e5ed1a4c708ac45a737159f7cfae Mon Sep 17 00:00:00 2001
From: Mario Raciti <mario.raciti@inaf.it>
Date: Tue, 9 Mar 2021 18:51:49 +0100
Subject: [PATCH] TMSS-474: Update cycle start and stop dates to actual values

---
 SAS/TMSS/backend/src/tmss/tmssapp/populate.py | 143 +++++++++++++++++-
 1 file changed, 140 insertions(+), 3 deletions(-)

diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
index d9352294552..099b190a54d 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
@@ -133,11 +133,55 @@ def populate_test_data():
 
 
 def populate_cycles(apps, schema_editor):
-    for nr in range(0, 18):
+    cycles_info = []   # TODO: For debugging purposes, remove it when done.
+
+    #  Cycle 0 deviates from any patterns
+    cycle = models.Cycle.objects.create(name="Cycle 00",
+                                        description="Lofar Cycle 0",
+                                        start=datetime(2013, 2, 11, 0, 0, 0, 0,
+                                                       tzinfo=timezone.utc),
+                                        stop=datetime(2013, 11, 14, 0, 0, 0, 0,
+                                                      tzinfo=timezone.utc))
+
+    models.CycleQuota.objects.bulk_create([models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="observing_time"),
+                                                             value=0.8 * cycle.duration.total_seconds()),
+                                           # rough guess. 80% of total time available for observing
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="cep_processing_time"),
+                                                             value=0.8 * cycle.duration.total_seconds()),
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(name="lta_storage"),
+                                                             value=0),  # needs to be filled in by user (SOS)
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="support_time"),
+                                                             value=0),  # needs to be filled in by user (SOS)
+
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="observing_time_commissioning"),
+                                                             value=0.05 * cycle.duration.total_seconds()),
+                                           # rough guess. 5% of total time available for observing
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="observing_time_prio_a"),
+                                                             value=0),  # needs to be filled in by user (SOS)
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="observing_time_prio_b"),
+                                                             value=0)  # needs to be filled in by user (SOS)
+                                           ])
+    cycles_info.append((cycle.name, cycle.start, cycle.stop))
+
+    #  Cycles 1-10 follow the same pattern
+    for nr in range(1, 11):
         cycle = models.Cycle.objects.create(name="Cycle %02d" % nr,
                                             description="Lofar Cycle %s" % nr,
-                                            start=datetime(2013+nr//2, 6 if nr%2==0 else 11, 1, 0, 0, 0, 0, tzinfo=timezone.utc),
-                                            stop=datetime(2013+(nr+1)//2, 6 if nr%2==1 else 11, 1, 0, 0, 0, 0, tzinfo=timezone.utc))
+                                            start=datetime(2013+nr//2, 5 if nr%2==0 else 11, 15, 0, 0, 0, 0, tzinfo=timezone.utc),
+                                            stop=datetime(2013+(nr+1)//2, 5 if nr%2==1 else 11, 14, 0, 0, 0, 0, tzinfo=timezone.utc))
 
         models.CycleQuota.objects.bulk_create([models.CycleQuota(cycle=cycle,
                                                                  resource_type=ResourceType.objects.get(name="observing_time"),
@@ -162,6 +206,99 @@ def populate_cycles(apps, schema_editor):
                                                                  resource_type=ResourceType.objects.get(name="observing_time_prio_b"),
                                                                  value=0) # needs to be filled in by user (SOS)
                                                ])
+        cycles_info.append((cycle.name, cycle.start, cycle.stop))
+
+    #  Cycle 11 deviates from any patterns
+    cycle = models.Cycle.objects.create(name="Cycle 11",
+                                        description="Lofar Cycle 11",
+                                        start=datetime(2018, 11, 15, 0, 0, 0, 0,
+                                                       tzinfo=timezone.utc),
+                                        stop=datetime(2019, 5, 31, 0, 0, 0, 0,
+                                                      tzinfo=timezone.utc))
+
+    models.CycleQuota.objects.bulk_create([models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="observing_time"),
+                                                             value=0.8 * cycle.duration.total_seconds()),
+                                           # rough guess. 80% of total time available for observing
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="cep_processing_time"),
+                                                             value=0.8 * cycle.duration.total_seconds()),
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="lta_storage"),
+                                                             value=0),  # needs to be filled in by user (SOS)
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="support_time"),
+                                                             value=0),  # needs to be filled in by user (SOS)
+
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="observing_time_commissioning"),
+                                                             value=0.05 * cycle.duration.total_seconds()),
+                                           # rough guess. 5% of total time available for observing
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="observing_time_prio_a"),
+                                                             value=0),  # needs to be filled in by user (SOS)
+                                           models.CycleQuota(cycle=cycle,
+                                                             resource_type=ResourceType.objects.get(
+                                                                 name="observing_time_prio_b"),
+                                                             value=0)  # needs to be filled in by user (SOS)
+                                           ])
+    cycles_info.append((cycle.name, cycle.start, cycle.stop))
+
+    #  Cycles 12-19 follow the same pattern
+    for nr in range(12, 20):
+        cycle = models.Cycle.objects.create(name="Cycle %02d" % nr,
+                                            description="Lofar Cycle %s" % nr,
+                                            start=datetime(2013 + nr // 2, 6 if nr % 2 == 0 else 12, 1, 0, 0, 0, 0,
+                                                           tzinfo=timezone.utc),
+                                            stop=datetime(2013 + (nr + 1) // 2, 5 if nr % 2 == 1 else 11,
+                                                          30 if nr % 2 == 0 else 31, 0, 0,
+                                                          0, 0, tzinfo=timezone.utc))
+
+        models.CycleQuota.objects.bulk_create([models.CycleQuota(cycle=cycle,
+                                                                 resource_type=ResourceType.objects.get(
+                                                                     name="observing_time"),
+                                                                 value=0.8 * cycle.duration.total_seconds()),
+                                               # rough guess. 80% of total time available for observing
+                                               models.CycleQuota(cycle=cycle,
+                                                                 resource_type=ResourceType.objects.get(
+                                                                     name="cep_processing_time"),
+                                                                 value=0.8 * cycle.duration.total_seconds()),
+                                               models.CycleQuota(cycle=cycle,
+                                                                 resource_type=ResourceType.objects.get(
+                                                                     name="lta_storage"),
+                                                                 value=0),  # needs to be filled in by user (SOS)
+                                               models.CycleQuota(cycle=cycle,
+                                                                 resource_type=ResourceType.objects.get(
+                                                                     name="support_time"),
+                                                                 value=0),  # needs to be filled in by user (SOS)
+
+                                               models.CycleQuota(cycle=cycle,
+                                                                 resource_type=ResourceType.objects.get(
+                                                                     name="observing_time_commissioning"),
+                                                                 value=0.05 * cycle.duration.total_seconds()),
+                                               # rough guess. 5% of total time available for observing
+                                               models.CycleQuota(cycle=cycle,
+                                                                 resource_type=ResourceType.objects.get(
+                                                                     name="observing_time_prio_a"),
+                                                                 value=0),  # needs to be filled in by user (SOS)
+                                               models.CycleQuota(cycle=cycle,
+                                                                 resource_type=ResourceType.objects.get(
+                                                                     name="observing_time_prio_b"),
+                                                                 value=0)  # needs to be filled in by user (SOS)
+                                               ])
+        cycles_info.append((cycle.name, cycle.start, cycle.stop))
+
+    logger.info('\n')
+    for ci in cycles_info:
+        logger.info('%s\t\tStart: %s\t\tStop: %s' % ci)
+    logger.info('\n')
+
 
 def populate_projects(apps, schema_editor):
     from lofar.sas.tmss.test.tmss_test_data_django_models import SchedulingSet_test_data
-- 
GitLab