def get_correlations(db, db_session):#, t1, t2):
    """Loops through tables and computes pearson correlations between columns"""
    
    meta = MetaData(db)
    meta.reflect()
    tablenames = meta.tables.keys()
    tablemds = [Metadata.load_from_tablename(db, tn) for tn in tablenames]
    tablemds = filter(lambda md: md.state >= 3, tablemds)
    
    tablestats = []
    for tablemd in tablemds:
        table = tablemd.tablename
        radius = compute_radius(db, table)
        if radius == None:
            continue
        bshape = has_shape(db, table)
        tablestats.append((tablemd, radius, bshape))
    
    res = []
    for idx, (tmd1, r1, s1) in enumerate(tablestats):
        for tmd2, r2, s2 in tablestats[idx+1:]:

            if len(db_session.query(CorrelationPair).filter(
                CorrelationPair.md1 == tmd1,
                CorrelationPair.md2 == tmd2 ).all()):
                print "skipping", tmd1.tablename, tmd2.tablename
                continue
            
            t1, t2 = tmd1.tablename, tmd2.tablename
            r = float(np.mean([r1, r2]))
            djoinres = dist_join(db, t1, t2, r)

            for corr, statname, col1, col2 in test_correlation(djoinres):

                agg1 = col1[2] if len(col1) > 2 else None
                agg2 = col2[2] if len(col2) > 2 else None
                cp = CorrelationPair(corr, r, statname,
                                     col1[0], col1[1], agg1,
                                     col2[0], col2[1], agg2,
                                     tmd1, tmd2)

                db_session.add(cp)
                db_session.commit()
                print cp
                res.append(cp)
    return res
dataset/ETHPy150Open sirrice/dbtruck/dbtruck/analyze/fuzzyjoin.py/get_correlations/original