Spaces:
Sleeping
Sleeping
File size: 2,546 Bytes
e2bff0a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
from dataclasses import dataclass
@dataclass
class BodyMeasurements:
shoulder: float # in cm
chest: float # in cm
waist: float # in cm
def determine_fit(measurements: BodyMeasurements) -> str:
"""
Determine the general fit based on shoulder, chest, and waist measurements.
The algorithm uses two simple ratios:
- waist-to-chest ratio: a lower ratio suggests a more tapered torso (slim fit).
- chest-to-shoulder ratio: a higher ratio suggests a broader chest relative to the shoulder,
which is often associated with a slimmer profile.
Thresholds (assumed for demonstration purposes):
- Slim Fit: waist/chest < 0.85 and chest/shoulder >= 1.45
- Regular Fit: waist/chest between 0.85 and 0.95 and chest/shoulder between 1.3 and 1.45
- Loose Fit: any measurements outside the above ranges
Args:
measurements (BodyMeasurements): User measurements in centimeters.
Returns:
str: A recommendation of 'Slim Fit', 'Regular Fit', or 'Loose Fit'.
"""
# Calculate ratios
waist_chest_ratio = measurements.waist / measurements.chest
chest_shoulder_ratio = measurements.chest / measurements.shoulder
# Determine fit based on ratio thresholds
if waist_chest_ratio < 0.85 and chest_shoulder_ratio >= 1.45:
return "Slim Fit"
elif 0.85 <= waist_chest_ratio <= 0.95 and 1.3 <= chest_shoulder_ratio < 1.45:
return "Regular Fit"
else:
return "Loose Fit"
def get_fit(shoulder: float, chest: float, waist: float) -> str:
"""
Get a fit recommendation based on input measurements.
Args:
shoulder (float): Shoulder measurement in cm.
chest (float): Chest measurement in cm.
waist (float): Waist measurement in cm.
Returns:
str: The recommended fit category.
"""
measurements = BodyMeasurements(shoulder=shoulder, chest=chest, waist=waist)
return determine_fit(measurements)
if __name__ == "__main__":
# Example interactive usage:
try:
shoulder_input = float(input("Enter your shoulder measurement (cm): "))
chest_input = float(input("Enter your chest measurement (cm): "))
waist_input = float(input("Enter your waist measurement (cm): "))
except ValueError:
print("Please enter valid numeric values.")
exit(1)
recommended_fit = get_fit(shoulder_input, chest_input, waist_input)
print(f"Based on your measurements, your recommended fit is: {recommended_fit}")
|