Beispiel #1
0
def weekly(start_date, filename, func):
    """ Run func once per week and store the data in JSON. """
    # Number of days to query between, SQL Between is inclusive so this is 7 days of actual data.
    num_days = 6
    dataloc = tools.parse_cached_json(filename)['json']
    for daystring in tools.date_range(start_date, num_days+1):
        if daystring not in dataloc:
            dataloc[daystring] = {}
            print(daystring)
            curdate = datetime.datetime.strptime(daystring, "%Y-%m-%d").date()
            dataloc[daystring] = func(curdate, num_days)
        with open(filename, 'w') as file:
            json.dump(dataloc, file)
Beispiel #2
0
def percent_old(end_date, num_days, filename):
    """ Determine the percentage of users on versions before Telemetry to divide the total by."""
    data = tools.parse_cached_json(filename)['json']
    start_date = end_date - datetime.timedelta(num_days)
    daterange = end_date - start_date
    percents = []

    for d in range(daterange.days):
        daystring = (start_date + datetime.timedelta(d)).strftime("%Y-%m-%d")
        total = 0
        for version, count in data[daystring]['versions'].items():
            major = version.split('.')[0]
            try:
                if int(major) < settings.first_version:
                    total += int(count)
            except ValueError:
                pass
        if total > 0:
            percent = 1 - ((total * 1.0) / data[daystring]['count'])
            percents.append(percent)
    return sum(percents) / float(len(percents))
Beispiel #3
0
        daystring = (start_date + datetime.timedelta(d)).strftime("%Y-%m-%d")
        total = 0
        for version, count in data[daystring]['versions'].items():
            major = version.split('.')[0]
            try:
                if int(major) < settings.first_version:
                    total += int(count)
            except ValueError:
                pass
        if total > 0:
            percent = 1 - ((total * 1.0) / data[daystring]['count'])
            percents.append(percent)
    return sum(percents) / float(len(percents))


cached = tools.parse_cached_json(filename)
dataloc = cached['json']

# One data point per week.
for daystring in tools.date_range(start_date, 7):
    if daystring not in dataloc:
        dataloc[daystring] = {}
        print(daystring)
        curdate = datetime.datetime.strptime(daystring, "%Y-%m-%d").date()
        q = tools.TotalUsers(curdate, num_days)
        d = {
            "start_date":
            (curdate - datetime.timedelta(num_days)).strftime("%Y-%m-%d"),
            "ami":
            q.query_totalusers().totalusers,
            "78":
Beispiel #4
0
import datetime
import json
import settings
import tools
from pathlib import Path

start_date = datetime.date(2020, 11, 29)
filename = Path(__file__).parent / '../docs/addon_stats.json'
# Number of days to query between, SQL Between is inclusive so this is
# 7 days of actual data.
num_days = 6

dataloc = tools.parse_cached_json(filename)['json']
# One data point per week.
for daystring in tools.date_range(start_date, 7):
    if daystring not in dataloc:
        dataloc[daystring] = {}
        print(daystring)
        curdate = datetime.datetime.strptime(daystring, "%Y-%m-%d").date()
        q = tools.TotalAddonUsers(curdate, num_days, settings.release_version)
        d = {
            "total": q.query_totalusers().totalusers,
            "addon_count": q.addon_totalusers,
            "minustop10_count": q.query_totalusers(10).addon_totalusers
        }
        dataloc[daystring] = d
    with open(filename, 'w') as file:
        json.dump(dataloc, file)