Browse Source

Fix `elabelizer.py` (shifted energy seasons)

Thanks Andrei Erofeev for the bug report

> Скрипт elabelizer.py выдаёт ярлыки и энергии точек,
> смещённые по циклу относительно
> названия сезона? Вот часть вывода:
> LOW2020,     935_89976, 934.705
> HIGH2020,     945_91878, 945.461
compton 1 year ago
parent
commit
25dc8c5af1
1 changed files with 20 additions and 13 deletions
  1. 20 13
      elabelizer.py

+ 20 - 13
elabelizer.py

@@ -3,8 +3,10 @@ The script is for corresponding the elabels from database and compton average me
 run it on cc-8 with the command:
 run it on cc-8 with the command:
 `python3 elabelizer.py`
 `python3 elabelizer.py`
 
 
-If this script is not working properly, try to setup environment firstly with the following command in shell:
+If this script is not working properly, try to setup environment firstly with the following command in bash:
 `source /sl/cmd3/cc8-64/Cmd3Off/tune.cmd3_runs_scripts.sh`
 `source /sl/cmd3/cc8-64/Cmd3Off/tune.cmd3_runs_scripts.sh`
+
+This script is inspired by listoffdata.py script (/sl/cmd3/cc7-64/Cmd3Off/scripts/listoffdata.py)
 """
 """
 
 
 import os 
 import os 
@@ -17,7 +19,7 @@ django.setup()
 from cmdweb.apps.cmd3off.energypoints.models import EnergyPoint, Param, ParamData
 from cmdweb.apps.cmd3off.energypoints.models import EnergyPoint, Param, ParamData
 from urllib.request import urlopen
 from urllib.request import urlopen
 
 
-    
+
 def retrieve_elabels(startrun, stoprun):
 def retrieve_elabels(startrun, stoprun):
     """Retrieves elabels from database
     """Retrieves elabels from database
     
     
@@ -34,17 +36,22 @@ def retrieve_elabels(startrun, stoprun):
         list of elabels and information about them
         list of elabels and information about them
         (elabel, firstrun, lastrun, nominal energy, starttime, stoptime, season)
         (elabel, firstrun, lastrun, nominal energy, starttime, stoptime, season)
     """
     """
-    elabels = []
-    season = ""
-    for e in EnergyPoint.objects.all():
-        if (e.name).startswith('Season'):
-            season = e.name[7:]
-        if e.startrun >= startrun and e.endrun <= stoprun:
-            elabel_info = (e.name, e.startrun, e.endrun, e.energy, e.starttime, e.endtime, season)
-            if (e.name).startswith('Season'):
-                continue
-            elabels.append(elabel_info)
-    return elabels
+    
+    points, seasons = [], []
+    # Get seasons (they are sorted by date)
+    for e in EnergyPoint.objects.filter(name__startswith="Season"):
+        info = [e.name[7:], e.startrun, e.endrun]
+        seasons.append(info)
+    
+    # Get energy points (they are sorted by date) and match corresponing seasons
+    season_idx = 0
+    for e in EnergyPoint.objects.filter(startrun__gte=startrun, endrun__lte=stoprun):
+        while((e.startrun < seasons[season_idx][1]) or (e.endrun > seasons[season_idx][2])):
+            season_idx+=1
+        info = (e.name, e.startrun, e.endrun, e.energy, e.starttime, e.endtime, seasons[season_idx][0])
+        if not(e.name.startswith("Season")):
+            points.append(info)
+    return points
     
     
 def get_available_compton_seasons():
 def get_available_compton_seasons():
     tables_url = 'https://cmd.inp.nsk.su/~compton/gitlist/compton_tables/raw/dev/tables/'
     tables_url = 'https://cmd.inp.nsk.su/~compton/gitlist/compton_tables/raw/dev/tables/'