# Path: nilmtk/tests/testingtools.py
# def data_dir():
#     # Taken from http://stackoverflow.com/a/6098238/732596
#     current_file_path = os.path.dirname(inspect.getfile(inspect.currentframe()))
#     data_dir = os.path.join(current_file_path, '..', '..', 'data')
#     data_dir = os.path.abspath(data_dir)
#     assert os.path.isdir(data_dir), data_dir + " does not exist."
#     return data_dir
# 
# Path: nilmtk/measurement.py
# def measurement_columns(column_tuples):
#     """
#     Parameters
#     ----------
#     column_tuples : list of 2-tuples
#     
#     Returns
#     -------
#     pd.MultiIndex
#     """
#     for physical_quantity, ac_type in column_tuples:
#         check_physical_quantity(physical_quantity)
#         if physical_quantity in ['energy', 'cumulative energy', 'power']:
#             check_ac_type(ac_type)
#     return pd.MultiIndex.from_tuples(column_tuples, names=LEVEL_NAMES)
# 
# AC_TYPES = ['active', 'apparent', 'reactive']
# 
# Path: nilmtk/utils.py
# def flatten_2d_list(list2d):
#     list1d = []
#     for item in list2d:
#         if isinstance(item, str):
#             list1d.append(item)
#         else:
#             try:
#                 len(item)
#             except TypeError:
#                 list1d.append(item)
#             else:
#                 list1d.extend(item)
#     return list1d


import pandas as pd
import itertools
import numpy as np
from datetime import timedelta
from nilmtk.tests.testingtools import data_dir
from os.path import join
from collections import OrderedDict
from nilmtk.consts import JOULES_PER_KWH
from nilmtk.measurement import measurement_columns, AC_TYPES
from nilmtk.utils import flatten_2d_list
    node = store.get_node(key)
    md = {
        'instance': 1,
        'elec_meters': elec_meters,
        'appliances': appliances
    }
    node._f_setattr('metadata', md)


def create_co_test_hdf5():
    FILENAME = join(data_dir(), 'co_test.h5')
    N_METERS = 3
    chunk = 1000
    N_PERIODS = 4 * chunk
    rng = pd.date_range('2012-01-01', freq='S', periods=N_PERIODS)

    dfs = OrderedDict()
    data = OrderedDict()

    # mains meter data
    data[1] = np.array([0, 200, 1000, 1200] * chunk)

    # appliance 1 data
    data[2] = np.array([0, 200, 0, 200] * chunk)

    # appliance 2 data
    data[3] = np.array([0, 0, 1000, 1000] * chunk)

    for i in range(1, 4):
        dfs[i] = pd.DataFrame(data=data[i], index=rng, dtype=np.float32,

# Path: nilmtk/tests/testingtools.py
# def data_dir():
#     # Taken from http://stackoverflow.com/a/6098238/732596
#     current_file_path = os.path.dirname(inspect.getfile(inspect.currentframe()))
#     data_dir = os.path.join(current_file_path, '..', '..', 'data')
#     data_dir = os.path.abspath(data_dir)
#     assert os.path.isdir(data_dir), data_dir + " does not exist."
#     return data_dir
# 
# Path: nilmtk/measurement.py
# def measurement_columns(column_tuples):
#     """
#     Parameters
#     ----------
#     column_tuples : list of 2-tuples
#     
#     Returns
#     -------
#     pd.MultiIndex
#     """
#     for physical_quantity, ac_type in column_tuples:
#         check_physical_quantity(physical_quantity)
#         if physical_quantity in ['energy', 'cumulative energy', 'power']:
#             check_ac_type(ac_type)
#     return pd.MultiIndex.from_tuples(column_tuples, names=LEVEL_NAMES)
# 
# AC_TYPES = ['active', 'apparent', 'reactive']
# 
# Path: nilmtk/utils.py
# def flatten_2d_list(list2d):
#     list1d = []
#     for item in list2d:
#         if isinstance(item, str):
#             list1d.append(item)
#         else:
#             try:
#                 len(item)
#             except TypeError:
#                 list1d.append(item)
#             else:
#                 list1d.extend(item)
#     return list1d


# Path: nilmtk/tests/generate_data.py
import pandas as pd
import itertools
import numpy as np
from datetime import timedelta
from nilmtk.tests.testingtools import data_dir
from os.path import join
from collections import OrderedDict
from nilmtk.consts import JOULES_PER_KWH
from nilmtk.measurement import measurement_columns, AC_TYPES
from nilmtk.utils import flatten_2d_list

    node = store.get_node(key)
    md = {
        'instance': 1,
        'elec_meters': elec_meters,
        'appliances': appliances
    }
    node._f_setattr('metadata', md)


def create_co_test_hdf5():
    FILENAME = join(data_dir(), 'co_test.h5')
    N_METERS = 3
    chunk = 1000
    N_PERIODS = 4 * chunk
    rng = pd.date_range('2012-01-01', freq='S', periods=N_PERIODS)

    dfs = OrderedDict()
    data = OrderedDict()

    # mains meter data
    data[1] = np.array([0, 200, 1000, 1200] * chunk)

    # appliance 1 data
    data[2] = np.array([0, 200, 0, 200] * chunk)

    # appliance 2 data
    data[3] = np.array([0, 0, 1000, 1000] * chunk)

    for i in range(1, 4):
        dfs[i] = pd.DataFrame(data=data[i], index=rng, dtype=np.float32,

                              columns=measurement_columns([('power', 'active')]))