bhf_smarthealth.parse.intraday_parser

bhf_smarthealth.parse.intraday_parser#

This module contains functions to process raw Fitbit intraday activity data ingressed to the Smart Health pipeline

Attributes#

Functions#

load_json(→ List[Dict[str, Any]])

Load the raw JSON file and return list of dictionaries for validation.

validate_data(...)

Uses Pydantic model to convert and validate the dictionaries

create_dataframe(→ pandas.DataFrame)

Creates a pandas DataFrame from a Pydantic model instance.

Module Contents#

bhf_smarthealth.parse.intraday_parser.logger#
bhf_smarthealth.parse.intraday_parser.load_json(json_path: str | pathlib.Path, activity_source: str) → List[Dict[str, Any]][source]#

Load the raw JSON file and return list of dictionaries for validation.

Parameters:
  • json_path (str | Path) – JSON file Path

  • activity_source (str) – The source of intraday activity data to load (e.g., heart rate or steps). The key is constructed as “activities-{activity_source}-intraday”.

Returns:

List of dictionaries containing raw, unvalidated Fitbit activity datapoints with sheffield_id and date appended

Return type:

List[Dict[str, Any]]

Raises:
  • FileNotFoundError – Raised if file not found

  • ValueError – Raised if file metadata cannot be validated

bhf_smarthealth.parse.intraday_parser.validate_data(intraday_data_dict: List[Dict[str, Any]]) → bhf_smarthealth.validate.fitbit_schema.IntradayDataList[source]#

Uses Pydantic model to convert and validate the dictionaries containing the raw data.

Parameters:

intraday_data_dict (List of intraday_datapoint) – List of dictionaries containing raw activity datapoints

Returns:

Pydantic model class containing the converted data

Return type:

IntradayDataList

Raises:

DataValidationError – Raised if the pydantic schema validation fails

bhf_smarthealth.parse.intraday_parser.create_dataframe(time_series: bhf_smarthealth.validate.fitbit_schema.IntradayDataList) → pandas.DataFrame[source]#

Creates a pandas DataFrame from a Pydantic model instance.

Parameters:

time_series (IntradayDataList) – The Pydantic model instance containing the time-series data, which is expected to have a ‘timestamp’ field.

Returns:

A DataFrame containing the data from the Pydantic model, with the ‘timestamp’ field converted to datetime objects and set as the index.

Return type:

pd.DataFrame