Commit d8b6bc109a4981d032623e1e396b22ef06c8dd87

Authored by Alexis Koralewski
1 parent 9e92c25f
Exists in dev

Add schema (Md file) to explain workflow when user import a sequence file

CHANGELOG
  1 +04-04-2023 (AKo): v0.6.21.0
  2 + - Improve check of ObsConfig load function and renaming functions of ObsConfig & PyrosUser
  3 + - Add schema (Md file) to explain workflow when user import a sequence file
  4 +
1 5 20-03-2023 (AKo): v0.6.20.0
2 6 - Add night_id to sequences, create folder for night_id
3 7 - Change sequences_pickle location (relocate in data folder)
... ...
VERSION
1   -0.6.17.0
2 1 \ No newline at end of file
  2 +0.6.21.0
3 3 \ No newline at end of file
... ...
src/core/pyros_django/obsconfig/obsconfig_class.py
... ... @@ -59,15 +59,17 @@ class OBSConfig:
59 59 self.CONFIG_PATH = os.path.dirname(observatory_config_file)+"/"
60 60 self.obs_config_path = self.CONFIG_PATH
61 61 #self.CONFIG_PATH = self.obs_config_path
  62 + # If the pickle doesn't exists
62 63 if os.path.isfile(self.CONFIG_PATH+self.pickle_file) == False:
63 64 return True
64 65 else:
  66 + # pickle file exists
65 67 pickle_file_mtime = os.path.getmtime(
66 68 self.CONFIG_PATH+self.pickle_file)
67 69 obs_config_mtime = os.path.getmtime(observatory_config_file)
68 70  
69   - obs_config = self.read_and_check_config_file(
70   - observatory_config_file)
  71 + #obs_config = self.read_and_check_config_file(
  72 + # observatory_config_file)
