Пример #1
0
def count_round0clusters(query, minl, maxl, maxfetch=10000):
    con, cur = sql_connection()

    print("Executing query... (be patient)")

    cur.execute(query)

    cluster_data, type_count = defaultdict(lambda:[0, 0]), [0, 0]
    sims = [cur.fetchone()]

    while sims != [None]:
        print("Fetching data... (" + str(maxfetch) + " rows)")
        sims += cur.fetchmany(maxfetch)

        print("Counting clusters...")
        for lattice, p, type, array in sims:

            # Get clusters from array data
            clusters = cca.get_clusters_from_list(
                zip(array[0], array[1], array[2]), lattice
            )

            # Remove single clusters
            clusters = [
                cluster
                for cluster in clusters.values()
                if len(cluster) >= minl and len(cluster) <= maxl
            ]

            cluster_data = cca.get_count(clusters, cluster_data, lattice, type)

            type_count[type] += 1

        sims = [cur.fetchone()]
    else:
        cur.close()
        con.close()

    return (
        sorted(cluster_data.items(), key=lambda kv: sum(kv[1]), reverse=True),
        type_count,
    )
Пример #2
0
def count_round1clusters(query, minl, maxl, maxfetch=10000):
    con, cur = sql_connection("../cposguf.ini")

    print("Executing query... (be patient)")

    cur.execute(query)

    cluster_data, type_count = {}, [0, 0]
    sims = [cur.fetchone()]

    while sims != [None]:
        print("Fetching data... (" + str(maxfetch) + " rows)")
        sims += cur.fetchmany(maxfetch)

        print("Counting clusters...")
        for lattice, p, type, array in sims:

            clusters = cca.get_clusters_from_list(
                zip(array[0], array[1], array[2]), lattice
            )

            cca.plot_cluster(
                cca.flatten(list(clusters.values())), lattice - 1, lattice - 1
            )

            type_count[type] += 1

        sims = [cur.fetchone()]
    else:
        cur.close()
        con.close()

    return (
        sorted(cluster_data.items(), key=lambda kv: sum(kv[1]), reverse=True),
        type_count,
    )
###########################################################

if os.path.exists(file + ".pkl"):  # Load data_base if pickled file exists
    print("loading data " + file)
    data = pk.load_obj(file)
    data_p, data_n = data["data_p"], data["data_n"]
    countp, countn = data["countp"], data["countn"]
else:  # Initate database
    data_p, data_n = [dd(d2) for _ in range(2)]
    countp, countn = [dd(d0) for _ in range(2)]

for lattice in L:
    for p in P:

        con, cur = sql_connection()
        print("\nGetting count of L{}, p{}...".format(lattice, p))
        cur.execute(
            "SELECT tree_wins, list_wins FROM cases WHERE lattice = {} and p = {}"
            .format(lattice, p))
        tlcount = cur.fetchone()
        countp[(lattice, p)] = [tlcount[0], tlcount[1]]

        cur.execute(fetch_query("COUNT(*)", lattice, p))
        num = cur.fetchone()[0]
        print("fetching {} simulations...".format(num))

        cur.execute(fetch_query("ftree_tlist, seed", lattice, p))
        sims = [cur.fetchone()]
        graph = go.init_toric_graph(lattice)