Exemple #1
0
def plot_monthly_cycles(monthly_cycles, prefix, ylims=(None, None)):
    weekly_plotinfo = {}
    daily_plotinfo = {}

    for month in monthly_cycles.keys():
        weekly_plotinfo[month] = {}
        weekly_plotinfo[month]["x"] = range(7 * 24)
        weekly_plotinfo[month]["y"] = monthly_cycles[month]["weekly"]
        weekly_plotinfo[month]["line_style"] = "-"
        weekly_plotinfo[month]["label"] = "Total: " + month

        daily_plotinfo[month] = {}
        daily_plotinfo[month]["x"] = range(24)
        daily_plotinfo[month]["y"] = monthly_cycles[month]["hourly"]
        daily_plotinfo[month]["line_style"] = "-"
        daily_plotinfo[month]["label"] = "Total: " + month

    weekly_axisinfo = {
        "filename": prefix + "per_month_weekly",
        "ylabel": r"Number of page-views",
        "ylim": get_ylims(weekly_plotinfo),
    }
    plot_week(weekly_plotinfo, weekly_axisinfo, ylims=ylims)

    daily_axisinfo = {
        "filename": prefix + "per_month_hourly",
        "ylabel": r"Number of page-views",
        "ylim": get_ylims(daily_plotinfo),
    }
    plot_day(daily_plotinfo, daily_axisinfo, ylims=ylims)
Exemple #2
0
def plot_cycles(cycles, prefix, yearly=False, monthly=False):
    weekly_plotinfo = {"normal": {}}
    weekly_plotinfo["normal"]["x"] = xrange(7 * 24)
    weekly_plotinfo["normal"]["y"] = cycles.weekly
    weekly_plotinfo["normal"]["line_style"] = "-"
    weekly_plotinfo["normal"]["line_color"] = "blue"
    weekly_plotinfo["normal"]["label"] = "Total"

    weekly_axisinfo = {
        "filename": prefix + "weekly",
        "ylabel": r"Number of page-views",
        "ylim": get_ylims(weekly_plotinfo),
    }
    plot_week(weekly_plotinfo, weekly_axisinfo)

    daily_plotinfo = {"normal": {}}
    daily_plotinfo["normal"]["x"] = range(24)
    daily_plotinfo["normal"]["y"] = cycles.hourly
    daily_plotinfo["normal"]["line_style"] = "-"
    daily_plotinfo["normal"]["line_color"] = "blue"
    daily_plotinfo["normal"]["label"] = "Total"

    daily_axisinfo = {
        "filename": prefix + "hourly",
        "ylabel": r"Number of page-views",
        "ylim": get_ylims(daily_plotinfo),
    }
    plot_day(daily_plotinfo, daily_axisinfo)

    if yearly:
        plot_yearly_cycles(cycles.yearly_cycles, prefix)
    if monthly:
        plot_monthly_cycles(cycles.monthly_cycles, prefix)
Exemple #3
0
def plot_yearly_cycles(yearly_cycles, prefix, ylims=(None, None)):
    weekly_plotinfo = {}
    daily_plotinfo = {}

    for year in yearly_cycles.keys():
        weekly_plotinfo[year] = {}
        weekly_plotinfo[year]["x"] = range(7 * 24)
        weekly_plotinfo[year]["y"] = yearly_cycles[year]["weekly"]
        weekly_plotinfo[year]["line_style"] = "-"
        weekly_plotinfo[year]["label"] = "Total: " + str(year)

        daily_plotinfo[year] = {}
        daily_plotinfo[year]["x"] = range(24)
        daily_plotinfo[year]["y"] = yearly_cycles[year]["hourly"]
        daily_plotinfo[year]["line_style"] = "-"
        daily_plotinfo[year]["label"] = "Total: " + str(year)

    weekly_axisinfo = {
        "filename": prefix + "per_year_weekly",
        "ylabel": r"Number of page-views",
        "ylim": get_ylims(weekly_plotinfo),
    }
    plot_week(weekly_plotinfo, weekly_axisinfo, ylims=ylims)

    daily_axisinfo = {
        "filename": prefix + "per_year_hourly",
        "ylabel": r"Number of page-views",
        "ylim": get_ylims(daily_plotinfo),
    }
    plot_day(daily_plotinfo, daily_axisinfo, ylims=ylims)