71 73 if obs_config_mtime > pickle_file_mtime:
72 74 # create obs file (yaml) from pickle["obsconfig"] with date of pickle within history folder-> nom ficher + année + mois + jour + datetime (avec secondes) -> YYYY/MM/DD H:m:s
73 75 pickle_datetime = datetime.utcfromtimestamp(
... ... @@ -81,23 +83,32 @@ class OBSConfig:
81 83 with open(file_name, 'w') as f:
82 84 f.write(config_file.read())
83 85 return True
84   - if obs_config == None:
85   - print(
86   - f"Error when trying to read config file (path of config file : {observatory_config_file}")
87   - return -1
88   - self.obs_config = obs_config
89   - # check last date of modification for devices files
90   - for device in self.obs_config["OBSERVATORY"]["INVENTORY"]["DEVICES"]:
91   - device_file = self.CONFIG_PATH+device["DEVICE"]["file"]
92   - device_file_mtime = os.path.getmtime(device_file)
93   - if device_file_mtime > pickle_file_mtime:
94   - return True
95   -
96   - for computer in self.obs_config["OBSERVATORY"]["INVENTORY"]["COMPUTERS"]:
97   - computer_file = self.CONFIG_PATH+computer["COMPUTER"]["file"]
98   - computer_file_mtime = os.path.getmtime(computer_file)
99   - if computer_file_mtime > pickle_file_mtime:
100   - return True
  86 + # if obs_config == None:
  87 + # print(
  88 + # f"Error when trying to read config file (path of config file : {observatory_config_file}")
  89 + # return -1
  90 +
  91 + for file in os.listdir(self.CONFIG_PATH):
  92 + # loop on each file in obsconfig folder exluding pickle itself and global obsconfig file (observatory_config_file)
  93 + if file != observatory_config_file and ".p" not in file:
  94 + file_path = self.CONFIG_PATH + file
  95 + if os.path.getmtime(file_path) > pickle_file_mtime:
  96 + return True
  97 +
  98 + # Old version not optimized
  99 + # self.obs_config = obs_config
  100 + # # check last date of modification for devices files
  101 + # for device in self.obs_config["OBSERVATORY"]["INVENTORY"]["DEVICES"]:
  102 + # device_file = self.CONFIG_PATH+device["DEVICE"]["file"]
  103 + # device_file_mtime = os.path.getmtime(device_file)
  104 + # if device_file_mtime > pickle_file_mtime:
  105 + # return True
  106 +
  107 + # for computer in self.obs_config["OBSERVATORY"]["INVENTORY"]["COMPUTERS"]:
  108 + # computer_file = self.CONFIG_PATH+computer["COMPUTER"]["file"]
  109 + # computer_file_mtime = os.path.getmtime(computer_file)
  110 + # if computer_file_mtime > pickle_file_mtime:
  111 + # return True
101 112 return False
102 113  
103 114 def load(self, observatory_config_file):
... ... @@ -1119,7 +1130,7 @@ class OBSConfig:
1119 1130 uneditable_fields[attribute] = attributes[attribute]
1120 1131 return uneditable_fields
1121 1132  
1122   - def getEditableAttributesOfChannel(self, unit_name: str, channel_name: str) -> list:
  1133 + def getEditableChannelAttributes(self, unit_name: str, channel_name: str) -> list:
1123 1134 capabilities = self.getChannelCapabilities(unit_name, channel_name)
1124 1135 # merged_result = {}
1125 1136 # for capability in capabilities:
... ... @@ -1154,7 +1165,7 @@ class OBSConfig:
1154 1165 def getAlbumByName(self, unit_name: str, name_of_album):
1155 1166 return self.get_albums(unit_name)["albums"][name_of_album]
1156 1167  
1157   - def getEditableAttributesOfMount(self, unit_name):
  1168 + def getEditableMountAttributes(self, unit_name):
1158 1169 capabilities = self.get_device_capabilities(
1159 1170 self.get_device_for_agent(unit_name, "mount")["name"])
1160 1171 merged_result = []
... ... @@ -1347,7 +1358,7 @@ def main():
1347 1358 # print(config.getChannelCapabilities(unit_name,"OpticalChannel_up"))
1348 1359 # print(config.get_channel_groups(unit_name))
1349 1360 # print(config.getEditableAttributesOfCapability(config.getChannelCapabilities(unit_name,"OpticalChannel_up")[0]))
1350   - # print(config.getEditableAttributesOfChannel(unit_name,"OpticalChannel_up"))
  1361 + # print(config.getEditableChannelAttributes(unit_name,"OpticalChannel_up"))
1351 1362 config = OBSConfig("../../../../privatedev/config/tnc/observatory_tnc.yml")
1352 1363 unit_name = config.get_units_name()[0]
1353 1364 # dc = config.getDeviceControllerNameForAgent(unit_name,"mount")[0]
... ... @@ -1356,8 +1367,8 @@ def main():
1356 1367 # print(config.getChannelCapabilities(unit_name,"OpticalChannel_down2"))
1357 1368 # print(config.get_channel_groups(unit_name))
1358 1369 # print(config.getEditableAttributesOfCapability(config.getChannelCapabilities(unit_name,"OpticalChannel_down2")[0]))
1359   - # print(config.getEditableAttributesOfChannel(unit_name,"OpticalChannel_down2"))
1360   - #print(config.getEditableAttributesOfMount(unit_name))
  1370 + # print(config.getEditableChannelAttributesnit_name,"OpticalChannel_down2"))
  1371 + #print(config.getEditableMountAttributes(unit_name))
1361 1372 config.get_devices()
1362 1373  
1363 1374 #print(config.get_output_data_device("TAROT_meteo").get("CV7"))
... ...
src/core/pyros_django/routine_manager/templates/routine_manager/view_sequence.html
... ... @@ -44,14 +44,14 @@
44 44 <td>&nbsp</td>
45 45 <td><button type="submit" class="btn btn-success" name="action" value="check_validity">Check validity</button></td>
46 46 <td>&nbsp</td>
47   - {% if seq.complete and seq.scientific_program in request.user.get_scientific_program and seq.status == "DRAFT" %}
  47 + {% if seq.complete and seq.scientific_program in request.user.get_scientific_programs and seq.status == "DRAFT" %}
48 48 <td><button type="submit" class="btn btn-success" name="action" value="save_and_submit">Save and Submit</button></td>
49 49 <td>&nbsp</td>
50 50 {% else %}
51 51 <td><button type="submit" class="btn btn-success" name="action" value="save_and_submit" disabled>Save and Submit</button></td>
52 52 <td>&nbsp</td>
53 53 {% endif %}
54   - {% if seq.status == "TBP" and seq.scientific_program in request.user.get_scientific_program %}
  54 + {% if seq.status == "TBP" and seq.scientific_program in request.user.get_scientific_programs %}
55 55  
56 56 <td><a href="{% url "unsubmit_sequence" seq.id %}" class="btn btn-warning" onclick="return confirm('The sequence will be unsubmitted')"
57 57 title="The sequence will be unsubmitted">Unsubmit sequence</a></td>
... ...
src/core/pyros_django/routine_manager/tests.py
... ... @@ -268,9 +268,9 @@ class SequencesTests(TestCase):
268 268 pyros_user=self.usr1).order_by("-created").first()
269 269 seq_id = created_seq.id
270 270 config = OBSConfig(os.environ["PATH_TO_OBSCONF_FILE"])
271   - sp_of_user = self.usr1.get_scientific_program()
  271 + sp_of_user = self.usr1.get_scientific_programs()
