<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_time_features(self, year=False, month=False, week=True, tod=True, dow=True):
 """ Add time features to dataframe. Parameters year : bool Year. month : bool Month. week : bool Week. tod : bool Time of Day. dow : bool Day of Week. """


        var_to_expand = []

        if self.preprocessed_data.empty:
            data = self.original_data
        else:
            data = self.preprocessed_data

        if year:
            data["year"] = data.index.year
            var_to_expand.append("year")
        if month:
            data["month"] = data.index.month
            var_to_expand.append("month")
        if week:
            data["week"] = data.index.week
            var_to_expand.append("week")
        if tod:
            data["tod"] = data.index.hour
            var_to_expand.append("tod")
        if dow:
            data["dow"] = data.index.weekday
            var_to_expand.append("dow")

        # One-hot encode the time features
        for var in var_to_expand:
                
                add_var = pd.get_dummies(data[var], prefix=var, drop_first=True)
                
                # Add all the columns to the model data
                data = data.join(add_var)

                # Drop the original column that was expanded
                data.drop(columns=[var], inplace=True)

        self.preprocessed_data = data