In [139]:
import pandas as pd
from itertools import combinations
from pprint import pprint
import operator
divers = pd.read_csv("teams.csv", index_col='name')
divers
Out[139]:
Adam, Andrea, Chiara and Elena have pretty much decided on Dimar. If you don't want to delete them, comment out this line:
In [140]:
allDivers = divers.copy()
divers = divers.drop(divers.index[[2, 10, 13, 14]])
In [144]:
tierra = divers[divers['tierra'] == 1]
dimar = allDivers[allDivers['dimar'] == 1]
datatre = divers[divers['datatre'] == 1]
sella = divers[divers['sella'] == 1]
In [145]:
tierra
Out[145]:
In [146]:
dimar
Out[146]:
In [147]:
datatre
Out[147]:
In [148]:
sella
Out[148]:
In [156]:
def computeScores(teamDF, howManyToPrint=10):
ranking = []
combs = combinations(teamDF.T, 5)
#define scores given to a second diver of the kind
skillscores = {'dev': 0.5, 'ds': 0.5, 'design': 0.2}
for comb in combs:
skillset = {'dev': 0, 'ds': 0, 'design': 0}
score = 0
for name in comb:
for skill in ('dev', 'ds', 'design'):
if allDivers.ix[name][skill] == 1:
#add skill to the team's skillset
skillset[skill] += 1
#first skill of its kind is better than the next
if skillset[skill] == 1:
score += 1
else:
score += skillscores[skill]
#penalty for not having one of the skills
for skill in skillset:
if skillset[skill] == 0:
score -= 1
#penalty for the difference between the number of the most well represented skill and the next one being greater than 1(e.g. if there are 4 devs and 1 data scientist)
sortedSkillset = sorted(skillset.items(), key=operator.itemgetter(1))
if (sortedSkillset[2][1] - sortedSkillset[1][1]) > 1:
score -= 1
ranking.append({'score': score, 'skillset': skillset, 'names': comb})
import pprint
for team in (sorted(ranking, key=lambda x: -1*x['score']))[:howManyToPrint]:
pprint.pprint(team)
In [157]:
computeScores(tierra)
In [158]:
computeScores(dimar)
In [159]:
computeScores(datatre, 20)
In [160]:
computeScores(sella, 20)
In [ ]: