@@ -113,9 +113,9 services: | |||||
113 | - backend_sirm |
|
113 | - backend_sirm | |
114 | labels: |
|
114 | labels: | |
115 | ofelia.enabled: "true" |
|
115 | ofelia.enabled: "true" | |
116 |
ofelia.job-exec.adq-exp.schedule: "@every |
|
116 | ofelia.job-exec.adq-exp.schedule: "@every 10s" | |
117 | ofelia.job-exec.adq-exp.command: "python manage.py adq_exp" |
|
117 | ofelia.job-exec.adq-exp.command: "python manage.py adq_exp" | |
118 |
ofelia.job-exec.restart-exp.schedule: " |
|
118 | ofelia.job-exec.restart-exp.schedule: "0 0 0/17 ? * *" | |
119 | ofelia.job-exec.restart-exp.command: "python manage.py restart_exp" |
|
119 | ofelia.job-exec.restart-exp.command: "python manage.py restart_exp" | |
120 | logging: |
|
120 | logging: | |
121 | driver: "json-file" |
|
121 | driver: "json-file" |
@@ -7,9 +7,9 from datetime import datetime | |||||
7 |
|
7 | |||
8 | class Command(BaseCommand): |
|
8 | class Command(BaseCommand): | |
9 | """ |
|
9 | """ | |
10 |
Check data acquisition each |
|
10 | Check data acquisition each 10 seconds. | |
11 | Example: |
|
11 | Example: | |
12 |
manage.py adq_exp |
|
12 | manage.py adq_exp | |
13 | """ |
|
13 | """ | |
14 | def handle(self, *args, **options): |
|
14 | def handle(self, *args, **options): | |
15 | restart_experiment(self) |
|
15 | restart_experiment(self) | |
@@ -20,20 +20,30 def check_experiment(): | |||||
20 | else: |
|
20 | else: | |
21 | return False |
|
21 | return False | |
22 |
|
22 | |||
23 |
def |
|
23 | def acquisition_start(self, id_exp): | |
24 | exp = get_object_or_404(Experiment, pk=id_exp) |
|
24 | all_status = Experiment.objects.filter(status=2) | |
25 | if exp.status != 2 and exp.mode_stop == 'adq': |
|
25 | check_id = False | |
26 | exp.status = exp.start() |
|
|||
27 | exp.save() |
|
|||
28 | self.stdout.write(f'Experiment "{exp.name}" was restarted') |
|
|||
29 |
|
26 | |||
30 | def experiment_stop(self, id_exp): |
|
27 | if len(all_status) > 0: | |
31 | exp = get_object_or_404(Experiment, pk=id_exp) |
|
28 | check_id = all_status[0].pk | |
32 | if exp.status == 2 or exp.status == 4 or exp.status == 5: |
|
29 | ||
33 | exp.status = exp.stop() |
|
30 | if check_id and check_id == id_exp: | |
34 | exp.mode_stop = 'adq' |
|
31 | exp = get_object_or_404(Experiment, pk=id_exp) | |
35 | exp.save() |
|
32 | name = '{}-R@{}'.format(exp.name, datetime.now().strftime('%Y-%m-%dT%H-%M-%S')) | |
36 | self.stdout.write(f'Experiment "{exp.name}" was stoped') |
|
33 | exp.reception_rx.start_device(name_experiment = name, restart = True) | |
|
34 | self.stdout.write(f'"{exp.name}" experiment: Data acquisition was restarted') | |||
|
35 | ||||
|
36 | def acquisition_stop(self, id_exp): | |||
|
37 | all_status = Experiment.objects.filter(status=2) | |||
|
38 | check_id = False | |||
|
39 | ||||
|
40 | if len(all_status) > 0: | |||
|
41 | check_id = all_status[0].pk | |||
|
42 | ||||
|
43 | if check_id and check_id == id_exp: | |||
|
44 | exp = get_object_or_404(Experiment, pk=id_exp) | |||
|
45 | exp.reception_rx.stop_device() | |||
|
46 | self.stdout.write(f'"{exp.name}" experiment: Data acquisition "{exp.name}" was stopped') | |||
37 |
|
47 | |||
38 | def count_data(datadir): |
|
48 | def count_data(datadir): | |
39 | pattern = "rf@*.h5" |
|
49 | pattern = "rf@*.h5" | |
@@ -69,15 +79,16 def check_count(datadir, old_numbers): | |||||
69 | numbers = count_data(datadir) |
|
79 | numbers = count_data(datadir) | |
70 |
|
80 | |||
71 | for key, value in numbers.items(): |
|
81 | for key, value in numbers.items(): | |
|
82 | if old_numbers[key] > numbers[key]: | |||
|
83 | old_numbers[key] = 0 | |||
72 | diff[key] = numbers[key] - old_numbers[key] |
|
84 | diff[key] = numbers[key] - old_numbers[key] | |
73 | return numbers, diff |
|
85 | return numbers, diff | |
74 |
|
86 | |||
75 | def restart_experiment(self): |
|
87 | def restart_experiment(self): | |
76 | old_numbers={'ch0': 0, 'ch1': 0} |
|
88 | old_numbers={'ch0': 0, 'ch1': 0} | |
77 | new_check = True |
|
89 | for count in range(5): | |
78 | for _ in range(5): |
|
90 | time.sleep(1) | |
79 | time.sleep(2) |
|
91 | if check_experiment(): | |
80 | if check_experiment() and new_check: |
|
|||
81 | all_status = Experiment.objects.filter(status=2) |
|
92 | all_status = Experiment.objects.filter(status=2) | |
82 | id_exp = all_status[0].pk |
|
93 | id_exp = all_status[0].pk | |
83 | datadir_exp = all_status[0].reception_rx.datadir |
|
94 | datadir_exp = all_status[0].reception_rx.datadir | |
@@ -87,8 +98,11 def restart_experiment(self): | |||||
87 | if diff['ch0'] > 0 and diff['ch1'] > 0: |
|
98 | if diff['ch0'] > 0 and diff['ch1'] > 0: | |
88 | self.stdout.write(f'Data acquisition is running') |
|
99 | self.stdout.write(f'Data acquisition is running') | |
89 | else: |
|
100 | else: | |
90 | experiment_stop(self, id_exp) |
|
101 | count = count + 1 | |
91 | time.sleep(14) |
|
102 | if count == 5: | |
92 |
|
|
103 | acquisition_stop(self, id_exp) | |
93 | old_numbers={'ch0': 0, 'ch1': 0} |
|
104 | time.sleep(1) | |
94 | new_check = False No newline at end of file |
|
105 | acquisition_start(self, id_exp) | |
|
106 | old_numbers={'ch0': 0, 'ch1': 0} | |||
|
107 | else: | |||
|
108 | self.stdout.write(f'An error ocurred while trying to read data acquisition, Retry!') No newline at end of file |
@@ -189,7 +189,7 class USRPRXConfiguration(Configuration): | |||||
189 |
|
189 | |||
190 | return True |
|
190 | return True | |
191 |
|
191 | |||
192 | def start_device(self, name_experiment=False): |
|
192 | def start_device(self, name_experiment=False, restart = False): | |
193 |
|
193 | |||
194 | try: |
|
194 | try: | |
195 | usrp = USRPRXConfiguration.objects.get(pk=self) |
|
195 | usrp = USRPRXConfiguration.objects.get(pk=self) | |
@@ -199,8 +199,9 class USRPRXConfiguration(Configuration): | |||||
199 | usrp_timesource = usrp.get_timesource_display() |
|
199 | usrp_timesource = usrp.get_timesource_display() | |
200 |
|
200 | |||
201 | if name_experiment: |
|
201 | if name_experiment: | |
202 | self.datadir = os.path.join(os.environ['EXPOSE_NAS'], name_experiment, 'rawdata') |
|
202 | if not restart: | |
203 | self.save() |
|
203 | self.datadir = os.path.join(os.environ['EXPOSE_NAS'], name_experiment, 'rawdata') | |
|
204 | self.save() | |||
204 |
|
205 | |||
205 | name_experiment = name_experiment.split("@") |
|
206 | name_experiment = name_experiment.split("@") | |
206 | dt = datetime.strptime(name_experiment[1], '%Y-%m-%dT%H-%M-%S') |
|
207 | dt = datetime.strptime(name_experiment[1], '%Y-%m-%dT%H-%M-%S') |
General Comments 0
You need to be logged in to leave comments.
Login now