Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Universidade Federal de Minas Gerais
  4. Departamento de Ciência da Computação
  5. Programa de Pós-Graduação em Ciência da Computação
  6.  
  7. Redes sem Fio
  8. Gerador de Gráficos
  9.  
  10. Feito por Gabriel de Biasi, 2016672212.
  11. """
  12. import sys, re
  13. import matplotlib.pyplot as plt
  14.  
  15. def line_to_list(string):
  16. return [float(x) for x in re.findall(r'[+-]?\d+\.*\d*', string)]
  17.  
  18. def on_key(event):
  19. if event.key == 'escape':
  20. exit()
  21.  
  22. if __name__ == '__main__':
  23.  
  24. # Teste de parâmetro.
  25. if len(sys.argv) != 2:
  26. print 'fail'
  27. exit()
  28.  
  29. # Abertura dos arquivos.
  30. data_x1 = []
  31. data_y1 = []
  32. data_x2 = []
  33. data_y2 = []
  34. data_x3 = []
  35. data_y3 = []
  36. data_x4 = []
  37. data_y4 = []
  38.  
  39. with open(sys.argv[1], 'r') as handle:
  40. p1, p2 = data_x1, data_y1
  41. for line in handle:
  42. qq = line_to_list(line)
  43. x = qq[0]
  44. y = qq[1]
  45. if x == -1.0 and y == -1.0:
  46. p1, p2 = data_x2, data_y2
  47. elif x == -2.0 and y == -2.0:
  48. p1, p2 = data_x3, data_y3
  49. elif x == -3.0 and y == -3.0:
  50. p1, p2 = data_x4, data_y4
  51. else:
  52. p1.append(float(x))
  53. p2.append(float(y))
  54.  
  55. figura = plt.figure()
  56. figura.canvas.set_window_title(u'Redes sem Fio')
  57. figura.canvas.mpl_connect('key_press_event', on_key)
  58.  
  59. plt.axvline(x=150, color='k', linestyle='--', linewidth=1.4)
  60. plt.axvline(x=350, color='k', linestyle='--', linewidth=1.4)
  61.  
  62. plt.plot(data_x1, data_y1, 'g', label=u'Clean', markevery=7, marker='o')
  63. plt.errorbar(data_x1, data_y1, [5,5,5], None, 'g', linestyle='None')
  64.  
  65. plt.plot(data_x3, data_y3, 'r', label=u'DDoS', markevery=9, marker='D')
  66. plt.errorbar(data_x3, data_y3, [5,5,5], None, 'r', linestyle='None')
  67.  
  68. plt.plot(data_x2, data_y2, 'b', label=u'Black Hole', markersize=8, markevery=8, marker='^')
  69. plt.errorbar(data_x2, data_y2, [5,5,5], None, 'b', linestyle='None')
  70.  
  71. plt.plot(data_x4, data_y4, 'y', label=u'Overflow', markevery=8, marker='s')
  72. plt.errorbar(data_x4, data_y4, [5,5,5], None, 'y', linestyle='None')
  73.  
  74. plt.legend(loc=3)
  75.  
  76.  
  77. #plt.gca().set_title(u'Result')
  78. #plt.gca().set_aspect('auto')
  79. plt.ylabel(u'Packet Delivery Rate (PDR)')
  80. plt.xlabel(u'Time (s)')
  81. plt.ylim((0,105))
  82. plt.xlim((1, 500))
  83. plt.grid(True)
  84. plt.draw()
  85.  
  86.  
  87. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement