46 self.login_url = urlparse.urljoin(self.base_url, 'accounts/login/') |
46 self.login_url = urlparse.urljoin(self.base_url, 'accounts/login/') |
47 self.logout_url = urlparse.urljoin(self.base_url, 'accounts/logout/') |
47 self.logout_url = urlparse.urljoin(self.base_url, 'accounts/logout/') |
48 self.list_measurements_url = urlparse.urljoin(self.base_url, 'data_processing/measurements/') |
48 self.list_measurements_url = urlparse.urljoin(self.base_url, 'data_processing/measurements/') |
49 |
49 |
50 self.upload_url = urlparse.urljoin(self.base_url, 'data_processing/measurements/quick/') |
50 self.upload_url = urlparse.urljoin(self.base_url, 'data_processing/measurements/quick/') |
|
51 self.download_hirelpp_pattern = urlparse.urljoin(self.base_url, |
|
52 'data_processing/measurements/{0}/download-hirelpp/') |
|
53 self.download_cloudmask_pattern = urlparse.urljoin(self.base_url, |
|
54 'data_processing/measurements/{0}/download-cloudmask/') |
|
55 |
51 self.download_preprocessed_pattern = urlparse.urljoin(self.base_url, |
56 self.download_preprocessed_pattern = urlparse.urljoin(self.base_url, |
52 'data_processing/measurements/{0}/download-preprocessed/') |
57 'data_processing/measurements/{0}/download-preprocessed/') |
53 self.download_optical_pattern = urlparse.urljoin(self.base_url, |
58 self.download_optical_pattern = urlparse.urljoin(self.base_url, |
54 'data_processing/measurements/{0}/download-optical/') |
59 'data_processing/measurements/{0}/download-optical/') |
55 self.download_graph_pattern = urlparse.urljoin(self.base_url, |
60 self.download_graph_pattern = urlparse.urljoin(self.base_url, |
56 'data_processing/measurements/{0}/download-plots/') |
61 'data_processing/measurements/{0}/download-plots/') |
|
62 self.download_elic_pattern = urlparse.urljoin(self.base_url, |
|
63 'data_processing/measurements/{0}/download-elic/') |
57 self.delete_measurement_pattern = urlparse.urljoin(self.base_url, 'admin/database/measurements/{0}/delete/') |
64 self.delete_measurement_pattern = urlparse.urljoin(self.base_url, 'admin/database/measurements/{0}/delete/') |
58 |
65 |
59 self.api_base_url = urlparse.urljoin(self.base_url, 'api/v1/') |
66 self.api_base_url = urlparse.urljoin(self.base_url, 'api/v1/') |
60 self.api_measurement_pattern = urlparse.urljoin(self.api_base_url, 'measurements/{0}/') |
67 self.api_measurement_pattern = urlparse.urljoin(self.api_base_url, 'measurements/{0}/') |
61 self.api_measurements_url = urlparse.urljoin(self.api_base_url, 'measurements') |
68 self.api_measurements_url = urlparse.urljoin(self.api_base_url, 'measurements') |
163 local_file = os.path.join(local_dir, basename) |
170 local_file = os.path.join(local_dir, basename) |
164 |
171 |
165 with open(local_file, 'wb') as f: |
172 with open(local_file, 'wb') as f: |
166 f.write(zip_file.read(ziped_name)) |
173 f.write(zip_file.read(ziped_name)) |
167 |
174 |
|
175 def download_hirelpp(self, measurement_id): |
|
176 """ Download HiRElPP files for the measurement id. """ |
|
177 # Construct the download url |
|
178 download_url = self.download_hirelpp_pattern.format(measurement_id) |
|
179 self.download_files(measurement_id, 'hirelpp', download_url) |
|
180 |
|
181 def download_cloudmask(self, measurement_id): |
|
182 """ Download preprocessed files for the measurement id. """ |
|
183 # Construct the download url |
|
184 download_url = self.download_cloudmask_pattern.format(measurement_id) |
|
185 self.download_files(measurement_id, 'cloudmask', download_url) |
|
186 |
168 def download_preprocessed(self, measurement_id): |
187 def download_preprocessed(self, measurement_id): |
169 """ Download preprocessed files for the measurement id. """ |
188 """ Download preprocessed files for the measurement id. """ |
170 # Construct the download url |
189 # Construct the download url |
171 download_url = self.download_preprocessed_pattern.format(measurement_id) |
190 download_url = self.download_preprocessed_pattern.format(measurement_id) |
172 self.download_files(measurement_id, 'scc_preprocessed', download_url) |
191 self.download_files(measurement_id, 'scc_preprocessed', download_url) |
181 """ Download profile graphs for the measurement id. """ |
200 """ Download profile graphs for the measurement id. """ |
182 # Construct the download url |
201 # Construct the download url |
183 download_url = self.download_graph_pattern.format(measurement_id) |
202 download_url = self.download_graph_pattern.format(measurement_id) |
184 self.download_files(measurement_id, 'scc_plots', download_url) |
203 self.download_files(measurement_id, 'scc_plots', download_url) |
185 |
204 |
186 # TODO: Add download method for other types of files. |
205 def download_elic(self, measurement_id): |
|
206 """ Download profile graphs for the measurement id. """ |
|
207 # Construct the download url |
|
208 download_url = self.download_elic_pattern.format(measurement_id) |
|
209 self.download_files(measurement_id, 'elic', download_url) |
187 |
210 |
188 def rerun_processing(self, measurement_id, monitor=True): |
211 def rerun_processing(self, measurement_id, monitor=True): |
189 measurement, status = self.get_measurement(measurement_id) |
212 measurement, status = self.get_measurement(measurement_id) |
190 |
213 |
191 if measurement: |
214 if measurement: |
262 |
285 |
263 logger.info('Measurement %s found', measurement_id) |
286 logger.info('Measurement %s found', measurement_id) |
264 |
287 |
265 if measurement is not None: |
288 if measurement is not None: |
266 while measurement.is_running: |
289 while measurement.is_running: |
267 logger.info("Measurement is being processed (status: %s, %s, %s). Please wait.", measurement.upload, measurement.pre_processing, measurement.processing) |
290 logger.info("Measurement is being processed. Please wait.") |
268 time.sleep(10) |
291 time.sleep(10) |
269 measurement, status = self.get_measurement(measurement_id) |
292 measurement, status = self.get_measurement(measurement_id) |
270 |
293 |
271 logger.info("Measurement processing finished (status: %s, %s, %s).", measurement.upload, measurement.pre_processing, measurement.processing) |
294 logger.info("Measurement processing finished.") |
272 if measurement.pre_processing == 127: |
295 if measurement.hirelpp == 127: |
|
296 logger.info("Downloading hirelpp files.") |
|
297 self.download_hirelpp(measurement_id) |
|
298 if measurement.cloudmask == 127: |
|
299 logger.info("Downloading cloudmask files.") |
|
300 self.download_cloudmask(measurement_id) |
|
301 if measurement.elpp == 127: |
273 logger.info("Downloading preprocessed files.") |
302 logger.info("Downloading preprocessed files.") |
274 self.download_preprocessed(measurement_id) |
303 self.download_preprocessed(measurement_id) |
275 if measurement.processing == 127: |
304 if measurement.elda == 127: |
276 logger.info("Downloading optical files.") |
305 logger.info("Downloading optical files.") |
277 self.download_optical(measurement_id) |
306 self.download_optical(measurement_id) |
278 logger.info("Downloading graphs.") |
307 logger.info("Downloading graphs.") |
279 self.download_graphs(measurement_id) |
308 self.download_graphs(measurement_id) |
|
309 if measurement.elic == 127: |
|
310 logger.info("Downloading preprocessed files.") |
|
311 self.download_elic(measurement_id) |
280 logger.info("--- Processing finished. ---") |
312 logger.info("--- Processing finished. ---") |
281 return measurement |
313 return measurement |
282 |
314 |
283 def get_measurement(self, measurement_id): |
315 def get_measurement(self, measurement_id): |
284 measurement_url = self.api_measurement_pattern.format(measurement_id) |
316 measurement_url = self.api_measurement_pattern.format(measurement_id) |
448 """ This class represents the measurement object as returned in the SCC API. |
480 """ This class represents the measurement object as returned in the SCC API. |
449 """ |
481 """ |
450 |
482 |
451 @property |
483 @property |
452 def rerun_processing_url(self): |
484 def rerun_processing_url(self): |
453 url_pattern = urlparse.urljoin(self.base_url, 'data_processing/measurements/{0}/rerun-optical/') |
485 url_pattern = urlparse.urljoin(self.base_url, 'data_processing/measurements/{0}/rerun-elda/') |
454 return url_pattern.format(self.id) |
486 return url_pattern.format(self.id) |
455 |
487 |
456 @property |
488 @property |
457 def rerun_all_url(self): |
489 def rerun_all_url(self): |
458 ulr_pattern = urlparse.urljoin(self.base_url, 'data_processing/measurements/{0}/rerun-all/') |
490 ulr_pattern = urlparse.urljoin(self.base_url, 'data_processing/measurements/{0}/rerun-all/') |