attendance106 = ia.attendance_tables(106)

"""
Explanation: Start by getting the attendence information for IETF.
End of explanation
"""


attendance106.groupby('Organization') \
             .count()['First Name'] \
             .sort_values(ascending=False)[:30]

"""
Explanation: What organizations are best represented?
End of explanation
"""


attendance106['Organization'].dropna().unique().shape

"""
Explanation: Even in this short list, there are repeat names. We need to apply entity resolution.
End of explanation
"""


N = 250
topN = attendance106.groupby('Organization')\
                    .count()['First Name']\
                    .sort_values(ascending=False)[:N]

distance_matrix = process.matricize(topN.index,
                                    process.containment_distance) \
                         .replace(to_replace=float('inf'), value= 100)

plt.pcolor(distance_matrix)
plt.colorbar()

ents = process.resolve_entities(topN,
                                process.containment_distance,
                                threshold=.25)

replacements = {}
for r in [{name: ent for name in ents[ent]} for ent in ents]:
    replacements.update(r)

attendance106_clean = attendance106.replace(to_replace=replacements)

attendance106_clean.groupby('Organization') \
                   .size() \
                   .sort_values(ascending=False)[:30]

"""
Explanation: This is too many names! It will overwhelm the entity resolver. Let's use a subset of the most relevant entities.
End of explanation
"""


