Switched from file looger to stream logger.

This commit is contained in:
Peter Yefi 2023-04-17 17:40:27 -04:00
commit e75bf3a367
18 changed files with 574 additions and 30 deletions

View File

@ -1,16 +1,32 @@
import logging as logger
from pathlib import Path
import os
import logging
import sys
log_dir = (Path(__file__).parent.parent / 'logs').resolve()
log_file = (log_dir / 'hub.log').resolve()
try:
if not os.path.isfile(log_file):
if not os.path.exists(log_dir):
os.mkdir(log_dir)
with open(log_file, 'x'):
pass
logger.basicConfig(filename=log_file, format="%(asctime)s:%(levelname)s:{%(pathname)s:%(funcName)s:%(lineno)d} "
"- %(message)s", level=logger.DEBUG)
except IOError as err:
print(f'I/O exception: {err}')
def get_logger(file_logger=False):
"""
Returns a logging object
:param file_logger: a boolean to indicate the kind of logging
object to return, true (default) means a file logger is required
:return:
"""
log_format = "%(asctime)s:%(levelname)s:{%(pathname)s:%(funcName)s:%(lineno)d} - %(message)s"
if file_logger:
log_dir = (Path(__file__).parent.parent / 'logs').resolve()
log_file = (log_dir / 'hub.log').resolve()
try:
if not os.path.isfile(log_file):
if not os.path.exists(log_dir):
os.mkdir(log_dir)
with open(log_file, 'x'):
pass
logger.basicConfig(filename=log_file, format=log_format, level=logger.DEBUG)
return logger
except IOError as err:
print(f'I/O exception: {err}')
else:
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
logging.getLogger().setLevel(logging.DEBUG)
return logger.getLogger()

View File

@ -7,7 +7,7 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
import datetime
import math
import sys
from hub.hub_logger import logger
from hub.hub_logger import get_logger
import hub.helpers.constants as cte
from hub.catalog_factories.construction_catalog_factory import ConstructionCatalogFactory
@ -17,11 +17,14 @@ from hub.helpers.dictionaries import Dictionaries
from hub.imports.construction.helpers.construction_helper import ConstructionHelper
from hub.imports.construction.helpers.storeys_generation import StoreysGeneration
logger = get_logger()
class NrcanPhysicsParameters:
"""
NrcanPhysicsParameters class
"""
def __init__(self, city, base_path, divide_in_storeys=False):
self._city = city
self._path = base_path
@ -79,7 +82,7 @@ class NrcanPhysicsParameters:
construction_period_limits = building_archetype.construction_period.split('_')
if int(construction_period_limits[0]) <= int(year_of_construction) <= int(construction_period_limits[1]):
if (str(function) == str(building_archetype.function)) and \
(climate_zone == str(building_archetype.climate_zone)):
(climate_zone == str(building_archetype.climate_zone)):
return building_archetype
raise KeyError('archetype not found')

View File

@ -7,7 +7,7 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
"""
import sys
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.catalog_factories.construction_catalog_factory import ConstructionCatalogFactory
from hub.city_model_structure.building_demand.layer import Layer
from hub.city_model_structure.building_demand.material import Material
@ -15,6 +15,8 @@ from hub.helpers.dictionaries import Dictionaries
from hub.imports.construction.helpers.construction_helper import ConstructionHelper
from hub.imports.construction.helpers.storeys_generation import StoreysGeneration
logger = get_logger()
class NrelPhysicsParameters:
"""

View File

@ -7,11 +7,13 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
"""
from pathlib import Path
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type
from hub.imports.construction.nrel_physics_parameters import NrelPhysicsParameters
from hub.imports.construction.nrcan_physics_parameters import NrcanPhysicsParameters
logger = get_logger()
class ConstructionFactory:
"""

View File

@ -9,7 +9,9 @@ from pathlib import Path
from hub.imports.energy_systems.air_source_hp_parameters import AirSourceHeatPumpParameters
from hub.imports.energy_systems.water_to_water_hp_parameters import WaterToWaterHPParameters
from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger
from hub.hub_logger import get_logger
logger = get_logger()
class EnergySystemsFactory:

View File

@ -13,7 +13,9 @@ from hub.imports.geometry.rhino import Rhino
from hub.imports.geometry.gpandas import GPandas
from hub.imports.geometry.geojson import Geojson
from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger
from hub.hub_logger import get_logger
logger = get_logger()
class GeometryFactory:

View File

