# Path: mimic3models/common_utils.py
# def convert_to_dict(data, header, channel_info):
# def extract_features_from_rawdata(chunk, header, period, features):
# def read_chunk(reader, chunk_size):
# def sort_and_shuffle(data, batch_size):
# def add_common_arguments(parser):
#     def __init__(self, dataset_dir, listfile=None, small_part=False):
#     def _read_timeseries(self, ts_filename):
# def create_directory(directory):
# def pad_zeros(arr, min_length=None):
# class DeepSupervisionDataLoader:


from mimic3models import common_utils
import threading
import os
import numpy as np
import random
    def __init__(self, reader, discretizer, normalizer,
                 batch_size, steps, shuffle, return_names=False):
        self.reader = reader
        self.discretizer = discretizer
        self.normalizer = normalizer
        self.batch_size = batch_size
        self.shuffle = shuffle
        self.return_names = return_names

        if steps is None:
            self.n_examples = reader.get_number_of_examples()
            self.steps = (self.n_examples + batch_size - 1) // batch_size
        else:
            self.n_examples = steps * batch_size
            self.steps = steps

        self.chunk_size = min(1024, self.steps) * batch_size
        self.lock = threading.Lock()
        self.generator = self._generator()

    def _generator(self):
        B = self.batch_size
        while True:
            if self.shuffle:
                self.reader.random_shuffle()
            remaining = self.n_examples
            while remaining > 0:
                current_size = min(self.chunk_size, remaining)
                remaining -= current_size


# Path: mimic3models/common_utils.py
# def convert_to_dict(data, header, channel_info):
# def extract_features_from_rawdata(chunk, header, period, features):
# def read_chunk(reader, chunk_size):
# def sort_and_shuffle(data, batch_size):
# def add_common_arguments(parser):
#     def __init__(self, dataset_dir, listfile=None, small_part=False):
#     def _read_timeseries(self, ts_filename):
# def create_directory(directory):
# def pad_zeros(arr, min_length=None):
# class DeepSupervisionDataLoader:


# Path: mimic3models/decompensation/utils.py
from mimic3models import common_utils
import threading
import os
import numpy as np
import random

    def __init__(self, reader, discretizer, normalizer,
                 batch_size, steps, shuffle, return_names=False):
        self.reader = reader
        self.discretizer = discretizer
        self.normalizer = normalizer
        self.batch_size = batch_size
        self.shuffle = shuffle
        self.return_names = return_names

        if steps is None:
            self.n_examples = reader.get_number_of_examples()
            self.steps = (self.n_examples + batch_size - 1) // batch_size
        else:
            self.n_examples = steps * batch_size
            self.steps = steps

        self.chunk_size = min(1024, self.steps) * batch_size
        self.lock = threading.Lock()
        self.generator = self._generator()

    def _generator(self):
        B = self.batch_size
        while True:
            if self.shuffle:
                self.reader.random_shuffle()
            remaining = self.n_examples
            while remaining > 0:
                current_size = min(self.chunk_size, remaining)
                remaining -= current_size


                ret = common_utils.read_chunk(self.reader, current_size)