# Path: src/helper_functions.py
# def grab_all(connection, cmd, *args):
#     return connection.execute(cmd, *args).fetchall()
# 
# def load_options(f_option_file="options_simple_connected.json"):
#     # Load the file into a string
#     try:
#         with open(f_option_file) as FIN:
#             raw_text = FIN.read()
#     except:
#         msg = "Couldn't find option file {}".format(f_option_file)
#         raise IOError(msg)
# 
#     # Parse the text as json
#     try:
#         return json.loads(raw_text)
#     except Exception as Ex:
#         msg = "Couldn't parse JSON file {}, {}".format(f_option_file, Ex)
#         raise IOError(msg)


import sqlite3
import logging
import argparse
from src.helper_functions import grab_all, load_options
#######################################################################

# Find the relations that are subsets (and not equalities)
cmd = '''
SELECT relation_id, s1_id,s2_id FROM relations
WHERE subset=1'''
relations_subset = grab_all(seq_conn, cmd)

line = "\n# Subset relations (converse is not true)\n"
FOUT.write(line)

msg = "+ `{}{}{}` -> `{}{}{}`\n"
for ridx, s1, s2 in relations_subset:

    # FLIP THE ORDER FOR SUBSETS
    f1, c1, v1 = info(s2)
    f2, c2, v2 = info(s1)

    vals = (f1, c1, v1, f2, c2, v2)
    if f1 not in ignored_functions and f2 not in ignored_functions:

        if (s1, s2) not in EQ_SET:
            FOUT.write(msg.format(*vals))

#######################################################################

# Find the relations that are exclusive
cmd = '''
SELECT relation_id, s1_id,s2_id FROM relations
WHERE exclusive=1'''

# Path: src/helper_functions.py
# def grab_all(connection, cmd, *args):
#     return connection.execute(cmd, *args).fetchall()
# 
# def load_options(f_option_file="options_simple_connected.json"):
#     # Load the file into a string
#     try:
#         with open(f_option_file) as FIN:
#             raw_text = FIN.read()
#     except:
#         msg = "Couldn't find option file {}".format(f_option_file)
#         raise IOError(msg)
# 
#     # Parse the text as json
#     try:
#         return json.loads(raw_text)
#     except Exception as Ex:
#         msg = "Couldn't parse JSON file {}, {}".format(f_option_file, Ex)
#         raise IOError(msg)


# Path: verification/raw_dump_relations.py
import sqlite3
import logging
import argparse
from src.helper_functions import grab_all, load_options

#######################################################################

# Find the relations that are subsets (and not equalities)
cmd = '''
SELECT relation_id, s1_id,s2_id FROM relations
WHERE subset=1'''
relations_subset = grab_all(seq_conn, cmd)

line = "\n# Subset relations (converse is not true)\n"
FOUT.write(line)

msg = "+ `{}{}{}` -> `{}{}{}`\n"
for ridx, s1, s2 in relations_subset:

    # FLIP THE ORDER FOR SUBSETS
    f1, c1, v1 = info(s2)
    f2, c2, v2 = info(s1)

    vals = (f1, c1, v1, f2, c2, v2)
    if f1 not in ignored_functions and f2 not in ignored_functions:

        if (s1, s2) not in EQ_SET:
            FOUT.write(msg.format(*vals))

#######################################################################

# Find the relations that are exclusive
cmd = '''
SELECT relation_id, s1_id,s2_id FROM relations
WHERE exclusive=1'''

relations_ex = grab_all(seq_conn, cmd)