import time

import numpy as np

from config.config import get_config
from .hdf5_tdms import HDF5_tdms as HDF5


cfg = get_config(validate_present=['data_folder'])
if cfg:
    log_folder=cfg['data_folder']
else:
    log_folder = "C:\\Users\mkemp\\Documents\\Python\\hdf5\\LOG_FILES\\"  # folder location

with HDF5(log_folder) as logger:

    # start a log
    logger.new_log()                # open a new file & datasets
    for n in range(2):             # data acquisition loop
        N = 10
        data = np.random.rand(4, N)  # read data
        t = np.zeros(N)
        logger.append(t, data)         # log it
        logger.flush()
#    logger.stop()                   # close the file

    time.sleep(2)                   # some time passes ...
    
    #start a second log
    logger.new_log()
    for n in range(10):
        N = 2
        data = np.random.rand(4,N)
        t = np.zeros(N)
        logger.append(t, data)
    logger.stop()