272 272 sp_list = ScientificProgram.objects.observable_programs().filter(id__in=sp_of_user)
273   - sequence_form = SequenceForm(instance=created_seq, data_from_config=config.getEditableAttributesOfMount(
  273 + sequence_form = SequenceForm(instance=created_seq, data_from_config=config.getEditableMountAttributes(
274 274 config.unit_name), layouts=config.get_layouts(config.unit_name), sp_list=sp_list)
275 275 layout = list(config.get_layouts(config.unit_name)
276 276 ["layouts"].values())[0]["name"]
... ... @@ -317,7 +317,7 @@ class SequencesTests(TestCase):
317 317 # but this plan doesn't have config_attributes, we need to add them
318 318 plan = Plan.objects.get(album=album)
319 319 post_data = {}
320   - plan_form = PlanForm(data_from_config=config.getEditableAttributesOfChannel(
  320 + plan_form = PlanForm(data_from_config=config.getEditableChannelAttributes(
321 321 config.unit_name, list(config.get_channels(config.unit_name).keys())[0]), edited_plan=None)
322 322 for field_name, field in plan_form.fields.items():
323 323 if field.__dict__.get("_choices"):
... ... @@ -359,9 +359,9 @@ class SequencesTests(TestCase):
359 359 pyros_user=self.usr1).order_by("-created").first()
360 360 seq_id = created_seq.id
361 361 config = OBSConfig(os.environ["PATH_TO_OBSCONF_FILE"])
362   - sp_of_user = self.usr1.get_scientific_program()
  362 + sp_of_user = self.usr1.get_scientific_programs()
363 363 sp_list = ScientificProgram.objects.observable_programs().filter(id__in=sp_of_user)
364   - sequence_form = SequenceForm(instance=created_seq, data_from_config=config.getEditableAttributesOfMount(
  364 + sequence_form = SequenceForm(instance=created_seq, data_from_config=config.getEditableMountAttributes(
365 365 config.unit_name), layouts=config.get_layouts(config.unit_name), sp_list=sp_list)
366 366 layout = list(config.get_layouts(config.unit_name)
367 367 ["layouts"].values())[0]["name"]
... ...
src/core/pyros_django/user_manager/models.py
... ... @@ -219,12 +219,13 @@ class PyrosUser(AbstractUser):
219 219 else:
220 220 return str
221 221  
222   - def get_scientific_program(self) -> QuerySet:
  222 + def get_scientific_programs(self) -> QuerySet:
223 223 sp_where_user_is_sp_pi = ScientificProgram.objects.filter(
224 224 sp_pi=self.id)
225   - other_sp_of_user = ScientificProgram.objects.filter(id__in=SP_Period.objects.filter(id__in=SP_Period_User.objects.filter(
  225 + # Get all SP of user where he's not an SP PI
  226 + user_other_sp = ScientificProgram.objects.filter(id__in=SP_Period.objects.filter(id__in=SP_Period_User.objects.filter(
226 227 user=PyrosUser.objects.get(username=self.username)).values("SP_Period")).values_list("scientific_program", flat=True))
227   - sp_of_user = sp_where_user_is_sp_pi | other_sp_of_user
  228 + sp_of_user = sp_where_user_is_sp_pi | user_other_sp
228 229 return sp_of_user
229 230  
230 231 def get_scientific_program_where_user_is_sp_pi(self) -> QuerySet:
... ...
src/core/pyros_django/user_manager/views.py
... ... @@ -229,7 +229,7 @@ def users(request):
229 229 inactive_pyros_users = PyrosUser.objects.filter(
230 230 is_active=False).order_by("-id")
231 231 else:
232   - sp_of_current_user = current_user.get_scientific_program()
  232 + sp_of_current_user = current_user.get_scientific_programs()
233 233 sp_periods_of_current_user = SP_Period.objects.filter(
234 234 scientific_program__in=sp_of_current_user)
235 235 common_scientific_programs = sp_of_current_user
... ... @@ -325,7 +325,7 @@ def user_detail_view(request, pk):
325 325 "role") in ("Admin", "Unit-PI", "Unit-board")
326 326 CAN_VIEW_MOTIVE_OF_REGISTRATION = request.session.get("role") in (
327 327 "Admin", "Unit-PI", "Unit-board") and len(user.motive_of_registration) > 0
328   - scientific_programs = user.get_scientific_program()
  328 + scientific_programs = user.get_scientific_programs()
329 329 except PyrosUser.DoesNotExist:
330 330 raise Http404("User does not exist")
331 331 return render(request, 'user_manager/user_detail.html', context={
... ...
upload_sequence.md 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +```mermaid
  2 +flowchart TD
  3 + A[Receive yaml file]-->B[Load yaml file]
  4 + B-->id1
  5 + subgraph id1 [Transcript file into Sequence]
  6 + subgraph id2 [Process sequence]
  7 + C[Get scientific program of Sequence]-->D[Process form fields]
  8 + end
  9 + id2-->id3
  10 + subgraph id3 [Process albums]
  11 + F[Get album name]-->G[Create album]
  12 + end
  13 + id3-->id4
  14 + subgraph id4 [Process plan]
  15 + H[Process plan fields]-->I[Create plan]
  16 + end
  17 + end
  18 + id1-->J[Create Sequence]
  19 + J-->K[Return sequence id]
  20 +```
0 21 \ No newline at end of file
... ...