diff --git a/ARGO/oceancurrent/argo_oceancurrent.py b/ARGO/oceancurrent/argo_oceancurrent.py index 2ba822af..3c90ecc9 100755 --- a/ARGO/oceancurrent/argo_oceancurrent.py +++ b/ARGO/oceancurrent/argo_oceancurrent.py @@ -5,8 +5,51 @@ # Specify the directory path PROFILES_PATH = "/mnt/oceancurrent/website/profiles/" +CURRENT_METERS_PATH = "/mnt/oceancurrent/website/timeseries/ANMN_P48/" +def parse_filename(filename): + # Extract the part before the extension (if any) + base_name = filename.split('.')[0] + # Split the parts before any underscore (to safely ignore _zt or _xyz suffixes) + main_parts = base_name.split('_')[0] + parts = main_parts.split('-') + + if len(parts) >= 5: # Check there are enough parts to parse + date = parts[1] # Assume the second element is the date + identifier = '-'.join(parts[2:-1]) # Join the identifier parts + nominal_depth = parts[-1] # The last part before _zt or _xyz is the nominal depth + return identifier, nominal_depth, date + return None, None, None + +def scan_subdirectory(subdir_path): + result = [] + if os.path.exists(subdir_path) and os.path.isdir(subdir_path): + for filename in os.listdir(subdir_path): + # Skip HTML files + if filename.endswith('.html'): + continue + identifier, nominal_depth, date = parse_filename(filename) + if identifier and nominal_depth and date: # Ensure all parts were correctly parsed + result.append({ + 'currentMeterIdentifier': identifier, + 'instrumentNominalDepth': nominal_depth, + 'date': date, + 'filename': filename + }) + else: + print("Directory not found or is not a directory:", subdir_path) + return result + +def scan_current_meters(): + result = {} + # Scan each subdirectory in the specified path + for subdir_name in os.listdir(CURRENT_METERS_PATH): + subdir_path = os.path.join(CURRENT_METERS_PATH, subdir_name) + if os.path.isdir(subdir_path): + result[subdir_name] = scan_subdirectory(subdir_path) + return result + def main(): platform_codes = os.listdir(PROFILES_PATH) @@ -49,3 +92,8 @@ def main(): if __name__ == '__main__': main() + data = scan_current_meters() + print("Final result:", json.dumps(data, indent=4)) + # Optionally, write to a file + with open(os.path.join(CURRENT_METERS_PATH, 'current_meters.json'), 'w') as f: + json.dump(data, f, indent=4) diff --git a/ARGO/oceancurrent/test_argo_oceancurrent.py b/ARGO/oceancurrent/test_argo_oceancurrent.py index c3abddd7..7b34abb4 100644 --- a/ARGO/oceancurrent/test_argo_oceancurrent.py +++ b/ARGO/oceancurrent/test_argo_oceancurrent.py @@ -6,6 +6,52 @@ from unittest.mock import patch from argo_oceancurrent import main, PROFILES_PATH +from argo_oceancurrent import scan_current_meters, CURRENT_METERS_PATH + +class TestCurrentMeterScanning(unittest.TestCase): + def setUp(self): + # Create a temporary directory + self.test_dir = tempfile.mkdtemp() + + # Set up a structure for the test + os.makedirs(os.path.join(self.test_dir, 'xyz')) + os.makedirs(os.path.join(self.test_dir, 'zt')) + + # Example test files for 'xyz' and 'zt' directories + self.test_files = { + 'xyz': ["SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.gif", "SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.gif"], + 'zt': ["SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.gif"] + } + + # Create test files in the respective directories + for subdir, files in self.test_files.items(): + for file in files: + with open(os.path.join(self.test_dir, subdir, file), 'w') as f: + f.write("Dummy content") + + def tearDown(self): + # Remove the temporary directory and all its contents + shutil.rmtree(self.test_dir) + + def test_current_meters_scanning(self): + with patch('argo_oceancurrent.CURRENT_METERS_PATH', new=self.test_dir): + # Run the scan_current_meters to generate the results + result = scan_current_meters() + + # Define the expected result based on the test files + expected_result = { + 'xyz': [ + {'currentMeterIdentifier': 'Long-Ranger-Workhorse-ADCP', 'instrumentNominalDepth': '485p8', 'date': '0812', 'filename': 'SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.gif'}, + {'currentMeterIdentifier': 'Long-Ranger-Workhorse-ADCP', 'instrumentNominalDepth': '509p9', 'date': '0902', 'filename': 'SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.gif'} + ], + 'zt': [ + {'currentMeterIdentifier': 'Long-Ranger-Workhorse-ADCP', 'instrumentNominalDepth': '485p8', 'date': '0812', 'filename': 'SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.gif'} + ] + } + + # Check if the results match the expected output + self.assertEqual(result, expected_result, "The scanned output does not match the expected output.") + class TestProfilesJsonGeneration(unittest.TestCase): diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/index.html b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/index.html new file mode 100644 index 00000000..c2f21cc2 --- /dev/null +++ b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/index.html @@ -0,0 +1,12 @@ + SAM1DS +OceanCurrent - Current meters + - Aust + - SA +

SAM1DS

+

layer-average velocity vector scatter plots
+

+

depth-time plots
+

+

Deployment metadata and tidal constituents
+

data download from AODN

+Updated: 17-Aug-2024 19:40:21 diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.gif b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.gif new file mode 100644 index 00000000..4867f4ab Binary files /dev/null and b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.gif differ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.html b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.html new file mode 100644 index 00000000..84aac420 --- /dev/null +++ b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.html @@ -0,0 +1,14 @@ + SAM1DS/xyz + +[PREV] +[NEXT] +[LIST]
+
+

© Copyright 2017, CSIRO Australia
+ +Use of this web site and information available from it is +subject to our
+ + +Legal Notice and Disclaimer

+ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.gif b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.gif new file mode 100644 index 00000000..230dbfd5 Binary files /dev/null and b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.gif differ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.html b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.html new file mode 100644 index 00000000..450255b2 --- /dev/null +++ b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.html @@ -0,0 +1,14 @@ + SAM1DS/xyz + +[PREV] +[NEXT] +[LIST]
+
+

© Copyright 2017, CSIRO Australia
+ +Use of this web site and information available from it is +subject to our
+ + +Legal Notice and Disclaimer

+ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/index.html b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/index.html new file mode 100644 index 00000000..d1af743c --- /dev/null +++ b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/index.html @@ -0,0 +1,15 @@ + SAM1DS/xyz + +[up] [index.html] + +

© Copyright 2017, CSIRO Australia
+ +Use of this web site and information available from it is +subject to our
+ + +Legal Notice and Disclaimer

+ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/latest.gif b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/latest.gif new file mode 100644 index 00000000..230dbfd5 Binary files /dev/null and b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/latest.gif differ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/latest.html b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/latest.html new file mode 100644 index 00000000..450255b2 --- /dev/null +++ b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/xyz/latest.html @@ -0,0 +1,14 @@ + SAM1DS/xyz + +[PREV] +[NEXT] +[LIST]
+
+

© Copyright 2017, CSIRO Australia
+ +Use of this web site and information available from it is +subject to our
+ + +Legal Notice and Disclaimer

+ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.gif b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.gif new file mode 100644 index 00000000..b4be19cf Binary files /dev/null and b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.gif differ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.html b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.html new file mode 100644 index 00000000..e2af7dbe --- /dev/null +++ b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.html @@ -0,0 +1,14 @@ + SAM1DS/zt + +[PREV] +[NEXT] +[LIST]
+
+

© Copyright 2017, CSIRO Australia
+ +Use of this web site and information available from it is +subject to our
+ + +Legal Notice and Disclaimer

+ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.gif b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.gif new file mode 100644 index 00000000..2762a8e4 Binary files /dev/null and b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.gif differ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.html b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.html new file mode 100644 index 00000000..84c19b36 --- /dev/null +++ b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.html @@ -0,0 +1,14 @@ + SAM1DS/zt + +[PREV] +[NEXT] +[LIST]
+
+

© Copyright 2017, CSIRO Australia
+ +Use of this web site and information available from it is +subject to our
+ + +Legal Notice and Disclaimer

+ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/index.html b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/index.html new file mode 100644 index 00000000..84328e15 --- /dev/null +++ b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/index.html @@ -0,0 +1,15 @@ + SAM1DS/zt + +[up] [index.html] + +

© Copyright 2017, CSIRO Australia
+ +Use of this web site and information available from it is +subject to our
+ + +Legal Notice and Disclaimer

+ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/latest.gif b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/latest.gif new file mode 100644 index 00000000..2762a8e4 Binary files /dev/null and b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/latest.gif differ diff --git a/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/latest.html b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/latest.html new file mode 100644 index 00000000..84c19b36 --- /dev/null +++ b/ARGO/oceancurrent/tests/mnt/oceancurrent/website/timeseries/ANMN_P48/SAM1DS/zt/latest.html @@ -0,0 +1,14 @@ + SAM1DS/zt + +[PREV] +[NEXT] +[LIST]
+
+

© Copyright 2017, CSIRO Australia
+ +Use of this web site and information available from it is +subject to our
+ + +Legal Notice and Disclaimer

+