Skip to content

Commit

Permalink
Add icons for DataFetcher properties in repr
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaze committed Oct 2, 2024
1 parent 253e3bb commit 146e53f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 27 deletions.
12 changes: 7 additions & 5 deletions argopy/data_fetchers/argovis_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@


class ArgovisDataFetcher(ArgoDataFetcherProto):
data_source = "argovis"

###
# Methods to be customised for a specific Argovis request
###
Expand Down Expand Up @@ -127,17 +129,17 @@ def __init__(

def __repr__(self):
summary = ["<datafetcher.argovis>"]
summary.append("Name: %s" % self.definition)
summary.append("API: %s" % api_server)
summary.append(self._repr_data_source)
summary.append(self._repr_access_point)
summary.append(self._repr_server)
api_key = self.fs.fs.client_kwargs["headers"]["x-argokey"]
if api_key == DEFAULT["argovis_api_key"]:
summary.append(
"API KEY: '%s' (get a free key at https://argovis-keygen.colorado.edu)"
"🗝 API KEY: '%s' (get a free key at https://argovis-keygen.colorado.edu)"
% api_key
)
else:
summary.append("API KEY: '%s'" % api_key)
summary.append("Domain: %s" % format_oneline(self.cname()))
summary.append("🗝 API KEY: '%s'" % api_key)
return "\n".join(summary)

def _add_history(self, this, txt):
Expand Down
11 changes: 6 additions & 5 deletions argopy/data_fetchers/erddap_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ErddapArgoDataFetcher(ArgoDataFetcherProto):
This class is a prototype not meant to be instantiated directly
"""
data_source = "erddap"

###
# Methods to be customised for a specific erddap request
Expand Down Expand Up @@ -232,13 +233,13 @@ def __init__( # noqa: C901

def __repr__(self):
summary = ["<datafetcher.erddap>"]
summary.append("Name: %s" % self.definition)
summary.append("API: %s" % self.server)
summary.append("Domain: %s" % format_oneline(self.cname()))
summary.append(self._repr_data_source)
summary.append(self._repr_access_point)
summary.append(self._repr_server)
if self.dataset_id in ["bgc", "bgc-s"]:
summary.append("Parameters: %s" % self._bgc_vlist_params)
summary.append("📗 Parameters: %s" % self._bgc_vlist_params)
summary.append(
"BGC 'must be measured' parameters: %s" % self._bgc_vlist_measured
"📕 BGC 'must be measured' parameters: %s" % self._bgc_vlist_measured
)
return "\n".join(summary)

Expand Down
20 changes: 9 additions & 11 deletions argopy/data_fetchers/gdac_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class GDACArgoDataFetcher(ArgoDataFetcherProto):
This class is a prototype not meant to be instantiated directly
"""
data_source = "gdac"


###
# Methods to be customised for a specific request
Expand Down Expand Up @@ -138,25 +140,21 @@ def __init__(

def __repr__(self):
summary = ["<datafetcher.gdac>"]
summary.append("Name: %s" % self.definition)
summary.append("Index: %s" % self.indexfs.index_file)
summary.append("Server: %s" % self.server)
if hasattr(self, "BOX"):
summary.append("Domain: %s" % self.cname())
else:
summary.append("Domain: %s" % format_oneline(self.cname()))
summary.append(self._repr_data_source)
summary.append(self._repr_access_point)
summary.append(self._repr_server)
if hasattr(self.indexfs, "index"):
summary.append("Index loaded: True (%i records)" % self.N_RECORDS)
summary.append("📗 Index: %s (%i records)" % (self.indexfs.index_file, self.N_RECORDS))
else:
summary.append("Index loaded: False")
summary.append("📕 Index: %s (not loaded)" % self.indexfs.index_file)
if hasattr(self.indexfs, "search"):
match = "matches" if self.N_FILES > 1 else "match"
summary.append(
"Index searched: True (%i %s, %0.4f%%)"
"📸 Index searched: True (%i %s, %0.4f%%)"
% (self.N_FILES, match, self.N_FILES * 100 / self.N_RECORDS)
)
else:
summary.append("Index searched: False")
summary.append("📷 Index searched: False")
return "\n".join(summary)

def cname(self):
Expand Down
36 changes: 35 additions & 1 deletion argopy/data_fetchers/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
from ..plot import dashboard
from ..utils.lists import list_standard_variables, list_bgc_s_variables
from ..utils.format import UriCName
from ..utils.format import UriCName, format_oneline


log = logging.getLogger("argopy.fetcher.proto")
Expand Down Expand Up @@ -120,3 +120,37 @@ def dashboard(self, **kw):
return dashboard(wmo=self.WMO[0], **kw)
else:
warnings.warn("Dashboard only available for a single float or profile request")

@property
def _icon_access_point(self):
if self.WMO is not None:
if self.CYC is not None:
return "⚓"
else:
return "🤖"
else:
return "🗺"

@property
def _icon_data_source(self):
if self.data_source == 'erddap':
return "⭐"
if self.data_source == 'gdac':
return "🌐"
if self.data_source == 'argovis':
return "👁"

@property
def _repr_access_point(self):
if hasattr(self, "BOX"):
return "%s Domain: %s" % (self._icon_access_point, self.cname())
else:
return "%s Domain: %s" % (self._icon_access_point, format_oneline(self.cname()))

@property
def _repr_server(self):
return "🔗 API: %s" % self.server

@property
def _repr_data_source(self):
return "%s Name: %s" % (self._icon_data_source, self.definition)
51 changes: 46 additions & 5 deletions argopy/fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,24 @@ def __init__(self, mode: str = "", src: str = "", ds: str = "", **fetcher_kwargs
version="v0.0.17",
)

def __repr__(self):
@property
def _icon_user_mode(self):
if self._mode == "standard":
return "🏊"
elif self._mode == "research":
return "🚣"
elif self._mode == "expert":
return "🏄"

@property
def _icon_dataset(self):
if self._dataset_id in ['bgc', 'bgc-s']:
return "🟢"
elif self._dataset_id in ['phy']:
return "🟡+🔵"

@property
def _icon_performances(self):
para = (
self.fetcher_options["parallel"]
if "parallel" in self.fetcher_options
Expand All @@ -185,18 +202,42 @@ def __repr__(self):
cache = (
self.fetcher_options["cache"] if "cache" in self.fetcher_options else False
)
if not para and not cache:
return "🪫"
else:
return "🔋"

@property
def _repr_user_mode(self):
return "%s User mode: %s" % (self._icon_user_mode, self._mode)

@property
def _repr_dataset(self):
return "%s Dataset: %s" % (self._icon_dataset, self._dataset_id)

@property
def _repr_performances(self):
para = (
self.fetcher_options["parallel"]
if "parallel" in self.fetcher_options
else False
)
cache = (
self.fetcher_options["cache"] if "cache" in self.fetcher_options else False
)
return "%s Performances: cache=%s, parallel=%s" % (self._icon_performances, str(cache), str(para))

def __repr__(self):
if self.fetcher:
summary = [self.fetcher.__repr__()]
else:
summary = ["<datafetcher.%s> 'No access point initialised'" % self._src]
summary.append(
"Available access points: %s" % ", ".join(self.Fetchers.keys())
)

summary.append("Performances: cache=%s, parallel=%s" % (str(cache), str(para)))
summary.append("User mode: %s" % self._mode)
summary.append("Dataset: %s" % self._dataset_id)
summary.append(self._repr_user_mode)
summary.append(self._repr_dataset)
summary.append(self._repr_performances)
return "\n".join(summary)

def __getattr__(self, key):
Expand Down

0 comments on commit 146e53f

Please sign in to comment.