{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "inputHidden": false, "outputHidden": false }, "outputs": [], "source": [ "#would be good if in this and the two following notebooks, the editor could be manually changed so that each notebook can be used individually. \n", "# same goes for changing the page here. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "\n", "%store -r the_page\n", "%store -r the_editor\n", "%store -r agg_actions\n", "%store -r editor_inputname\n", "%store -r calculator\n", "\n", "if ('the_page' not in locals() or \n", " 'the_editor' not in locals() or \n", " 'agg_actions' not in locals() or \n", " 'editor_inputname' not in locals() or \n", " 'calculator' not in locals()):\n", " import pickle\n", " print(\"Loading default data...\")\n", " the_page = pickle.load(open(\"data/the_page.p\",'rb'))\n", " the_editor = pickle.load(open(\"data/the_editor.p\",'rb'))\n", " agg_actions = pickle.load(open(\"data/agg_actions.p\",'rb'))\n", " editor_inputname = pickle.load(open(\"data/editor_inputname.p\",'rb'))\n", " calculator = pickle.load(open(\"data/calculator.p\",'rb'))\n", "\n", "\n", "from IPython.display import display, Markdown as md\n", "display(md(\"---\"))\n", "display(md(f\"# A. Detecting conflicting editors\"))\n", "display(md(f\"***Page: {the_page['title']}***\"))\n", "display(md(f\"***Editor: {the_editor['name']}***\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "conflicting_actions = calculator.get_conflicting_actions(editor_inputname)\n", "\n", "from external.wikipedia import WikipediaDV, WikipediaAPI\n", "wikipedia_dv = WikipediaDV(WikipediaAPI(domain='en.wikipedia.org'))\n", "\n", "conflicting_editors = conflicting_actions['editor'].unique().tolist()\n", "\n", "editors = wikipedia_dv.get_editors([int(x) for x in conflicting_editors if x[:2] != '0|'])\n", "editors['userid'] = editors['userid'].astype('str')\n", "\n", "full_editors_conflicts = calculator.get_conflict_score_per_editor()\n", "editors[['userid','name','registration']].merge( full_editors_conflicts, \n", " right_index=True, left_on='userid',how='left').set_index('userid')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import display, Markdown as md\n", "display(md(\"---\"))\n", "display(md(f\"# B. Activity of conflicting editors\"))\n", "display(md(f\"***Page: {the_page['title']}***\"))\n", "display(md(f\"***Editor: {the_editor['name']}***\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "editors['userid'] = editors['userid'].astype('int')\n", "conf_editor_agg_actions = editors[['userid','name','registration']].merge(agg_actions, \n", " left_on='userid', right_on='editor_id', how='left').set_index('userid')\n", "\n", "# Listener\n", "from visualization.actions_listener import ActionsListener\n", "listener = ActionsListener(conf_editor_agg_actions)\n", "actions = (conf_editor_agg_actions.loc[:,'total':'total_stopword_count'].columns.append(\n", " conf_editor_agg_actions.loc[:,'adds':'reins_stopword_count'].columns)).values.tolist()\n", "\n", "# Visualization\n", "from ipywidgets import interact\n", "from utils.notebooks import get_date_slider_from_datetime\n", "from ipywidgets.widgets import Dropdown\n", "\n", "interact(listener.listen, \n", " _range = get_date_slider_from_datetime(conf_editor_agg_actions['year_month']),\n", " editor=Dropdown(options=['All'] + editors['name'].values.tolist(), value='All'),\n", " granularity=Dropdown(options=['Yearly', 'Monthly'], value='Monthly'),\n", " black=Dropdown(options=actions, value='total'), \n", " red=Dropdown(options= ['None'] + actions, value='total_surv_48h'),\n", " green=Dropdown(options= ['None'] + actions, value='None'), \n", " blue=Dropdown(options= ['None'] + actions, value='None'))\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import display, Markdown as md\n", "display(md(\"---\"))\n", "display(md(f\"# C. Tokens of conflicting editors\"))\n", "display(md(f\"***Page: {the_page['title']}***\"))\n", "display(md(f\"***Editor: {the_editor['name']}***\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "editors['userid'] = editors['userid'].astype('str')\n", "editor_conflicts = editors[['userid','name','registration']].merge(conflicting_actions, \n", " left_on='userid', right_on='editor', how='left').set_index('userid')\n", "sources = {\n", " f'Actions (Conflicting with {the_editor[\"name\"]})': editor_conflicts,\n", " f'Only Conflicts (Conflicting with {the_editor[\"name\"]})': editor_conflicts[~editor_conflicts['conflict'].isnull()]\n", "}\n", "\n", "# listener\n", "from visualization.wordcloud_listener import WCListener\n", "listener = WCListener(sources)\n", "\n", "# visualization\n", "from utils.notebooks import get_date_slider_from_datetime\n", "from ipywidgets import interact\n", "from ipywidgets.widgets import Dropdown\n", "\n", "interact(listener.listen, \n", " _range=get_date_slider_from_datetime(editor_conflicts['rev_time']),\n", " editor=Dropdown(options=['All'] + editors['name'].values.tolist(), value='All', layout={'width': '400px'}),\n", " source=Dropdown(options=list(listener.sources.keys()), value= f'Actions (Conflicting with {the_editor[\"name\"]})', layout={'width': '400px'}),\n", " action=Dropdown(options=['Both', 'Just Insertions', 'Just Deletions'], value='Both', layout={'width': '400px'}))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import HTML\n", "from utils.notebooks import get_next_notebook\n", "\n", "display(HTML(f'Go to next workbook'))\n" ] } ], "metadata": { "kernel_info": { "name": "python3" }, "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.6.5" }, "nteract": { "version": "0.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }