Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ilanasegall
Created November 23, 2015 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilanasegall/5b37f800c3f94e9bc257 to your computer and use it in GitHub Desktop.
Save ilanasegall/5b37f800c3f94e9bc257 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{"nbformat_minor": 0, "cells": [{"execution_count": 113, "cell_type": "code", "source": "import ujson as json\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport numpy as np\nimport plotly.plotly as py\nfrom operator import itemgetter\n\nfrom moztelemetry import get_pings, get_pings_properties, get_one_ping_per_client, get_clients_history", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": 9, "cell_type": "code", "source": "sc.defaultParallelism", "outputs": [{"execution_count": 9, "output_type": "execute_result", "data": {"text/plain": "16"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "pings = get_pings(sc, \n app=\"Firefox\", \n channel=\"nightly\", #\"*\" causing crash. follow up.\n submission_date=(\"20151101\", \"20151122\"), \n fraction=0.01)", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": 98, "cell_type": "code", "source": "subset = get_pings_properties(pings, [\"clientId\", \"environment/settings/userPrefs\", \"application\"])\nsubset = get_one_ping_per_client(subset)", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": 99, "cell_type": "code", "source": "cached = subset.cache()\ncached.count()\ncached.first()", "outputs": [{"execution_count": 99, "output_type": "execute_result", "data": {"text/plain": "{'application': {u'architecture': u'x86',\n u'buildId': u'20151103023037',\n u'channel': u'beta',\n u'name': u'Firefox',\n u'platformVersion': u'43.0',\n u'vendor': u'Mozilla',\n u'version': u'43.0',\n u'xpcomAbi': u'x86-msvc'},\n 'clientId': u'bd694e00-cab2-4bd0-84e0-7798c706289f',\n 'environment/settings/userPrefs': {u'accessibility.browsewithcaret': True,\n u'browser.cache.disk.capacity': 358400,\n u'browser.newtabpage.enhanced': True,\n u'browser.startup.homepage': u'<user-set>'}}"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": 107, "cell_type": "code", "source": "def extractPrefs(d):\n channel = d.get(\"application\",{}).get(\"channel\",\"NA\")\n version = d.get(\"application\",{}).get(\"version\",\"NA\")[0:2] #makeshift\n prefs = d.get(\"environment/settings/userPrefs\",{})\n suggest = prefs.get(\"browser.urlbar.suggest.searches\", \"undefined\")\n choice = prefs.get(\"browser.urlbar.userMadeSearchSuggestionsChoice\", \"undefined\")\n return ((version, channel, suggest, choice),1)", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": 115, "cell_type": "code", "source": "out = cached.map(lambda x: extractPrefs(x)).reduceByKey(lambda x,y:x+y).collectAsMap()", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": 116, "cell_type": "code", "source": "print \"(version, channel, suggest.searches, madechoice)\"\nfor k in sorted(out.keys()):\n print k,out[k]", "outputs": [{"output_type": "stream", "name": "stdout", "text": "(version, channel, suggest.searches, madechoice)\n(u'39', u'beta', 'undefined', 'undefined') 1518\n(u'40', u'beta', 'undefined', 'undefined') 2647\n(u'41', u'beta', 'undefined', 'undefined') 9481\n(u'42', u'beta', True, True) 18\n(u'42', u'beta', True, 'undefined') 2\n(u'42', u'beta', 'undefined', True) 17\n(u'42', u'beta', 'undefined', 'undefined') 34244\n(u'43', u'beta', True, True) 4319\n(u'43', u'beta', True, 'undefined') 104\n(u'43', u'beta', 'undefined', True) 6196\n(u'43', u'beta', 'undefined', 'undefined') 48128\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment