Exemplo n.º 1
0
    def load_metadata(self, key='/'):

        if key == '/':
            filepath = self._get_metadata_path()
            metadata = _load_file(filepath, 'dataset.yaml')
            meter_devices = _load_file(filepath, 'meter_devices.yaml')
            metadata['meter_devices'] = meter_devices
        else:
            key_object = Key(key)
            if key_object.building and not key_object.meter:
                # load building metadata from file
                filename = 'building' + str(key_object.building) + '.yaml'
                filepath = self._get_metadata_path()
                metadata = _load_file(filepath, filename)
                # set data_location
                for meter_instance in metadata['elec_meters']:
                    # not sure why I need to use meter_instance-1
                    data_location = '/building{:d}/elec/meter{:d}'.format(
                        key_object.building, meter_instance)
                    metadata['elec_meters'][meter_instance][
                        'data_location'] = data_location
            else:
                raise NotImplementedError("NotImplementedError")

        return metadata
Exemplo n.º 2
0
 def _key_to_abs_path(self, key):
     abs_path = self.filename
     if key and len(key) > 1:
         relative_path = key
         if key[0] == '/':
             relative_path = relative_path[1:]
         abs_path = join(self.filename, relative_path)
         key_object = Key(key)
         if key_object.building and key_object.meter:
             abs_path += '.csv'
     return abs_path
Exemplo n.º 3
0
    def save_metadata(self, key, metadata):

        if key == '/':
            # Extract meter_devices
            meter_devices_metadata = metadata['meter_devices']
            dataset_metadata = dict(metadata)
            del dataset_metadata['meter_devices']
            # Write dataset metadata
            metadata_filename = join(self._get_metadata_path(), 'dataset.yaml')
            write_yaml_to_file(metadata_filename, dataset_metadata)
            # Write meter_devices metadata
            metadata_filename = join(self._get_metadata_path(),
                                     'meter_devices.yaml')
            write_yaml_to_file(metadata_filename, meter_devices_metadata)
        else:
            # Write building metadata
            key_object = Key(key)
            assert key_object.building and not key_object.meter
            metadata_filename = join(
                self._get_metadata_path(),
                'building{:d}.yaml'.format(key_object.building))
            write_yaml_to_file(metadata_filename, metadata)