import json
import os
import logging
import numpy as np
import matplotlib.image as mimg
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from ..utils.LabeledLine import LabeledLine

logger = logging.getLogger(__name__)


# noinspection PyPackageRequirements
class CASASHome:
    """Load Home Data Structure from JSON file

    Attributes:
        data_dict (:obj:`dict`): A dictionary contains information about smart home.
        directory (:obj:`str`): Directory that stores CASAS smart home data

    Parameters:
        directory (:obj:`str`): Directory that stores CASAS smart home data
    """
    def __init__(self, directory):
        self.directory = directory
        dataset_json_fname = directory + '/dataset.json'
        if os.path.exists(dataset_json_fname):
            f = open(dataset_json_fname, 'r')
            self.data_dict = json.load(f)
        else:
            logger.error('Smart home metadata file %s does not exist. Create an empty CASASHome Structure'
                        % dataset_json_fname)
            raise FileNotFoundError('File %s not found.' % dataset_json_fname)
            # self.data_dict = {
            #     'name': '',
            #     'floorplan': '',
            #     'sensors': [],
            #     'activities': [],
            #     'residents': []
            # }

    def get_name(self):
        """Get the smart home name

        Returns:
            :obj:`str`: smart home name
        """
        return self.data_dict['name']

    def get_all_activities(self):