Comments (5)
@francescolosterzo If you check the apple_health_data_processor.ipynb, you'll see this line:
convert_tz = lambda x: x.to_pydatetime().replace(tzinfo=pytz.utc).astimezone(pytz.timezone('Asia/Shanghai'))
There is where we set the tz and then subsequent lines parse it to correct timezones. Check that to see if it works for your needs.
To be honest, that code is one of the older parts so I'm not sure if it's up to data to any changes Apple made in their export files and timestamps.
from qs_ledger.
@markwk I am continuing this since now I see other things I would like to ask you and they still fall under the title of this issue.
-
I see that heart rate points are not equally spaced in time, in the night they are less frequent that during the day. I guess Apple understands to the activity level and adapts the sampling time (e.g. during the night a point every few minutes is ok). Or there might be anything else going on here?
-
following your example, I am using the
startDate
as a reference and I see that data are sometimes not ordered in time, i.e. when I plot my heart rate vs time withmatplotlib.pyplot.plot
I see the line going back and forth every now and then. Do you have any idea why this is happening? Is it safe to sort the rows of the dataframe bystartDate
? Or will it mess thing up?
from qs_ledger.
@francescolosterzo you didn't share your code so I'm only guessing but it sounds like you didn't convert it to datetime or process it like the other examples.
I went ahead and added a quick example in code showing and plotting HR now in that notebook. Still a small issue with x-axis labeling or ticks but you shouuld have the idea now.
from qs_ledger.
Hi @markwk
you are right, here is what I do:
- load the data
df = pd.read_csv('HeartRate.csv', skipinitialspace=True)
- add a timezone column based on when I went to the US
cList = [
(datetime.datetime(2019,7,24), datetime.datetime(2019,8,3,12), 'Europe/Zurich'),
(datetime.datetime(2019,8,3,12,1), datetime.datetime(2019,8,13,12), 'America/Detroit'),
(datetime.datetime(2019,8,13,12,1), datetime.datetime(2019,9,26), 'Europe/Zurich'),
]
dfList = []
for entry in chunkList:
startDate, stopDate, tz = entry
this_df = df[ (pd.to_datetime(df['startDate']) >= startDate) & (pd.to_datetime(df['startDate']) <= stopDate) ]
this_df = this_df.assign(timezone = tz)
dfList.append(this_df)
df_out = pd.concat(dfList, ignore_index=True)
- assign the timezone and get the timezone-naive timestamp (in order to have things smoother)
df['timestamp'] = df.groupby('timezone')['startDate'].apply(lambda x: x.dt.tz_localize('UTC').dt.tz_convert(x.name).dt.tz_localize(None))
This might cause problems on the days in which I actually changed timezone, but this is not the problem right now.
The real problem I was referring to is that if I chart the HR vs timestamp in a single night, I get points flipped in time every now and then. Here is an example:
df[ (df.startDate >= datetime.datetime(2019,7,25,1)) & (df.startDate <= datetime.datetime(2019,7,25,2)) ][['startDate', 'timestamp', 'value']].values
array([ ...
[Timestamp('2019-07-25 01:19:25'), 1564017565, 69.0],
[Timestamp('2019-07-25 01:26:50'), 1564018010, 69.0],
[Timestamp('2019-07-25 01:31:05'), 1564018265, 72.4528],
[Timestamp('2019-07-25 01:30:15'), 1564018215, 66.0],
[Timestamp('2019-07-25 01:34:12'), 1564018452, 68.0],
[Timestamp('2019-07-25 01:43:51'), 1564019031, 68.0],
...], dtype=object)
As you can see above the 3rd and the 4th entries are flipped in time. This happens a few times in each night.
So I was wondering if you have any idea about why this happens?
from qs_ledger.
@francescolosterzo Sorry. I haven't seen this error in my data and not sure why it's appearing for you. You should be able to do a new sort on the data to correct it without any issues.
from qs_ledger.
Related Issues (14)
- strava - authorization flow change HOT 4
- Add support for Whoop activity tracker?
- Apple Health Extractor not working? HOT 1
- import dashboard to Kibana issue
- Demogrhaphic information is not parsed
- Toggl Updates (to api.track.toggl.com) and FileNotFound Error HOT 1
- apple_health_data2elastic NOT WORKING :(
- any help is appreciated.. HOT 5
- apple health: parse error after upgrading to iOS 16 HOT 3
- Using iOS 16.6 health data extraction does not work
- How to get started? HOT 8
- Error on running Todoist analysis HOT 2
- I wonder if there is a bug apple-health-data-parser.py ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qs_ledger.