replace github nrel with cerc offline nrcan_data
This commit is contained in:
parent
89d0d0eae8
commit
57388a9dc4
@ -8,6 +8,8 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import xmltodict
|
import xmltodict
|
||||||
|
|
||||||
import hub.helpers.constants as cte
|
import hub.helpers.constants as cte
|
||||||
@ -28,12 +30,11 @@ class NrcanCatalog(Catalog):
|
|||||||
Nrcan catalog class
|
Nrcan catalog class
|
||||||
"""
|
"""
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
path = str(path / 'nrcan.xml')
|
self._schedules_path = Path(path / 'nrcan_schedules.json').resolve()
|
||||||
|
self._space_types_path = Path(path / 'nrcan_space_types.json').resolve()
|
||||||
|
self._space_compliance_path = Path(path / 'nrcan_space_compliance_2015.json').resolve()
|
||||||
self._content = None
|
self._content = None
|
||||||
self._schedules = {}
|
self._schedules = {}
|
||||||
with open(path, 'r', encoding='utf-8') as xml:
|
|
||||||
self._metadata = xmltodict.parse(xml.read())
|
|
||||||
self._base_url = self._metadata['nrcan']['@base_url']
|
|
||||||
self._load_schedules()
|
self._load_schedules()
|
||||||
self._content = Content(self._load_archetypes())
|
self._content = Content(self._load_archetypes())
|
||||||
|
|
||||||
@ -55,11 +56,9 @@ class NrcanCatalog(Catalog):
|
|||||||
return Schedule(hub_type, raw['values'], data_type, time_step, time_range, day_types)
|
return Schedule(hub_type, raw['values'], data_type, time_step, time_range, day_types)
|
||||||
|
|
||||||
def _load_schedules(self):
|
def _load_schedules(self):
|
||||||
usage = self._metadata['nrcan']
|
|
||||||
url = f'{self._base_url}{usage["schedules"]}'
|
|
||||||
_schedule_types = []
|
_schedule_types = []
|
||||||
with urllib.request.urlopen(url) as json_file:
|
with open(self._schedules_path, 'r') as f:
|
||||||
schedules_type = json.load(json_file)
|
schedules_type = json.load(f)
|
||||||
for schedule_type in schedules_type['tables']['schedules']['table']:
|
for schedule_type in schedules_type['tables']['schedules']['table']:
|
||||||
schedule = NrcanCatalog._extract_schedule(schedule_type)
|
schedule = NrcanCatalog._extract_schedule(schedule_type)
|
||||||
if schedule_type['name'] not in _schedule_types:
|
if schedule_type['name'] not in _schedule_types:
|
||||||
@ -80,14 +79,11 @@ class NrcanCatalog(Catalog):
|
|||||||
|
|
||||||
def _load_archetypes(self):
|
def _load_archetypes(self):
|
||||||
usages = []
|
usages = []
|
||||||
name = self._metadata['nrcan']
|
with open(self._space_types_path, 'r') as f:
|
||||||
url_1 = f'{self._base_url}{name["space_types"]}'
|
space_types = json.load(f)['tables']['space_types']['table']
|
||||||
url_2 = f'{self._base_url}{name["space_types_compliance"]}'
|
|
||||||
with urllib.request.urlopen(url_1) as json_file:
|
|
||||||
space_types = json.load(json_file)['tables']['space_types']['table']
|
|
||||||
space_types = [st for st in space_types if st['space_type'] == 'WholeBuilding']
|
space_types = [st for st in space_types if st['space_type'] == 'WholeBuilding']
|
||||||
with urllib.request.urlopen(url_2) as json_file:
|
with open(self._space_compliance_path, 'r') as f:
|
||||||
space_types_compliance = json.load(json_file)['tables']['space_compliance']['table']
|
space_types_compliance = json.load(f)['tables']['space_compliance']['table']
|
||||||
space_types_compliance = [st for st in space_types_compliance if st['space_type'] == 'WholeBuilding']
|
space_types_compliance = [st for st in space_types_compliance if st['space_type'] == 'WholeBuilding']
|
||||||
space_types_dictionary = {}
|
space_types_dictionary = {}
|
||||||
for space_type in space_types_compliance:
|
for space_type in space_types_compliance:
|
||||||
|
@ -56,3 +56,10 @@ class UsageCatalogFactory:
|
|||||||
:return: Catalog
|
:return: Catalog
|
||||||
"""
|
"""
|
||||||
return getattr(self, self._catalog_type, lambda: None)
|
return getattr(self, self._catalog_type, lambda: None)
|
||||||
|
@property
|
||||||
|
def catalog_debug(self) -> Catalog:
|
||||||
|
"""
|
||||||
|
Enrich the city given to the class using the class given handler
|
||||||
|
:return: Catalog
|
||||||
|
"""
|
||||||
|
return NrcanCatalog(self._path)
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<nrcan base_url="https://nextgenerations-cities.encs.concordia.ca/gitea/CERC/nrcan_data/raw/branch/main/">
|
|
||||||
<space_types>space_types.json</space_types>
|
|
||||||
<space_types_compliance>space_compliance_2015.json</space_types_compliance>>
|
|
||||||
<schedules>schedules.json</schedules>
|
|
||||||
</nrcan>
|
|
8685
hub/data/usage/nrcan_schedules.json
Normal file
8685
hub/data/usage/nrcan_schedules.json
Normal file
File diff suppressed because it is too large
Load Diff
3211
hub/data/usage/nrcan_space_compliance_2015.json
Normal file
3211
hub/data/usage/nrcan_space_compliance_2015.json
Normal file
File diff suppressed because it is too large
Load Diff
26170
hub/data/usage/nrcan_space_types.json
Normal file
26170
hub/data/usage/nrcan_space_types.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,7 @@ class TestConstructionCatalog(TestCase):
|
|||||||
self.assertEqual(32, len(content.usages), 'Wrong number of usages')
|
self.assertEqual(32, len(content.usages), 'Wrong number of usages')
|
||||||
|
|
||||||
def test_nrcan_catalog(self):
|
def test_nrcan_catalog(self):
|
||||||
catalog = UsageCatalogFactory('nrcan').catalog
|
catalog = UsageCatalogFactory('nrcan').catalog_debug
|
||||||
self.assertIsNotNone(catalog, 'catalog is none')
|
self.assertIsNotNone(catalog, 'catalog is none')
|
||||||
content = catalog.entries()
|
content = catalog.entries()
|
||||||
self.assertEqual(34, len(content.usages), 'Wrong number of usages')
|
self.assertEqual(34, len(content.usages), 'Wrong number of usages')
|
||||||
|
Loading…
Reference in New Issue
Block a user