import os
import sys


import numpy as np
import pandas as pd
import plotly.graph_objs as go
import plotly.offline as offline
import seaborn as sns
import statsmodels.api as sm
from sklearn.decomposition import PCA

TEST_METHOD: bool = False
TEST_FOUR_DAYS: bool = False  # cannot be True if TEST_METHOD is True

INTERPOLATE_DATA: bool = True  # cannot be True if TEST_METHOD is True
TIME_WINDOW: int = 4
USE_FOURIER_TRANSFORM: bool = False
FOURIER_COEF_NUM: int = 15
HODRICK_PRESCOTT_LAMBDA: int = 15000


try:
    assert sys.version_info.major == 3
    assert sys.version_info.minor > 5
except AssertionError:
    raise RuntimeError("This code requires Python 3.6+.")


def interpolate_data(df):
    """Interpolate to hourly data so that FFT works correctly.

    Parameters
    ----------
        df: pandas DataFrame
            Index([
                'timepoint', 'elapsed_time', 'temperature',
                'experiment', 'case', 'id', 'condition'])

    Returns
    -------
        A interpolated long DataFrame.
    """
    df_interp = pd.DataFrame(columns=df.columns)
    for uuid in ids:
        df_uuid = df[df["id"] == uuid][["timepoint", "temperature"]]
        timepoint = pd.date_range(
            start=df_uuid.timepoint.min(),
            end=df_uuid.timepoint.max(),
            freq="30min"
        )
        df_return = pd.DataFrame(dict(timepoint=timepoint, id=uuid))
        df_return = df_return.join(df_uuid.set_index("timepoint"), on="timepoint", how="left")
        df_return = df_return.interpolate(method="cubic")