in crashes.py [0:0]
def generateSparklineJS(sigStats, operatingSystems, operatingSystemVers, firefoxVers, archs, className):
# generate stats data for crash rate over time graphs
# data = [ {name: "Bitcoin", date: "2017-01-01", value: 967.6}, ]
#"Windows": {
# "6.1": {
# "x86": {
# "91.0a1": {
# "clientcount": 1,
# "crashcount": 3
# }
# }
# }
#}
rawData = dict()
for dateStr in sigStats['crashdata']:
for os in operatingSystems:
for osver in operatingSystemVers:
for arch in archs:
for fxver in firefoxVers:
try:
stats = sigStats['crashdata'][dateStr][os][osver][arch][fxver]
rawData[dateStr] = { 'os': os, 'crashcount': stats['crashcount'] }
except:
pass # some dates may not apply to a particular combination
# average data for each os to smooth out the graph
# {name: "Windows", date: "2021-06-24", value: 84}
# generate a list of dates
avgData = dict()
dates = list(rawData.keys())
dates.sort()
# generate an os list [not used]
osList = list()
for targetDate in dates:
os = rawData[targetDate]['os']
if os not in osList:
osList.append(os)
# generate plot data
plotData = '['
template = '{name: "$name", date: "$date", value: $value},'
for targetDate in dates:
pd = date.fromisoformat(targetDate)
minDate = pd - timedelta(3)
maxDate = pd + timedelta(4)
crashCount = 0
dataPoints = 0
for tmpDateStr in dates:
tmpDate = date.fromisoformat(tmpDateStr)
if tmpDate >= minDate and tmpDate <= maxDate:
crashCount += rawData[pd.isoformat()]['crashcount']
dataPoints += 1
if dataPoints == 0:
avgData[targetDate] = 0
else:
avgData[targetDate] = crashCount / dataPoints
#print("date:%s cc=%d dp=%d avg=%f" % (targetDate, crashCount, dataPoints, avgData[targetDate]))
plotData += Template(template).substitute(name='All', date=targetDate, value=avgData[targetDate])
plotData += ']'
#print(plotData)
template = 'sparkline(document.querySelector("$cname"), $data, sloptions);' ## sloptions defined in template.html
return Template(template).substitute(data=plotData, cname='.' + className)