Spaces:
Running
Running
File size: 3,708 Bytes
7a83d16 6445bd1 7a83d16 6445bd1 7a83d16 6445bd1 7a83d16 6445bd1 7a83d16 6445bd1 7a83d16 ba180cd 7a83d16 ba180cd 7a83d16 ba180cd 7a83d16 ba180cd 7a83d16 17b6c6d 6445bd1 17b6c6d 6445bd1 17b6c6d 6445bd1 7a83d16 6445bd1 7a83d16 | 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | from size_chart import SIZE_CHART
PRIORITY = ["shoulder", "chest", "waist", "bicep"]
def evaluate_size(measurements):
"""
Evaluates the base size based on measurements.
Returns: (size, reason)
"""
ordered_sizes = ["XS", "S", "M", "L", "XL"]
for i, size in enumerate(ordered_sizes):
limits = SIZE_CHART[size]
valid = True
# Check if measurements fit within this size's limits
for key in PRIORITY:
# We strictly check the upper bound.
# If measurement > max, this size is too small.
if measurements[key] > limits[key][1]:
valid = False
break
if valid:
# This is the smallest size that fits.
# Determine reasoning.
if i == 0:
return size, f"Your measurements fit well in size {size}."
# Check why the previous size failed logic
prev_size = ordered_sizes[i-1]
prev_limits = SIZE_CHART[prev_size]
simplified_reasons = []
for key in PRIORITY:
if measurements[key] > prev_limits[key][1]:
simplified_reasons.append(f"{key.capitalize()} ({measurements[key]}) is larger than size {prev_size}")
reason_str = f"We recommend size {size} because your " + " and ".join(simplified_reasons) + "."
return size, reason_str
# If even XL fails (XL max is exceeded)
# We return XL+
# Find what exceeded XL
xl_limits = SIZE_CHART["XL"]
return "XL+", f"Your measurements are larger than size XL."
def apply_fit_preference(base_size, preference, measurements=None):
"""
Applies fit preference to the base size.
For 'Regular', requires measurements to re-evaluate.
Returns: (final_size, reason)
"""
sizes = ["XS", "S", "M", "L", "XL"]
if base_size not in sizes:
return base_size, "Fit preference not applicable for sizes outside chart"
idx = sizes.index(base_size)
if preference == "Slim":
return base_size, "Fit: Slim (Kept base size)"
if preference == "Loose":
if idx < len(sizes) - 1:
return sizes[idx + 1], "Fit: Loose (Moved up one size)"
else:
return base_size, "Fit: Loose (Already at max size)"
if preference == "Regular":
if measurements is None:
return base_size, "Fit: Regular (No measurements provided for adjustment)"
from size_chart import SIZE_CHART
limits = SIZE_CHART[base_size]
reasons = []
extension_needed = False
for key in measurements:
# Check if integer part matches the size limit's upper bound
# e.g., measurement 40.0 (int 40) matches limit 40 (int 40)
if int(measurements[key]) == int(limits[key][1]):
extension_needed = True
reasons.append(f"{key}")
if extension_needed:
if idx < len(sizes) - 1:
# Extract just the key names for the reason
matching_keys = [r.split()[0].capitalize() for r in reasons]
keys_str = " and ".join(matching_keys)
return sizes[idx + 1], f"Your {keys_str} is at the very top of size {base_size}, so we suggest size {sizes[idx + 1]} for a comfortable Regular fit."
else:
return base_size, f"You are at the top of size {base_size}, which is the largest available."
else:
return base_size, f"Size {base_size} provides the best Regular fit for you."
return base_size, "Unknown preference"
|