Skip to content

Commit

Permalink
wip new data-mappings approach
Browse files Browse the repository at this point in the history
  • Loading branch information
maaikelimper committed May 16, 2024
1 parent a8f4203 commit 245004d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
9 changes: 6 additions & 3 deletions wis2box-management/wis2box/data_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ def get_data_mappings() -> dict:
continue
if 'data_mappings' not in record['wis2box']:
continue
key = record['wis2box']['topic_hierarchy']
value = record['wis2box']['data_mappings']
value['metadata_id'] = record['id']
data_mappings[key] = value
if 'wmo:topicHierarchy' not in record['properties']:
LOGGER.error(f'No topic hierarchy for {record["id"]}')
continue
value['topic_hierarchy'] = record['properties']['wmo:topicHierarchy']
metadata_id = record['id']
data_mappings[metadata_id] = value
except Exception as err:
msg = f'Issue loading data mappings: {err}'
LOGGER.error(msg)
Expand Down
36 changes: 35 additions & 1 deletion wis2box-management/wis2box/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,51 @@

from wis2box import cli_helpers
from wis2box.data import add_collection
from wis2box.data_mappings import get_data_mappings
from wis2box.metadata.discovery import publish, unpublish

LOGGER = logging.getLogger(__name__)

class Dataset:
def __init__(self, path: Union[Path, str]) -> None:
self.path = str(path)
self.dotpath = None
self.dirpath = None

self.metadata_id = None
self.topic_hierarchy = None

# determine if path matches a metadata_id
for metadata_id, data_mappings in get_data_mappings().items():
if metadata_id in self.path:
self.metadata_id = metadata_id
self.topic_hierarchy = data_mappings['topic_hierarchy']

if self.metadata_id is None:
# otherwise directory represents topic_hierarchy
if not self.path.startswith('origin/a/wis2'):
self.topic_hierarchy = f'origin/a/wis2/{self.path}'
else:
self.topic_hierarchy = self.path
for metadata_id, data_mappings in get_data_mappings().items():
if self.topic_hierarchy == data_mappings['topic_hierarchy']:
self.metadata_id = metadata_id

if '/' in self.path:
LOGGER.debug('Transforming from directory to dotted path')
self.dirpath = self.path
self.dotpath = self.path.replace('/', '.')
elif '.' in self.path:
LOGGER.debug('Transforming from dotted to directory path')
self.dotpath = self.path
self.dirpath = self.path.replace('.', '/')


@click.group()
def dataset():
"""Dataset workflow"""
pass


@click.command('publish')
@click.pass_context
@cli_helpers.ARGUMENT_FILEPATH
Expand Down

0 comments on commit 245004d

Please sign in to comment.