mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-18 11:20:21 +00:00
Run black on utils
This commit is contained in:
+18
-14
@@ -9,23 +9,26 @@ from ifc4d.pp2ifc import PP2Ifc
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser .add_argument('-f','--file', action='store', type=str,
|
||||
required=True, help="schedule file name to be parsed")
|
||||
parser .add_argument('-s','--schedule', action='store', required=True,
|
||||
type=str, help='file format as xer, p6xml, mspxml, pp')
|
||||
parser .add_argument('-i', '--ifcfile', action='store', required=False,
|
||||
type=str, help='ifc file name as string e.g. \"file.ifc\"')
|
||||
parser .add_argument('-o', '--output', action='store', required=True,
|
||||
type=str, help='ifc file name as string e.g. \"file.ifc\"')
|
||||
args = parser .parse_args()
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-f", "--file", action="store", type=str, required=True, help="schedule file name to be parsed")
|
||||
parser.add_argument(
|
||||
"-s", "--schedule", action="store", required=True, type=str, help="file format as xer, p6xml, mspxml, pp"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i", "--ifcfile", action="store", required=False, type=str, help='ifc file name as string e.g. "file.ifc"'
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o", "--output", action="store", required=True, type=str, help='ifc file name as string e.g. "file.ifc"'
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
def get_file():
|
||||
ifcfile = None
|
||||
if args.ifcfile:
|
||||
ifcfile = ifcopenshell.open(args.ifcfile)
|
||||
elif args.output:
|
||||
ifc = ifcopenshell.file(schema='IFC4')
|
||||
ifc = ifcopenshell.file(schema="IFC4")
|
||||
ifc.create_entity("IfcWorkPlan")
|
||||
ifc.create_entity("IfcProject")
|
||||
ifc.write(args.output)
|
||||
@@ -34,6 +37,7 @@ def get_file():
|
||||
ifcfile = None
|
||||
return ifcfile
|
||||
|
||||
|
||||
if not args.ifcfile:
|
||||
print("You need to provide an ifc file to add schedule")
|
||||
print("Examples python ifc4d -i model.ifc -s xer -f schedule.xer -o newifc.ifc")
|
||||
@@ -41,7 +45,7 @@ elif not args.output:
|
||||
print("an output file is required to save changes")
|
||||
print("python ifc4d -o newfile.ifc -s xer -f schedule.xer")
|
||||
|
||||
elif args.schedule== "xer":
|
||||
elif args.schedule == "xer":
|
||||
p6xer = P6XER2Ifc()
|
||||
p6xer.xer = args.file
|
||||
p6xer.output = args.output
|
||||
@@ -49,7 +53,8 @@ elif args.schedule== "xer":
|
||||
if ifcfile:
|
||||
p6xer.file = ifcfile
|
||||
p6xer.execute()
|
||||
else: raise Exception("No files provided for output")
|
||||
else:
|
||||
raise Exception("No files provided for output")
|
||||
elif args.schedule == "mspxml":
|
||||
msp = MSP2Ifc()
|
||||
msp.xml = args.file()
|
||||
@@ -76,4 +81,3 @@ elif args.schedule == "pp":
|
||||
pp.execute()
|
||||
else:
|
||||
print("schedule type you selected is not implemented at the moment")
|
||||
|
||||
|
||||
@@ -246,12 +246,11 @@ class ScheduleIfcGenerator:
|
||||
"ScheduleStart": activity["StartDate"],
|
||||
"ScheduleFinish": activity["FinishDate"],
|
||||
"DurationType": "WORKTIME" if activity["PlannedDuration"] else None,
|
||||
"ScheduleDuration": timedelta(
|
||||
days=float(activity["PlannedDuration"]) / float(calendar["HoursPerDay"] or 8)
|
||||
)
|
||||
or None
|
||||
if activity["PlannedDuration"]
|
||||
else None,
|
||||
"ScheduleDuration": (
|
||||
timedelta(days=float(activity["PlannedDuration"]) / float(calendar["HoursPerDay"] or 8)) or None
|
||||
if activity["PlannedDuration"]
|
||||
else None
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -86,12 +86,36 @@ class Csv2Ifc:
|
||||
|
||||
task_relationships = self.parse_task_rel(row[self.headers["Relationships"]])
|
||||
|
||||
scheduled_start_date = ifcopenshell.util.date.string_to_date(row[self.headers["ScheduleStart"]]) if row[self.headers["ScheduleStart"]] else None
|
||||
scheduled_finish_date = ifcopenshell.util.date.string_to_date(row[self.headers["ScheduleFinish"]]) if row[self.headers["ScheduleFinish"]] else None
|
||||
scheduled_duration = ifcopenshell.util.date.string_to_duration(row[self.headers["ScheduleDuration"]]) if row[self.headers["ScheduleDuration"]] else None
|
||||
actual_start_date = ifcopenshell.util.date.string_to_date(row[self.headers["ActualStart"]]) if row[self.headers["ActualStart"]] else None
|
||||
actual_finish_date = ifcopenshell.util.date.string_to_date(row[self.headers["ActualFinish"]]) if row[self.headers["ActualFinish"]] else None
|
||||
actual_duration = ifcopenshell.util.date.string_to_duration(row[self.headers["ActualDuration"]]) if row[self.headers["ActualDuration"]] else None
|
||||
scheduled_start_date = (
|
||||
ifcopenshell.util.date.string_to_date(row[self.headers["ScheduleStart"]])
|
||||
if row[self.headers["ScheduleStart"]]
|
||||
else None
|
||||
)
|
||||
scheduled_finish_date = (
|
||||
ifcopenshell.util.date.string_to_date(row[self.headers["ScheduleFinish"]])
|
||||
if row[self.headers["ScheduleFinish"]]
|
||||
else None
|
||||
)
|
||||
scheduled_duration = (
|
||||
ifcopenshell.util.date.string_to_duration(row[self.headers["ScheduleDuration"]])
|
||||
if row[self.headers["ScheduleDuration"]]
|
||||
else None
|
||||
)
|
||||
actual_start_date = (
|
||||
ifcopenshell.util.date.string_to_date(row[self.headers["ActualStart"]])
|
||||
if row[self.headers["ActualStart"]]
|
||||
else None
|
||||
)
|
||||
actual_finish_date = (
|
||||
ifcopenshell.util.date.string_to_date(row[self.headers["ActualFinish"]])
|
||||
if row[self.headers["ActualFinish"]]
|
||||
else None
|
||||
)
|
||||
actual_duration = (
|
||||
ifcopenshell.util.date.string_to_duration(row[self.headers["ActualDuration"]])
|
||||
if row[self.headers["ActualDuration"]]
|
||||
else None
|
||||
)
|
||||
|
||||
return {
|
||||
"Hierarchy": hierarchy,
|
||||
@@ -191,7 +215,7 @@ class Csv2Ifc:
|
||||
self.file,
|
||||
related_process=task_2,
|
||||
relating_process=task_1,
|
||||
sequence_type = rel_type,
|
||||
sequence_type=rel_type,
|
||||
)
|
||||
if rel_type:
|
||||
ifcopenshell.api.run(
|
||||
|
||||
@@ -46,9 +46,9 @@ class Ifc2P6:
|
||||
self.root = ET.Element("APIBusinessObjects")
|
||||
self.root.attrib["xmlns"] = "http://xmlns.oracle.com/Primavera/P6Professional/V18.8/API/BusinessObjects"
|
||||
self.root.attrib["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance"
|
||||
self.root.attrib[
|
||||
"xsi:schemaLocation"
|
||||
] = "http://xmlns.oracle.com/Primavera/P6Professional/V18.8/API/BusinessObjects http://xmlns.oracle.com/Primavera/P6Professional/V18.8/API/p6apibo.xsd"
|
||||
self.root.attrib["xsi:schemaLocation"] = (
|
||||
"http://xmlns.oracle.com/Primavera/P6Professional/V18.8/API/BusinessObjects http://xmlns.oracle.com/Primavera/P6Professional/V18.8/API/p6apibo.xsd"
|
||||
)
|
||||
|
||||
self.schedule = self.file.by_type("IfcWorkSchedule")[0]
|
||||
|
||||
|
||||
+37
-29
@@ -112,13 +112,12 @@ class MSP2Ifc:
|
||||
# If first column = "all" then retrieve all columns
|
||||
if len(self.optionalColumns) and self.optionalColumns[0] == "all":
|
||||
self.optionalColumns = [child.tag.split("}")[1] for child in task]
|
||||
|
||||
|
||||
for column in self.optionalColumns:
|
||||
if not self.tasks[task_id].get(column):
|
||||
self.tasks[task_id][column] = task.find(f"pr:{column}", self.ns).text if task.find(f"pr:{column}", self.ns) else None
|
||||
|
||||
|
||||
|
||||
self.tasks[task_id][column] = (
|
||||
task.find(f"pr:{column}", self.ns).text if task.find(f"pr:{column}", self.ns) else None
|
||||
)
|
||||
|
||||
def parse_calendar_xml(self, project):
|
||||
def parse_working_times(day):
|
||||
@@ -139,27 +138,37 @@ class MSP2Ifc:
|
||||
work_times = parse_working_times(exception)
|
||||
time_period = exception.find("pr:TimePeriod", self.ns)
|
||||
data = {
|
||||
"Name": exception.find("pr:Name", self.ns).text
|
||||
if exception.find("pr:Name", self.ns) is not None
|
||||
else None,
|
||||
"FromDate": datetime.datetime.fromisoformat(time_period.find("pr:FromDate", self.ns).text)
|
||||
if time_period is not None
|
||||
else None,
|
||||
"ToDate": datetime.datetime.fromisoformat(time_period.find("pr:ToDate", self.ns).text)
|
||||
if time_period is not None
|
||||
else None,
|
||||
"Occurrences": int(exception.find("pr:Occurrences", self.ns).text)
|
||||
if exception.find("pr:Occurrences", self.ns) is not None
|
||||
else None,
|
||||
"Month": exception.find("pr:Month", self.ns).text
|
||||
if exception.find("pr:Month", self.ns) is not None
|
||||
else None,
|
||||
"MonthDay": exception.find("pr:MonthDay", self.ns).text
|
||||
if exception.find("pr:MonthDay", self.ns) is not None
|
||||
else None,
|
||||
"Type": exception.find("pr:Type", self.ns).text
|
||||
if exception.find("pr:Type", self.ns) is not None
|
||||
else None,
|
||||
"Name": (
|
||||
exception.find("pr:Name", self.ns).text if exception.find("pr:Name", self.ns) is not None else None
|
||||
),
|
||||
"FromDate": (
|
||||
datetime.datetime.fromisoformat(time_period.find("pr:FromDate", self.ns).text)
|
||||
if time_period is not None
|
||||
else None
|
||||
),
|
||||
"ToDate": (
|
||||
datetime.datetime.fromisoformat(time_period.find("pr:ToDate", self.ns).text)
|
||||
if time_period is not None
|
||||
else None
|
||||
),
|
||||
"Occurrences": (
|
||||
int(exception.find("pr:Occurrences", self.ns).text)
|
||||
if exception.find("pr:Occurrences", self.ns) is not None
|
||||
else None
|
||||
),
|
||||
"Month": (
|
||||
exception.find("pr:Month", self.ns).text
|
||||
if exception.find("pr:Month", self.ns) is not None
|
||||
else None
|
||||
),
|
||||
"MonthDay": (
|
||||
exception.find("pr:MonthDay", self.ns).text
|
||||
if exception.find("pr:MonthDay", self.ns) is not None
|
||||
else None
|
||||
),
|
||||
"Type": (
|
||||
exception.find("pr:Type", self.ns).text if exception.find("pr:Type", self.ns) is not None else None
|
||||
),
|
||||
"WorkingTimes": work_times,
|
||||
"ifc": None,
|
||||
}
|
||||
@@ -283,16 +292,15 @@ class MSP2Ifc:
|
||||
for subtask_id in task["subtasks"]:
|
||||
self.create_task(self.tasks[subtask_id], parent_task=task)
|
||||
|
||||
|
||||
# create pset for optional columns
|
||||
if len(self.optionalColumns):
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=task["ifc"] , name="Pset_MSP_Task")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=task["ifc"], name="Pset_MSP_Task")
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties= {name: str(task[name]) for name in self.optionalColumns if task[name]}
|
||||
properties={name: str(task[name]) for name in self.optionalColumns if task[name]},
|
||||
)
|
||||
|
||||
def process_working_week(self, week, calendar):
|
||||
|
||||
@@ -62,6 +62,7 @@ class AstaCalendarWorkPattern:
|
||||
if wp["DayOfWeek"] == days[lang][index]:
|
||||
wp["DayOfWeek"] = days["en"][index]
|
||||
return
|
||||
|
||||
translate_days(self.Days, self.dict_wp[-1])
|
||||
|
||||
for day in self.Days["en"]:
|
||||
|
||||
Reference in New Issue
Block a user