Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinefalisse committed Sep 5, 2023
1 parent 9644e49 commit 6e098cc
Showing 1 changed file with 21 additions and 56 deletions.
77 changes: 21 additions & 56 deletions gait_analysis/function/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import os
import numpy as np

from gait_analysis import gait_analysis
from utils import get_trial_id, download_trial
from utilsKinematics import Kinematics
from utils import download_kinematics


def handler(event, context):
""" AWS Lambda function handler. This function performs a gait analysis.
""" AWS Lambda function handler. This function calculates
maximal center of mass vertical position for specified session and trials.
To invoke the function do POST request on the following url
http://localhost:8080/2015-03-31/functions/function/invocations
Expand All @@ -52,65 +53,29 @@ def handler(event, context):
specific_trial_names = kwargs['specific_trial_names']

# Specify where to download the data.
sessionDir = os.path.join("/tmp/Data", session_id)
data_folder = os.path.join("/tmp/Data", session_id)

# %% Download data.
trial_id = get_trial_id(session_id,specific_trial_names[0])
trial_name = download_trial(trial_id,sessionDir,session_id=session_id)

# Select how many gait cycles you'd like to analyze. Select -1 for all gait
# cycles detected in the trial.
n_gait_cycles = -1

# Select lowpass filter frequency for kinematics data.
filter_frequency = 6

# Select scalar names to compute.
scalar_names = {'gait_speed','stride_length','step_width','cadence',
'single_support_time','double_support_time'}
trial_names, modelName = download_kinematics(session_id, folder=data_folder, trialNames=specific_trial_names)

# %% Process data.
gait_r = gait_analysis(
sessionDir, trial_name, leg='r',
lowpass_cutoff_frequency_for_coordinate_values=filter_frequency,
n_gait_cycles=n_gait_cycles)
gait_l = gait_analysis(
sessionDir, trial_name, leg='l',
lowpass_cutoff_frequency_for_coordinate_values=filter_frequency,
n_gait_cycles=n_gait_cycles)

gaitResults = {}
gaitResults['scalars_r'] = gait_r.compute_scalars(scalar_names)
# gaitResults['curves_r'] = gait_r.get_coordinates_normalized_time()
gaitResults['scalars_l'] = gait_l.compute_scalars(scalar_names)
# gaitResults['curves_l'] = gait_l.get_coordinates_normalized_time()

right_gait_speed = np.round(gaitResults['scalars_r']['gait_speed'], 2)
right_stride_length = np.round(gaitResults['scalars_r']['stride_length'], 2)
right_step_width = np.round(gaitResults['scalars_r']['step_width'], 2)
right_cadence = np.round(gaitResults['scalars_r']['cadence'], 2)
right_single_support_time = np.round(gaitResults['scalars_r']['single_support_time'], 2)
right_double_support_time = np.round(gaitResults['scalars_r']['double_support_time'], 2)

left_gait_speed = np.round(gaitResults['scalars_l']['gait_speed'], 2)
left_stride_length = np.round(gaitResults['scalars_l']['stride_length'], 2)
left_step_width = np.round(gaitResults['scalars_l']['step_width'], 2)
left_cadence = np.round(gaitResults['scalars_l']['cadence'], 2)
left_single_support_time = np.round(gaitResults['scalars_l']['single_support_time'], 2)
left_double_support_time = np.round(gaitResults['scalars_l']['double_support_time'], 2)

kinematics, center_of_mass = {}, {}
center_of_mass['values'] = {}
for trial_name in trial_names:
# Create object from class kinematics.
kinematics[trial_name] = Kinematics(
data_folder, trial_name, modelName=modelName, lowpass_cutoff_frequency_for_coordinate_values=10
)
# Get center of mass values, speeds, and accelerations.
center_of_mass['values'][trial_name] = kinematics[trial_name].get_center_of_mass_values(
lowpass_cutoff_frequency=10
)

max_center_of_mass = np.round(np.max(center_of_mass['values'][trial_names[0]]['y']), 2)
return {
'statusCode': 200,
'headers': {'Content-Type': 'application/json'},
'body': {
'message': f'Gait speed - Right: {right_gait_speed} m/s'
# 'message': f'''
# Gait speed - Right: {right_gait_speed} m/s, Left: {left_gait_speed} m/s \n
# Stride length - Right: {right_stride_length} m, Left: {left_stride_length} m \n
# Step width - Right: {right_step_width} m, Left: {left_step_width} m \n
# Cadence - Right: {right_cadence} step/s, Left: {left_cadence} step/s \n
# Single support time - Right: {right_single_support_time} s, Left: {left_single_support_time} s \n
# Double support time - Right: {right_double_support_time} s, Left: {left_double_support_time} s \n
# '''
'message': f'Maximal center of mass vertical position: {max_center_of_mass} m'
}
}
}

0 comments on commit 6e098cc

Please sign in to comment.