Spaces:
Running
Running
| 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" | |