Show min/avg/max in Combo TDD dialog.

(cherry picked from commit 348b53a)
This commit is contained in:
Johannes Mockenhaupt 2017-11-26 12:38:54 +01:00
parent b46165e52a
commit ffb5ee3b22
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 22 additions and 5 deletions

View file

@ -23,15 +23,29 @@ public class ComboTddHistoryDialog extends DialogFragment {
if (tdds.isEmpty()) {
text.setText(R.string.combo_empty_tdd_history_note);
} else {
boolean first = true;
StringBuilder sb = new StringBuilder();
DateFormat dateFormatter = DateFormat.getDateInstance();
double avg = 0;
double min = 999;
double max = 0;
int count = 0;
for (Tdd tdd : tdds) {
if (first) {
first = false;
} else {
sb.append("\n");
if (tdd.total > 0) {
avg += tdd.total;
count++;
}
if (tdd.total < min) min = tdd.total;
if (tdd.total > max) max = tdd.total;
}
avg = avg / count;
sb.append(String.format(Locale.getDefault(), getString(R.string.combo_tdd_minimum), min));
sb.append("\n");
sb.append(String.format(Locale.getDefault(), getString(R.string.combo_tdd_average), avg));
sb.append("\n");
sb.append(String.format(Locale.getDefault(), getString(R.string.combo_tdd_maximum), max));
sb.append("\n");
for (Tdd tdd : tdds) {
sb.append("\n");
sb.append(dateFormatter.format(tdd.timestamp));
sb.append(" ");
sb.append(String.format(Locale.getDefault(), "%3.1f", tdd.total));

View file

@ -817,5 +817,8 @@
<string name="combo_empty_alert_history_note">To retrieve the alert history from the pump, long press the Refresh button.</string>
<string name="combo_empty_tdd_history_note">To retrieve the TDD history from the pump, long press the Refresh button.</string>
<string name="key_sync_profile_to_pump">sync_profile_to_pump</string>
<string name="combo_tdd_minimum">Minimum: %3.1f U</string>
<string name="combo_tdd_average">Average: %3.1f U</string>
<string name="combo_tdd_maximum">Maximum: %3.1f U</string>
</resources>