Skip to content

Instantly share code, notes, and snippets.

@mhammond
Last active January 31, 2017 09:56
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 mhammond/c9a9a928e7634bdd9a586aac6bcc8732 to your computer and use it in GitHub Desktop.
Save mhammond/c9a9a928e7634bdd9a586aac6bcc8732 to your computer and use it in GitHub Desktop.
Max validation errors
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Unable to parse whitelist (/home/hadoop/anaconda2/lib/python2.7/site-packages/moztelemetry/histogram-whitelists.json). Assuming all histograms are acceptable.\n"
]
}
],
"source": [
"from moztelemetry import get_pings, get_pings_properties\n",
"\n",
"# filter the ones we care about early...\n",
"def filterOurs(ping):\n",
" try:\n",
" syncs = ping[\"payload\"][\"syncs\"]\n",
" except KeyError:\n",
" return False\n",
" for sync in syncs:\n",
" for engine in sync.get(\"engines\", []):\n",
" if \"name\" in engine and engine[\"name\"] == \"bookmarks\" and \"validation\" in engine and \"problems\" in engine[\"validation\"]:\n",
" return True\n",
" return False\n",
" \n",
"pings = get_pings(sc, doc_type='sync', fraction=1.0).filter(filterOurs)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{u'clientCycles': 7,\n",
" u'clientMissing': 84,\n",
" u'deletedChildren': 14,\n",
" u'deletedParents': 17,\n",
" u'differences': 63,\n",
" u'duplicateChildren': 1,\n",
" u'missingChildren': 914,\n",
" u'multipleParents': 17,\n",
" u'orphans': 62,\n",
" u'parentChildMismatches': 53,\n",
" u'parentNotFolder': 17,\n",
" u'rootOnServer': 1,\n",
" u'sdiff:childGUIDs': 7,\n",
" u'sdiff:parentid': 15,\n",
" u'serverMissing': 62473,\n",
" u'serverUnexpected': 48,\n",
" u'structuralDifferences': 22,\n",
" u'wrongParentName': 62}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def flattenBookmarkValidations(ping):\n",
" result = []\n",
" for sync in ping[\"payload\"][\"syncs\"]:\n",
" for engine in sync.get(\"engines\", []):\n",
" if \"validation\" in engine:\n",
" # turn it into a dict.\n",
" this = {}\n",
" for problem in engine[\"validation\"][\"problems\"]:\n",
" this[problem[\"name\"]] = problem[\"count\"]\n",
" result.append(this)\n",
" return result\n",
"\n",
"# And reduce each one into the max\n",
"def reduceToMax(a, b):\n",
" allKeys = set(a.keys())\n",
" allKeys.update(b.keys())\n",
" result = {}\n",
" for key in allKeys:\n",
" result[key] = max(a.get(key, 0), b.get(key, 0))\n",
" return result\n",
"\n",
"\n",
"pings.flatMap(flattenBookmarkValidations).reduce(reduceToMax)"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [default]",
"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.12"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
# coding: utf-8
# In[1]:
from moztelemetry import get_pings, get_pings_properties
# filter the ones we care about early...
def filterOurs(ping):
try:
syncs = ping["payload"]["syncs"]
except KeyError:
return False
for sync in syncs:
for engine in sync.get("engines", []):
if "name" in engine and engine["name"] == "bookmarks" and "validation" in engine and "problems" in engine["validation"]:
return True
return False
pings = get_pings(sc, doc_type='sync', fraction=1.0).filter(filterOurs)
# In[2]:
def flattenBookmarkValidations(ping):
result = []
for sync in ping["payload"]["syncs"]:
for engine in sync.get("engines", []):
if "validation" in engine:
# turn it into a dict.
this = {}
for problem in engine["validation"]["problems"]:
this[problem["name"]] = problem["count"]
result.append(this)
return result
# And reduce each one into the max
def reduceToMax(a, b):
allKeys = set(a.keys())
allKeys.update(b.keys())
result = {}
for key in allKeys:
result[key] = max(a.get(key, 0), b.get(key, 0))
return result
pings.flatMap(flattenBookmarkValidations).reduce(reduceToMax)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment