# Path: boris/project_functions.py
# def check_observation_exhaustivity(events: list, ethogram: list, state_events_list: list = []):
#     def interval_len(interval):
#     def interval_number(interval):
# def behavior_category(ethogram: dict) -> dict:
# def check_coded_behaviors(pj: dict) -> set:
# def check_if_media_available(observation: dict, project_file_name: str) -> bool:
# def check_state_events_obs(obsId: str, ethogram: dict, observation: dict, time_format: str = HHMMSS) -> tuple:
# def check_project_integrity(pj: dict,
#                             time_format: str,
#                             project_file_name: str,
#                             media_file_available: bool = True) -> str:
# def create_subtitles(pj: dict, selected_observations: list, parameters: dict, export_dir: str) -> tuple:
#     def subject_color(subject):
# def export_observations_list(pj: dict, selected_observations: list, file_name: str, output_format: str) -> bool:
# def remove_media_files_path(pj):
# def media_full_path(media_file: str, project_file_name: str) -> str:
# def observed_interval(observation: dict):
# def observation_total_length(observation: dict):
# def observation_length(pj, selected_observations: list) -> tuple:
# def events_start_stop(ethogram, events):
# def extract_observed_subjects(pj: dict, selected_observations: list) -> list:
# def open_project_json(projectFileName: str) -> tuple:
# def event_type(code: str, ethogram: dict) -> str:
# def fix_unpaired_state_events(obsId, ethogram, observation, fix_at_time):


import sqlite3
import os
import logging
import time
from boris.config import *
from boris import project_functions
        selected_observations (list):
        selected_subjects (list):
        selected_behaviors (list):

    Returns:
        bool: True if OK else False
        str: error message
        database connector: db connector if bool True else None

    """

    logging.debug(f"function: load_aggregated_events_in_db")

    # if no observation selected select all
    if not selected_observations:
        selected_observations = sorted([x for x in pj[OBSERVATIONS]])

    # if no subject selected select all
    if not selected_subjects:
        selected_subjects = sorted([pj[SUBJECTS][x][SUBJECT_NAME] for x in pj[SUBJECTS]] + [NO_FOCAL_SUBJECT])

    # if no behavior selected select all
    if not selected_behaviors:
        selected_behaviors = sorted([pj[ETHOGRAM][x][BEHAVIOR_CODE] for x in pj[ETHOGRAM]])

    intervals = {}

    # check if state events are paired
    out = ""
    for obsId in selected_observations:

# Path: boris/project_functions.py
# def check_observation_exhaustivity(events: list, ethogram: list, state_events_list: list = []):
#     def interval_len(interval):
#     def interval_number(interval):
# def behavior_category(ethogram: dict) -> dict:
# def check_coded_behaviors(pj: dict) -> set:
# def check_if_media_available(observation: dict, project_file_name: str) -> bool:
# def check_state_events_obs(obsId: str, ethogram: dict, observation: dict, time_format: str = HHMMSS) -> tuple:
# def check_project_integrity(pj: dict,
#                             time_format: str,
#                             project_file_name: str,
#                             media_file_available: bool = True) -> str:
# def create_subtitles(pj: dict, selected_observations: list, parameters: dict, export_dir: str) -> tuple:
#     def subject_color(subject):
# def export_observations_list(pj: dict, selected_observations: list, file_name: str, output_format: str) -> bool:
# def remove_media_files_path(pj):
# def media_full_path(media_file: str, project_file_name: str) -> str:
# def observed_interval(observation: dict):
# def observation_total_length(observation: dict):
# def observation_length(pj, selected_observations: list) -> tuple:
# def events_start_stop(ethogram, events):
# def extract_observed_subjects(pj: dict, selected_observations: list) -> list:
# def open_project_json(projectFileName: str) -> tuple:
# def event_type(code: str, ethogram: dict) -> str:
# def fix_unpaired_state_events(obsId, ethogram, observation, fix_at_time):


# Path: boris/db_functions.py
import sqlite3
import os
import logging
import time
from boris.config import *
from boris import project_functions

        selected_observations (list):
        selected_subjects (list):
        selected_behaviors (list):

    Returns:
        bool: True if OK else False
        str: error message
        database connector: db connector if bool True else None

    """

    logging.debug(f"function: load_aggregated_events_in_db")

    # if no observation selected select all
    if not selected_observations:
        selected_observations = sorted([x for x in pj[OBSERVATIONS]])

    # if no subject selected select all
    if not selected_subjects:
        selected_subjects = sorted([pj[SUBJECTS][x][SUBJECT_NAME] for x in pj[SUBJECTS]] + [NO_FOCAL_SUBJECT])

    # if no behavior selected select all
    if not selected_behaviors:
        selected_behaviors = sorted([pj[ETHOGRAM][x][BEHAVIOR_CODE] for x in pj[ETHOGRAM]])

    intervals = {}

    # check if state events are paired
    out = ""
    for obsId in selected_observations:

        r, msg = project_functions.check_state_events_obs(obsId, pj[ETHOGRAM], pj[OBSERVATIONS][obsId], HHMMSS)