From c2ae8209a1934557c62ccb0290c59f6419989be1 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 09:33:21 -0400 Subject: [PATCH 01/18] Correct link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4944253..e8b3761 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.com/louisleroy5/translater.svg?branch=develop)](https://travis-ci.com/louisleroy5/translater) +[![Build Status](https://travis-ci.com/louisleroy5/translater.svg?token=qpRnYhTVUeLJ5WM1w9Wx&branch=master)](https://travis-ci.com/louisleroy5/translater) [![Coverage Status](https://coveralls.io/repos/github/louisleroy5/translater/badge.svg)](https://coveralls.io/github/louisleroy5/translater) [![Documentation Status](https://readthedocs.org/projects/translater/badge/?version=latest)](https://translater.readthedocs.io/en/latest/?badge=latest) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) From 1c2da3a5f088a64f6dd93e7c59bb7c78cc9b8d9c Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 09:41:52 -0400 Subject: [PATCH 02/18] Try with other spelling --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2a39319..c79aabe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,19 +12,19 @@ jobs: include: - name: Python 3.8 on Xenial Linux python: 3.8 # this works for Linux but is ignored on macOS or Windows - script: py.test --cov=translater --verbose tests/ - after_success: - - coverage report -m - - coveralls + script: pytest --cov=translater --verbose tests/ - name: Python 3.8 on macOS os: osx osx_image: xcode11.2 language: objective-c - script: py.test --cov=translater --verbose tests/ + script: pytest --cov=translater --verbose tests/ - name: "Python 3.8 on Windows" os: windows # Windows 10.0.17134 N/A Build 17134 language: shell # 'language: python' is an error on Travis CI Windows - script: py.test --cov=translater --verbose tests/ + script: pytest --cov=translater --verbose tests/ + after_success: + - coverage report -m + - coveralls - stage: deploy script: echo "Deploying to PyPi and GitHub releases ..." deploy: From 1f24a8228a66a8510d6c5dc22fbb5ca2e8c9edc5 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 11:05:45 -0400 Subject: [PATCH 03/18] Try --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c79aabe..a7e6361 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,9 @@ jobs: - name: Python 3.8 on Xenial Linux python: 3.8 # this works for Linux but is ignored on macOS or Windows script: pytest --cov=translater --verbose tests/ + after_success: + - coverage report -m + - coveralls - name: Python 3.8 on macOS os: osx osx_image: xcode11.2 @@ -22,9 +25,6 @@ jobs: os: windows # Windows 10.0.17134 N/A Build 17134 language: shell # 'language: python' is an error on Travis CI Windows script: pytest --cov=translater --verbose tests/ - after_success: - - coverage report -m - - coveralls - stage: deploy script: echo "Deploying to PyPi and GitHub releases ..." deploy: From c960c066d967dcec1d1ccab692e0ef02a2cb88d7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 11:14:45 -0400 Subject: [PATCH 04/18] New commit --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a7e6361..8f4961d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ jobs: script: pytest --cov=translater --verbose tests/ after_success: - coverage report -m - - coveralls + - coverall - name: Python 3.8 on macOS os: osx osx_image: xcode11.2 From b370aff918cb6210d4e897ca5311a04b9fa82846 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 11:14:59 -0400 Subject: [PATCH 05/18] Correct typo --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8f4961d..a7e6361 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ jobs: script: pytest --cov=translater --verbose tests/ after_success: - coverage report -m - - coverall + - coveralls - name: Python 3.8 on macOS os: osx osx_image: xcode11.2 From e1c997b80bbf77f0ef075c5bc77ea62d278b7647 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 11:44:11 -0400 Subject: [PATCH 06/18] Update badge links --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e8b3761..473456e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Build Status](https://travis-ci.com/louisleroy5/translater.svg?token=qpRnYhTVUeLJ5WM1w9Wx&branch=master)](https://travis-ci.com/louisleroy5/translater) -[![Coverage Status](https://coveralls.io/repos/github/louisleroy5/translater/badge.svg)](https://coveralls.io/github/louisleroy5/translater) +[![Coverage Status](https://coveralls.io/repos/github/louisleroy5/translater/badge.svg?branch=develop&t=PLPFwA)](https://coveralls.io/github/louisleroy5/translater?branch=develop) [![Documentation Status](https://readthedocs.org/projects/translater/badge/?version=latest)](https://translater.readthedocs.io/en/latest/?badge=latest) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) From dfefcd0c53880601d1ef5b62f1e72e3fff29d935 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 11:50:01 -0400 Subject: [PATCH 07/18] Replace "archetypal" by "translater" --- docs/index.rst | 2 +- docs/package_modules.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 24d5390..bfe37d9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -3,7 +3,7 @@ You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. -archetypal |version| +translater |version| ==================== `translater` is a Python package designed with the objective of helping building energy modelers and researchers diff --git a/docs/package_modules.rst b/docs/package_modules.rst index 5418280..82c2bbf 100644 --- a/docs/package_modules.rst +++ b/docs/package_modules.rst @@ -4,7 +4,7 @@ Modules IDF Class --------- -.. currentmodule:: archetypal.idfclass +.. currentmodule:: translater.idfclass .. autosummary:: :template: autosummary.rst From 95bab46cf06ccd1e8e41ebfc8a3bc16f74ef9d13 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 14:22:21 -0400 Subject: [PATCH 08/18] Delete unused tests --- translater/utils.py | 241 +------------------------------------------- 1 file changed, 1 insertion(+), 240 deletions(-) diff --git a/translater/utils.py b/translater/utils.py index dc2d2dd..df32aa6 100644 --- a/translater/utils.py +++ b/translater/utils.py @@ -278,57 +278,13 @@ def make_str(value): return str(value) -def load_umi_template_objects(filename): - """Reads - - Args: - filename (str): path of template file - - Returns: - dict: Dict of umi_objects - """ - with open(filename) as f: - umi_objects = json.load(f) - return umi_objects - - -def umi_template_object_to_dataframe(umi_dict, umi_object): - """Returns flattened DataFrame of umi_objects - - Args: - umi_dict (dict): dict of umi objects - umi_object (str): umi_object name - - Returns: - pandas.DataFrame: flattened DataFrame of umi_objects - """ - return json_normalize(umi_dict[umi_object]) - - -def get_list_of_common_umi_objects(filename): - """Returns list of common umi objects - - Args: - filename (str): path to umi template file - - Returns: - dict: Dict of common umi objects - """ - umi_objects = load_umi_template(filename) - components = OrderedDict() - for umi_dict in umi_objects: - for x in umi_dict: - components[x] = umi_dict[x].columns.tolist() - return components - - def newrange(previous, following): """Takes the previous DataFrame and calculates a new Index range. Returns a DataFrame with a new index Args: previous (pandas.DataFrame): previous DataFrame - following (pandas.DataFrame): follwoing DataFrame + following (pandas.DataFrame): following DataFrame Returns: pandas.DataFrame: DataFrame with an incremented new index @@ -345,170 +301,6 @@ def newrange(previous, following): return following -def type_surface(row): - """Takes a boundary and returns its corresponding umi-type - - Args: - row: - - Returns: - str: The umi-type of boundary - """ - - # Floors - if row["Surface_Type"] == "Floor": - if row["Outside_Boundary_Condition"] == "Surface": - return 3 - if row["Outside_Boundary_Condition"] == "Ground": - return 2 - if row["Outside_Boundary_Condition"] == "Outdoors": - return 4 - else: - return np.NaN - - # Roofs & Ceilings - if row["Surface_Type"] == "Roof": - return 1 - if row["Surface_Type"] == "Ceiling": - return 3 - # Walls - if row["Surface_Type"] == "Wall": - if row["Outside_Boundary_Condition"] == "Surface": - return 5 - if row["Outside_Boundary_Condition"] == "Outdoors": - return 0 - return np.NaN - - -def label_surface(row): - """Takes a boundary and returns its corresponding umi-Category - - Args: - row: - """ - # Floors - if row["Surface_Type"] == "Floor": - if row["Outside_Boundary_Condition"] == "Surface": - return "Interior Floor" - if row["Outside_Boundary_Condition"] == "Ground": - return "Ground Floor" - if row["Outside_Boundary_Condition"] == "Outdoors": - return "Exterior Floor" - else: - return "Other" - - # Roofs & Ceilings - if row["Surface_Type"] == "Roof": - return "Roof" - if row["Surface_Type"] == "Ceiling": - return "Interior Floor" - # Walls - if row["Surface_Type"] == "Wall": - if row["Outside_Boundary_Condition"] == "Surface": - return "Partition" - if row["Outside_Boundary_Condition"] == "Outdoors": - return "Facade" - return "Other" - - -def layer_composition(row): - """Takes in a series with $id and thickness values and return an array of - dict of the form {'Material': {'$ref': ref}, 'thickness': thickness} If - thickness is 'nan', it returns None. - - Returns (list): List of dicts - - Args: - row (pandas.Series): a row - """ - array = [] - ref = row["$id", "Outside_Layer"] - thickness = row["Thickness", "Outside_Layer"] - if np.isnan(ref): - pass - else: - array.append({"Material": {"$ref": str(int(ref))}, "Thickness": thickness}) - for i in range(2, len(row["$id"]) + 1): - ref = row["$id", "Layer_{}".format(i)] - if np.isnan(ref): - pass - else: - thickness = row["Thickness", "Layer_{}".format(i)] - array.append( - {"Material": {"$ref": str(int(ref))}, "Thickness": thickness} - ) - return array - - -def schedule_composition(row): - """Takes in a series with $id and \*_ScheduleDay_Name values and return an - array of dict of the form {'$ref': ref} - - Args: - row (pandas.Series): a row - - Returns: - list: list of dicts - """ - # Assumes 7 days - day_schedules = [] - days = [ - "Monday_ScheduleDay_Name", - "Tuesday_ScheduleDay_Name", - "Wednesday_ScheduleDay_Name", - "Thursday_ScheduleDay_Name", - "Friday_ScheduleDay_Name", - "Saturday_ScheduleDay_Name", - "Sunday_ScheduleDay_Name", - ] # With weekends last (as defined in - # umi-template) - # Let's start with the `Outside_Layer` - for day in days: - try: - ref = row["$id", day] - except: - pass - else: - day_schedules.append({"$ref": str(int(ref))}) - return day_schedules - - -def year_composition(row): - """Takes in a series with $id and ScheduleWeek_Name_{} values and return an - array of dict of the form {'FromDay': fromday, 'FromMonth': frommonth, - 'Schedule': {'$ref': int( ref)}, 'ToDay': today, 'ToMonth': tomonth} - - Args: - row (pandas.Series): a row - - Returns: - list: list of dicts - """ - parts = [] - for i in range(1, 26 + 1): - try: - ref = row["$id", "ScheduleWeek_Name_{}".format(i)] - except: - pass - else: - if ~np.isnan(ref): - fromday = row["Schedules", "Start_Day_{}".format(i)] - frommonth = row["Schedules", "Start_Month_{}".format(i)] - today = row["Schedules", "End_Day_{}".format(i)] - tomonth = row["Schedules", "End_Month_{}".format(i)] - - parts.append( - { - "FromDay": fromday, - "FromMonth": frommonth, - "Schedule": {"$ref": str(int(ref))}, - "ToDay": today, - "ToMonth": tomonth, - } - ) - return parts - - def date_transform(date_str): """Simple function transforming one-based hours (1->24) into zero-based hours (0->23) @@ -790,23 +582,6 @@ def write_lines(file_path, lines): temp_idf_file.close() -def load_umi_template(json_template): - """ - Args: - json_template: Absolute or relative filepath to an umi json_template - - Returns: - pandas.DataFrame: 17 DataFrames, one for each component groups - """ - if os.path.isfile(json_template): - with open(json_template) as f: - dicts = json.load(f, object_pairs_hook=OrderedDict) - - return [{key: json_normalize(value)} for key, value in dicts.items()] - else: - raise ValueError("File {} does not exist".format(json_template)) - - def check_unique_name(first_letters, count, name, unique_list, suffix=False): """Making sure new_name does not already exist @@ -983,20 +758,6 @@ def lcm(x, y): return lcm -def reduce(function, iterable, **attr): - """ - Args: - function: - iterable: - **attr: - """ - it = iter(iterable) - value = next(it) - for element in it: - value = function(value, element, **attr) - return value - - def _unpack_tuple(x): """Unpacks one-element tuples for use as return values From 565c8a4251f94a4cc691a500201c25ddcc0df798 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 15:21:26 -0400 Subject: [PATCH 09/18] Add test for utils --- tests/test_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/test_utils.py diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..9ef2456 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,8 @@ +import pytest + +from translater import utils + + + + + From dfdf384a401e46ab033ee3946770583d00bd2edd Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 15:22:28 -0400 Subject: [PATCH 10/18] Test rotate() increase coverage --- tests/test_utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 9ef2456..38a1279 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,6 +3,16 @@ import pytest from translater import utils +def test_rotate(config): + # Shift list elements to the left + l1 = [1, 2, 3] # list + n = 1 # shift 1 position to the left + l2 = utils.rotate(l1, n) + + assert (l2 == [2, 3, 1]) + + + From 0a1ab1a9a51c3ae21021f43c94ad196f2f6746de Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 15:22:50 -0400 Subject: [PATCH 11/18] Test lcm() Increase coverage --- tests/test_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 38a1279..3fddc92 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -12,6 +12,15 @@ def test_rotate(config): assert (l2 == [2, 3, 1]) +def test_lcm(config): + # This function takes two integers and returns the L.C.M. + x = 10 + y = 50 + lcm = utils.lcm(x, y) + + assert (lcm == 5) + + From 35ce6b4d8ea6d81e20db9700214ac7bf3bdd30d0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 15:25:58 -0400 Subject: [PATCH 12/18] Test timeit() Increase coverage --- tests/test_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 3fddc92..36c855d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,6 +1,6 @@ import pytest -from translater import utils +from translater import utils, timeit def test_rotate(config): @@ -11,7 +11,7 @@ def test_rotate(config): assert (l2 == [2, 3, 1]) - +@timeit def test_lcm(config): # This function takes two integers and returns the L.C.M. x = 10 From 67d4afff553821170bf858bea0ce19f229645d07 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 15:40:32 -0400 Subject: [PATCH 13/18] test float_round() Increase coverage --- tests/test_utils.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 36c855d..5e474f7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,6 +1,8 @@ import pytest +import numpy as np from translater import utils, timeit +from geomeppy.geom.polygons import Polygon3D def test_rotate(config): @@ -9,7 +11,8 @@ def test_rotate(config): n = 1 # shift 1 position to the left l2 = utils.rotate(l1, n) - assert (l2 == [2, 3, 1]) + assert l2 == [2, 3, 1] + @timeit def test_lcm(config): @@ -18,10 +21,16 @@ def test_lcm(config): y = 50 lcm = utils.lcm(x, y) - assert (lcm == 5) - - - + assert lcm == 5 + + +def test_float_round(config): + # Makes sure a variable is a float and round it at "n" decimals + num = 40.24 + n = 1 + float_num = utils.float_round(num, n) + + assert float_num == 40.2 From c71bf29fd7a641f2d1ac1f74ddee9de0298a3e7d Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 15:41:00 -0400 Subject: [PATCH 14/18] Test angle() Increase coverage --- tests/test_utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 5e474f7..dc4257b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -33,4 +33,14 @@ def test_float_round(config): assert float_num == 40.2 +def test_angle(v1, v2, acute=False): + # Calculate the angle between 2 vectors + # Polygon1 & vector1 + poly1 = Polygon3D( + [(215.5, 5.0, 0.5), (215.5, 5.0, 2.0), (217.0, 5.0, 2.0), (217.0, 5.0, 0.5)] + ) + v1 = poly1.normal_vector + v2 = v1 + angle = utils.angle(v1, v2, acute=False) + assert angle == 2 * np.pi From aeb4dc97137f03b52b9ea098170aeea8b04175e7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 15:46:32 -0400 Subject: [PATCH 15/18] Test write_lines() Increase coverage --- tests/test_utils.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index dc4257b..0545861 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,7 +1,9 @@ import pytest +import os + import numpy as np -from translater import utils, timeit +from translater import utils, timeit, settings from geomeppy.geom.polygons import Polygon3D @@ -33,7 +35,7 @@ def test_float_round(config): assert float_num == 40.2 -def test_angle(v1, v2, acute=False): +def test_angle(config): # Calculate the angle between 2 vectors # Polygon1 & vector1 poly1 = Polygon3D( @@ -44,3 +46,12 @@ def test_angle(v1, v2, acute=False): angle = utils.angle(v1, v2, acute=False) assert angle == 2 * np.pi + + +def test_write_lines(config): + # Delete file if exists, then write lines in it + path = settings.data_folder + lines = ["Test to write lines in file", "2nd line", "end of document"] + utils.write_lines(path, lines) + + assert os.path.exists(path) From 681f08b39378daadf82b3570359128b8f3e165df Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 15:51:58 -0400 Subject: [PATCH 16/18] Test date_transform() Increase coverage --- tests/test_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 0545861..d06bcb4 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -55,3 +55,11 @@ def test_write_lines(config): utils.write_lines(path, lines) assert os.path.exists(path) + + +def test_date_transform(config): + # Simple function transforming one-based hours (1->24) into zero-based hours (0->23) + date_str = "08:10" + new_date = utils.date_transform(date_str) + + assert new_date == "07:10" From 8b1803e1b824a688fd7d5b2aea598d6b45c858cc Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 16:06:41 -0400 Subject: [PATCH 17/18] Correct bugs and assertions --- tests/test_utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index d06bcb4..7053f66 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -5,6 +5,7 @@ import numpy as np from translater import utils, timeit, settings from geomeppy.geom.polygons import Polygon3D +from datetime import datetime def test_rotate(config): @@ -15,15 +16,14 @@ def test_rotate(config): assert l2 == [2, 3, 1] - @timeit -def test_lcm(config): +def test_lcm(): # This function takes two integers and returns the L.C.M. x = 10 y = 50 lcm = utils.lcm(x, y) - assert lcm == 5 + assert lcm == 50 def test_float_round(config): @@ -50,7 +50,7 @@ def test_angle(config): def test_write_lines(config): # Delete file if exists, then write lines in it - path = settings.data_folder + path = os.path.join(settings.data_folder, "write_lines.txt") lines = ["Test to write lines in file", "2nd line", "end of document"] utils.write_lines(path, lines) @@ -62,4 +62,4 @@ def test_date_transform(config): date_str = "08:10" new_date = utils.date_transform(date_str) - assert new_date == "07:10" + assert new_date == datetime(1900, 1, 1, 7, 10) From 71e6cc4f1d86c15cd90e9799a485884ba17c6eba Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 24 Jun 2020 17:25:08 -0400 Subject: [PATCH 18/18] Bump to version 1.0.3 --- translater/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translater/__init__.py b/translater/__init__.py index 0a29483..84d67ed 100644 --- a/translater/__init__.py +++ b/translater/__init__.py @@ -6,7 +6,7 @@ ################################################################################ # Version of the package -__version__ = "1.0.2" +__version__ = "1.0.3" # warn if a newer version of translater is available from outdated import warn_if_outdated