MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / parse_bar

Method parse_bar

src/ifc4d/ifc4d/pp2ifc.py:121–188  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

119 )
120
121 def parse_bar(self) -> None:
122 bars = self.get_json("BAR")
123 expanded_tasks = {t["BAR"]: t for t in self.get_json("EXPANDED_TASK")}
124 tasks = {t["BAR"]: t for t in self.get_json("TASK")}
125 milestones = {m["BAR"]: m for m in self.get_json("MILESTONE")}
126 expanded_tasks_to_bars: dict[int, int] = {v["ID"]: k for k, v in expanded_tasks.items()}
127
128 wbs_activities: defaultdict[int, list[int]] = defaultdict(list)
129
130 for bar in bars:
131 extra_type = None
132 extra_data = None
133 bar_id: int = bar["ID"]
134
135 if bar_id in expanded_tasks:
136 extra_type = "EXPANDED_TASK"
137 extra_data = expanded_tasks[bar_id]
138 elif bar_id in tasks:
139 extra_type = "TASK"
140 extra_data = tasks[bar_id]
141 elif bar_id in milestones:
142 extra_type = "MILESTONE"
143 extra_data = milestones[bar_id]
144 else:
145 # Not sure where this might be the case
146 continue
147
148 name = bar["NAME"]
149 if extra_data["NAME"]:
150 name += f" - {extra_data['NAME']}"
151
152 parent_task_id = expanded_tasks_to_bars[bar["EXPANDED_TASK"]] if bar["EXPANDED_TASK"] > 0 else None
153 if extra_type == "EXPANDED_TASK":
154 self.wbs[bar_id] = {
155 "Name": name,
156 "Code": bar_id,
157 "ParentObjectId": parent_task_id,
158 "ifc": None,
159 "rel": None,
160 "activities": [],
161 }
162 else:
163 if "PLANNED_DURATION" in extra_data.keys():
164 activity_duration = float(
165 extra_data["PLANNED_DURATION"].split(",")[-2].replace("<", "").replace(">", "")
166 )
167 elif "GIVEN_DURATION" in extra_data.keys():
168 activity_duration = float(
169 extra_data["GIVEN_DURATION"].split(",")[-2].replace("<", "").replace(">", "")
170 )
171 else:
172 activity_duration = 0.0
173
174 self.activities[bar_id] = Activity(
175 Name=name,
176 Identification=bar_id,
177 StartDate=datetime.datetime.fromisoformat(extra_data["LINKABLE_START"]),
178 FinishDate=datetime.datetime.fromisoformat(extra_data["LINKABLE_FINISH"]),

Callers 1

parse_ppMethod · 0.95

Calls 6

get_jsonMethod · 0.95
ActivityClass · 0.85
splitMethod · 0.80
itemsMethod · 0.45
keysMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected