Ejemplo n.º 1
0
    def _get_status_table():
        status_title = log.format_color(" ".join(["time =", settings.PRECISION, "s(abs)"]).format(Scheduler.time), "green")
        status_data = [["NODE", "STATUS", "QUEUE", "TO", "FOR s(rel)", "UNTIL s(abs)", "LOST", "SENT", "RECEIVED", "COLLIDED"]]

        for node in NODES:
            if node.is_idle():
                status = log.format_evidence("IDLE", "green")
                time_relative = "-"
                time_absolute = "-"
            elif node.is_sending():
                status = log.format_evidence("SENDING", "cyan")
                time_relative = settings.PRECISION.format(node.sending_until-Scheduler.time)
                time_absolute = settings.PRECISION.format(node.sending_until)
            elif node.is_receiving():
                status = log.format_evidence("RECEIVING", "magenta")
                time_relative = settings.PRECISION.format(node.receiving_until-Scheduler.time)
                time_absolute = settings.PRECISION.format(node.receiving_until)

            destinations = []
            for neighbour in node.neighbours:
                destinations.append(neighbour.id)

            queued = []
            for packet in node.queue:
                queued.append(packet.id)

            status_data.append([str(node.id), status, str(queued), str(destinations), time_relative, time_absolute, str(node.packets_lost), str(node.packets_sent), str(node.packets_received), str(node.packets_collided)])

        return AsciiTable(status_data, status_title).table
Ejemplo n.º 2
0
    def _get_heap_table():
        heap_title = log.format_color("events", "green")
        heap_data = [["TIME", "NODE", "PACKET"]]

        ordered_events = heap_read(len(Scheduler.events), Scheduler.events)
        for packet in ordered_events:
            if packet.time == Scheduler.time:
                time = log.format_evidence(settings.PRECISION.format(packet.time), "yellow")
            else:
                time = settings.PRECISION.format(packet.time)

            heap_data.append([time, str(packet.sender), str(packet.id)])

        return AsciiTable(heap_data, heap_title).table