Skip to content

Commit

Permalink
Fix power controller loading regression / overview stats refinement
Browse files Browse the repository at this point in the history
A failed load of power controller tanks loading the entire page because
Deferred objects have .then property that await will invoke and then
raise an error.

Cleanup ftp and weight display and editing.
  Use ? instead of 0 or blanks.
  Always show FTP
  Trim trailing zeros from weight
  • Loading branch information
mayfield committed Nov 12, 2023
1 parent 7039558 commit 1ffcbe1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
31 changes: 15 additions & 16 deletions src/site/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,13 +697,14 @@ sauce.ns('analysis', ns => {
}
}
assignTrailforksToSegments().catch(console.error);
const localeWeight = ns.weight ? L.weightFormatter.convert(ns.weight) : undefined;
renderTertiaryStats({
weight: H.number(L.weightFormatter.convert(ns.weight), 2),
weight: localeWeight && Number(localeWeight.toFixed(2)),
weightUnit: L.weightFormatter.shortUnitKey(),
weightNorm: H.weight(ns.weight),
weightOrigin: ns.weightOrigin,
weightNorm: ns.weight && H.weight(ns.weight).replace(/0+$/, '').replace(/\.$/, ''),
weightOrigin: ns.weightOrigin || 'default',
ftp: ns.ftp,
ftpOrigin: ns.ftpOrigin,
ftpOrigin: ns.ftpOrigin || 'default',
intensity,
tss,
tTss,
Expand Down Expand Up @@ -2200,10 +2201,8 @@ sauce.ns('analysis', ns => {
if (!powerCtrl) {
_loadingPowerCtrl = undefined;
} else {
_loadingPowerCtrl = new Promise(resolve => {
powerCtrl.deferred.done(resolve);
powerCtrl.deferred.fail(resolve);
}).then(() => {
// Note: be careful with Deferred objects which have a `.then()` return value.
_loadingPowerCtrl = new Promise(resolve => powerCtrl.deferred.always(() => resolve())).then(() => {
if (!powerCtrl.has('athlete_ftp') && !powerCtrl.has('athlete_weight')) {
powerCtrl.set(sauce.perf.inferPowerDataAthleteInfo(powerCtrl.attributes));
}
Expand Down Expand Up @@ -2262,9 +2261,6 @@ sauce.ns('analysis', ns => {
if (lastKnown) {
info.ftp = lastKnown;
info.ftpOrigin = 'sauce';
} else {
info.ftp = 0;
info.ftpOrigin = 'default';
}
}
}
Expand Down Expand Up @@ -2345,9 +2341,6 @@ sauce.ns('analysis', ns => {
if (lastKnown) {
info.weight = lastKnown;
info.weightOrigin = 'sauce';
} else {
info.weight = 0;
info.weightOrigin = 'default';
}
}
}
Expand Down Expand Up @@ -3331,8 +3324,14 @@ sauce.ns('analysis', ns => {
await Promise.all([sauce.proxy.connected, _localeInit]);
Object.assign(ns, await initSyncActivity(activity, ns.athlete.id));
const athleteInfo = (await sauce.storage.getAthleteInfo(ns.athlete.id)) || {};
Object.assign(ns, await getWeightInfo(athleteInfo));
Object.assign(ns, await getFTPInfo(athleteInfo));
try {
Object.assign(ns, await getWeightInfo(athleteInfo));
Object.assign(ns, await getFTPInfo(athleteInfo));
} catch(e) {
// Have had a regression with these before and I don't trust them to not fail
// in the future due to upstream changes..
console.error('Error while looking for weight of FTP:', e);
}
if (athleteInfo.gender != ns.gender) {
updateAthleteInfo({gender: ns.gender}); // bg okay
}
Expand Down
3 changes: 3 additions & 0 deletions src/site/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ sauce.ns('locale', ns => {

function humanWeight(kg, options={}) {
assertInit();
if (kg == null || kg === '' || Number.isNaN(kg)) {
return '';
}
const precision = options.precision != null ? options.precision : 1;
if (options.html) {
const save = ns.weightFormatter.precision;
Expand Down
26 changes: 12 additions & 14 deletions templates/tertiary-stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,22 @@

<div class="divider"></div>

<% if (obj.ftpOrigin) { %>
<li>
<strong class="sauce-editable-field ftp">
<a class="origin-{{ftpOrigin}}"
title="{{{ftp_link_tooltip}}}">{{humanNumber(ftp)}}</a><!--
--><input data-width="5ch" type="text" value="{{ftp}}"
title="{{{ftp_input_tooltip}}}"/><!--
--><abbr class="unit" title="Watts">W</abbr>
</strong>
<div class="label">FTP</div>
</li>
<% } %>
<li>
<strong class="sauce-editable-field ftp">
<a class="origin-{{ftpOrigin}}"
title="{{{ftp_link_tooltip}}}">{{ftp ? humanNumber(ftp) : '?'}}</a><!--
--><input data-width="5ch" type="text" value="{{ftp || ''}}"
title="{{{ftp_input_tooltip}}}"/><!--
--><abbr class="unit" title="Watts">W</abbr>
</strong>
<div class="label">FTP</div>
</li>

<li>
<strong class="sauce-editable-field weight">
<a class="origin-{{weightOrigin}}"
title="{{{weight_link_tooltip}}}">{{weightNorm}}</a><!--
--><input data-width="6ch" type="text" value="{{weight}}"
title="{{{weight_link_tooltip}}}">{{weightNorm || '?'}}</a><!--
--><input data-width="6ch" type="text" value="{{weight || ''}}"
title="{{{weight_input_tooltip}}}"/><!--
--><abbr class="unit" title="Weight">{{weightUnit}}</abbr>
</strong>
Expand Down

0 comments on commit 1ffcbe1

Please sign in to comment.