Skip to content

Instantly share code, notes, and snippets.

@mhammond
Last active March 20, 2018 00:14
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/56e58de91226a942fee19c7431c384b2 to your computer and use it in GitHub Desktop.
Save mhammond/56e58de91226a942fee19c7431c384b2 to your computer and use it in GitHub Desktop.
Number of desktop pings per day
Display the source blob
Display the rendered blob
Raw
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 = datetime.date.fromtimestamp(time.time() - ndays * 24 * 60 * 60)
earliest_ping_str = earliest_ping.strftime("%Y%m%d")
latest_ping = datetime.date.fromtimestamp(time.time())
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):
try:
# 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
).filter(filterOurs
).map(mapToDate
).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()):
ticks.append(date2num(when))
vals.append(verData[when] / fraction)
ax.plot_date(ticks,
vals,
'-',
label=channel)
ax.get_yaxis().set_major_formatter(ticker.FuncFormatter(lambda x, p: format(int(x), ",")))
fig, ax = plt.subplots()
plotChannel("nightly")
plotChannel("beta")
ax.legend(loc='upper left')
fig, ax = plt.subplots()
plotChannel("release")
ax.legend(loc='upper left')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment