Esempio n. 1
0
def setup(logname):
    from src.modules.utils.config_loader import get_config
    conf = get_config()
    # associate command line arguments with logging levels
    log_dict = {
        'debug': logging.DEBUG,
        'info': logging.INFO,
        'warning': logging.WARNING,
        'error': logging.ERROR,
        'critical': logging.CRITICAL
    }

    # currently parses only the logging level, but you can add more arguments as well (see python docs on logging)
    parser = argparse.ArgumentParser(usage='%(prog)s [-l]')
    parser.add_argument('-l',
                        '--log',
                        nargs='?',
                        choices=log_dict.keys(),
                        default='info',
                        const='info',
                        help="logging level for console")
    args, extra_args = parser.parse_known_args()

    # create logging file if doesn't exist
    log_file_path = os.path.join(conf.dirs.logs,
                                 os.getlogin() + "_" + logname + ".log")
    if not os.path.exists(conf.dirs.logs):
        os.makedirs(conf.dirs.logs)
    if not os.path.exists(log_file_path):
        open(log_file_path, "w").close()

    # set up logging to file (file always does debug level)
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(levelname)-4s|%(message)s',
                        datefmt='%Y/%m/%d %H:%M:%S',
                        filename=os.path.join(
                            conf.dirs.logs,
                            os.getlogin() + "_" + logname + ".log"),
                        filemode='a')
    # set up logging to console (only do this if there are no handlers)
    if len(logging.getLogger('').handlers) < 2:
        console = logging.StreamHandler()
        console.setLevel(log_dict[args.log])
        formatter = logging.Formatter(
            '%(asctime)s %(levelname)-4s|%(message)s', '%Y/%m/%d %H:%M:%S')
        console.formatter = formatter
        logging.getLogger('').addHandler(console)
    logging.info(
        "============================================================")
    return conf
# ====== External package imports ================
import pandas as pd
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
# ====== Internal package imports ================
from src.modules.data.database_io import DatabaseIO
from src.modules.utils.misc import run_and_catch_exceptions
# ============== Logging  ========================
import logging
from src.modules.utils.setup import setup, IndentLogger
logger = IndentLogger(logging.getLogger(''), {})
# =========== Config File Loading ================
from src.modules.utils.config_loader import get_config
conf  = get_config()
# ================================================


def interval_overlap(interval_a, interval_b):
    """Given two intervals on the real line, determine their overlap

    :param interval_a: tuple of (left, right) for first point
    :param interval_b: tuple of (left, right) for second point
    :return: float which is overlap
    """
    x1, x2 = interval_a
    x3, x4 = interval_b

    if x3 < x1:
        if x4 < x1:
Esempio n. 3
0
import glob
import os
# ####### Logging and config file loading ########
import logging
from src.modules.utils.setup import setup, IndentLogger
logger = IndentLogger(logging.getLogger(''), {})
# ########### Config File Loading ################
from src.modules.utils.config_loader import get_config
conf, confp = get_config()
##################################################

conf, confp = setup("process_subtitles")

# import / output files
subtitle_dir = confp.dirs.subtitles
output_file_name = "video_metadata_full.csv"

# create metadata file
f_out = open(subtitle_dir + output_file_name, 'w')
f_out.write("file,time_stamp,date_and_time\n")
for i, f_path in enumerate(glob.glob(subtitle_dir + "*.srt")):
    with open(f_path) as f:
        f_name = os.path.basename(f_path).split(".")[0]
        print("Collecting metadata from file {}:{}".format(i, f_name))
        for line in f.readlines():
            if "AM" in line or "PM" in line:
                f_out.write(line.replace(",", "").replace("\n", "") + '\n')
            elif '-->' in line:
                f_out.write(f_name + ',' + line[:8] + ',')
f_out.close()