518 logger.warning("No response received from the SCC when asked for available measurements.") |
518 logger.warning("No response received from the SCC when asked for available measurements.") |
519 measurements = None |
519 measurements = None |
520 |
520 |
521 return measurements |
521 return measurements |
522 |
522 |
523 def list_measurements(self, station=None, system=None, start=None, stop=None, upload_status=None, |
523 def list_measurements(self, id_exact=None, id_startswith=None): |
524 processing_status=None, optical_processing=None): |
|
525 |
524 |
526 # TODO: Change this to work through the API |
525 # TODO: Change this to work through the API |
527 |
526 |
528 # Need to set to empty string if not specified, we won't get any results |
527 # Need to set to empty string if not specified, we won't get any results |
529 params = { |
528 params = {} |
530 "station": station if station is not None else "", |
529 |
531 "system": system if system is not None else "", |
530 if id_exact is not None: |
532 "stop": stop if stop is not None else "", |
531 params['id__exact'] = id_exact |
533 "start": start if start is not None else "", |
532 else: |
534 "upload_status": upload_status if upload_status is not None else "", |
533 params['id__startswith'] = id_startswith |
535 "preprocessing_status": processing_status if processing_status is not None else "", |
534 |
536 "optical_processing_status": optical_processing if optical_processing is not None else "" |
535 response_json = self.session.get(self.api_measurements_url, params=params).text |
537 } |
536 |
538 |
537 return response_json |
539 response_txt = self.session.get(self.list_measurements_url, params=params).text |
|
540 tbl_rgx = re.compile(r'<table id="measurements">(.*?)</table>', re.DOTALL) |
|
541 entry_rgx = re.compile(r'<tr>(.*?)</tr>', re.DOTALL) |
|
542 measurement_rgx = re.compile( |
|
543 r'.*?<td><a[^>]*>(\w+)</a>.*?<td>.*?<td>([\w-]+ [\w:]+)</td>.*<td data-order="([-]?\d+),([-]?\d+),([-]?\d+)".*', |
|
544 re.DOTALL) |
|
545 matches = tbl_rgx.findall(response_txt) |
|
546 if len(matches) != 1: |
|
547 return [] |
|
548 |
|
549 ret = [] |
|
550 for entry in entry_rgx.finditer(matches[0]): |
|
551 m = measurement_rgx.match(entry.string[entry.start(0):entry.end(0)]) |
|
552 if m: |
|
553 name, date, upload, preproc, optical = m.groups() |
|
554 ret.append( |
|
555 Measurement(self.base_url, {"id": name, "upload": int(upload), "pre_processing": int(preproc), |
|
556 "processing": int(optical)})) |
|
557 |
|
558 return ret |
|
559 |
538 |
560 def measurement_id_for_date(self, t1, call_sign, base_number=0): |
539 def measurement_id_for_date(self, t1, call_sign, base_number=0): |
561 """ Give the first available measurement id on the SCC for the specific |
540 """ Give the first available measurement id on the SCC for the specific |
562 date. |
541 date. |
563 """ |
542 """ |
825 logger.info("Rerunning (optical) processing for %s" % m_id) |
804 logger.info("Rerunning (optical) processing for %s" % m_id) |
826 scc.rerun_elpp(m_id, monitor) |
805 scc.rerun_elpp(m_id, monitor) |
827 scc.logout() |
806 scc.logout() |
828 |
807 |
829 |
808 |
830 def list_measurements(settings, station=None, system=None, start=None, stop=None, upload_status=None, |
809 def list_measurements(settings, id_exact=None, id_startswith=None): |
831 preprocessing_status=None, |
|
832 optical_processing=None): |
|
833 """List all available measurements""" |
810 """List all available measurements""" |
834 with SCC(settings['basic_credentials'], settings['output_dir'], settings['base_url']) as scc: |
811 with SCC(settings['basic_credentials'], settings['output_dir'], settings['base_url']) as scc: |
835 scc.login(settings['website_credentials']) |
812 scc.login(settings['website_credentials']) |
836 ret = scc.list_measurements(station=station, system=system, start=start, stop=stop, upload_status=upload_status, |
813 |
837 processing_status=preprocessing_status, optical_processing=optical_processing) |
814 results_json = scc.list_measurements(id_exact=id_exact, id_startswith=id_startswith) |
838 for entry in ret: |
815 print(results_json) |
839 print("%s" % entry.id) |
816 |
840 scc.logout() |
817 scc.logout() |
841 |
818 |
842 |
819 |
843 def download_measurements(measurement_ids, max_retries, exit_if_missing, settings): |
820 def download_measurements(measurement_ids, max_retries, exit_if_missing, settings): |
844 """Download all measurements for the specified IDs""" |
821 """Download all measurements for the specified IDs""" |
940 parser.set_defaults(execute=upload_file_from_args) |
917 parser.set_defaults(execute=upload_file_from_args) |
941 |
918 |
942 |
919 |
943 def setup_list_measurements(parser): |
920 def setup_list_measurements(parser): |
944 def list_measurements_from_args(parsed): |
921 def list_measurements_from_args(parsed): |
945 # TODO: Fix this |
922 list_measurements(parsed.config, id_exact=parsed.id_exact, id_startswith=parsed.id_startswith) |
946 logger.warning("This method needs to be updated. Cross-chceck any results.") |
923 |
947 |
924 group = parser.add_mutually_exclusive_group() |
948 list_measurements(parsed.config, station=parsed.station, system=parsed.system, start=parsed.start, |
925 group.add_argument("--id_exact", help="Exact measurement id.") |
949 stop=parsed.stop, |
926 group.add_argument("--id_startswith", help="Initial part of measurement id.") |
950 upload_status=parsed.upload_status, preprocessing_status=parsed.preprocessing_status, |
927 |
951 optical_processing=parsed.optical_processing_status) |
|
952 |
|
953 def status(arg): |
|
954 if -127 <= int(arg) <= 127: |
|
955 return arg |
|
956 else: |
|
957 raise argparse.ArgumentTypeError("Status must be between -127 and 127") |
|
958 |
|
959 def date(arg): |
|
960 if re.match(r'\d{4}-\d{2}-\d{2}', arg): |
|
961 return arg |
|
962 else: |
|
963 raise argparse.ArgumentTypeError("Date must be in format 'YYYY-MM-DD'") |
|
964 |
|
965 parser.add_argument("--station", help="Filter for only the selected station") |
|
966 parser.add_argument("--system", help="Filter for only the selected station") |
|
967 parser.add_argument("--start", help="Filter for only the selected station", type=date) |
|
968 parser.add_argument("--stop", help="Filter for only the selected station", type=date) |
|
969 parser.add_argument("--upload-status", help="Filter for only the selected station", type=status) |
|
970 parser.add_argument("--preprocessing-status", help="Filter for only the selected station", type=status) |
|
971 parser.add_argument("--optical-processing-status", help="Filter for only the selected station", type=status) |
|
972 parser.set_defaults(execute=list_measurements_from_args) |
928 parser.set_defaults(execute=list_measurements_from_args) |
973 |
929 |
974 |
930 |
975 def setup_download_measurements(parser): |
931 def setup_download_measurements(parser): |
976 def download_measurements_from_args(parsed): |
932 def download_measurements_from_args(parsed): |