# Path: nilmtk/datastore/key.py
# class Key(object):
#     """A location of data or metadata within NILMTK.
#     
#     Attributes
#     ----------
#     building : int
#     meter : int
#     utility : str
#     """
# 
#     def __init__(self, string=None, building=None, meter=None):
#         """
#         Parameters
#         ----------
#         string : str, optional
#             e.g. 'building1/elec/meter1'
#         building : int, optional
#         meter : int, optional
#         """
#         self.utility = None
#         if string is None:
#             self.building = building
#             self.meter = meter
#         else:
#             split = string.strip('/').split('/')
#             assert split[0].startswith('building'), "The first element must be 'building<I>', e.g. 'building1'; not '{}'.".format(split[0])
#             try:
#                 self.building = int(split[0].replace("building", ""))
#             except ValueError as e:
#                 raise ValueError("'building' must be followed by an integer.\n{}"
#                                  .format(e))
#             if len(split) > 1:
#                 self.utility = split[1]
#             if len(split) == 3:
#                 assert split[2].startswith('meter')
#                 self.meter = int(split[-1].replace("meter", ""))
#             else:
#                 self.meter = None
#         self._check()
# 
#     def _check(self):
#         assert isinstance(self.building, int)
#         assert self.building >= 1
#         if self.meter is not None:
#             assert isinstance(self.meter, int)
#             assert self.meter >= 1
# 
#     def __repr__(self):
#         self._check()
#         s = "/building{:d}".format(self.building)
#         if self.meter is not None:
#             s += "/elec/meter{:d}".format(self.meter)
#         return s
# 
# Path: nilmtk/measurement.py
# LEVEL_NAMES = ['physical_quantity', 'type']
# 
# Path: nilmtk/utils.py
# def check_directory_exists(d):
#     if not isdir(d):
#         raise IOError("Directory '{}' does not exist.".format(d))
# 
# def get_datastore(filename, format=None, mode='r'):
#     """
#     Parameters
#     ----------
#     filename : string
#     format : 'CSV' or 'HDF', default: infer from filename ending.
#     mode : 'r' (read-only), 'a' (append) or 'w' (write), default: 'r'
# 
#     Returns
#     -------
#     metadata : dict
#     """
#     if not format:
#         if filename.endswith(".h5"):
#             format = "HDF"
#         elif filename.endswith(".csv"):
#             format = "CSV"
# 
#     if filename is not None:
#         if format == "HDF":
#             return HDFDataStore(filename, mode)
#         elif format == "CSV":
#             return CSVDataStore(filename)
#         else:
#             raise ValueError('format not recognised')
#     else:
#         ValueError('filename is None')
# 
# def get_module_directory():
#     # Taken from http://stackoverflow.com/a/6098238/732596
#     path_to_this_file = dirname(getfile(currentframe()))
#     if not isdir(path_to_this_file):
#         encoding = getfilesystemencoding()
#         path_to_this_file = dirname(unicode(__file__, encoding))
#     if not isdir(path_to_this_file):
#         abspath(getsourcefile(lambda _: None))
#     if not isdir(path_to_this_file):
#         path_to_this_file = getcwd()
#     assert isdir(path_to_this_file), path_to_this_file + ' is not a directory'
#     return path_to_this_file


from os.path import join, isdir, dirname, abspath
from os import getcwd
from sys import getfilesystemencoding
from collections import OrderedDict
from nilm_metadata import convert_yaml_to_hdf5
from nilmtk.datastore import Key
from nilmtk.measurement import LEVEL_NAMES
from nilmtk.utils import check_directory_exists, get_datastore, get_module_directory
import os
import pandas as pd

