log['timestamp'] = pd.to_datetime(log['timestamp'])
log.head()

log['age'] = pd.Timestamp("today") - log['timestamp']
log.head()

log['component'] = log['path'].str.split("/").str[:2].str.join(":")
log.head()

age_per_component = log.groupby('component')['age'].min().sort_values()
age_per_component.head()

age_per_component.plot.bar(
    title="Alter pro Komponente (in Jahren)",
    figsize=[15,5]);

"""
Explanation: No-Go Areas
End of explanation
"""


knowledge = log.groupby(
    ['path', 'author']).agg(
        {'timestamp':'min', 'line':'count'}
    )
knowledge.head()

"""
Explanation: Wissensinseln
Bewertung des vorhandenen Wissens
...anhand der zuletzt geänderten Quellcodezeilen
Gruppieren mit minimalen Zeitstempel und Zeilenanzahl
=> Jüngste Änderung und Anzahl geänderter Zeilen pro Datei und Autor
End of explanation
"""


knowledge['all_lines'] = knowledge.groupby('path')['line'].transform('sum')
knowledge['knowing'] = knowledge['line'] / knowledge['all_lines']
knowledge.head()

"""
Explanation: Wissensanteile berechnen
=> Prozentualer Anteil der zuletzt geänderten Zeilen pro Datei und Autor
End of explanation
"""


max_knowledge_per_file = knowledge.groupby(['path'])['knowing'].transform(max)
knowledge_carriers = knowledge[knowledge['knowing'] == max_knowledge_per_file]
knowledge_carriers = knowledge_carriers.reset_index(level=1)
knowledge_carriers.head()

"""
Explanation: Maximales Wissen pro Datei identifizieren
=> Hauptautor pro Datei
End of explanation
"""


from ausi import d3

d3.create_json_for_zoomable_circle_packing(
    knowledge_carriers.reset_index(),
    'author',
    'author',
    'path',
    '/',
    'all_lines',
    'knowing',
    'linux_circle_packing'
)

"""
Explanation: Visualisierung erstellen
=> Export in D3 Visualisierung "Zoomable Circle Packing"
End of explanation
"""


