Open Data - SPEs¶
OnsOpenData(ons)
¶
Class used for handling ONS open data. Can be accessed via ons.opendata
.
Parameters:
-
ons
¶Ons
) –Top level object carrying all functionality.
Source code in echo_ons/ons_opendata.py
def __init__(self, ons: e_o.Ons) -> None:
"""Class used for handling ONS open data. Can be accessed via `ons.opendata`.
Parameters
----------
ons : Ons
Top level object carrying all functionality.
"""
super().__init__(ons)
# * subclasses
self.sites = OnsOpenDataSites(ons)
self.spes = OnsOpenDataSpes(ons)
import_database(period, skip_existing=True)
¶
Method to import all open data for a given period.
This currently includes:
- Site definitions
- SPE definitions
- Site limitations
- SPE limitations
Parameters:
-
period
¶DateTimeRange
) –Period to import data for.
-
skip_existing
¶bool
, default:True
) –When importing the definitions of SPEs and Sites, skip those already in the database. If set to False will reset all attributes of the existing objects. By default True.
Returns:
-
ErrorDataSource
–Error summary of the import process.
Source code in echo_ons/ons_opendata.py
def import_database(self, period: DateTimeRange, skip_existing: bool = True) -> ErrorDataSource:
"""Method to import all open data for a given period.
This currently includes:
- Site definitions
- SPE definitions
- Site limitations
- SPE limitations
Parameters
----------
period : DateTimeRange
Period to import data for.
skip_existing : bool, optional
When importing the definitions of SPEs and Sites, skip those already in the database. If set to False will reset all attributes of the existing objects. By default True.
Returns
-------
ErrorDataSource
Error summary of the import process.
"""
# creating error summary
errs = ErrorDataSource(name="ons_open_data")
# first importing SPEs definitions
logger.info("Importing SPEs definitions")
try:
self._ons.opendata.spes.import_database(skip_existing=skip_existing)
except Exception as e:
logger.exception("Error importing SPEs definitions")
errs.add_exception(e)
# then importing Sites definitions
logger.info("Importing Sites definitions")
try:
self._ons.opendata.sites.import_database(skip_existing=skip_existing)
except Exception as e:
logger.exception("Error importing Sites definitions")
errs.add_exception(e)
# then importing Site limitations
logger.info("Importing Site limitations")
try:
self._ons.opendata.sites.limitations.import_database(period=period)
except Exception as e:
logger.exception("Error importing Site limitations")
errs.add_exception(e)
# then importing SPE limitations
logger.info("Importing SPE limitations")
try:
self._ons.opendata.spes.limitations.import_database(period=period)
except Exception as e:
logger.exception("Error importing SPE limitations")
errs.add_exception(e)
return errs