-
Notifications
You must be signed in to change notification settings - Fork 3
pre-processing new module update #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from datetime import datetime | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
def base_line_analysis(sub_id, date_of, st): | ||
|
||
# Inputs to Function: | ||
# ID of participant | ||
# Date of experiment (**Issue- would like to update so it pulls this from file) | ||
# Participant skin tone (**Issue- would like to update so it pulls this from file) | ||
|
||
# Outputs to Function: | ||
# .csv file with all timestamps for every participant in the study, which has all devices used in the study, skin tone, activity condition, and participant ID | ||
|
||
# Set filepath of folder with all subject data | ||
filepath = (Path('filepath') / sub_id).absolute() | ||
|
||
df = pd.read_csv('filepath\\skintonestudyTIMES.csv', header=True) | ||
time = df.loc[df['ï..Subject.ID'] == sub_id] | ||
f = lambda t: round(datetime.strptime('%m/%d/%Y %H:%M:%S', t).timestamp()) | ||
for dst, src in (('R', 'Baseline'), ('A', 'Activity'), ('B', 'DB'), ('T', 'Type')): | ||
for i in range(1, 4): | ||
src_key, dst_key = f'{src}{i}', f'{dst}{i}' | ||
time[dst_key] = time[src_key].apply(f) | ||
|
||
date_num = datetime.strptime(f'%Y-%m_%d', date_of).timestamp() | ||
df_hr = pd.read_csv(filepath / 'HR.csv', header=False) | ||
df_hrt = pd.read_csv(filepath / 'HRT.csv', header=False) | ||
df_hrt = np.round_(df_hrt + date_num) | ||
df_ecg = pd.concat([df_hrt, df_hr], axis=1) | ||
df_ecg.rename(columns=dict(zip(df_ecg.columns, ('Time', 'ECG'))), inplace=True) | ||
|
||
df_e4: pd.DataFrame = pd.read_csv(filepath / 'Empatica/HR.csv', header=False) | ||
e4_start_time = df_e4.loc[:, 1] | ||
df_e4 = df_e4.loc[:, [-1, -2]] | ||
seconds_passed_e4 = df_e4.shape[0] | ||
e4_end_time = e4_start_time + seconds_passed_e4 | ||
e4_time = [i for i in range(e4_start_time, e4_end_time)] | ||
df_e4 = pd.concat([e4_time, df_e4]) | ||
df_e4.rename(columns=dict(zip(df_ecg.columns, ('Time', 'Empatica'))), inplace=True) | ||
|
||
df_aw = pd.read_csv(filepath / 'Apple Watch.csv', header=False) | ||
aw_start_time = df_aw.loc[1, 2] | ||
apple_hr = df_aw.loc[1:7, 2] | ||
apple_sec = df_aw.loc[1:7, 1] + aw_start_time | ||
df_apple_watch = pd.DataFrame([apple_sec, apple_hr], columns=['Time', 'AppleWatch']) | ||
|
||
df_fb = pd.read_csv(filepath / 'Fitbit.csv', header=False) | ||
fb_hr = df_fb.loc[-1, 2] | ||
fb_time = df_fb[-1, 1] | ||
df_fitbit = pd.DataFrame([fb_time, fb_hr], columns=["Time", "Fitbit"]) | ||
|
||
if (filepath / 'garmin.tcx').exists(): | ||
df_gm = pd.read_xml(filepath / 'garmin.tcx') | ||
df_ecg.rename(columns=dict(zip(df_gm.columns, ('Time', 'Garmin'))), inplace=True) | ||
else: | ||
df_gm = pd.DataFrame([], columns=['Time', 'Garmin']) | ||
|
||
if (filepath / 'Miband.xls').exists(): | ||
df_miband = pd.read_xml(filepath / 'Miband.xls') | ||
df_miband.rename(columns=dict(zip(df_gm.columns, ('Time', 'Miband'))), inplace=True) | ||
else: | ||
df_miband = pd.DataFrame([], columns=['Time', 'Miband']) | ||
|
||
if (filepath / 'Biovotion\\BHR.csv').exists(): | ||
df_biovotion = pd.read_xml(filepath / 'Biovotion\\BHR.csv') | ||
df_biovotion.rename(columns=dict(zip(df_gm.columns, ('Time', 'Biovotion'))), inplace=True) | ||
else: | ||
df_biovotion = pd.DataFrame([], columns=['Time', 'Biovotion']) | ||
|
||
df = pd.merge(df_ecg, df_apple_watch, on='Time') | ||
df = pd.merge(df, df_e4, on='Time') | ||
df = pd.merge(df, df_gm, on='Time') | ||
df = pd.merge(df, df_fitbit, on='Time') | ||
df = pd.merge(df, df_miband, on='Time') | ||
df = pd.merge(df, df_biovotion, on='Time') | ||
df['ID'] = sub_id | ||
df['ST'] = st | ||
df['Condition'] = '' | ||
|
||
for condition, count in ( | ||
('Activity', 300), | ||
('Rest', 240), | ||
('Breathe', 60), | ||
('Type', 60), | ||
): | ||
for i in range(1, 4): | ||
key = f'{condition[0]}{i}' | ||
df.loc[(df['Time'] > time[key]) & (df['Time'] < time[key] + count)] = condition | ||
df.to_csv('filename.csv', index=False, header=False) | ||
|
||
|
||
if __name__ == '__main__': | ||
base_line_analysis('19-###', '2019-##-##', '#') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
""" | ||
Created on 6/9/22 | ||
|
||
@author: qinyuzhu | ||
""" | ||
import flirt | ||
zhuchloe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import pandas as pd | ||
from datetime import datetime, timedelta | ||
|
||
df = pd.read_csv("test_conversion.csv") | ||
print(df) | ||
|
||
lst = [] | ||
for date in df: | ||
new = datetime.strptime(date, '') | ||
df["new_date"] = datetime.strftime() | ||
|
||
ini_time = "Jul 17 2019 11:49AM" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we are seeing a specific time here? Or should it be a comment? |
||
|
||
""" | ||
the functions below can be used to do data conversion of different types followed the comments | ||
""" | ||
x= "" | ||
base="" | ||
|
||
#Converts x to an integer. base specifies the base if x is a string. | ||
int(x [,base]) | ||
#Converts x to a long integer. base specifies the base if x is a string. | ||
long(x[, base] ) | ||
#Converts x to a floating-point number. | ||
float(x) | ||
# Creates a complex number. | ||
complex(real[, imag]) | ||
# Converts object x to a string representation. | ||
str(x) | ||
# Converts object x to an expression string. | ||
repr(x) | ||
# Evaluates a string and returns an object. | ||
eval(str) | ||
# Converts random varaible s to a tuple. | ||
tuple(s) | ||
# Converts random variable s to a list. | ||
list(s) | ||
# Converts random varaiable s to a set. | ||
set(s) | ||
# Creates a dictionary. d must be a sequence of (key,value) tuples. | ||
dict(d) | ||
# Converts s to a frozen set. | ||
frozenset(s) | ||
# Converts an integer to a character. | ||
chr(x) | ||
# Converts an integer to a Unicode character. | ||
unichr(x) | ||
# Converts a single character to its integer value. | ||
ord(x) | ||
# Converts an integer to a hexadecimal string. | ||
hex(x) | ||
# Converts an integer to an octal string. | ||
oct(x) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we using this line? |
||
print(df) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we seeing these lines of code here? |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be: "date_conversion: function to convert the format of time in a csv file"?