@ -11,7 +11,9 @@ from hub.imports.life_cycle_assessment.lca_vehicle import LcaVehicle
from hub.imports.life_cycle_assessment.lca_machine import LcaMachine
from hub.imports.life_cycle_assessment.lca_material import LcaMaterial
from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger
from hub.hub_logger import get_logger
logger = get_logger()
class LifeCycleAssessment:

View File

@ -8,11 +8,13 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
from pathlib import Path
from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.imports.results.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from hub.imports.results.insel_monthly_energry_balance import InselMonthlyEnergyBalance
from hub.imports.results.insel_heatpump_energy_demand import InselHeatPumpEnergyDemand
logger = get_logger()
class ResultFactory:
"""

View File

@ -6,9 +6,11 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
from pathlib import Path
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type
logger = get_logger(False)
class SensorsFactory:
"""

View File

@ -8,7 +8,7 @@ import copy
import sys
import numpy
from hub.hub_logger import logger
from hub.hub_logger import get_logger
import hub.helpers.constants as cte
from hub.helpers.dictionaries import Dictionaries
from hub.city_model_structure.building_demand.usage import Usage
@ -21,6 +21,8 @@ from hub.city_model_structure.attributes.schedule import Schedule
from hub.city_model_structure.building_demand.internal_gain import InternalGain
from hub.catalog_factories.usage_catalog_factory import UsageCatalogFactory
logger = get_logger()
class ComnetUsageParameters:
"""

View File

@ -7,7 +7,7 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
import sys
from hub.hub_logger import logger
from hub.hub_logger import get_logger
import hub.helpers.constants as cte
from hub.helpers.dictionaries import Dictionaries
from hub.city_model_structure.building_demand.usage import Usage
@ -18,6 +18,8 @@ from hub.city_model_structure.building_demand.thermal_control import ThermalCont
from hub.city_model_structure.building_demand.domestic_hot_water import DomesticHotWater
from hub.catalog_factories.usage_catalog_factory import UsageCatalogFactory
logger = get_logger()
class NrcanUsageParameters:
"""

View File

@ -9,9 +9,11 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
from pathlib import Path
from hub.imports.usage.comnet_usage_parameters import ComnetUsageParameters
from hub.imports.usage.nrcan_usage_parameters import NrcanUsageParameters
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type
logger = get_logger()
class UsageFactory:
"""

View File

@ -7,9 +7,11 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
from pathlib import Path
from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters
from hub.imports.weather.epw_weather_parameters import EpwWeatherParameters
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type
logger = get_logger()
class WeatherFactory:
"""

View File

@ -106,9 +106,9 @@ class TestExports(TestCase):
path=file_path,
function_to_hub=Dictionaries().alkis_function_to_hub_function).city
self.assertIsNotNone(city, 'city is none')
# EnergyBuildingsExportsFactory('idf', city, self._output_path).export()
# ConstructionFactory('nrcan', city).enrich()
# EnergyBuildingsExportsFactory('idf', city, self._output_path).export()
EnergyBuildingsExportsFactory('idf', city, self._output_path).export()
ConstructionFactory('nrcan', city).enrich()
EnergyBuildingsExportsFactory('idf', city, self._output_path).export()
UsageFactory('nrcan', city).enrich()
try:
EnergyBuildingsExportsFactory('idf', city, self._output_path).export()

View File

