From 96d19952e9772dcb9ec044063bb1446d5f14c27c Mon Sep 17 00:00:00 2001 From: Sigma Dimensions <79010126+myoualid@users.noreply.github.com> Date: Thu, 8 Sep 2022 03:15:41 +0100 Subject: [PATCH] Quality check - run black on api/resource --- .../ifcopenshell/api/resource/add_resource.py | 7 ++++++- .../api/resource/assign_resource.py | 11 +++++++--- .../api/resource/calculate_resource_work.py | 20 +++++++++++++------ .../ifcopenshell/api/resource/data.py | 6 +++++- .../api/resource/edit_resource_time.py | 17 +++++++++++++--- .../api/resource/unassign_resource.py | 9 +++++++-- 6 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/resource/add_resource.py b/src/ifcopenshell-python/ifcopenshell/api/resource/add_resource.py index 49fc26bc1a..0dc326f953 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/resource/add_resource.py +++ b/src/ifcopenshell-python/ifcopenshell/api/resource/add_resource.py @@ -50,5 +50,10 @@ class Usecase: ) else: context = self.file.by_type("IfcContext")[0] - ifcopenshell.api.run("project.assign_declaration", self.file, definition=resource, relating_context=context) + ifcopenshell.api.run( + "project.assign_declaration", + self.file, + definition=resource, + relating_context=context, + ) return resource diff --git a/src/ifcopenshell-python/ifcopenshell/api/resource/assign_resource.py b/src/ifcopenshell-python/ifcopenshell/api/resource/assign_resource.py index 4b17e86475..ce1c16433f 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/resource/assign_resource.py +++ b/src/ifcopenshell-python/ifcopenshell/api/resource/assign_resource.py @@ -35,7 +35,8 @@ class Usecase: for assignment in self.settings["related_object"].HasAssignments: if ( assignment.is_a("IfclRelAssignsToResource") - and assignment.RelatingResource == self.settings["relating_resource"] + and assignment.RelatingResource + == self.settings["relating_resource"] ): return @@ -47,13 +48,17 @@ class Usecase: related_objects = list(resource_of.RelatedObjects) related_objects.append(self.settings["related_object"]) resource_of.RelatedObjects = related_objects - ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": resource_of}) + ifcopenshell.api.run( + "owner.update_owner_history", self.file, **{"element": resource_of} + ) else: resource_of = self.file.create_entity( "IfcRelAssignsToResource", **{ "GlobalId": ifcopenshell.guid.new(), - "OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file), + "OwnerHistory": ifcopenshell.api.run( + "owner.create_owner_history", self.file + ), "RelatedObjects": [self.settings["related_object"]], "RelatingResource": self.settings["relating_resource"], } diff --git a/src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_work.py b/src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_work.py index 7040aec456..532da62f3f 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_work.py +++ b/src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_work.py @@ -30,23 +30,31 @@ class Usecase: self.settings[key] = value def execute(self): - self.productivity = ifcopenshell.util.element.get_psets(self.settings["resource"]).get( - "EPset_Productivity", None - ) + self.productivity = ifcopenshell.util.element.get_psets( + self.settings["resource"] + ).get("EPset_Productivity", None) if not self.productivity: return unit_consumed = self.get_unit_consumed() - self.unit_produced_name = self.productivity.get("BaseQuantityProducedName", None) + self.unit_produced_name = self.productivity.get( + "BaseQuantityProducedName", None + ) unit_produced = self.productivity.get("BaseQuantityProducedValue", None) total_produced = self.get_total_produced() if not unit_consumed or not unit_produced or not total_produced: return if not self.settings["resource"].Usage: - ifcopenshell.api.run("resource.add_resource_time", self.file, resource=self.settings["resource"]) + ifcopenshell.api.run( + "resource.add_resource_time", + self.file, + resource=self.settings["resource"], + ) if "T" in self.productivity.get("BaseQuantityConsumed", None): seconds = (unit_consumed.days * 24 * 60 * 60) + unit_consumed.seconds amount_worked = total_produced / unit_produced * seconds - self.settings["resource"].Usage.ScheduleWork = f"PT{amount_worked / 60 / 60}H" + self.settings[ + "resource" + ].Usage.ScheduleWork = f"PT{amount_worked / 60 / 60}H" else: days = unit_consumed.days + (unit_consumed.seconds / (24 * 60 * 60)) amount_worked = total_produced / unit_produced * days diff --git a/src/ifcopenshell-python/ifcopenshell/api/resource/data.py b/src/ifcopenshell-python/ifcopenshell/api/resource/data.py index 442297eca6..36094f8d70 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/resource/data.py +++ b/src/ifcopenshell-python/ifcopenshell/api/resource/data.py @@ -59,7 +59,11 @@ class Data(CostValueTrait): data["ResourceOf"] = [] for rel in resource.ResourceOf: [data["ResourceOf"].append(o.id()) for o in rel.RelatedObjects] - data["HasContext"] = resource.HasContext[0].RelatingContext.id() if resource.HasContext else None + data["HasContext"] = ( + resource.HasContext[0].RelatingContext.id() + if resource.HasContext + else None + ) if resource.Usage: data["Usage"] = data["Usage"].id() data["TotalCostQuantity"] = cls.get_total_quantity(resource) diff --git a/src/ifcopenshell-python/ifcopenshell/api/resource/edit_resource_time.py b/src/ifcopenshell-python/ifcopenshell/api/resource/edit_resource_time.py index e5ea65e3bd..c9290b9839 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/resource/edit_resource_time.py +++ b/src/ifcopenshell-python/ifcopenshell/api/resource/edit_resource_time.py @@ -36,16 +36,27 @@ class Usecase: and "ScheduleFinish" in self.settings["attributes"].keys() ): del self.settings["attributes"]["ScheduleFinish"] - if self.settings["attributes"].get("ActualWork", None) and "ActualFinish" in self.settings["attributes"].keys(): + if ( + self.settings["attributes"].get("ActualWork", None) + and "ActualFinish" in self.settings["attributes"].keys() + ): del self.settings["attributes"]["ActualFinish"] for name, value in self.settings["attributes"].items(): if value: if "Start" in name or "Finish" in name or name == "StatusTime": value = ifcopenshell.util.date.datetime2ifc(value, "IfcDateTime") - elif name == "ScheduleWork" or name == "ActualWork" or name == "RemainingTime": + elif ( + name == "ScheduleWork" + or name == "ActualWork" + or name == "RemainingTime" + ): value = ifcopenshell.util.date.datetime2ifc(value, "IfcDuration") setattr(self.settings["resource_time"], name, value) def get_resource(self): - return [e for e in self.file.get_inverse(self.settings["resource_time"]) if e.is_a("IfcResource")][0] + return [ + e + for e in self.file.get_inverse(self.settings["resource_time"]) + if e.is_a("IfcResource") + ][0] diff --git a/src/ifcopenshell-python/ifcopenshell/api/resource/unassign_resource.py b/src/ifcopenshell-python/ifcopenshell/api/resource/unassign_resource.py index cb89f03227..1cb6525935 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/resource/unassign_resource.py +++ b/src/ifcopenshell-python/ifcopenshell/api/resource/unassign_resource.py @@ -31,12 +31,17 @@ class Usecase: def execute(self): for rel in self.settings["related_object"].HasAssignments or []: - if not rel.is_a("IfcRelAssignsToResource") or rel.RelatingResource != self.settings["relating_resource"]: + if ( + not rel.is_a("IfcRelAssignsToResource") + or rel.RelatingResource != self.settings["relating_resource"] + ): continue if len(rel.RelatedObjects) == 1: return self.file.remove(rel) related_objects = list(rel.RelatedObjects) related_objects.remove(self.settings["related_object"]) rel.RelatedObjects = related_objects - ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel}) + ifcopenshell.api.run( + "owner.update_owner_history", self.file, **{"element": rel} + ) return rel