Skip to content

Commit

Permalink
Merge pull request #56 from Physics-Comp/feat/analysis
Browse files Browse the repository at this point in the history
Feat/analysis
  • Loading branch information
Physics-Comp committed Jan 25, 2023
2 parents fc450e4 + e7eeb74 commit 9c83def
Show file tree
Hide file tree
Showing 28 changed files with 435 additions and 985 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Generate CSV #
*.csv
*.csv
*.xml
10 changes: 10 additions & 0 deletions Health_API/Health_API.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Metadata-Version: 2.1
Name: Health-API
Version: 0.0.0
Summary: UNKNOWN
Home-page: UNKNOWN
License: UNKNOWN
Platform: UNKNOWN

UNKNOWN

9 changes: 9 additions & 0 deletions Health_API/Health_API.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
setup.py
Health_API.egg-info/PKG-INFO
Health_API.egg-info/SOURCES.txt
Health_API.egg-info/dependency_links.txt
Health_API.egg-info/top_level.txt
analysis/__init__.py
analysis/analysis.py
health_path/__init__.py
health_path/path.py
1 change: 1 addition & 0 deletions Health_API/Health_API.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions Health_API/Health_API.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
analysis
health_path

This file was deleted.

419 changes: 0 additions & 419 deletions Health_API/Health_API_Notebook/Health_API_Demo.ipynb

This file was deleted.

Binary file not shown.
Binary file not shown.
114 changes: 0 additions & 114 deletions Health_API/Health_API_Notebook/datasubset.xml

This file was deleted.

120 changes: 0 additions & 120 deletions Health_API/Health_API_Notebook/healthAPI.py

This file was deleted.

File renamed without changes.
Empty file added Health_API/analysis/__init__.py
Empty file.
Binary file not shown.
105 changes: 105 additions & 0 deletions Health_API/analysis/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#Import API to parse XML data
import re
from health_path.path import Path

class Record:
#Extract all the XML Record tags and output the number of each tag
def record_dictionary(root):
"""
Summary:
Output a dictionary containg all the type attributes of each record tag and the number of each record.
Args:
root: The path comtaining your health biometrics.
Returns:
A dictionary containing biometrics as keys and the corresponding number of records for each biometric as values.
Ex:
Analysis.data_tag(root)
"""
record_dict = {}
for activity in root.findall('Record'):
record_dict[activity.get('type')] = record_dict.get(activity.get('type'), 0) + 1
return record_dict

#Concise naming conventions for health biometric
@staticmethod
def biometric(root):
"""
Summary:
This function takes in a single argument "root" and returns a dictionary of biometric data with modified keys that are more readable and consistent.
Args:
root (str): The root directory of the biometric data.
Returns:
record_dict (dict): A dictionary of biometric data with modified keys.
Ex:
record_dict = concise_biometric_dict("Root/data/biometric")
"""

record_dict = Record.record_dictionary(root)
remove_prefix = [re.sub(r'^HKQuantityTypeIdentifier|^HKDataType|^HKCategoryTypeIdentifier', "", records) for records in record_dict.keys()]
edit_name = [re.sub(r"([a-z])([A-Z])", r"\1_\2", t) for t in remove_prefix]
return(dict(zip(edit_name, record_dict.keys())))

#Determine the date range (Use excerciseID function to obtain data_type)
"""
Extracts the date range
Ex.
dataRange('HeartRate')
Note: In order to use the condenced naming conventions you must call the exerciseID function.
"""
@staticmethod
def data_range_of_biometric(name):

dates = []
name_biometric = Record.concise_biometric_name(root)[name]
for record in root.findall('Record'):
if record.get('type') == name_biometric:
creationDate = record.get('creationDate')
dates.append(creationDate)
print('First Date:',dates[0])
print('Last Date:', dates[-1])

#Show preliminary data about the specified biometric such as the number of data points and date range.

def prelimData(self, name, path):
"""
Gives a general description of the biometric data given a particular health metric. The following information should be given
1.) Name of the health metric
2.) First date the particular health metric was recoreded
3.) Last recorded date of the specified health metric
4.) Test case that checks if there are any missing data entries in the dataset
"""
print('Preliminary',self.name,'Data')
print('--------------------------------------')

#Number of child elements in root
exerciseData = []
for record in self.fileRoot(path).findall('Record'):
if record.get('type') == self.exerciseID(name):
value = record.get('value')
exerciseData.append(value)
lengthOfDataEntries = len(exerciseData)
print('The number of entries:',lengthOfDataEntries)

#Display the number of attributes within each element
numDict = []
for record in self.fileRoot(path).iter('Record'):
if record.get('type') == self.exerciseID(name):
numDict.append(record.attrib)
lengthOfDiction = len(numDict)

#List the date range for exercise data
self.dataRange(self.name)

#Test Case: The number of child elements in the root should equal the number of dictionaries. If this is not the case then we have missing data entries.
def testElementEqualChild():
assert exerciseData != lengthOfDiction, "Missing data entries (Warning)"

testElementEqualChild()
print("(No missing data entries)")
Loading

0 comments on commit 9c83def

Please sign in to comment.