Created
August 22, 2016 10:52
-
-
Save georgf/3b305ce613689c9ff30c8b6cf31b03e6 to your computer and use it in GitHub Desktop.
activePlugins is not an array
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": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false, | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Populating the interactive namespace from numpy and matplotlib\n" | |
] | |
} | |
], | |
"source": [ | |
"from moztelemetry import get_pings\n", | |
"\n", | |
"%pylab inline" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"pings = get_pings(sc, app=\"Firefox\", channel=\"nightly\", submission_date=\"20160820\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"class NoPlugins:\n", | |
" dummy = 1" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"def get_active_plugins(x):\n", | |
" try:\n", | |
" return x[\"environment\"][\"addons\"][\"activePlugins\"]\n", | |
" except:\n", | |
" return NoPlugins()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{}\n" | |
] | |
} | |
], | |
"source": [ | |
"print pings.map(get_active_plugins).filter(lambda x: not isinstance(x, list)).first()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def name(x):\n", | |
" s = str(type(x))\n", | |
" if s != \"<type 'instance'>\":\n", | |
" return s\n", | |
" else:\n", | |
" return x.__class__.__name__" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"defaultdict(<type 'int'>, {\"<type 'dict'>\": 9232, 'NoPlugins': 121, \"<type 'list'>\": 61903})\n" | |
] | |
} | |
], | |
"source": [ | |
"print pings.map(get_active_plugins)\\\n", | |
" .map(lambda x: (name(x), 1))\\\n", | |
" .countByKey()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.11" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
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
# coding: utf-8 | |
# In[2]: | |
from moztelemetry import get_pings | |
get_ipython().magic(u'pylab inline') | |
# In[3]: | |
pings = get_pings(sc, app="Firefox", channel="nightly", submission_date="20160820") | |
# In[7]: | |
class NoPlugins: | |
dummy = 1 | |
# In[8]: | |
def get_active_plugins(x): | |
try: | |
return x["environment"]["addons"]["activePlugins"] | |
except: | |
return NoPlugins() | |
# In[9]: | |
print pings.map(get_active_plugins).filter(lambda x: not isinstance(x, list)).first() | |
# In[14]: | |
def name(x): | |
s = str(type(x)) | |
if s != "<type 'instance'>": | |
return s | |
else: | |
return x.__class__.__name__ | |
# In[15]: | |
print pings.map(get_active_plugins) .map(lambda x: (name(x), 1)) .countByKey() | |
# In[ ]: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment