Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This code parse Qs Ranking
- f = open("uni.txt").read().split('\n')
- matriz = []
- def parse(data):
- index = 0
- pos = 0
- uni = 0
- parsed = open('parsed.txt','w')
- while index < len(data)-1:
- pos = data[index]
- if data[index+1][0].isdigit() or data[index+1][0]== '=':
- index += 1
- uni = data[index+1]
- index += 2
- pais = uni.split('More ')[1].replace('\t','')
- uni = uni.split('Logo')[0]
- parsed.write("%s#%s#%s\n" % (pos,uni,pais))
- matriz.append((pos,uni,pais))
- parse(f)
- def count(c1,c2,MIN,MAX):
- p1 = 0
- p2 = 0
- for i in range(MIN,MAX):
- if matriz[i][-1] == c1:
- p1 += 1
- elif matriz[i][-1] == c2:
- p2 += 1
- return {c1:p1,c2:p2}
- def getPaises():
- paises = {}
- computados = []
- for index in range(len(matriz)):
- m = matriz[index]
- p = m[-1]
- if p not in computados:
- computados.append(p)
- paises[p] = [index,index+50]
- return paises
- def compare(c1,c2,dados):
- MIN = min(dados[c1][0],dados[c2][0])
- MAX = max(dados[c1][0],dados[c2][0])
- pc1 = 0
- pc2 = 0
- linha = MIN
- contagem = 0
- while (contagem < 50 or linha < MAX+50) and linha < len(matriz):
- if matriz[linha][-1] == c1:
- pc1 += 1000-linha
- contagem += 1
- elif matriz[linha][-1] == c2:
- pc2 += 1000-linha
- contagem += 1
- linha += 1
- sc1 = pc1
- sc2 = pc2
- print sc1,c1,sc2,c2
- dif = (max(sc1,sc2))/(min(sc1,sc2))
- return ((float('%1.6f'% dif),c1,sc1,c2,sc2))
- def compareAll(c1,dados):
- ranking = []
- for i in dados.keys():
- if c1 != i:
- ranking.append(compare(c1,i,dados))
- ranking.sort()
- return ranking
- def computeLevel():
- paises = getPaises()
- r = compareAll('United States',paises)
- for i in r:
- print i[-2],'-',i[-1]
- computeLevel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement