From cc297872364c0b530fa15941092d9f2d37597508 Mon Sep 17 00:00:00 2001 From: Chloe Zhu <79296642+piggychloe@users.noreply.github.com> Date: Fri, 24 Jun 2022 00:04:55 -0400 Subject: [PATCH 1/5] Add files via upload --- data_conversion.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 data_conversion.py diff --git a/data_conversion.py b/data_conversion.py new file mode 100644 index 0000000..2c1f869 --- /dev/null +++ b/data_conversion.py @@ -0,0 +1,56 @@ +""" +Created on 6/9/22 + +@author: qinyuzhu +""" +import flirt +import pandas as pd +from datetime import datetime, timedelta + +df = pd.read_csv("test_conversion.csv") +print(df) + +# the codes below is for further use of conversion +""" +# class conversion: +# +# def __init__(self, data) -> None: +# self.data = data +# def convert_integer(self, data): +# return int(self.data) +# def convert_daytime(self, data): +# delta = timedelta(microseconds=-1) +# return delta +# def convert_string(self,data): +# return str() +# def convert_list(self, data): +# return list() +# def convert_tuple(self, data): +# return tuple() +# def convert_set(self, data): +# return set() +""" +lst = [] +for date in df: + new = datetime.strptime(date, '') +df["new_date"] = datetime.strftime() + +ini_time = "Jul 17 2019 11:49AM" +# print("initial_date", str(ini_time_for_now)) + +# ini_time_for_now = datetime.strptime(ini_time, '%b %d %Y %I:%M%p') +# +# +# lst=[] +# new_final_time = ini_time_for_now + timedelta(days=1) +# difference = new_final_time - ini_time_for_now +# lst.append(difference) +# +# +# df["converted_time"] = lst + + + + +if __name__ == '__main__': + print(df) From 0349e1c0eead1aab1bddaf11f1e47a64215db404 Mon Sep 17 00:00:00 2001 From: Chloe Zhu <79296642+piggychloe@users.noreply.github.com> Date: Fri, 8 Jul 2022 00:28:01 -0400 Subject: [PATCH 2/5] Update data_conversion.py --- data_conversion.py | 74 +++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/data_conversion.py b/data_conversion.py index 2c1f869..ec67725 100644 --- a/data_conversion.py +++ b/data_conversion.py @@ -3,54 +3,48 @@ @author: qinyuzhu """ -import flirt + import pandas as pd from datetime import datetime, timedelta -df = pd.read_csv("test_conversion.csv") -print(df) +def type_conversion(): + """Function that do data type conversion for time features + Parameters + ---------- + column name of the time feature in the file as the parameter of the funtion named type_conversion + + Returns + ------- + a new csv file with one new column of the converted start time + + Raises + ------ + Exception + raise exception when the initial time (ini_time) is not set or the format of initial time is not '%b %d %Y %I:%M%p' + raise exception when the output csv file name is not written + """ + df = pd.read_csv("") -# the codes below is for further use of conversion -""" -# class conversion: -# -# def __init__(self, data) -> None: -# self.data = data -# def convert_integer(self, data): -# return int(self.data) -# def convert_daytime(self, data): -# delta = timedelta(microseconds=-1) -# return delta -# def convert_string(self,data): -# return str() -# def convert_list(self, data): -# return list() -# def convert_tuple(self, data): -# return tuple() -# def convert_set(self, data): -# return set() -""" -lst = [] -for date in df: - new = datetime.strptime(date, '') -df["new_date"] = datetime.strftime() -ini_time = "Jul 17 2019 11:49AM" -# print("initial_date", str(ini_time_for_now)) + lst = [] + for date in df: + new = datetime.strptime(date, '') + df["new_date"] = datetime.strftime() + + ini_time = "" + ini_time_for_now = datetime.strptime(ini_time, '%b %d %Y %I:%M%p') + + lst=[] + new_final_time = ini_time_for_now + timedelta(days=1) + difference = new_final_time - ini_time_for_now + lst.append(difference) + + lst.to_csv("") + -# ini_time_for_now = datetime.strptime(ini_time, '%b %d %Y %I:%M%p') -# -# -# lst=[] -# new_final_time = ini_time_for_now + timedelta(days=1) -# difference = new_final_time - ini_time_for_now -# lst.append(difference) -# -# -# df["converted_time"] = lst if __name__ == '__main__': - print(df) + pass From 1ce8912cad4b88e938e3dee20ebd031b952c8ecd Mon Sep 17 00:00:00 2001 From: Chloe Zhu <79296642+piggychloe@users.noreply.github.com> Date: Fri, 8 Jul 2022 00:32:35 -0400 Subject: [PATCH 3/5] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 5ac20fc..25e6e2c 100644 --- a/README.md +++ b/README.md @@ -183,4 +183,8 @@ various health monitoring sensors | ### Continued Development +### Data type conversion functions: + data_conversion: with funciton used to convert the time feature in the csv file + + We are frequently updating this package with new devices and insights from the DBDP (Digital Biomarker Discovery Pipeline). From 64c2ec5b939b85c580d5b3c9acd24320f06ced0f Mon Sep 17 00:00:00 2001 From: Chloe Zhu <79296642+piggychloe@users.noreply.github.com> Date: Fri, 22 Jul 2022 07:52:37 -0400 Subject: [PATCH 4/5] R code recreate to python code --- R2PY.py | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 R2PY.py diff --git a/R2PY.py b/R2PY.py new file mode 100644 index 0000000..fbdc0bf --- /dev/null +++ b/R2PY.py @@ -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-##-##', '#') From ea6d3a9c0a390c62266a371f553c547ced48ea12 Mon Sep 17 00:00:00 2001 From: Chloe Zhu <79296642+piggychloe@users.noreply.github.com> Date: Fri, 5 Aug 2022 07:49:29 -0400 Subject: [PATCH 5/5] new version of data conversion function --- data_conversion.py | 82 ++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/data_conversion.py b/data_conversion.py index ec67725..6086d50 100644 --- a/data_conversion.py +++ b/data_conversion.py @@ -3,43 +3,61 @@ @author: qinyuzhu """ - +import flirt import pandas as pd from datetime import datetime, timedelta -def type_conversion(): - """Function that do data type conversion for time features - Parameters - ---------- - column name of the time feature in the file as the parameter of the funtion named type_conversion - - Returns - ------- - a new csv file with one new column of the converted start time - - Raises - ------ - Exception - raise exception when the initial time (ini_time) is not set or the format of initial time is not '%b %d %Y %I:%M%p' - raise exception when the output csv file name is not written - """ - df = pd.read_csv("") +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" +""" +the functions below can be used to do data conversion of different types followed the comments +""" +x= "" +base="" - lst = [] - for date in df: - new = datetime.strptime(date, '') - df["new_date"] = datetime.strftime() +#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) - ini_time = "" - ini_time_for_now = datetime.strptime(ini_time, '%b %d %Y %I:%M%p') - - lst=[] - new_final_time = ini_time_for_now + timedelta(days=1) - difference = new_final_time - ini_time_for_now - lst.append(difference) - - lst.to_csv("") @@ -47,4 +65,4 @@ def type_conversion(): if __name__ == '__main__': - pass + print(df)