@ -0,0 +1,500 @@
{
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"id":61,
"geometry":{
"type":"Polygon",
"coordinates":[
[
[
-73.581331685358023,
45.496339861264602
],
[
-73.581495589151359,
45.496397069022393
],
[
-73.581659493276376,
45.496454276544178
],
[
-73.58168666005416,
45.496412005833101
],
[
-73.581691744107914,
45.496410636233648
],
[
-73.581696828161469,
45.496409266633989
],
[
-73.581710858767352,
45.496387723325341
],
[
-73.581706721781543,
45.496380406051642
],
[
-73.581730842862044,
45.49634227589177
],
[
-73.581701093051677,
45.496332497870313
],
[
-73.581731477738074,
45.496299105409058
],
[
-73.581761862388561,
45.496265712939518
],
[
-73.581774316031783,
45.496272956769531
],
[
-73.581786769678189,
45.4962802005981
],
[
-73.581824431504643,
45.496248169764563
],
[
-73.581837147124517,
45.496247239214689
],
[
-73.581847881702487,
45.49623810260335
],
[
-73.581858616277003,
45.496228965990873
],
[
-73.581857897330806,
45.496224642754363
],
[
-73.581857178384737,
45.49622031951786
],
[
-73.581876413726803,
45.496203960060448
],
[
-73.581895649057742,
45.496187600599789
],
[
-73.581842274513562,
45.49615655823299
],
[
-73.581859500938194,
45.496141905422547
],
[
-73.581856894962897,
45.496140391052457
],
[
-73.581854288987728,
45.496138876682252
],
[
-73.581793615137897,
45.496103529268709
],
[
-73.581785765307259,
45.496099035667939
],
[
-73.581766876804949,
45.496088048593947
],
[
-73.581747988309985,
45.496077061516765
],
[
-73.581747119333016,
45.496077809009442
],
[
-73.581727302588305,
45.496097349810981
],
[
-73.581668357736703,
45.496063076407488
],
[
-73.58160941295661,
45.496028802973363
],
[
-73.581510002221876,
45.495970995968079
],
[
-73.581531317641378,
45.495952587937964
],
[
-73.58145535526792,
45.495909080668568
],
[
-73.581393070223612,
45.495962872768587
],
[
-73.581361517432285,
45.495944799378165
],
[
-73.581299526180459,
45.495998339261185
],
[
-73.581315219340254,
45.496007326533764
],
[
-73.58133091250501,
45.496016313804212
],
[
-73.58115870121425,
45.496165045576909
],
[
-73.581139672628638,
45.496158904160374
],
[
-73.581120644047132,
45.4961527627406
],
[
-73.581106446415831,
45.496165028701654
],
[
-73.581101908525355,
45.496163591272989
],
[
-73.581100605401687,
45.496163178269839
],
[
-73.581099303558815,
45.496162766165654
],
[
-73.581064125009632,
45.496191314400576
],
[
-73.581017766360233,
45.496228935586124
],
[
-73.581024985489066,
45.496230847133859
],
[
-73.581018991176308,
45.496235413596153
],
[
-73.581016246096425,
45.49623949183772
],
[
-73.58110189843822,
45.49626797861545
],
[
-73.581187550866289,
45.496296465328768
],
[
-73.581190053361496,
45.496292756191671
],
[
-73.581331685358023,
45.496339861264602
]
],
[
[
-73.581553299714173,
45.496289653917884
],
[
-73.581399865000748,
45.496238625211241
],
[
-73.581383505132877,
45.496233183812073
],
[
-73.581367145268175,
45.496227742410568
],
[
-73.581369909469274,
45.496223632652359
],
[
-73.581372673670003,
45.49621952289413
],
[
-73.581369166917398,
45.496210000540536
],
[
-73.581365660166014,
45.4962004781868
],
[
-73.581358632345427,
45.496198143597525
],
[
-73.581351604525409,
45.49619580900778
],
[
-73.581379394801772,
45.49616438914606
],
[
-73.581407185047212,
45.496132969277411
],
[
-73.581409515820837,
45.496134416365564
],
[
-73.581435561265749,
45.496104208023915
],
[
-73.581449810838819,
45.496110280811543
],
[
-73.58147816069669,
45.496107624049252
],
[
-73.581486680692677,
45.496097737681239
],
[
-73.581511446963205,
45.496112135516441
],
[
-73.581577646910176,
45.49615110100666
],
[
-73.581643846948523,
45.496190066458105
],
[
-73.581597909083825,
45.49624058954555
],
[
-73.581553299714173,
45.496289653917884
]
]
]
},
"properties":{
"OBJECTID_12":61,
"gml_id":"1065569",
"gml_parent":"fme-gen-5fa2a82b-c38e-4bf0-9e8f-10a47b9f64f7",
"citygml_ta":"http://www.opengis.net/citygml/building/2.0",
"citygml_fe":"cityObjectMember",
"citygml__1":" ",
"citygml__2":" ",
"gml_descri":" ",
"gml_name":" ",
"citygml_cr":" ",
"citygml_te":" ",
"externalRe":" ",
"external_1":" ",
"external_2":" ",
"citygml_ge":" ",
"citygml_re":" ",
"citygml__3":" ",
"citygml_ap":" ",
"citygml_cl":" ",
"citygml__4":" ",
"citygml_fu":" ",
"citygml__5":" ",
"citygml_us":" ",
"citygml__6":" ",
"citygml_ye":" ",
"citygml__7":" ",
"citygml_ro":" ",
"citygml__8":" ",
"citygml_me":31.244,
"citygml__9":"#m",
"citygml_st":" ",
"citygml_10":" ",
"citygml_11":" ",
"citygml_12":" ",
"citygml_13":" ",
"citygml_14":" ",
"citygml_ou":" ",
"citygml_in":" ",
"citygml_bo":" ",
"citygml_le":" ",
"citygml_15":" ",
"citygml_co":" ",
"citygml_ad":" ",
"Volume":"40148.301",
"parcelle":" ",
"OBJECTID":1275,
"gml_id_1":"6f3f99e2-2679-4115-b973-b00e55a86b09",
"gml_pare_1":"1065569",
"citygml_16":"http://www.opengis.net/citygml/building/2.0",
"citygml_17":"boundedBy",
"citygml_18":" ",
"citygml_19":" ",
"gml_desc_1":" ",
"gml_name_1":" ",
"citygml_20":" ",
"citygml_21":" ",
"external_3":" ",
"external_4":" ",
"external_5":" ",
"citygml_22":" ",
"citygml_23":" ",
"citygml_24":" ",
"citygml_25":" ",
"citygml_26":" ",
"citygml_op":" ",
"Area":"1787.549",
"FID_":0,
"Join_Count":1,
"TARGET_FID":1277,
"gml_id_12":"1065569",
"gml_pare_2":"fme-gen-5fa2a82b-c38e-4bf0-9e8f-10a47b9f64f7",
"citygml_27":"http://www.opengis.net/citygml/building/2.0",
"citygml_28":"cityObjectMember",
"citygml_29":" ",
"citygml_30":" ",
"gml_desc_2":" ",
"gml_name_2":" ",
"citygml_31":" ",
"citygml_32":" ",
"external_6":" ",
"external_7":" ",
"external_8":" ",
"citygml_33":" ",
"citygml_34":" ",
"citygml_35":" ",
"citygml_36":" ",
"citygml_37":" ",
"citygml_38":" ",
"citygml_39":" ",
"citygml_40":" ",
"citygml_41":" ",
"citygml_42":" ",
"citygml_43":" ",
"citygml_44":" ",
"citygml_45":" ",
"citygml_46":" ",
"citygml_47":31.244,
"citygml_48":"#m",
"citygml_49":" ",
"citygml_50":" ",
"citygml_51":" ",
"citygml_52":" ",
"citygml_53":" ",
"citygml_54":" ",
"citygml_55":" ",
"citygml_56":" ",
"citygml_57":" ",
"citygml_58":" ",
"citygml_59":" ",
"citygml_60":" ",
"citygml_61":" ",
"Volume_1":"40148.301",
"Field":0,
"Field1":0,
"OBJECTID_1":1275,
"gml_id_12_":"6f3f99e2-2679-4115-b973-b00e55a86b09",
"gml_pare_3":"1065569",
"citygml_62":"http://www.opengis.net/citygml/building/2.0",
"citygml_63":"boundedBy",
"citygml_64":" ",
"citygml_65":" ",
"gml_desc_3":" ",
"gml_name_3":" ",
"citygml_66":" ",
"citygml_67":" ",
"external_9":" ",
"externa_10":" ",
"externa_11":" ",
"citygml_68":" ",
"citygml_69":" ",
"citygml_70":" ",
"citygml_71":" ",
"citygml_72":" ",
"citygml_73":" ",
"Area_1":"1787.549",
"cityGML_hi":0,
"Z_Min":48.349800000000002,
"Z_Max":79.593999999999994,
"Shape_Leng":279.11949200800001,
"ID_UEV":"01002786",
"CIVIQUE_DE":" 1600",
"CIVIQUE_FI":" 1618",
"NOM_RUE":"rue Sherbrooke Ouest (MTL+MTO+WMT)",
"MUNICIPALI":"50",
"ETAGE_HORS":4,
"NOMBRE_LOG":74,
"ANNEE_CONS":1900,
"CODE_UTILI":"1000",
"LIBELLE_UT":"Logement",
"CATEGORIE_":"Régulier",
"MATRICULE8":"9839-45-3087-1-000-0000",
"SUPERFICIE":2239,
"SUPERFIC_1":6828,
"NO_ARROND_":"REM19",
"Shape_Le_1":0.0021498420682500002,
"Shape_Ar_1":2.5776665013299998e-07,
"Z_Min_1":null,
"Z_Max_1":null,
"Shape_Length":279.11949200793288,
"Shape_Area":1746.3879250126859
}
}
]
}

View File

@ -1 +1 @@
__version__ = '0.1.7.10'
__version__ = '0.1.7.11'

View File

@ -24,4 +24,6 @@ geopandas
triangle
psycopg2-binary
Pillow
shapely==2.0.1
shapely==2.0.1
pathlib

View File

@ -80,6 +80,7 @@ setup(
'hub.imports'
],
setup_requires=install_requires,
install_requires=install_requires,
data_files=[
('hub', glob.glob('requirements.txt')),
('hub/config', glob.glob('hub/config/*.ini')),