import pandas as pd
from pathlib import Path


class HDatReader:
    def __init__(self, file):
        self.file = file

    def read_csv(self):
        self.read_sleep_data()
        self.read_walk_run_data()

    def read_sleep_data(self):
        df = pd.read_csv(self.file, skiprows=1)
        df['endDate'] = pd.to_datetime(df['endDate'])
        df['startDate'] = pd.to_datetime(df['startDate'])
        df['sleepDuration'] = (df['endDate'] - df['startDate']).dt.total_seconds() / 3600
        return df

    def steps(self):
        df = pd.read_csv(self.file, skiprows=1)
        df['endDate'] = pd.to_datetime(df['endDate'])
        df['startDate'] = pd.to_datetime(df['startDate'])
        df['value'] = pd.to_numeric(df['value'])
        df['stepAverage'] = \
            df['value'] / ((df['endDate'] - df['startDate']).dt.total_seconds()/60)
        return df

    def read_walk_run_data(self):
        df = pd.read_csv(self.file, skiprows=1)
        df['endDate'] = pd.to_datetime(df['endDate'])
        df['startDate'] = pd.to_datetime(df['startDate'])
        df['value'] = pd.to_numeric(df['value'])
        df['milesPerHour'] = \
            df['value'] / ((df['endDate'] - df['startDate']).dt.total_seconds()/3600)
        return df

    def audio_data(self):
        df = pd.read_csv(self.file, skiprows=1)
        df['endDate'] = pd.to_datetime(df['endDate'])
        df['startDate'] = pd.to_datetime(df['startDate'])
        df['listenDuration'] = df['endDate'] - df['startDate']
        return df


class FitBit:
    def __init__(self, directory):
        self.directory = directory

    def daily_activity(self):
        return pd.read_csv(Path(self.directory, 'dailyActivity_merged.csv'))

    def daily_calories(self):
        return pd.read_csv(Path(self.directory, 'dailyCalories_merged.csv'))

    def daily_intensities(self):
        return pd.read_csv(Path(self.directory, 'dailyIntensities_merged.csv'))

    def daily_steps(self):
        return pd.read_csv(Path(self.directory, 'dailySteps_merged.csv'))

    def heartrate_seconds(self):
        return pd.read_csv(Path(self.directory, 'heartrate_seconds_merged.csv'))

    def hourly_calories(self):
        return pd.read_csv(Path(self.directory, 'hourlyCalories_merged.csv'))

    def hourly_intensities(self):
        return pd.read_csv(Path(self.directory, 'hourlyIntensities_merged.csv'))

    def hourly_steps(self):
        return pd.read_csv(Path(self.directory, 'hourlySteps_merged.csv'))

    def minute_calories_wide(self):
        return pd.read_csv(Path(self.directory, 'minuteCaloriesNarrow_merged.csv'))

    def minute_calories_narrow(self):
        return pd.read_csv(Path(self.directory, 'minuteCaloriesWide_merged.csv'))

    def minute_intensities_wide(self):
        return pd.read_csv(Path(self.directory, 'minuteIntensitiesNarrow_merged.csv'))

    def minute_intensities_narrow(self):
        return pd.read_csv(Path(self.directory, 'minuteIntensitiesWide_merged.csv'))

    def minute_mets_narrow(self):
        return pd.read_csv(Path(self.directory, 'minuteMETsNarrow_merged.csv'))

    def minute_sleep(self):
        return pd.read_csv(Path(self.directory, 'minuteSleep_merged.csv'))

    def minute_steps_narrow(self):
        return pd.read_csv(Path(self.directory, 'minuteStepsNarrow_merged.csv'))

    def minute_steps_wide(self):
        return pd.read_csv(Path(self.directory, 'minuteStepsWide_merged.csv'))

    def day_sleep(self):
        return pd.read_csv(Path(self.directory, 'sleepDay_merged.csv'))

    def weight_log_info(self):
        return pd.read_csv(Path(self.directory, 'weightLogInfo_merged.csv'))