{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "\n", "%store -r the_page\n", "%store -r agg_actions\n", "%store -r calculator\n", "\n", "if ('the_page' not in locals() or \n", " 'agg_actions' 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", " agg_actions = pickle.load(open(\"data/agg_actions.p\",'rb'))\n", " calculator = pickle.load(open(\"data/calculator.p\",'rb'))\n", " \n", "from IPython.display import display, Markdown as md\n", "display(md(\"---\"))\n", "display(md(f\"# A. Select a conflicting editor\"))\n", "display(md(f\"***Page: {the_page['title']}***\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "inputHidden": false, "outputHidden": false }, "outputs": [], "source": [ "#same explanation of terms related to conflict missing as in notebook 2\n", "#user 'MelbourneStar' in the 'Barack_Obama' article shows weird behavior in the first two line graphs, with total actions in the first one (per month) being higher than in the second one (see december 2014). also, in the first one, why are total and conflict_score shown in the graph when they are 0? and how can there be a tag cloud with conflicted words if conflict score = 0 all the time? " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from external.wikipedia import WikipediaDV, WikipediaAPI\n", "# Grab the editors conflicts\n", "editors_conflicts = calculator.get_conflict_score_per_editor()\n", "elegible_actions = calculator.elegible_actions\n", "\n", "# Grab user names from wikipedia and merge them to the editors_conflict dataframe\n", "from external.wikipedia import WikipediaDV, WikipediaAPI\n", "wikipedia_dv = WikipediaDV(WikipediaAPI(domain='en.wikipedia.org'))\n", "\n", "editors = wikipedia_dv.get_editors([int(x) for x in editors_conflicts.index if x.isdigit()])\n", "editors['userid'] = editors['userid'].astype('str')\n", "\n", "editors_conflicts = editors[['userid','name','registration']].merge( editors_conflicts, \n", " right_index=True, left_on='userid',how='left').set_index('userid')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "from visualization.conflicts_listener import ConflictsListener\n", "\n", "def display_conflict_score(eleg_actions):\n", " from visualization.conflicts_listener import ConflictsListener\n", " listener = ConflictsListener(eleg_actions)\n", "\n", " metrics = ['Conflict Score', 'Conflict Ratio', 'Total Conflicts', \n", " 'Total Elegible Actions', 'Total Actions', 'Total Time',\n", " 'Time per Elegible Action']\n", "\n", " display(md(f'**Page conflict score: {calculator.get_page_conflict_score()}**'))\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(eleg_actions['rev_time']),\n", " granularity=Dropdown(options=['Yearly', 'Monthly', 'Daily'], value='Daily'),\n", " black=Dropdown(options=metrics, value='Conflict Score'),\n", " red=Dropdown(options= ['None'] + metrics, value='None'))\n", "\n", "def select_editor(editor):\n", " global the_editor\n", " global editor_inputname\n", " editor_inputname=editor\n", " \n", " wikipedia_dv = WikipediaDV(WikipediaAPI(domain='en.wikipedia.org'))\n", " try:\n", " the_editor = wikipedia_dv.get_editor(int(editor_inputname))\n", " except:\n", " the_editor = wikipedia_dv.get_editor(editor_inputname[2:])\n", "\n", " with out:\n", " %store the_editor\n", " %store editor_inputname\n", "\n", " clear_output()\n", " display(md(\"### Current Selection:\"))\n", " \n", " if 'invalid' in the_editor:\n", " display(f\"The editor {editor_inputname} was not found, try a different editor\")\n", " else:\n", " # display the data that will be passed to the next notebook\n", " display(the_editor.to_frame('values'))\n", " display(md(f\"#### Evolution of the Conflict Score of *{the_editor['name']}*\"))\n", " \n", " display_conflict_score(elegible_actions[elegible_actions['editor'] == editor_inputname].copy())\n", "\n", "\n", "def on_selection_change(change):\n", "\n", " try:\n", " select_editor(qg_obj.get_selected_df().iloc[0].name)\n", " except:\n", " print('Problem parsing the name. Execute the cell again and try a different editor.')\n", "\n", "import qgrid\n", "qgrid.set_grid_option('maxVisibleRows', 5)\n", "qg_obj = qgrid.show_grid(editors_conflicts)\n", "qg_obj.observe(on_selection_change, names=['_selected_rows'])\n", " \n", "from ipywidgets import Output\n", "from IPython.display import display, clear_output, Markdown as md\n", "display(md(\"### Select one editor row for the next notebook:\"))\n", "display(md('**Recomendation:** select an editor with *many conflicts* and *mid-high conflict score*'))\n", "display(qg_obj)\n", "out = Output()\n", "display(out)\n", "\n", "# select an editor that does not contain 0| at the beginning\n", "for ed in editors_conflicts.index:\n", " if ed[:2] != '0|':\n", " select_editor(ed)\n", " break\n", "\n", " \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import widgets\n", "from IPython.display import display, Javascript\n", "\n", "def run_below(ev):\n", " display(Javascript('IPython.notebook.execute_cells_below()'))\n", "\n", "button = widgets.Button(description=\"Refresh Notebook\", button_style='info', min_width=500)\n", "button.on_click(run_below)\n", "display(button)" ] }, { "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. History of editor on a page\"))\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": [ "editor_agg_actions = agg_actions[agg_actions['editor_id']==the_editor.userid]\n", "\n", "#Listener\n", "from visualization.actions_listener import ActionsListener\n", "listener = ActionsListener(editor_agg_actions)\n", "actions = (editor_agg_actions.loc[:,'total':'total_stopword_count'].columns.append(\n", " editor_agg_actions.loc[:,'adds':'reins_stopword_count'].columns)).values.tolist()\n", "\n", "# Visualization\n", "from utils.notebooks import get_date_slider_from_datetime\n", "from ipywidgets import interact, fixed\n", "from ipywidgets.widgets import Dropdown\n", "\n", "interact(listener.listen, \n", " _range = get_date_slider_from_datetime(agg_actions['year_month']),\n", " editor=fixed('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 that enter into conflict with other 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": [ "sources = {\n", " 'All actions': calculator.all_actions[calculator.all_actions['editor']==editor_inputname],\n", " 'Elegible Actions': calculator.elegible_actions[calculator.elegible_actions['editor']==editor_inputname],\n", " 'Only Conflicts': calculator.conflicts[calculator.conflicts['editor']==editor_inputname],\n", "}\n", "\n", "# listener\n", "from visualization.wordcloud_listener import WCListener\n", "\n", "listener = WCListener(sources)\n", "\n", "# visualization\n", "from utils.notebooks import get_date_slider_from_datetime\n", "from ipywidgets import interact, fixed\n", "from ipywidgets.widgets import Dropdown\n", "\n", "interact(listener.listen, \n", " _range=get_date_slider_from_datetime(calculator.all_actions['rev_time']),\n", " source=Dropdown(options=list(listener.sources.keys()), value='Only Conflicts'),\n", " action=Dropdown(options=['Both', 'Just Insertions', 'Just Deletions'], value='Both'),\n", " editor=fixed('All'))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import display, Markdown as md\n", "display(md(\"---\"))\n", "display(md(f\"# D. Tokens on the page owned by the editor\"))\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": [ "from visualization.owned_listener import OwnedListener\n", "owned = calculator.all_actions\n", "listener = OwnedListener(owned, editor_inputname)\n", "\n", "traces = ['Tokens Owned', 'Tokens Owned (%)']\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(owned['rev_time']),\n", " granularity=Dropdown(options=['Yearly', 'Monthly', 'Daily'], value='Daily'),\n", " trace=Dropdown(options=traces, value='Tokens Owned (%)'))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import HTML\n", "from utils.notebooks import get_next_notebook, get_previous_notebook\n", "\n", "editor_actions = calculator.elegible_actions[calculator.elegible_actions['editor']==editor_inputname]\n", "\n", "if len(editor_actions) > 0:\n", " display(HTML(f'Go to next workbook'))\n", "else:\n", " display(HTML(f'Go back to the previous workbook'))" ] } ], "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 }