Advertisement
Guest User

codigo

a guest
Jun 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #This code parse Qs Ranking
  2.  
  3. f = open("uni.txt").read().split('\n')
  4. matriz = []
  5.  
  6. def parse(data):
  7. index = 0
  8. pos = 0
  9. uni = 0
  10. parsed = open('parsed.txt','w')
  11. while index < len(data)-1:
  12. pos = data[index]
  13. if data[index+1][0].isdigit() or data[index+1][0]== '=':
  14. index += 1
  15. uni = data[index+1]
  16. index += 2
  17. pais = uni.split('More ')[1].replace('\t','')
  18. uni = uni.split('Logo')[0]
  19. parsed.write("%s#%s#%s\n" % (pos,uni,pais))
  20. matriz.append((pos,uni,pais))
  21.  
  22. parse(f)
  23.  
  24. def count(c1,c2,MIN,MAX):
  25. p1 = 0
  26. p2 = 0
  27. for i in range(MIN,MAX):
  28. if matriz[i][-1] == c1:
  29. p1 += 1
  30. elif matriz[i][-1] == c2:
  31. p2 += 1
  32.  
  33. return {c1:p1,c2:p2}
  34.  
  35.  
  36. def getPaises():
  37. paises = {}
  38. computados = []
  39.  
  40. for index in range(len(matriz)):
  41. m = matriz[index]
  42. p = m[-1]
  43. if p not in computados:
  44. computados.append(p)
  45. paises[p] = [index,index+50]
  46. return paises
  47.  
  48. def compare(c1,c2,dados):
  49. MIN = min(dados[c1][0],dados[c2][0])
  50. MAX = max(dados[c1][0],dados[c2][0])
  51. pc1 = 0
  52. pc2 = 0
  53. linha = MIN
  54. contagem = 0
  55. while (contagem < 50 or linha < MAX+50) and linha < len(matriz):
  56. if matriz[linha][-1] == c1:
  57. pc1 += 1000-linha
  58. contagem += 1
  59. elif matriz[linha][-1] == c2:
  60. pc2 += 1000-linha
  61. contagem += 1
  62. linha += 1
  63. sc1 = pc1
  64. sc2 = pc2
  65. print sc1,c1,sc2,c2
  66.  
  67. dif = (max(sc1,sc2))/(min(sc1,sc2))
  68.  
  69. return ((float('%1.6f'% dif),c1,sc1,c2,sc2))
  70.  
  71. def compareAll(c1,dados):
  72. ranking = []
  73. for i in dados.keys():
  74. if c1 != i:
  75. ranking.append(compare(c1,i,dados))
  76. ranking.sort()
  77. return ranking
  78.  
  79. def computeLevel():
  80. paises = getPaises()
  81. r = compareAll('United States',paises)
  82. for i in r:
  83. print i[-2],'-',i[-1]
  84.  
  85.  
  86. computeLevel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement