import importlib # Check if xerparser is already installed try: importlib.import_module('xerparser') print("xerparser is already installed.") except ImportError: try: # Attempt installation %pip install xerparser except Exception as e: print("An error occurred while installing xerparser:", e) import requests url = "https://raw.githubusercontent.com/inigmat/exupery/main/files/schedule/MDL4D.xer" try: response = requests.get(url) if response.status_code == 200: print("Request successful!") else: print(f"Failed to retrieve data. Status code: {response.status_code}") except requests.exceptions.RequestException as e: print(f"An error occurred: {e}") from xerparser import Xer, CorruptXerFile try: xer = Xer(response.text) except CorruptXerFile as e: for error in e.errors: print(error) project = list(xer.projects.values())[0] WBS_LVL = 2 houses = [obj.name for obj in project.wbs_nodes[WBS_LVL:]] NbHouses= len(houses) houses workers = {} for res in project.resources: if res.rsrc_type == "RT_Labor": workers[res.rsrc_id] = res.resource.name NbWorkers = len(workers) import pandas as pd tasks_df = pd.DataFrame(columns=['TASK ID','Name','Type', 'WBS ID', 'Duration', 'Successors (ID, Link, Lag)']) for task in project.tasks: task_sucs = [] for pred_link in task.successors: task_suc = pred_link.task.uid task_link = pred_link.link task_lag = pred_link.lag task_sucs.append((task_suc, task_link, task_lag)) tasks_df = pd.concat([tasks_df, pd.DataFrame( {'TASK ID': [task.uid], 'Name': [task.name], 'Type': [task.type], 'WBS ID': [task.wbs_id], 'Duration': [task.duration], 'Successors (ID, Link, Lag)': [task_sucs], })], ignore_index=True) tasks_df.head(15) def get_task_dict_by_wbs_id(df, wbs_id): filtered_df = df[df['WBS ID'] == wbs_id] task_dict = dict(zip(filtered_df['TASK ID'], filtered_df['Name'])) return task_dict wbs_id = '26154' # wbs_id of activites on House 1 (taken from the dataframe above) task_dict = get_task_dict_by_wbs_id(tasks_df, wbs_id) TaskNames = tuple(task_dict.values()) durations = {task_id: tasks_df.loc[tasks_df['TASK ID'] == task_id, 'Duration'].values[0] for task_id in task_dict.keys()} Duration = list(durations.values()) prec = [] for task in project.tasks: if task.uid in task_dict: for pred_link in task.successors: suc_uid = pred_link.task.uid if suc_uid in task_dict: suc_name = pred_link.task.name prec.append((task.name,suc_name)) Precedences = prec lags = {} for rel in project.relationships: if str(rel.predecessor.type) == 'TaskType.TT_Mile': lags[rel.successor.wbs.name] = rel.lag lags ReleaseDate_dict = {key: lags.get(key) for key in sorted(lags)} ReleaseDate = list(ReleaseDate_dict.values()) print("NbWorkers =", NbWorkers, "\n") print("NbHouses =", NbHouses, "\n") print("TaskNames =", TaskNames, "\n") print("Duration =", Duration, "\n") print("ReleaseDate =", ReleaseDate, "\n") print("Precedences =", Precedences, "\n")