Skip to content

Commit

Permalink
changing a day to reflect local time
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-nykaza committed Jan 29, 2019
1 parent 9d69760 commit b015a1e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions projects/predict-simulate/get-users-settings-and-events.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,22 +668,28 @@ def isf_likely_units(df, columnHeading):
data["utcTime"] = pd.to_datetime(data["time"])
data["timezone"].fillna(method='ffill', inplace=True)
data["timezone"].fillna(method='bfill', inplace=True)
data["day"] = pd.DatetimeIndex(data["utcTime"]).date

# estimate local time (simple method)
data["tzo"] = data[['utcTime', 'timezone']].apply(lambda x: getTimezoneOffset(*x), axis=1)
data["localTime"] = data["utcTime"] + pd.to_timedelta(data["tzo"], unit="m")
data["day"] = pd.DatetimeIndex(data["localTime"]).date

# round to the nearest 5 minutes
# TODO: once roundTime is pushed to tidals repository then this line can be replaced
# with td.clean.round_time
data = round_time(data, timeIntervalMinutes=5, timeField="time",
roundedTimeFieldName="roundedTime", startWithFirstRecord=True,
verbose=False)

data["roundedLocalTime"] = data["roundedTime"] + pd.to_timedelta(data["tzo"], unit="m")
data.sort_values("uploadTime", ascending=False, inplace=True)


# %% ID, HASHID, AGE, & YLW
data["userID"] = userID
data["hashID"] = hashID
data["age"] = np.floor((data["utcTime"] - bDate).dt.days/365.25).astype(int)
data["ylw"] = np.floor((data["utcTime"] - dDate).dt.days/365.25).astype(int)
data["age"] = np.floor((data["localTime"] - bDate).dt.days/365.25).astype(int)
data["ylw"] = np.floor((data["localTime"] - dDate).dt.days/365.25).astype(int)


# %% BOLUS EVENTS (CORRECTION, AND MEAL INCLUING: CARBS, EXTENDED, DUAL)
Expand Down

0 comments on commit b015a1e

Please sign in to comment.