async def _traverse(self, traversal: Traversal, head_terminal: Terminal): traversal.reset() traversal.tracker.visit(head_terminal) await traversal.apply_step_actions(head_terminal, False) traversal.process_queue.extend(get_associated_terminals(head_terminal)) await traversal.trace()
async def find_es_breaker_terminal(es): """ From an EnergySource finds the closest connected Feeder CB (Breaker that is part of a substation). At the moment we assume that all EnergySource's with EnergySourcePhase's will be associated with at least a single feeder circuit breaker, and thus this function given an `EnergySource` will perform a trace that returns the first `zepben.evolve.iec61970.base.core.terminal.Terminal` encountered from that `EnergySource` that belongs to a `Breaker`. This `zepben.evolve.iec61970.base.core.terminal.Terminal` should always be the most downstream `zepben.evolve.iec61970.base.core.terminal.Terminal` on the `Breaker`, and thus can then be used for setting `Direction` downstream and away from this `Breaker`. TODO: check how ES are normally connected to feeder CB's. """ out_terminals = set() async def stop_on_sub_breaker(term, exc=None): if out_terminals: # stop as soon as we find a substation breaker. return True try: if term.conducting_equipment.is_substation_breaker(): out_terminals.add(term) return True except AttributeError: return False return False t = Traversal(queue_next=queue_next_terminal, start_item=es.terminals[0], process_queue=PriorityQueue(), stop_conditions=[stop_on_sub_breaker]) await t.trace() return out_terminals
def current_downstream_trace(queue: Queue = None, **kwargs): """ Create a downstream trace over current phases `queue` Queue to use for this trace. Defaults to a `zepben.evolve.traversals.queue.PriorityQueue` `kwargs` Args to be passed to `zepben.evolve.Traversal` Returns A `zepben.evolve.traversals.Traversal` """ return Traversal(queue_next=_create_downstream_queue_next( currently_open, current_phases), process_queue=queue, **kwargs)
def normal_downstream_trace(queue: Queue = None, **kwargs): """ Create a downstream trace over nominal phases. `queue` Queue to use for this trace. Defaults to a `zepben.evolve.traversals.queue.PriorityQueue` `kwargs` Args to be passed to `zepben.evolve.Traversal` Returns A `zepben.evolve.traversals.Traversal` """ if queue is None: queue = PriorityQueue() return Traversal(queue_next=_create_downstream_queue_next( normally_open, normal_phases), process_queue=queue, **kwargs)
async def _phase_log_trace(cond_equip): log_msg = [] async def log(e, exc): equip_msgs = [] for term in e.terminals: e_msg = f"{e.mrid}-T{term.sequence_number}:" for n in term.phases.single_phases: ps_n = normal_phases(term, n) phase_n_msg = f"n: {ps_n.phase().short_name}:{ps_n.direction().short_name}" ps_c = current_phases(term, n) phase_c_msg = f"c: {ps_c.phase().short_name}:{ps_c.direction().short_name}" e_msg = f"{e_msg} {{core {n}: {phase_n_msg} {phase_c_msg}}}" equip_msgs.append(e_msg) log_msg.append(equip_msgs) trace = Traversal(queue_next=queue_next_equipment, start_item=cond_equip, process_queue=LifoQueue(), step_actions=[log]) await trace.trace() return "\n".join([", ".join(x) for x in log_msg])
def new_trace(open_test: Callable[[ConductingEquipment, Optional[SinglePhaseKind]], bool] = ignore_open): return Traversal(queue_next=queue_next_terminal_if_closed(open_test), process_queue=LifoQueue(), tracker=AssociatedTerminalTracker())
def configure_stop_conditions(traversal: Traversal, feeder_start_points: Set[ConductingEquipment]): traversal.clear_stop_conditions() traversal.add_stop_condition(reached_equipment(feeder_start_points)) traversal.add_stop_condition(reached_substation_transformer)
def create_basic_depth_trace(queue_next: Callable[[T, Set[T]], Iterable[T]]): return Traversal(queue_next, depth_first())