From 4dadae012194d4311cdf31466d74fab221fc0261 Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Fri, 31 Jul 2020 14:54:25 -0400 Subject: [PATCH] Simplifies requirements and removes serialize() --- .gitignore | 2 + .idea/UmiTemplateDB.iml | 22 -- .idea/inspectionProfiles/Project_Default.xml | 39 --- .../inspectionProfiles/profiles_settings.xml | 6 - .idea/misc.xml | 7 - .idea/modules.xml | 8 - .idea/other.xml | 6 - .idea/vcs.xml | 6 - .idea/workspace.xml | 283 ------------------ requirements.txt | 42 +-- tests/test_mongodb_schema.py | 30 +- umitemplatedb/__init__.py | 2 +- umitemplatedb/core.py | 108 +------ 13 files changed, 24 insertions(+), 537 deletions(-) delete mode 100644 .idea/UmiTemplateDB.iml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/other.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore index b6e4761..b97131e 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,5 @@ dmypy.json # Pyre type checker .pyre/ + +.idea/ diff --git a/.idea/UmiTemplateDB.iml b/.idea/UmiTemplateDB.iml deleted file mode 100644 index b2720dd..0000000 --- a/.idea/UmiTemplateDB.iml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 6a19a25..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 87c77df..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 9d0bc29..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/other.xml b/.idea/other.xml deleted file mode 100644 index a708ec7..0000000 --- a/.idea/other.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 9ab6d06..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,283 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1595014505345 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 9aae576..460518c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,35 +1,7 @@ -attrs==19.3.0 -certifi==2020.6.20 -click==7.1.2 -click-plugins==1.1.1 -cligj==0.5.0 -Fiona==1.8.13.post1 -GDAL==3.0.4 -geojson==2.5.0 -geopandas==0.8.1 -importlib-metadata==1.7.0 -mockupdb==1.7.0 -mongoengine==0.20.0 -mongomock==3.19.0 -more-itertools==8.4.0 -munch==2.5.0 -numpy==1.18.1 -olefile==0.46 -packaging==20.4 -pandas==1.0.5 -Pillow==7.0.0 -pluggy==0.13.1 -py==1.9.0 -pycountry==20.7.3 -pymongo==3.10.1 -pyparsing==2.4.7 -pyproj==2.6.1.post1 -pytest==5.4.3 -python-dateutil==2.8.1 -pytz==2020.1 -sentinels==1.0.0 -Shapely==1.7.0 -six==1.15.0 -wcwidth==0.2.5 -zipp==3.1.0 -blinker==1.4 +archetypal +numpy +mongoengine +pycountry +pytest +geojson +mongomock \ No newline at end of file diff --git a/tests/test_mongodb_schema.py b/tests/test_mongodb_schema.py index fcdd3f4..2e317dd 100644 --- a/tests/test_mongodb_schema.py +++ b/tests/test_mongodb_schema.py @@ -5,18 +5,10 @@ import shapely.geometry from archetypal import UmiTemplateLibrary -from umitemplatedb.core import import_umitemplate, serialize +from umitemplatedb.core import import_umitemplate from umitemplatedb.mongodb_schema import * -@pytest.fixture(scope="session") -def db(): - connect("templatelibrary", host="mongomock://localhost") - # connect("templatelibrary") - yield - disconnect() - - def test_save_and_retrieve_building(bldg, window, struct, core): # To filter by an attribute of MetaData, use double underscore """ @@ -71,12 +63,6 @@ def test_filter_by_geo(bldg): assert a_bldg -@pytest.fixture(scope="session") -def imported(db): - path = "tests/test_templates/BostonTemplateLibrary.json" - import_umitemplate(path, Author="Carlos Cerezo", Country="US") - - def test_import_library(db, imported): """Try using recursive""" for bldg in BuildingTemplate.objects(): @@ -97,8 +83,18 @@ def test_serialize_templatelist(bldg, window, struct, core): lib.to_json() -def test_db_to_json(imported): - serialize() +@pytest.fixture(scope="session") +def db(): + connect("templatelibrary", host="mongomock://localhost") + # connect("templatelibrary") + yield + disconnect() + + +@pytest.fixture(scope="session") +def imported(db): + path = "tests/test_templates/BostonTemplateLibrary.json" + import_umitemplate(path, Author="Carlos Cerezo", Country="US") @pytest.fixture() diff --git a/umitemplatedb/__init__.py b/umitemplatedb/__init__.py index c213408..65b7052 100644 --- a/umitemplatedb/__init__.py +++ b/umitemplatedb/__init__.py @@ -1,2 +1,2 @@ -from .core import serialize, import_umitemplate +from .core import import_umitemplate from .mongodb_schema import * diff --git a/umitemplatedb/core.py b/umitemplatedb/core.py index fe641c8..f02acb9 100644 --- a/umitemplatedb/core.py +++ b/umitemplatedb/core.py @@ -1,29 +1,9 @@ -import hashlib -import json - import archetypal -import numpy as np from mongoengine import * from umitemplatedb import mongodb_schema from umitemplatedb.mongodb_schema import ( BuildingTemplate, - GasMaterial, - GlazingMaterial, - OpaqueMaterial, - OpaqueConstruction, - WindowConstruction, - StructureInformation, - DaySchedule, - WeekSchedule, - YearSchedule, - DomesticHotWaterSetting, - VentilationSetting, - ZoneConditioning, - ZoneConstructionSet, - ZoneLoad, - ZoneDefinition, - WindowSetting, ) @@ -125,90 +105,4 @@ def recursive(umibase, **metaattributes): YearTo=YearTo, Polygon=Polygon, Description=Description, - ) - - -class CustomJSONEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, np.bool_): - return bool(obj) - if isinstance(obj, QuerySet): - return [obj.to_json(cls=CustomJSONEncoder) for obj in obj] - return json.JSONEncoder.default(self, obj) - - -class MongoEncoder(json.JSONEncoder): - def default(self, o): - if isinstance(o, Document): - data = o.to_mongo() - _class = data.pop("_cls") - return data - return o.to_json() - - -def serialize(): - data = { - "GasMaterials": [obj.to_json(indent=3) for obj in GasMaterial.objects()], - "GlazingMaterials": [ - obj.to_json(indent=3) for obj in GlazingMaterial.objects() - ], - "OpaqueMaterials": [obj.to_json(indent=3) for obj in OpaqueMaterial.objects()], - "OpaqueConstructions": [ - obj.to_json(indent=3) for obj in OpaqueConstruction.objects() - ], - "WindowConstructions": [ - obj.to_json(indent=3) for obj in WindowConstruction.objects() - ], - "StructureDefinitions": [ - obj.to_json(indent=3) for obj in StructureInformation.objects() - ], - "DaySchedules": [obj.to_json(indent=3) for obj in DaySchedule.objects()], - "WeekSchedules": [obj.to_json(indent=3) for obj in WeekSchedule.objects()], - "YearSchedules": [obj.to_json(indent=3) for obj in YearSchedule.objects()], - "DomesticHotWaterSettings": [ - obj.to_json(indent=3) for obj in DomesticHotWaterSetting.objects() - ], - "VentilationSettings": [ - obj.to_json(indent=3) for obj in VentilationSetting.objects() - ], - "ZoneConditionings": [ - obj.to_json(indent=3) for obj in ZoneConditioning.objects() - ], - "ZoneConstructionSets": [ - obj.to_json(indent=3) for obj in ZoneConstructionSet.objects() - ], - "ZoneLoads": [obj.to_json(indent=3) for obj in ZoneLoad.objects()], - "Zones": [obj.to_json(indent=3) for obj in ZoneDefinition.objects()], - "WindowSettings": [obj.to_json(indent=3) for obj in WindowSetting.objects()], - "BuildingTemplates": [ - obj.to_json(indent=3) for obj in BuildingTemplate.objects().exclude("_cls") - ], - } - - class CustomJSONEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, np.bool_): - return bool(obj) - return obj - - with open("data.json", "w") as outfile: - # create hasher - data_dict = {} - for name, block in data.items(): - data_dict[name] = [json.loads(item) for item in block] - for component in data_dict[name]: - _id = component.pop("_id") # Gets rid of the _id field - _cls = component.pop("_cls") # Gets rid of the _cls field - _name = component["Name"] # Gets the component Name - - hasher = hashlib.md5() - hasher.update(_id.__str__().encode("utf-8")) - component["$id"] = hasher.hexdigest() # re-creates the unique id - for key, value in component.items(): - if isinstance(value, list): - try: - [value.pop("_cls", None) for value in value] - except AttributeError: - pass - response = json.dumps(data_dict, indent=3, cls=CustomJSONEncoder) - outfile.write(response) + ) \ No newline at end of file