<commit_before>#!/usr/bin/env python

import subprocess

import sqlite3 as sql
import numpy as np

from plots import post_dbs

query = """
SELECT tl.Time AS Time,TOTAL(sub.qty) AS Quantity
FROM timelist as tl
LEFT JOIN (
	SELECT t.simid AS simid,t.time as time,SUM(c.massfrac*r.quantity) as qty
	FROM transactions AS t
	JOIN resources as r ON t.resourceid=r.resourceid AND r.simid=t.simid
	JOIN agents as send ON t.senderid=send.agentid AND send.simid=t.simid
	JOIN agents as recv ON t.receiverid=recv.agentid AND recv.simid=t.simid
	JOIN compositions as c ON c.qualid=r.qualid AND c.simid=r.simid
	WHERE t.simid=?  AND recv.prototype=? AND t.commodity=?  
	GROUP BY t.time
) AS sub ON tl.time=sub.time AND tl.simid=sub.simid
WHERE tl.simid=?
GROUP BY tl.Time;
"""

def flow(db, commod, proto):
    con = sql.connect(db)
    cur = con.cursor()
    info = cur.execute('SELECT * from INFO').fetchall()
    simid = info[0][0]
    args = [simid, proto, commod, simid]
    data = np.array(cur.execute(query, args).fetchall())
    con.close()
    return data

def post_dbs(dbs):
    for name in dbs:
        cmd = "cyan -db {} post".format(name)
        subprocess.call(cmd.split(), shell=False)

cases = "base_case once_through military tariff outage"
commods = "uox mox b_uox mil_mox"
protos = "reactor b_reactor"

def main():
    for case in cases.split():
        print('Testing {}'.format(case))
        for commod in commods.split():
            for proto in protos.split():
                gdb = "{}.sqlite".format(case) 
                cdb = "{}_cbc.sqlite".format(case)
                post_dbs([gdb, cdb])
                greedy = flow(gdb, commod, proto)
                cbc = flow(cdb, commod, proto)
                msg = "Case: {}, Commod: {}, Proto: {}".format(
                    case, commod, proto)
                np.testing.assert_array_almost_equal(
                    greedy, cbc, err_msg=msg, verbose=True)

if __name__ == "__main__":
    main()
<commit_msg>test now tests everything with a better print msg<commit_after>#!/usr/bin/env python

import subprocess

import sqlite3 as sql
import numpy as np

from plots import post_dbs

query = """
SELECT TOTAL(sub.qty) AS Quantity
FROM timelist as tl
LEFT JOIN (
	SELECT t.simid AS simid,t.time as time,SUM(c.massfrac*r.quantity) as qty
	FROM transactions AS t
	JOIN resources as r ON t.resourceid=r.resourceid AND r.simid=t.simid
	JOIN agents as send ON t.senderid=send.agentid AND send.simid=t.simid
	JOIN agents as recv ON t.receiverid=recv.agentid AND recv.simid=t.simid
	JOIN compositions as c ON c.qualid=r.qualid AND c.simid=r.simid
	WHERE t.simid=?  AND recv.prototype=? AND t.commodity=?  
	GROUP BY t.time
) AS sub ON tl.time=sub.time AND tl.simid=sub.simid
WHERE tl.simid=?
GROUP BY tl.Time;
"""

def flow(db, commod, proto):
    con = sql.connect(db)
    cur = con.cursor()
    info = cur.execute('SELECT * from INFO').fetchall()
    simid = info[0][0]
    args = [simid, proto, commod, simid]
    data = np.array(cur.execute(query, args).fetchall())
    con.close()
    return data

def post_dbs(dbs):
    for name in dbs:
        cmd = "cyan -db {} post".format(name)
        subprocess.call(cmd.split(), shell=False)

cases = "base_case once_through military tariff outage"
commods = "uox mox b_uox mil_mox"
protos = "reactor b_reactor"

msg = """Case: {}, Commod: {}, Proto: {}
Different at t={}
"""

def main():
    for case in cases.split():
        print('Testing {}'.format(case))
        for commod in commods.split():
            for proto in protos.split():
                gdb = "{}.sqlite".format(case) 
                cdb = "{}_cbc.sqlite".format(case)
                post_dbs([gdb, cdb])
                greedy = flow(gdb, commod, proto)
                cbc = flow(cdb, commod, proto)
                if not np.allclose(greedy, cbc):
                    times = np.where(np.abs(greedy - cbc) > 1e-2)[0]
                    print(msg.format(case, commod, proto, times))

if __name__ == "__main__":
    main()

{'fraction_non_alphanumeric': 0.12684144818976278, 'fraction_numerical': 0.0022471910112359553, 'mean_word_length': 2.7265116279069765, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3074957', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1405, 'n_words': 394}