Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Number of desktop pings per day
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# coding: utf-8
# In[1]:
import re
import datetime
import time
from moztelemetry import get_pings
fraction = 0.2
# for now we are only interested in 59 and 60.
#versions = re.compile("(5[9])|(6[0])\..*") # ".*" for all
ndays = 240 # number of days in the past
# we only ask for ping submitted within these dates.
earliest_ping = - ndays * 24 * 60 * 60)
earliest_ping_str = earliest_ping.strftime("%Y%m%d")
latest_ping =
latest_ping_str = latest_ping.strftime("%Y%m%d")
channel = None
def getPlatform(ping):
application = ping["application"]
if "name" not in application or application.get("name") == "Fennec":
return "android" # ??
return "iOS" if application.get("architecture") == "arm" else "desktop"
def filterOurs(ping):
# if versions.match(ping["application"]["version"]) is None:
# return False
if ping["application"]["channel"] not in ["beta", "nightly", "release"]:
return False
platform = getPlatform(ping)
return platform == "desktop"
except (KeyError, ValueError):
return False
def mapToDate(ping):
when = datetime.datetime.strptime(ping["meta"]["submissionDate"], "%Y%m%d").date()
#version = ping["application"]["version"].split(".")[0]
channel = ping["application"]["channel"]
return (when, channel), 1
s = get_pings(sc, doc_type='sync', submission_date=(earliest_ping_str, latest_ping_str), channel=channel, fraction=fraction
).reduceByKey(lambda a, b: a+b
# In[2]:
# turn into dicts used to plot.
dataByVersionByDate = {}
for (when, channel), count in s.collect():
byDate = dataByVersionByDate.setdefault(channel, {})
byDate[when] = count
# In[3]:
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.dates import date2num
from pylab import rcParams
import itertools
get_ipython().magic(u"config InlineBackend.figure_format = 'svg'")
rcParams['figure.figsize'] = 12, 10
rcParams.update({'font.size': 6})
def plotChannel(channel):
verData = dataByVersionByDate[channel]
ticks = []
vals = []
for when in sorted(verData.keys()):
vals.append(verData[when] / fraction)
ax.get_yaxis().set_major_formatter(ticker.FuncFormatter(lambda x, p: format(int(x), ",")))
fig, ax = plt.subplots()
ax.legend(loc='upper left')
fig, ax = plt.subplots()
ax.legend(loc='upper left')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment