Ejemplo n.º 1
0
    def __init__(self):
        self.conn = None

        # Open or create DB
        fn_db = Conf.GetFn("whole_foods_loc_db")
        conn = None
        if os.path.exists(fn_db):
            with Cons.MT("Opening the existing db ..."):
                conn = sqlite3.connect(fn_db)
                if conn is None:
                    raise RuntimeError(
                        "Error! cannot create the database connection.")
                conn.row_factory = sqlite3.Row
                cur = conn.cursor()
                q = "SELECT count(*) as cnt FROM whole_foods_loc"
                cur.execute(q)
                r = cur.fetchone()
                Cons.P("There are %d records" % r["cnt"])
        else:
            with Cons.MT("Creating a new db ..."):
                conn = sqlite3.connect(fn_db)
                if conn is None:
                    raise RuntimeError(
                        "Error! cannot create the database connection.")
                conn.row_factory = sqlite3.Row
                cur = conn.cursor()
                q = """CREATE TABLE IF NOT EXISTS whole_foods_loc (
                 addr text NOT NULL
                 , lat real NOT NULL
                 , lon real NOT NULL
                 , PRIMARY KEY (addr)
               ); """
                cur.execute(q)
        self.conn = conn
Ejemplo n.º 2
0
def GetNumAccessesStat():
    fn_out = "%s/cdf-youtube-accesses-per-co" % Conf.DnOut()
    if os.path.exists(fn_out):
        return fn_out

    num_accesses = []
    fn_in = Conf.GetFn("video_accesses_by_COs")
    with open(fn_in) as fo:
        while True:
            line = fo.readline()
            if len(line) == 0:
                break

            line = line.strip()
            if len(line) == 0:
                continue
            if line[0] == "#":
                continue

            # 4 34.3305 -111.091 13
            t = line.split(" ")
            if len(t) != 4:
                raise RuntimeError("Unexpected: [%s]" % line)
            n = int(t[3])
            #Cons.P(n)
            num_accesses.append(n)

            for j in range(n):
                if len(fo.readline()) == 0:
                    raise RuntimeError("Unexpected")

    r = Stat.Gen(num_accesses, fn_out)
    #Cons.P(r)

    return fn_out
Ejemplo n.º 3
0
def GetTemporalDist():
  fn_in = Conf.GetFn("youtube_workload")
  fn_out = "%s/%s-temporal-dist-weekly" % (Conf.DnOut(), os.path.basename(fn_in))
  if os.path.isfile(fn_out):
    return (fn_out, _GetWeeklyMax(fn_out))
  cmd = "%s/_gen-plot-data.sh --youtube_workload=%s --out_fn=%s" % (os.path.dirname(__file__), fn_in, fn_out)
  Util.RunSubp(cmd)
  return (fn_out, _GetWeeklyMax(fn_out))
Ejemplo n.º 4
0
def GetObjPopDist():
    fn_in = Conf.GetFn("youtube_workload")
    fn_out = "%s/%s-obj-pop-dist" % (Conf.DnOut(), os.path.basename(fn_in))
    if os.path.isfile(fn_out):
        return fn_out

    cmd = "%s/_gen-plot-data.sh --youtube_workload=%s" % (
        os.path.dirname(__file__), fn_in)
    Util.RunSubp(cmd)
    return fn_out
Ejemplo n.º 5
0
def GetClusteredPoints():
    dist_sq_threshold = Conf.Get("dist_sq_threshold")

    fn_in = Conf.GetFn("youtube_workload")
    fn_out = "%s/%s-clustered-with-dist-sq-%s" % (
        Conf.DnOut(), os.path.basename(fn_in), dist_sq_threshold)
    #Cons.P(fn_out)
    if os.path.isfile(fn_out):
        return fn_out
    cmd = "%s/_cluster.sh --youtube_workload=%s --dist_sq_threshold=%s" \
        % (os.path.dirname(__file__), fn_in, dist_sq_threshold)
    Util.RunSubp(cmd)
    return fn_out