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
def __str__(self): lines = ["", log.format_color("- PACKET {} -".format(self.id), "cyan"), "sender = {}".format(self.sender), " ".join(["schedule time =", settings.PRECISION, "s(abs)"]).format(self.time), " ".join(["transfer time =", settings.PRECISION, "s(rel)"]).format(self.transfer_time), "size = {} byte".format(self.size), "status = {}".format("QUEUED" if self.is_queued else "PENDING")] return "\n".join(lines)
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
def handle_results(): if settings.FOLDER: file_total = open(settings.FOLDER+"\\total.csv", "a") file_nodes = open(settings.FOLDER+"\\nodes.csv", "a") results_title = log.format_color("results", "green") results_data = [["NODE", "THROUGHPUT (kB/s)", "COLLISION RATE (%)", "LOSS RATE (%)"]] loss_rate_total = 0 collision_rate_total = 0 throughput_total = 0 avarage_load = ((settings.UNIFORM_MAX-settings.UNIFORM_MIN)/2) / (settings.GAMMA_SHAPE*settings.GAMMA_SCALE) # mean of the size of each single packet divided by the mean of the inter arrival time for node in NODES: throughput = node.data_sent/nlargest(1, Scheduler.events)[0].time throughput_total += throughput loss_rate = node.packets_lost/node.packets_generated loss_rate_total += loss_rate try: collision_rate = node.packets_collided/(node.packets_received+node.packets_collided) except ZeroDivisionError: collision_rate = 0 collision_rate_total += collision_rate line = [str(node.id), settings.PRECISION.format(throughput/1000), settings.PRECISION.format(collision_rate*100), settings.PRECISION.format(loss_rate*100)] results_data.append(line) if settings.FOLDER: file_nodes.write(",".join([str(node.id), settings.PRECISION.format(settings.GAMMA_SCALE), settings.PRECISION.format(throughput), settings.PRECISION.format(avarage_load), settings.PRECISION.format(collision_rate*100), settings.PRECISION.format(loss_rate*100)])) file_nodes.write("\n") line = ["MEAN", settings.PRECISION.format(throughput_total/1000/len(NODES)), settings.PRECISION.format(collision_rate_total/len(NODES)*100), settings.PRECISION.format(loss_rate_total/len(NODES)*100)] results_data.append(line) if settings.FOLDER: file_total.write(",".join([settings.PRECISION.format(settings.GAMMA_SCALE), settings.PRECISION.format(throughput_total/len(NODES)), settings.PRECISION.format(avarage_load), settings.PRECISION.format(collision_rate_total/len(NODES)*100), settings.PRECISION.format(loss_rate_total/len(NODES)*100)])) file_total.write("\n") if not settings.QUIET: print("\n") print(AsciiTable(results_data, results_title).table) print("\n") print(" ".join(["SYSTEM THROUGHPUT (kB/s) =", settings.PRECISION.format(throughput_total/1000)])) if settings.FOLDER: file_nodes.close() file_total.close()