Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. import csv
  2. import os
  3. import matplotlib.pyplot as plt
  4.  
  5. maior_sub = []
  6.  
  7.  
  8. prob = ['0.01/', '0.110000/', '0.210000/', '0.310000/', '0.410000/', '0.510000/', '0.610000/', '0.710000/', '0.810000/', '0.910000/']
  9.  
  10.  
  11. def format_n(string):
  12. aux_str = ""
  13. for i in range(len(string)):
  14. if i > 4 and i < (len(string) - 4):
  15. aux_str += string[i]
  16.  
  17. return aux_str
  18.  
  19.  
  20. def format_prob(string):
  21. return string[:-1]
  22.  
  23.  
  24. def sort_prob(dic):
  25. new_dic = {}
  26. for key, value in sorted(dic.items()):
  27. print(key, value)
  28. new_dic.update({key: value})
  29.  
  30. return new_dic
  31.  
  32.  
  33. def main():
  34.  
  35. for j in range(10):
  36. dir = "/home/tiago/Desktop/MEI/Assigment1/data/output1/bubble/"+prob[j]
  37. arr = sorted(os.listdir(dir))
  38.  
  39. print(">>> prob: " + str(format_prob(prob[j])))
  40. plot_x = []
  41. plot_y = []
  42. prob_dic = {}
  43.  
  44. for i in range(10):
  45.  
  46. file = dir + arr[i]
  47.  
  48. with open(file) as csv_file:
  49. line = 0
  50. data = csv.reader(csv_file)
  51. for row in data:
  52. line += 1
  53. if line == 4:
  54. #print("N: " + str(format_n(arr[i])))
  55. #print(row)
  56. prob_dic.update({int(format_n(arr[i])): int(row[0])})
  57.  
  58. prob_dic = sort_prob(prob_dic)
  59.  
  60. #print(prob_dic)
  61. print(prob_dic.keys())
  62. print(prob_dic.values())
  63.  
  64. plt.plot(prob_dic.keys(), prob_dic.values())
  65. plt.title("Gráfico de sub-sequencia maior com prob: " + str(format_prob(prob[j])))
  66. plt.show()
  67.  
  68.  
  69. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement