# Path: nilmtk/utils.py
# 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
# 
# def check_directory_exists(d):
#     if not isdir(d):
#         raise IOError("Directory '{}' does not exist.".format(d))
# 
# 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']


import pandas as pd
import numpy as np
import sys
from os import listdir, getcwd
from os.path import isdir, join, dirname, abspath
from pandas import concat
from nilmtk.utils import get_module_directory, check_directory_exists
from nilmtk.datastore import Key
from nilmtk.measurement import LEVEL_NAMES
from nilm_metadata import convert_yaml_to_hdf5
                            8+phase:('voltage', ''),
                            13+phase:('phase_angle', ''),
                            'Q': ('power', 'reactive'),
                        }
                        df_phase.columns = pd.MultiIndex.from_tuples([
                            sm_column_name[col] for col in df_phase.columns
                        ])
                        
                        power_active = df_phase['power', 'active']
                        tmp_before = np.size(power_active)
                        df_phase = df_phase[power_active != -1]
                        power_active = df_phase['power', 'active']
                        tmp_after = np.size(power_active)
                        
                        if tmp_before != tmp_after:
                            print('Removed missing measurements - Size before: ' + str(tmp_before) + ', size after: ' + str(tmp_after))
                        
                        df_phase.columns.set_names(LEVEL_NAMES, inplace=True)
                        if not key in store:
                            store.put(key, df_phase, format='Table')
                        else:
                            store.append(key, df_phase, format='Table')
                            store.flush()
                        print('Building', building_no, ', Meter no.', phase,
                              '=> Done for ', fi[:-4])
                
            else:
                #Meter number to be used in key
                meter_num = int(fl) + 3
                

# Path: nilmtk/utils.py
# 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
# 
# def check_directory_exists(d):
#     if not isdir(d):
#         raise IOError("Directory '{}' does not exist.".format(d))
# 
# 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/dataset_converters/eco/convert_eco.py
import pandas as pd
import numpy as np
import sys
from os import listdir, getcwd
from os.path import isdir, join, dirname, abspath
from pandas import concat
from nilmtk.utils import get_module_directory, check_directory_exists
from nilmtk.datastore import Key
from nilmtk.measurement import LEVEL_NAMES
from nilm_metadata import convert_yaml_to_hdf5

                            8+phase:('voltage', ''),
                            13+phase:('phase_angle', ''),
                            'Q': ('power', 'reactive'),
                        }
                        df_phase.columns = pd.MultiIndex.from_tuples([
                            sm_column_name[col] for col in df_phase.columns
                        ])
                        
                        power_active = df_phase['power', 'active']
                        tmp_before = np.size(power_active)
                        df_phase = df_phase[power_active != -1]
                        power_active = df_phase['power', 'active']
                        tmp_after = np.size(power_active)
                        
                        if tmp_before != tmp_after:
                            print('Removed missing measurements - Size before: ' + str(tmp_before) + ', size after: ' + str(tmp_after))
                        
                        df_phase.columns.set_names(LEVEL_NAMES, inplace=True)
                        if not key in store:
                            store.put(key, df_phase, format='Table')
                        else:
                            store.append(key, df_phase, format='Table')
                            store.flush()
                        print('Building', building_no, ', Meter no.', phase,
                              '=> Done for ', fi[:-4])
                
            else:
                #Meter number to be used in key
                meter_num = int(fl) + 3
                

                key = str(Key(building=building_no, meter=meter_num))