# Path: boris/db_functions.py
# def load_events_in_db(pj: dict,
#                       selected_subjects: list,
#                       selected_observations: list,
#                       selected_behaviors: list,
#                       time_interval: str = TIME_FULL_OBS):
# def load_aggregated_events_in_db(pj: dict, selected_subjects: list, selected_observations: list,
#                                  selected_behaviors: list):
# def load_aggregated_events_in_intervals(pj: dict, selected_subjects: list, selected_observations: list,
#                                         selected_behaviors: list):


import os
import sys
import json
from boris import db_functions
        pj = json.loads(open("files/test.boris").read())

        cursor = db_functions.load_events_in_db(pj, ["subject2"], ["live"], ["s", "p"])
        cursor.execute("SELECT occurence FROM events WHERE observation = ? AND subject = ? AND code = ?",
                       ("live", "subject2", "s"))
        out = ""
        for r in cursor.fetchall():
            out += '{}\n'.format(r[0])

        REF = """12.509\n20.685\n"""

        assert out ==  REF


    def test_3(self):
        """
        no focal subject, observation with not paired events
        """

        pj = json.loads(open("files/test.boris").read())

        cursor = db_functions.load_events_in_db(pj, ["No focal subject"], ["live not paired"], ["s", "p"])
        cursor.execute("SELECT occurence FROM events WHERE observation = ? AND subject = ? AND code = ?",
                       ("live not paired", "No focal subject", "s"))
        out = ""
        for r in cursor.fetchall():
            out += '{}\n'.format(r[0])

        REF = """2.718\n10.478\n12.926\n17.47\n19.502\n24.318\n26.862\n"""


# Path: boris/db_functions.py
# def load_events_in_db(pj: dict,
#                       selected_subjects: list,
#                       selected_observations: list,
#                       selected_behaviors: list,
#                       time_interval: str = TIME_FULL_OBS):
# def load_aggregated_events_in_db(pj: dict, selected_subjects: list, selected_observations: list,
#                                  selected_behaviors: list):
# def load_aggregated_events_in_intervals(pj: dict, selected_subjects: list, selected_observations: list,
#                                         selected_behaviors: list):


# Path: tests/test_db_functions.py
import os
import sys
import json
from boris import db_functions

        pj = json.loads(open("files/test.boris").read())

        cursor = db_functions.load_events_in_db(pj, ["subject2"], ["live"], ["s", "p"])
        cursor.execute("SELECT occurence FROM events WHERE observation = ? AND subject = ? AND code = ?",
                       ("live", "subject2", "s"))
        out = ""
        for r in cursor.fetchall():
            out += '{}\n'.format(r[0])

        REF = """12.509\n20.685\n"""

        assert out ==  REF


    def test_3(self):
        """
        no focal subject, observation with not paired events
        """

        pj = json.loads(open("files/test.boris").read())

        cursor = db_functions.load_events_in_db(pj, ["No focal subject"], ["live not paired"], ["s", "p"])
        cursor.execute("SELECT occurence FROM events WHERE observation = ? AND subject = ? AND code = ?",
                       ("live not paired", "No focal subject", "s"))
        out = ""
        for r in cursor.fetchall():
            out += '{}\n'.format(r[0])

        REF = """2.718\n10.478\n12.926\n17.47\n19.502\n24.318\n26.862\n"""


        assert out ==  REF