Example #1
0
def get_cable(idx, field=None):
    conn = get_connexion()
    cur = conn.cursor(cursor_factory=DictCursor)
    cur.execute("SELECT * FROM cable WHERE id = %s LIMIT 1", (idx, ))
    if field == None:
        return cur.fetchone()
    else:
        return cur.fetchone().get(field)
Example #2
0
def get_analyse(idx):
    conn  = get_connexion()
    cable = get_cable(idx=idx)
    start_time = time.time()
    # Unkown cable id
    if not cable: return "Cable %s dosen't exist!" % idx
    analyse_cable(cable, conn)
    return "cable %s analysed (%ss)." % (idx, round(time.time() - start_time, 3))
Example #3
0
def get_cable(idx, field=None):
    conn = get_connexion()
    cur  = conn.cursor(cursor_factory=DictCursor)
    cur.execute("SELECT * FROM cable WHERE id = %s LIMIT 1", (idx,) )
    if field == None:
        return cur.fetchone()
    else:
        return cur.fetchone().get(field)
Example #4
0
def get_analyse(idx):
    conn = get_connexion()
    cable = get_cable(idx=idx)
    start_time = time.time()
    # Unkown cable id
    if not cable: return "Cable %s dosen't exist!" % idx
    analyse_cable(cable, conn)
    return "cable %s analysed (%ss)." % (idx, round(time.time() - start_time,
                                                    3))
Example #5
0
def get_bash_analyse(frm, to, verbose=True):
    PAGE_SIZE = 100
    LAST_PAGE = (to - frm)/PAGE_SIZE
    conn      = get_connexion()
    cur       = conn.cursor(cursor_factory=DictCursor)
    analysed  = 0
    page      = 0
    for page in range(0, LAST_PAGE):
        offset = frm + (page * PAGE_SIZE)    
        cur.execute("SELECT * FROM cable WHERE id >= %s AND id <= %s ORDER BY id LIMIT %s", (offset, to, PAGE_SIZE) )
        cables = cur.fetchall()
        analysed += len(cables)
        for cable in cables:
            start_time = time.time()
            analyse_cable(cable, conn)
            if verbose: print "Cable %s analysed (%ss)..." % (cable['id'], round(time.time() - start_time, 3))
    return "%s cable(s) analysed." % analysed
Example #6
0
def get_bash_analyse(frm, to, verbose=True):
    PAGE_SIZE = 100
    LAST_PAGE = (to - frm) / PAGE_SIZE
    conn = get_connexion()
    cur = conn.cursor(cursor_factory=DictCursor)
    analysed = 0
    page = 0
    for page in range(0, LAST_PAGE):
        offset = frm + (page * PAGE_SIZE)
        cur.execute(
            "SELECT * FROM cable WHERE id >= %s AND id <= %s ORDER BY id LIMIT %s",
            (offset, to, PAGE_SIZE))
        cables = cur.fetchall()
        analysed += len(cables)
        for cable in cables:
            start_time = time.time()
            analyse_cable(cable, conn)
            if verbose:
                print "Cable %s analysed (%ss)..." % (
                    cable['id'], round(time.time() - start_time, 3))
    return "%s cable(s) analysed." % analysed
Example #7
0
def install_ngram(force=False, halt_on_error=True):
    conn = get_connexion()
    cur = conn.cursor()
    try:
        # Force new table creating by removing the existing one
        if force:
            cur.execute("""DROP TABLE cable_ngram""")
        # Create the new tables
        cur.execute("""CREATE TABLE cable_ngram(
            cable      INTEGER,
            ngram      TEXT,
            count      INTEGER,
            created_at DATE,
            FOREIGN KEY (cable) REFERENCES cable(id),
            UNIQUE (cable, ngram)
        )""")
        # Commit actions
        conn.commit()
    except psycopg2.ProgrammingError as e:
        if halt_on_error: exit("Unable to create the table: %s" % e)
        else: pass
    print "Table ̀`cable_ngram` created."
Example #8
0
def install_ngram(force=False, halt_on_error=True):
    conn = get_connexion()
    cur  = conn.cursor()
    try:
        # Force new table creating by removing the existing one
        if force:
            cur.execute("""DROP TABLE cable_ngram""")
        # Create the new tables
        cur.execute("""CREATE TABLE cable_ngram(
            cable      INTEGER,
            ngram      TEXT,
            count      INTEGER,
            created_at DATE,
            FOREIGN KEY (cable) REFERENCES cable(id),
            UNIQUE (cable, ngram)
        )""")
        # Commit actions
        conn.commit()
    except psycopg2.ProgrammingError as e:
        if halt_on_error: exit("Unable to create the table: %s" % e)
        else: pass
    print "Table ̀`cable_ngram` created."
Example #9
0
def install_location(force=False, halt_on_error=True):
    conn = get_connexion()
    cur = conn.cursor()
    try:
        # Force new table creating by removing the existing one
        if force:
            cur.execute("""DROP TABLE cable_location""")
        cur.execute("""CREATE TABLE cable_location(
            cable      INTEGER,
            location   VARCHAR(255),
            type       VARCHAR(25),
            country    VARCHAR(25),
            lat        VARCHAR(15),
            lon        VARCHAR(15),
            created_at DATE,
            FOREIGN KEY (cable) REFERENCES cable(id),
            UNIQUE (cable, location, type)
        )""")
        # Commit actions
        conn.commit()
    except psycopg2.ProgrammingError as e:
        if halt_on_error: exit("Unable to create the table: %s" % e)
        else: pass
    print "Table ̀`cable_location` created."
Example #10
0
def install_location(force=False, halt_on_error=True):
    conn = get_connexion()
    cur  = conn.cursor()
    try:
        # Force new table creating by removing the existing one
        if force:
            cur.execute("""DROP TABLE cable_location""")
        cur.execute("""CREATE TABLE cable_location(
            cable      INTEGER,
            location   VARCHAR(255),
            type       VARCHAR(25),
            country    VARCHAR(25),
            lat        VARCHAR(15),
            lon        VARCHAR(15),
            created_at DATE,
            FOREIGN KEY (cable) REFERENCES cable(id),
            UNIQUE (cable, location, type)
        )""")
        # Commit actions
        conn.commit()
    except psycopg2.ProgrammingError as e:
        if halt_on_error: exit("Unable to create the table: %s" % e)
        else: pass
    print "Table ̀`cable_location` created."