Created
September 20, 2020 19:07
-
-
Save flxai/df705e4eb050874a0a2668ac33665349 to your computer and use it in GitHub Desktop.
Comparison of flipdot chat activity by protocol
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Comparison of chat activity by protocol\n", | |
"\n", | |
"#### Extracting IRC & Matrix and Telegram message count from WeeChat log file\n", | |
"\n", | |
"```bash\n", | |
"echo 'day,msgs' > msgs-irc-matrix.csv\n", | |
"cp msgs-irc-matrix.csv msgs-telegram.csv\n", | |
"grep -vE '(-->|<--||||ℹ|flipdot|flipdotd|flipbot)' irc.freenode.\\#flipdot.weechatlog | grep -vE '(teleflip.?|matterbridge.?)' | cut -f1 -d ' ' | uniq -c | awk '{OFS=\",\"; print $2,$1}' >> msgs-irc-matrix.csv\n", | |
"grep -vE '(-->|<--||||ℹ|flipdot|flipdotd|flipbot)' irc.freenode.\\#flipdot.weechatlog | grep -E '(teleflip.?|matterbridge.?)' | cut -f1 -d ' ' | uniq -c | awk '{OFS=\",\"; print $2,$1}' >> msgs-telegram.csv\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import matplotlib.dates as mdates\n", | |
"import pandas as pd\n", | |
"import pylab as plt" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"im = pd.read_csv('msgs-irc-matrix.csv', index_col='day')\n", | |
"tg = pd.read_csv('msgs-telegram.csv', index_col='day')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"t0 = min(im.index.min(), tg.index.min())\n", | |
"t1 = max(im.index.max(), tg.index.max())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"im.index = pd.DatetimeIndex(im.index)\n", | |
"tg.index = pd.DatetimeIndex(tg.index)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"days = pd.date_range(t0, t1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"im = im.reindex(days, fill_value=0)\n", | |
"tg = tg.reindex(days, fill_value=0)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Number of days for rolling window\n", | |
"d = 30" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def plot_rolling(d, save_file=None, plt_style=None):\n", | |
" if plt_style is not None:\n", | |
" plt.style.use(plt_style)\n", | |
" years = mdates.YearLocator()\n", | |
" years_fmt = mdates.DateFormatter('%Y')\n", | |
" fig, ax = plt.subplots(figsize=(20, 7))\n", | |
" plt.plot(im.index, im.msgs.rolling(d).mean(), label='IRC + Matrix')\n", | |
" plt.plot(tg.index, tg.msgs.rolling(d).mean(), label='Telegram')\n", | |
"\n", | |
" ax.xaxis.set_major_locator(years)\n", | |
" ax.xaxis.set_major_formatter(years_fmt)\n", | |
" ax.grid(True)\n", | |
"\n", | |
" plt.title(f\"Anzahl Nachrichten pro Tag (Gleitender Mittelwert über {d} Tage)\")\n", | |
" plt.legend()\n", | |
" if not save_file:\n", | |
" plt.show()\n", | |
" else:\n", | |
" plt.savefig(save_file)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"plot_rolling(7)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"plot_rolling(30)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"plt_style='seaborn-whitegrid'\n", | |
"plot_rolling(7, save_file='7d.png', plt_style=plt_style)\n", | |
"plot_rolling(30, save_file='30d.png', plt_style=plt_style)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
" " | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment