Skip to content

Commit

Permalink
Fix recommendation engine at similar fit results
Browse files Browse the repository at this point in the history
* use stretching math when two fits are equally bad
  • Loading branch information
nomasi committed May 2, 2022
1 parent e84e7bb commit eab8d8d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
26 changes: 24 additions & 2 deletions index1.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ <h2>Quick Overview</h2>
<option value="">Choose an Option...</option>
<option value="7" price="0">S</option>
<option value="6" price="0">M</option>
<option value="5" price="0">L</option>
<option value="4" price="0">XL</option>
<option value="5" price="0">L</option>
</select>
</div>
</dd>
Expand Down Expand Up @@ -677,6 +677,29 @@ <h2>Product Tags</h2>
"hat_width": 0,
"hood_height": 0,
},
"4": {
"chest": 590,
"waist": 560,
"sleeve": 250,
"sleeve_top_width": 232,
"wrist_width": 185,
"underbust": 0,
"neck_opening_width": 0,
"shoulder_width": 139,
"front_height": 760,
"pant_waist": 0,
"hips": 570,
"inseam": 0,
"outseam": 0,
"thigh_width": 0,
"knee_width": 0,
"calf_width": 0,
"pant_sleeve_width": 0,
"shoe_inside_length": 0,
"shoe_inside_width": 0,
"hat_width": 0,
"hood_height": 0,
},
"5": {
"chest": 560,
"waist": 540,
Expand All @@ -700,7 +723,6 @@ <h2>Product Tags</h2>
"hat_width": 0,
"hood_height": 0,
},

}
}
};
Expand Down
12 changes: 6 additions & 6 deletions index1s.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ <h2>Quick Overview</h2>
<option value="7" price="0">S</option>
<option value="6" price="0">M</option>
<option value="5" price="0">L</option>
<option value="4" price="0">XL</option>
<option value="41" price="0">XL</option>
</select>
<div class="woostify-variation-swatches quickview-support variation-circle" data-attribute_name="attribute_pa_size">
<span class="swatch swatch-label swatch-s" data-value="7">S</span>
<span class="swatch swatch-label swatch-m" data-value="6">M</span>
<span class="swatch swatch-label swatch-l" data-value="5">L</span>
<span class="swatch swatch-label swatch-xl" data-value="4">XL</span>
<span class="swatch swatch-label swatch-xl" data-value="41">XL</span>
</div>
</div>
</dd>
Expand Down Expand Up @@ -304,7 +304,7 @@ <h2>Quick Overview</h2>
"oldPrice": "0",
"products": ["18"]
}, {
"id": "4",
"id": "41",
"label": "XL",
"price": "0",
"oldPrice": "0",
Expand Down Expand Up @@ -629,7 +629,7 @@ <h2>Product Tags</h2>
"SS16_M2180B_BLUE_S": "7",
"SS16_M2180B_BLUE_M": "6",
"SS16_M2180B_BLUE_L": "5",
"SS16_M2180B_BLUE_XL": "4",
"SS16_M2180B_BLUE_XL": "41",
}
};
//]]>
Expand Down Expand Up @@ -715,7 +715,7 @@ <h2>Product Tags</h2>
"hat_width": 0,
"hood_height": 0,
},
"4": {
"41": {
"chest": 590,
"waist": 570,
"sleeve": 260,
Expand Down Expand Up @@ -806,7 +806,7 @@ <h2>Product Tags</h2>
<span class="label"><label for="vote_3">Black</label></span>
</li>
<li class="last even">
<input type="radio" name="vote" class="radio poll_vote" id="vote_4" value="4">
<input type="radio" name="vote" class="radio poll_vote" id="vote_4" value="41">
<span class="label"><label for="vote_4">Magenta</label></span>
</li>
</ul>
Expand Down
13 changes: 6 additions & 7 deletions src/api/sizeme-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,19 +374,18 @@ function getRecommendedFit (fitResults, optimalFit) {
.filter(([, res]) => res.accuracy > 0)
.reduce(([accSize, fit], [size, res]) => {
if ((res.totalFit < 1000) && (optFit >= 1000)) return [accSize, fit];
let maxStretchArr = [];
Object.entries(res.matchMap).forEach(([oKey, oValue]) => { maxStretchArr.push( oValue.componentStretch / stretchFactor(oKey) ); });
const maxStretch = Math.max.apply(null, maxStretchArr);
const newFit = (Math.abs(res.totalFit - optFit) * 100) + Math.abs(maxStretch - optStretch);
if (useStretchingMath(res.matchMap, optFit)) {
let maxStretchArr = [];
Object.entries(res.matchMap).forEach(([oKey, oValue]) => { maxStretchArr.push( oValue.componentStretch / stretchFactor(oKey) ); });
const maxStretch = Math.max.apply(null, maxStretchArr);
const newFit = (Math.abs(res.totalFit - 1000) * 100) + Math.abs(maxStretch - optStretch);
if (newFit <= (maxDist * 100) && (!accSize || newFit < fit)) {
if ((newFit <= (maxDist * 100)) && ((!accSize) || (newFit < fit))) {
return [size, newFit];
} else {
return [accSize, fit];
}
} else {
const newFit = Math.abs(res.totalFit - optFit);
if ((newFit <= maxDist) && (res.totalFit >= 1000) && ((!accSize) || (newFit < fit))) {
if ((newFit <= (maxDist * 100)) && (res.totalFit >= 1000) && ((!accSize) || (newFit < fit))) {
return [size, newFit];
} else {
return [accSize, fit];
Expand Down

0 comments on commit eab8d8d

Please sign in to comment.