Exemple #4
0
def plot_art(art, pattern, plotfolder):
    xticks = ["" for _ in art.views]
    i = 0
    while i < len(art.views):
        xticks[i] = str(i % 24) + "h"
        i += 6

    max_length = len(art.views)
    log_estimate = zeros(max_length).tolist()

    if art.pattern.has_gamma:
        log_estimate[art.pattern.start : art.pattern.length * 24] = [
            log(art.red_views[art.pattern.start]) + log(art.beta) * x for x in range(art.pattern.length * 24)
        ]
        log_estimate[art.pattern.length * 24 : max_length] = [
            log(art.red_views[art.pattern.start]) + log(art.gamma) + log(art.beta) * (x - 1)
            for x in range(art.pattern.length * 24, max_length)
        ]
    else:
        log_estimate[art.pattern.start : art.pattern.start + art.pattern.length * 24] = [
            log(art.red_views[art.pattern.start]) + log(art.beta) * x for x in range(art.pattern.length * 24)
        ]

    estimate = [exp(log_estimate[x]) for x in range(max_length)]

    plotinfo = {"normal": {}, "estimate": {}, "model": {}}
    plotinfo["normal"]["x"] = xrange(len(art.views))
    plotinfo["normal"]["y"] = art.views
    plotinfo["normal"]["line_style"] = "-"
    plotinfo["normal"]["line_color"] = "blue"
    plotinfo["normal"]["label"] = "Page-views"
    plotinfo["model"]["x"] = xrange(len(art.views))
    plotinfo["model"]["y"] = estimate
    plotinfo["model"]["line_style"] = "--"
    plotinfo["model"]["line_color"] = "green"
    plotinfo["model"]["label"] = "Model"
    plotinfo["estimate"]["x"] = xrange(len(art.views))
    plotinfo["estimate"]["y"] = art.est_params
    plotinfo["estimate"]["line_style"] = "--"
    plotinfo["estimate"]["line_color"] = "red"
    if pattern.has_gamma:
        plotinfo["estimate"]["label"] = r"Estimated views ($\beta,\gamma$)"
        plotinfo["gamma"] = {}
        plotinfo["gamma"]["x"] = xrange(len(art.views))
        plotinfo["gamma"]["y"] = art.est_gamma_func
        plotinfo["gamma"]["line_style"] = "--"
        plotinfo["gamma"]["line_color"] = "black"
        plotinfo["gamma"]["label"] = r"Estimated views ($\beta,\gamma(v_1)$)"
    else:
        plotinfo["estimate"]["label"] = r"Estimated views ($\beta$)"

    axisinfo = {
        "filename": plotfolder + art.link_title,
        "ylabel": r"Number of page-views",
        "xticks": xticks,
        "title": "Hourly progression of " + art.title,
        "xlim": {"start": 0, "end": len(xticks)},
        "ylim": get_ylims(plotinfo),
    }
    plot_pattern(plotinfo, axisinfo)

    plotinfo = {"cumsum": {}}
    plotinfo["cumsum"]
    plotinfo["cumsum"]["x"] = xrange(len(art.views))
    plotinfo["cumsum"]["y"] = cumsum(art.views)
    plotinfo["cumsum"]["line_style"] = "-"
    plotinfo["cumsum"]["line_color"] = "blue"
    plotinfo["cumsum"]["label"] = "Cumulative views"

    axisinfo = {
        "filename": plotfolder + "cum_" + art.link_title,
        "ylabel": r"Cumulative number of page-views",
        "xticks": xticks,
        "title": "Cumulative progression of " + art.title,
        "xlim": {"start": 0, "end": len(xticks)},
        "ylim": get_ylims(plotinfo),
    }
    plot_pattern(plotinfo, axisinfo)

    plotinfo = {"normalized": {}}
    plotinfo["normalized"]
    plotinfo["normalized"]["x"] = xrange(len(art.views))
    plotinfo["normalized"]["y"] = art.norm_views
    plotinfo["normalized"]["line_style"] = "-"
    plotinfo["normalized"]["line_color"] = "blue"
    plotinfo["normalized"]["label"] = "Normalized views"

    axisinfo = {
        "filename": plotfolder + "norm_" + art.link_title,
        "ylabel": r"Number of page-views",
        "xticks": xticks,
        "title": "Hourly progression of " + art.title,
        "xlim": {"start": 0, "end": len(xticks)},
        "ylim": {"start": 0, "end": ceil(max(plotinfo["normalized"]["y"]) * 100) / 100},
    }
    plot_pattern(plotinfo, axisinfo)