Spaces:
Runtime error
Runtime error
| import numpy as np | |
| def generate_task_info_name(walking_type, incline, walking_speed): | |
| """ | |
| Generate a standardized 'task_info' name string based on the walking type, incline, and walking speed. | |
| The returned string follows the format: | |
| For level walking: "{walking_type}_{formatted_speed}" | |
| For incline/decline: "{walking_type}_{incline}_deg_{formatted_speed}" | |
| where: | |
| - walking_type is expected to be one of: | |
| 'decline_walking', 'level_walking', or 'incline_walking' | |
| - incline is a numerical value indicating ground incline in degrees. | |
| - formatted_speed is a walking speed string, e.g., 's0x8' for 0.8 m/s, 's1' for 1.0 m/s, 's1x2' for 1.2 m/s. | |
| Args: | |
| walking_type (str): The type of walking. Expected values: 'decline_walking', 'level_walking', or 'incline_walking'. | |
| incline (float or int): Ground incline in degrees. | |
| walking_speed (float): Walking speed in m/s. | |
| Returns: | |
| str: The generated task_info name. | |
| Examples: | |
| >>> generate_task_info_name('decline_walking', -5, 0.8) | |
| 'decline_walking_5_deg_s0x8' | |
| >>> generate_task_info_name('level_walking', 0, 1.0) | |
| 'level_walking_s1' | |
| >>> generate_task_info_name('incline_walking', 5, 1.2) | |
| 'incline_walking_5_deg_s1x2' | |
| """ | |
| if 'stair' in walking_type: | |
| return walking_type | |
| if walking_type != 'level_walking' and (np.isnan(incline) or incline is None): | |
| print(f"Incline is NaN for task {walking_type} {incline} {walking_speed}") | |
| return None | |
| if np.isnan(walking_speed) or walking_speed is None: | |
| print(f"Walking speed is NaN for task {walking_type} {incline} {walking_speed}") | |
| return None | |
| def format_walking_speed(speed): | |
| # Map known speeds to specific string representations | |
| mapping = {0.8: "s0x8", 1.0: "s1", 1.2: "s1x2"} | |
| # Use the mapping if available, otherwise default to a generic string | |
| return mapping.get(speed, f"s{speed}") | |
| # Format walking speed | |
| speed_str = format_walking_speed(walking_speed) | |
| # For level walking, return simpler format without incline info | |
| if walking_type == 'level_walking': | |
| return f"{walking_type}_{speed_str}" | |
| # Format incline: if the value is an integer, do not show decimals. | |
| if incline == int(incline): | |
| incline_str = str(abs(int(incline))) | |
| else: | |
| incline_str = str(abs(incline)) | |
| # Build and return the standardized task_info string for incline/decline walking | |
| task_info = f"{walking_type}_{incline_str}_deg_{speed_str}_m_s" | |
| return task_info | |