#{"load_type": {"floor/wing":meter_number_in_nilmtk}
acad_block_meter_mapping = {'Building Total Mains': {'0': 1},
                            'Lifts': {'0': 2},
                            'Floor Total': {'1': 3, '2': 4, '3': 5, '4': 6, '5': 7},
                            'AHU': {'0': 8, '1': 9, '2': 10, '5': 11},
                            'Light': {'3': 12},
                            'Power Sockets': {'3': 13},

# Path: nilmtk/datastore/key.py
# class Key(object):
#     """A location of data or metadata within NILMTK.
#     
#     Attributes
#     ----------
#     building : int
#     meter : int
#     utility : str
#     """
# 
#     def __init__(self, string=None, building=None, meter=None):
#         """
#         Parameters
#         ----------
#         string : str, optional
#             e.g. 'building1/elec/meter1'
#         building : int, optional
#         meter : int, optional
#         """
#         self.utility = None
#         if string is None:
#             self.building = building
#             self.meter = meter
#         else:
#             split = string.strip('/').split('/')
#             assert split[0].startswith('building'), "The first element must be 'building<I>', e.g. 'building1'; not '{}'.".format(split[0])
#             try:
#                 self.building = int(split[0].replace("building", ""))
#             except ValueError as e:
#                 raise ValueError("'building' must be followed by an integer.\n{}"
#                                  .format(e))
#             if len(split) > 1:
#                 self.utility = split[1]
#             if len(split) == 3:
#                 assert split[2].startswith('meter')
#                 self.meter = int(split[-1].replace("meter", ""))
#             else:
#                 self.meter = None
#         self._check()
# 
#     def _check(self):
#         assert isinstance(self.building, int)
#         assert self.building >= 1
#         if self.meter is not None:
#             assert isinstance(self.meter, int)
#             assert self.meter >= 1
# 
#     def __repr__(self):
#         self._check()
#         s = "/building{:d}".format(self.building)
#         if self.meter is not None:
#             s += "/elec/meter{:d}".format(self.meter)
#         return s
# 
# Path: nilmtk/measurement.py
# LEVEL_NAMES = ['physical_quantity', 'type']
# 
# Path: nilmtk/utils.py
# def check_directory_exists(d):
#     if not isdir(d):
#         raise IOError("Directory '{}' does not exist.".format(d))
# 
# def get_datastore(filename, format=None, mode='r'):
#     """
#     Parameters
#     ----------
#     filename : string
#     format : 'CSV' or 'HDF', default: infer from filename ending.
#     mode : 'r' (read-only), 'a' (append) or 'w' (write), default: 'r'
# 
#     Returns
#     -------
#     metadata : dict
#     """
#     if not format:
#         if filename.endswith(".h5"):
#             format = "HDF"
#         elif filename.endswith(".csv"):
#             format = "CSV"
# 
#     if filename is not None:
#         if format == "HDF":
#             return HDFDataStore(filename, mode)
#         elif format == "CSV":
#             return CSVDataStore(filename)
#         else:
#             raise ValueError('format not recognised')
#     else:
#         ValueError('filename is None')
# 
# def get_module_directory():
#     # Taken from http://stackoverflow.com/a/6098238/732596
#     path_to_this_file = dirname(getfile(currentframe()))
#     if not isdir(path_to_this_file):
#         encoding = getfilesystemencoding()
#         path_to_this_file = dirname(unicode(__file__, encoding))
#     if not isdir(path_to_this_file):
#         abspath(getsourcefile(lambda _: None))
#     if not isdir(path_to_this_file):
#         path_to_this_file = getcwd()
#     assert isdir(path_to_this_file), path_to_this_file + ' is not a directory'
#     return path_to_this_file


# Path: nilmtk/dataset_converters/combed/convert_combed.py
from os.path import join, isdir, dirname, abspath
from os import getcwd
from sys import getfilesystemencoding
from collections import OrderedDict
from nilm_metadata import convert_yaml_to_hdf5
from nilmtk.datastore import Key
from nilmtk.measurement import LEVEL_NAMES
from nilmtk.utils import check_directory_exists, get_datastore, get_module_directory
import os
import pandas as pd


#{"load_type": {"floor/wing":meter_number_in_nilmtk}
acad_block_meter_mapping = {'Building Total Mains': {'0': 1},
                            'Lifts': {'0': 2},
                            'Floor Total': {'1': 3, '2': 4, '3': 5, '4': 6, '5': 7},
                            'AHU': {'0': 8, '1': 9, '2': 10, '5': 11},
                            'Light': {'3': 12},
                            'Power Sockets': {'3': 13},

                            'UPS Sockets': {'3': 14}}