def PlotPostStraightup(con=None, rows=None, y="avg_view"): if con is None: con = db_utils.Connect() if rows is None: rows = con.query(PostFrequencyQuery()) plot = plotting.WeekPlotter(title=y.replace("_", " ") + " over a week", name=y + "_week") plot.Plot(rows, x="hour_of_week", y=y, label=y.replace("_", " ")) plot.YLabel(y.replace("_", " ")) plot.Done()
def Render(self): con = db_utils.Connect() rows = con.query(self.sql) indep_var = rows.fieldnames[0] groups = list(rows.fieldnames[1:]) props = { "title" : "Video Views", "legend" : "always", "ylabel" : "Views", "labelsKMB" : True, } matrix = [(r[indep_var], [float(r[cn]) for cn in groups]) for r in rows] if "timestamp" in self.params: matrix = [(TimestampToDatetime(int(a)), b) for a,b in matrix] GraphRenderer(self.http_handler, self.params["title"], groups, matrix, props).Render()
def PlotPostFrequency(con=None, rows=None, save=False, scale=True, views=True, subs=True): if con is None: con = db_utils.Connect() if rows is None: rows = con.query(PostFrequencyQuery()) title_suffix = "" name_suffix = "" if subs and not views: title_suffix = " by subscribers" name_suffix = "_subs" if views and not subs: title_suffix = " by views" name_suffix = "_views" title = "post frequency over the week" + title_suffix name = "post_frequency_week" + name_suffix if save else None if scale: rows = SimpleScale(rows, "hour_of_week") title = "scaled " + title if save: name = "scaled_" + name plot = plotting.WeekPlotter(title=title, name=name) if scale: plot.YLabel("scaled number of videos") else: plot.YLabel("number of videos") ys = ["total"] if views: if scale: ys.append("over_100000_views") else: ys.extend( ["over_1000_views", "over_10000_views", "over_100000_views"]) if subs: if scale: ys.append("over_100000_subs") else: ys.extend( ["over_1000_subs", "over_10000_subs", "over_100000_subs"]) for y in ys: label = "total" if y == "total" else "videos with " + y.replace( "_", " ") plot.Plot(rows, label=label, y=y, x='hour_of_week') plot.Done()
def __init__(self, http_handler, params): self.http_handler = http_handler self.channels = params["channels"].split(",") if "channels" in params else None self.videos = params["videos"].split(",") if "videos" in params else None self.bin_hours = int(params["bin_hours"]) if "bin_hours" in params else 12 self.per_hour = bool(int(params["per_hour"])) if "per_hour" in params else False self.stacked = bool(int(params["stacked"])) if "stacked" in params else False self.min_time = "convert_tz('%s', 'system', 'gmt')" % params["min_time"] if "min_time" in params else None if self.min_time is None and "hours_ago" in params: self.min_time = "convert_tz(now() - interval %s hour, 'system', 'gmt')" % params["hours_ago"] self.max_time = "convert_tz('%s', 'system', 'gmt')" % params["max_time"] if "max_time" in params else None if self.max_time is None and "total_hours" in params: assert self.min_time is not None self.max_time = "%s + interval %s hour" % params["total_hours"] self.con = db_utils.Connect() if "videos_query_file" in params: assert self.videos is None sql = GetSQL(params["videos_query_file"]) self.videos = [r["video_id"] for r in self.con.query(sql % params)] self.tables = tables.Tables() self.rows = None self.interpolator = None
def __init__(self, frequency=None): self.last = time.time() self.frequency = frequency self.name = self.__class__.__name__ self.con = db_utils.Connect() self.tables = tables.Tables()
def __init__(self): con = db_utils.Connect(use_db=False) con.query("drop database if exists sarahlytics") con.query("create database sarahlytics") super(DatabaseInitWorker, self).__init__()
for y in ys: label = "total" if y == "total" else "videos with " + y.replace( "_", " ") plot.Plot(rows, label=label, y=y, x='hour_of_week') plot.Done() def PlotPostStraightup(con=None, rows=None, y="avg_view"): if con is None: con = db_utils.Connect() if rows is None: rows = con.query(PostFrequencyQuery()) plot = plotting.WeekPlotter(title=y.replace("_", " ") + " over a week", name=y + "_week") plot.Plot(rows, x="hour_of_week", y=y, label=y.replace("_", " ")) plot.YLabel(y.replace("_", " ")) plot.Done() if __name__ == "__main__": con = db_utils.Connect() rows = con.query(PostFrequencyQuery()) PlotPostFrequency(con=con, rows=rows, save=True, scale=True, subs=False) PlotPostFrequency(con=con, rows=rows, save=True, scale=True, views=False) PlotPostFrequency(con=con, rows=rows, save=True, scale=False, subs=False) PlotPostFrequency(con=con, rows=rows, save=True, scale=False, views=False) PlotPostStraightup(con=con, rows=rows, y="avg_view") PlotPostStraightup(con=con, rows=rows, y="avg_log_view") PlotPostStraightup(con=con, rows=rows, y="avg_view_per_sub") PlotPostStraightup(con=con, rows=rows, y="avg_log_view_per_sub")