Show variations in Runtime string

Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
Robert C. Helling 2017-08-29 12:26:00 +02:00 committed by Dirk Hohndel
parent 2832141d2c
commit aed5b7d267
3 changed files with 21 additions and 7 deletions

View file

@ -101,7 +101,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
get_current_date()); get_current_date());
} }
len += snprintf(buffer + len, sz_buffer - len, translate("gettextFromC", "Runtime: %dmin<br></div>"), len += snprintf(buffer + len, sz_buffer - len, translate("gettextFromC", "Runtime: %dmin VARIATIONS<br></div>"),
diveplan_duration(diveplan)); diveplan_duration(diveplan));
if (!plan_verbatim) { if (!plan_verbatim) {

View file

@ -892,7 +892,7 @@ struct divedatapoint * DivePlannerPointsModel::cloneDiveplan(struct diveplan *pl
return last_segment; return last_segment;
} }
void DivePlannerPointsModel::analyzeVariations(struct decostop *min, struct decostop *mid, struct decostop *max, const char *unit) int DivePlannerPointsModel::analyzeVariations(struct decostop *min, struct decostop *mid, struct decostop *max, const char *unit)
{ {
int leftsum = 0; int leftsum = 0;
int rightsum = 0; int rightsum = 0;
@ -906,17 +906,22 @@ void DivePlannerPointsModel::analyzeVariations(struct decostop *min, struct deco
leftsum += left; leftsum += left;
int right = max->time - mid->time; int right = max->time - mid->time;
rightsum += right; rightsum += right;
#ifdef SHOWSTOPVARIATIONS
if (min->time + mid->time + max->time) if (min->time + mid->time + max->time)
printf("%dm: %dmin + %ds/%s +- %ds/%s\n", mid->depth / 1000, printf("%dm: %dmin + %ds/%s +- %ds/%s\n", mid->depth / 1000,
(mid->time + 1)/60, (mid->time + 1)/60,
(left + right) / 2, unit, (left + right) / 2, unit,
(right - left) / 2, unit); (right - left) / 2, unit);
#endif
++min; ++min;
++mid; ++mid;
++max; ++max;
} }
printf("Total + %d:%02d/%s +- %d:%02d/%s\n\n", FRACTION((leftsum + rightsum) / 2, 60), unit, #ifdef SHOWSTOPVARIATIONS
FRACTION((rightsum - leftsum) / 2, 60), unit); printf("Total + %d:%02d/%s +- %d s/%s\n\n", FRACTION((leftsum + rightsum) / 2, 60), unit,
(rightsum - leftsum) / 2, unit);
#endif
return (leftsum + rightsum) / 2;
} }
void DivePlannerPointsModel::computeVariations() void DivePlannerPointsModel::computeVariations()
@ -961,9 +966,18 @@ void DivePlannerPointsModel::computeVariations()
free_dps(&plan_copy); free_dps(&plan_copy);
restore_deco_state(save, false); restore_deco_state(save, false);
#ifdef SHOWSTOPVARIATIONS
printf("\n\n"); printf("\n\n");
analyzeVariations(shallower, original, deeper, "m"); #endif
analyzeVariations(shorter, original, longer, "min");
QString notes(displayed_dive.notes);
free(displayed_dive.notes);
char buf[200];
sprintf(buf, "+ %d:%02d /m + %d:%02d /min", FRACTION(analyzeVariations(shallower, original, deeper, "m"),60),
FRACTION(analyzeVariations(shorter, original, longer, "min"), 60));
displayed_dive.notes = strdup(notes.replace("VARIATIONS", QString(buf)).toUtf8().data());
setRecalc(oldRecalc); setRecalc(oldRecalc);
} }

View file

@ -109,7 +109,7 @@ private:
struct diveplan diveplan; struct diveplan diveplan;
struct divedatapoint *cloneDiveplan(struct diveplan *plan_copy); struct divedatapoint *cloneDiveplan(struct diveplan *plan_copy);
void computeVariations(); void computeVariations();
void analyzeVariations(struct decostop *min, struct decostop *mid, struct decostop *max, const char *unit); int analyzeVariations(struct decostop *min, struct decostop *mid, struct decostop *max, const char *unit);
Mode mode; Mode mode;
bool recalc; bool recalc;
QVector<divedatapoint> divepoints; QVector<divedatapoint> divepoints;