Last active
January 15, 2021 10:45
-
-
Save smarie/09057f2006fc31616ebd06d41e056ec3 to your computer and use it in GitHub Desktop.
This script processes the attendance list csv from a teams meeting, and plots some useful graphs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
# --------------- You may need to change this ------------- | |
file_name = "meetingAttendanceList.csv" | |
user_fullname_colname = "Nom complet" | |
user_action_colname = "Action de l’utilisateur" | |
joined_text = "Rejoint" | |
left_text = "A quitté l'appel" | |
date_and_time_colname = "Date et heure" | |
# --------------------------------------------------------- | |
# note: make sure to convert your attendance list to utf-8 before hand | |
df = pd.read_csv(file_name, sep="\t", encoding="utf-8") | |
df["datetime"] = pd.to_datetime(df[date_and_time_colname], format="%d/%m/%Y à %H:%M:%S") | |
del df["Date et heure"] | |
# merging time spans for people who connected several times | |
for user in df[user_fullname_colname].unique(): | |
user_mask = df[user_fullname_colname] == user | |
joined = df.loc[user_mask & (df[user_action_colname] == joined_text)] | |
left = df.loc[user_mask & (df[user_action_colname] == left_text)] | |
if len(joined) > 1 or len(left) > 1: | |
assert len(joined) == len(left) | |
nb_slots = len(joined) | |
tot_time = None | |
for i in range(nb_slots): | |
j = joined.iloc[i]["datetime"] | |
l = left.iloc[i]["datetime"] | |
if tot_time is None: | |
tot_time = (l - j) | |
else: | |
tot_time += (l - j) | |
for j in range(nb_slots): | |
if j != 0: | |
df.drop(joined.iloc[j].name, axis=0, inplace=True) | |
if j != (nb_slots - 1): | |
df.drop(left.iloc[j].name, axis=0, inplace=True) | |
df.loc[user_mask, "total_time"] = tot_time | |
else: | |
assert len(joined) > 0 | |
left = df["datetime"].iloc[-1] if len(left) == 0 else left["datetime"].item() | |
df.loc[user_mask, "total_time"] = left - joined["datetime"].item() | |
# de-pivoting so that there is now one row per attendee | |
df = df.set_index([user_fullname_colname, user_action_colname]) | |
df = df.unstack() | |
df.columns = ['left_datetime', 'joined_datetime', '_', 'total_time'] | |
df = df[['total_time', 'joined_datetime', 'left_datetime']] | |
# Histogram of attendance time | |
df['total_time_mins'] = df['total_time'].dt.total_seconds() / 60 | |
df['total_time_mins'].hist(bins=20) | |
plt.title("Attendance total time in minutes (#attendees = %s)" % len(df)) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently this generates a single plot looking like this: