Source code for xerparser.model.predecessors

# PyP6XER
# Copyright (C) 2020, 2021 Hassan Emam <hassan@constology.com>
#
# This file is part of PyP6XER.
#
# PyP6XER library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License v2.1 as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyP6XER is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyP6XER.  If not, see <https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html>.


from xerparser.model.classes.taskpred import TaskPred
# from xerparser.model.classes.task import Task
from typing import List


[docs] class Predecessors: def __init__(self):
[docs] self.index=0
[docs] self.task_pred = []
[docs] def find_by_id(self, code_id) -> TaskPred: obj = list(filter(lambda x: x.task_pred_id == code_id, self.task_pred)) if len(obj) > 0: obj[0] else: obj = None return obj
[docs] def get_tsv(self): tsv = [] if len(self.task_pred) > 0: tsv.append(['%T', 'TASKPRED']) tsv.append(['%F', 'task_pred_id', 'task_id', 'pred_task_id', 'proj_id', 'pred_proj_id', 'pred_type', 'lag_hr_cnt', 'comments', 'float_path', 'aref', 'arls']) for pred in self.task_pred: tsv.append(pred.get_tsv()) return tsv
[docs] def add(self, params): pred = TaskPred(params) self.task_pred.append(pred)
@property
[docs] def relations(self) -> List[TaskPred]: return self.task_pred
@property
[docs] def leads(self): return list(filter(lambda x: x.lag_hr_cnt < 0 if x.lag_hr_cnt else None, self.task_pred))
@property
[docs] def finish_to_start(self) -> List[TaskPred]: return list(filter(lambda x: x.pred_type == 'PR_FS', self.task_pred))
[docs] def get_successors(self, act_id) -> List[TaskPred]: succ = list(filter(lambda x: x.pred_task_id == act_id, self.task_pred)) return succ
[docs] def get_predecessors(self, act_id) -> List[TaskPred]: succ = list(filter(lambda x: x.task_id == act_id, self.task_pred)) return succ
[docs] def count(self): return len(self.task_pred)
[docs] def __len__(self): return len(self.task_pred)
[docs] def __iter__(self): return self
[docs] def __next__(self) -> TaskPred: if self.index >= len(self.task_pred): raise StopIteration idx = self.index self.index += 1 return self.task_pred[idx]