import pandas as pd
import numpy as np
from IPython.display import HTML 

"""
Explanation: <div style="background-color: #262626"> 
    <img src='logos/pyconx.png' width='50%' />
</div>
End of explanation
"""


rankings = pd.read_csv('./ranking_pyconx.txt', sep='~', skiprows=1, header=0)
rankings.drop('TID', axis=1, inplace=True)
rankings.drop('Duration', axis=1, inplace=True)

union_jack = '\U0001F1EC\U0001F1E7'
tricolore = '\U0001F1EE\U0001F1F9'
female = '\U0001f469\u200d\U0001f3a4'
male = '\U0001f468\u200d\U0001f3a4'

rankings.Gender = rankings.Gender.apply(lambda g: '+'.join(female if l=='female' else male 
                                         for l in g.split('+')))
rankings.Lang = rankings.Lang.apply(lambda l: union_jack if l=='en' else tricolore)
pd.set_option('display.max_rows', rankings.index.size)
pd.set_option('display.max_colwidth', 300)

rankings.index = np.arange(1, rankings.index.size+1)

HTML(rankings.to_html())

trainings = rankings[rankings['Type'].values == 'Training']
talks = rankings[rankings['Type'].values == 'Talk']

# Drop cols
trainings = trainings.drop('Type', axis=1)
talks = talks.drop('Type', axis=1)

"""
Explanation: <a name="absolute_rank"></a>
Community Voting Results
Absolute Ranking
End of explanation
"""


from collections import defaultdict
speakers = defaultdict(set)

for i, speaker in enumerate(rankings.Speakers.values):
    for j, name in enumerate(speaker.split(',')):
        gender = rankings.Gender[i+1].split('+')[j]
        speakers[gender].add(name)

count_speakers = sum(len(s) for s in speakers.values())
print(count_speakers)

for k in speakers:
    print('{} --> {}'.format(k, len(speakers[k])))

"""
Explanation: <a name="stats"></a>
Stats
Speakers Stats
End of explanation
"""


print('Talks --> {}'.format(talks.index.size))
print('Trainings --> {}'.format(trainings.index.size))

"""
Explanation: Talks Stats
End of explanation
"""


rankings.Lang.value_counts()

"""
Explanation: Lang
End of explanation
"""


rankings.Level.value_counts()

"""
Explanation: Level
End of explanation
"""


trainings.index = np.arange(1, trainings.index.size+1)
HTML(trainings.to_html())

"""
Explanation: <a name="trainings"></a>
Trainings Ranking
End of explanation
"""


pydataers = talks[talks['Track'].values == 'PyData']
pydataers.index = np.arange(1, pydataers.index.size+1)
HTML(pydataers.to_html())

print('Number of Talks Proposed: ', pydataers.index.size, end='\n\n')

print('Language of Talks Proposed: ')
print(pydataers.Lang.value_counts(), end='\n\n')

print('Levels of Talks Proposed: ')
print(pydataers.Level.value_counts())

"""
Explanation: <a name="talks"></a>
Talks Ranking (per single Track)
<div style="background-color: #FAFAFA">
    <a name="pydata"></a>
    <img src='logos/PyDataLogo-no-location.png' style="align: center;" width="50%" />
</div>
End of explanation
"""


pylang = talks[talks['Track'].values == 'Python & Friends']
pylang.index = np.arange(1, pylang.index.size+1)
HTML(pylang.to_html())

print('Number of Talks Proposed: ', pylang.index.size, end='\n\n')

print('Language of Talks Proposed: ')
print(pylang.Lang.value_counts(), end='\n\n')

print('Levels of Talks Proposed: ')
print(pylang.Level.value_counts())

"""
Explanation: <a name="pylang"></a>
Track Python &amp; Friends
End of explanation
"""


pyweb = talks[talks['Track'].values == 'PyWeb & DevOps']
pyweb.index = np.arange(1, pyweb.index.size+1)
HTML(pyweb.to_html())

print('Number of Talks Proposed: ', pyweb.index.size, end='\n\n')

print('Language of Talks Proposed: ')
print(pyweb.Lang.value_counts(), end='\n\n')

print('Levels of Talks Proposed: ')
print(pyweb.Level.value_counts())

"""
Explanation: <a name="pyweb"></a>
Track PyWeb &amp; DevOps
End of explanation
"""


pydb = talks[talks['Track'].values == 'PyDatabase']
pydb.index = np.arange(1, pydb.index.size+1)
HTML(pydb.to_html())

print('Number of Talks Proposed: ', pydb.index.size, end='\n\n')

print('Language of Talks Proposed: ')
print(pydb.Lang.value_counts(), end='\n\n')

print('Levels of Talks Proposed: ')
print(pydb.Level.value_counts())

"""
Explanation: <a name="pydb"></a>
Track PyDatabase
End of explanation
"""


pybusiness = talks[talks['Track'].values == 'PyBusiness']
pybusiness.index = np.arange(1, pybusiness.index.size+1)
HTML(pybusiness.to_html())

print('Number of Talks Proposed: ', pybusiness.index.size, end='\n\n')

print('Language of Talks Proposed: ')
print(pybusiness.Lang.value_counts(), end='\n\n')

print('Levels of Talks Proposed: ')
print(pybusiness.Level.value_counts())

"""
Explanation: <a name="pybusiness"></a>
Track PyBusiness
End of explanation
"""


