From d8de61037c36696873edc46382923875f58eb7fa Mon Sep 17 00:00:00 2001 From: shoulinwei Date: Sun, 25 Dec 2022 19:50:34 +0800 Subject: [PATCH] hstdm --- README.md | 1 - csst_dfs_api/common/__init__.py | 1 + csst_dfs_api/facility/level0.py | 9 +++ csst_dfs_api/hstdm/__init__.py | 2 + csst_dfs_api/hstdm/level1.py | 79 ++++++++++++++++++++++++++ csst_dfs_api/hstdm/level1prc.py | 51 +++++++++++++++++ csst_dfs_api/msc/level1.py | 9 +++ csst_dfs_api/sls/level1.py | 9 +++ tests/facility/test_facility_level0.py | 4 ++ tests/hstdm/test_hstdm_level1.py | 40 +++++++++++++ tests/hstdm/test_hstdm_level1_prc.py | 26 +++++++++ 11 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 csst_dfs_api/hstdm/level1.py create mode 100644 csst_dfs_api/hstdm/level1prc.py create mode 100644 tests/hstdm/test_hstdm_level1.py create mode 100644 tests/hstdm/test_hstdm_level1_prc.py diff --git a/README.md b/README.md index 0886627..a2e45b1 100644 --- a/README.md +++ b/README.md @@ -28,4 +28,3 @@ enviroment variables - CSST_DFS_API_MODE = local or cluster # default: local - CSST_LOCAL_FILE_ROOT = [a local file directory] # required if DFS_API_MODE = local, default: /opt/temp/csst - CSST_DFS_GATEWAY = [gateway server's address] # required if DFS_API_MODE = cluster -wsl123 \ No newline at end of file diff --git a/csst_dfs_api/common/__init__.py b/csst_dfs_api/common/__init__.py index e69de29..a45b30a 100644 --- a/csst_dfs_api/common/__init__.py +++ b/csst_dfs_api/common/__init__.py @@ -0,0 +1 @@ +from .catalog import CatalogApi \ No newline at end of file diff --git a/csst_dfs_api/facility/level0.py b/csst_dfs_api/facility/level0.py index 0ca2cf8..7d6b08a 100644 --- a/csst_dfs_api/facility/level0.py +++ b/csst_dfs_api/facility/level0.py @@ -31,6 +31,15 @@ class Level0DataApi(object): ''' return self.stub.find(**kwargs) + def find_by_brick_ids(self, **kwargs): + ''' retrieve level0 records by brick_ids like [1,2,3,4] + + :param kwargs: Parameter dictionary, key items support: + brick_ids: [list] + :returns: csst_dfs_common.models.Result + ''' + return self.stub.find_by_brick_ids(**kwargs) + def get(self, **kwargs): ''' fetch a record from database diff --git a/csst_dfs_api/hstdm/__init__.py b/csst_dfs_api/hstdm/__init__.py index e69de29..d4f4fff 100644 --- a/csst_dfs_api/hstdm/__init__.py +++ b/csst_dfs_api/hstdm/__init__.py @@ -0,0 +1,2 @@ +from .level1 import Level1DataApi +from .level1prc import Level1PrcApi \ No newline at end of file diff --git a/csst_dfs_api/hstdm/level1.py b/csst_dfs_api/hstdm/level1.py new file mode 100644 index 0000000..73fd572 --- /dev/null +++ b/csst_dfs_api/hstdm/level1.py @@ -0,0 +1,79 @@ + +from ..common.delegate import Delegate + +class Level1DataApi(object): + """ + IFS Level1 Data Operation Class + """ + def __init__(self): + self.pymodule = Delegate().load(sub_module = "hstdm") + self.stub = getattr(self.pymodule, "Level1DataApi")() + + def find(self, **kwargs): + ''' retrieve level1 records from database + + :param kwargs: Parameter dictionary, key items support: + level0_id: [str], + data_type: [str], + create_time : (start, end), + qc1_status : [int], + prc_status : [int], + filename: [str] + limit: limits returns the number of records,default 0:no-limit + + :returns: csst_dfs_common.models.Result + ''' + return self.stub.find(**kwargs) + + def get(self, **kwargs): + ''' fetch a record from database + + :param kwargs: Parameter dictionary, key items support: + id : [int] + + :returns: csst_dfs_common.models.Result + ''' + return self.stub.get(**kwargs) + + + def update_proc_status(self, **kwargs): + ''' update the status of reduction + + :param kwargs: Parameter dictionary, key items support: + id = [int], + status = [int] + + :returns: csst_dfs_common.models.Result + ''' + return self.stub.update_proc_status(**kwargs) + + def update_qc1_status(self, **kwargs): + ''' update the status of QC0 + + :param kwargs: Parameter dictionary, key items support: + id = [int], + status = [int] + + :returns: csst_dfs_common.models.Result + ''' + return self.stub.update_qc1_status(**kwargs) + + def write(self, **kwargs): + ''' insert a level1 record into database + + :param kwargs: Parameter dictionary, key items support: + level0_id : [str] + data_type : [str] + cor_sci_id : [int] + prc_params : [str] + filename : [str] + file_path : [str] + prc_status : [int] + prc_time : [str] + pipeline_id : [str] + refs: [dict] + + :returns: csst_dfs_common.models.Result + ''' + return self.stub.write(**kwargs) + diff --git a/csst_dfs_api/hstdm/level1prc.py b/csst_dfs_api/hstdm/level1prc.py new file mode 100644 index 0000000..5f801e2 --- /dev/null +++ b/csst_dfs_api/hstdm/level1prc.py @@ -0,0 +1,51 @@ + +from ..common.delegate import Delegate + +class Level1PrcApi(object): + """ + Level 0 Data Operation API + """ + def __init__(self): + self.pymodule = Delegate().load(sub_module = "mci") + self.stub = getattr(self.pymodule, "Level1PrcApi")() + + def find(self, **kwargs): + ''' retrieve level1 procedure records from database + + :param kwargs: Parameter dictionary, key items support: + level1_id: [int] + pipeline_id: [str] + prc_module: [str] + prc_status : [int] + + :returns: csst_dfs_common.models.Result + ''' + return self.stub.find(**kwargs) + + def update_proc_status(self, **kwargs): + ''' update the status of reduction + + :param kwargs: Parameter dictionary, key items support: + id : [int], + status : [int] + + :returns: csst_dfs_common.models.Result + ''' + return self.stub.update_proc_status(**kwargs) + + def write(self, **kwargs): + ''' insert a level1 procedure record into database + + :param kwargs: Parameter dictionary, key items support: + level1_id : [int] + pipeline_id : [str] + prc_module : [str] + params_file_path : [str] + prc_status : [int] + prc_time : [str] + result_file_path : [str] + + :returns: csst_dfs_common.models.Result + ''' + return self.stub.write(**kwargs) + diff --git a/csst_dfs_api/msc/level1.py b/csst_dfs_api/msc/level1.py index 3d3cbeb..3e2ac71 100644 --- a/csst_dfs_api/msc/level1.py +++ b/csst_dfs_api/msc/level1.py @@ -25,6 +25,15 @@ class Level1DataApi(object): ''' return self.stub.find(**kwargs) + def find_by_brick_ids(self, **kwargs): + ''' retrieve level1 records by brick_ids like [1,2,3,4] + + :param kwargs: Parameter dictionary, key items support: + brick_ids: [list] + :returns: csst_dfs_common.models.Result + ''' + return self.stub.find_by_brick_ids(**kwargs) + def get(self, **kwargs): ''' fetch a record from database diff --git a/csst_dfs_api/sls/level1.py b/csst_dfs_api/sls/level1.py index 6105840..71aa208 100644 --- a/csst_dfs_api/sls/level1.py +++ b/csst_dfs_api/sls/level1.py @@ -24,6 +24,15 @@ class Level1DataApi(object): :returns: csst_dfs_common.models.Result ''' return self.stub.find(**kwargs) + + def find_by_brick_ids(self, **kwargs): + ''' retrieve level1 records by brick_ids like [1,2,3,4] + + :param kwargs: Parameter dictionary, key items support: + brick_ids: [list] + :returns: csst_dfs_common.models.Result + ''' + return self.stub.find_by_brick_ids(**kwargs) def find_by_prc_status(self, **kwargs): ''' retrieve level1 records from database diff --git a/tests/facility/test_facility_level0.py b/tests/facility/test_facility_level0.py index 456f187..9b190aa 100644 --- a/tests/facility/test_facility_level0.py +++ b/tests/facility/test_facility_level0.py @@ -11,6 +11,10 @@ class Level0DataTestCase(unittest.TestCase): recs = self.api.find(obs_id = '0000011', obs_type = 'sci', limit = 0) print('find:', recs) + def test_find_by_brick_ids(self): + recs = self.api.find_by_brick_ids(brick_ids = [1,2,3,4]) + print('find:', recs) + def test_get(self): rec = self.api.get(id = 3) print('get:', rec) diff --git a/tests/hstdm/test_hstdm_level1.py b/tests/hstdm/test_hstdm_level1.py new file mode 100644 index 0000000..c85d46e --- /dev/null +++ b/tests/hstdm/test_hstdm_level1.py @@ -0,0 +1,40 @@ +import unittest + +from csst_dfs_api.hstdm import Level1DataApi + +class HSTDMLevel1TestCase(unittest.TestCase): + + def setUp(self): + self.api = Level1DataApi() + + def test_find(self): + recs = self.api.find( + level0_id='50002981600', + create_time = ("2021-06-01 11:12:13","2021-06-08 11:12:13") + ) + print('find:', recs) + + def test_get(self): + rec = self.api.get(id = 1) + print('get:', rec) + + def test_update_proc_status(self): + rec = self.api.update_proc_status(id = 1, status = 4) + print('update_proc_status:', rec) + + def test_update_qc1_status(self): + rec = self.api.update_qc1_status(id = 1, status = 7) + print('update_qc1_status:', rec) + + def test_write(self): + rec = self.api.write( + level0_id='50002981600', + data_type = "sci", + prc_params = "/opt/dddasd.params", + prc_status = 3, + prc_time = '2021-10-22 11:12:13', + filename = "MSC_MS_210525121500_100000001_09_raw", + file_path = "/opt/temp/csst/MSC_MS_210525121500_100000001_09_raw.fits", + pipeline_id = "P2", + refs = {'dark': 1, 'bias': 2, 'flat': 3 }) + print('write:', rec) \ No newline at end of file diff --git a/tests/hstdm/test_hstdm_level1_prc.py b/tests/hstdm/test_hstdm_level1_prc.py new file mode 100644 index 0000000..9d10551 --- /dev/null +++ b/tests/hstdm/test_hstdm_level1_prc.py @@ -0,0 +1,26 @@ +import unittest + +from csst_dfs_api.hstdm.level1prc import Level1PrcApi + +class HSTDMLevel1PrcTestCase(unittest.TestCase): + + def setUp(self): + self.api = Level1PrcApi() + + def test_find(self): + recs = self.api.find(level1_id=1) + print('find:', recs) + + def test_update_proc_status(self): + rec = self.api.update_proc_status(id = 1, status = 4) + print('update_proc_status:', rec) + + def test_write(self): + rec = self.api.write(level1_id=1, + pipeline_id = "P1", + prc_module = "QC0", + params_file_path = "/opt/dddasd.params", + prc_status = 3, + prc_time = '2021-06-04 11:12:13', + result_file_path = "/opt/dddasd.header") + print('write:', rec) \ No newline at end of file -- GitLab