Merge pull request #70 from AdrianLxM/cpp_sum
Add sum to the overview of the basal profile.
This commit is contained in:
commit
41acb2d022
2 changed files with 26 additions and 6 deletions
|
@ -242,6 +242,9 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
|
|||
sb.append("</h3>");
|
||||
sb.append("<h4>");
|
||||
sb.append(getString(R.string.nsprofileview_basal_label));
|
||||
sb.append( " ( ∑");
|
||||
sb.append(DecimalFormatter.to2Decimal(circadianPercentageProfilePlugin.percentageBasalSum()));
|
||||
sb.append("U )");
|
||||
sb.append("</h4> " + circadianPercentageProfilePlugin.basalString());
|
||||
sb.append("<h4>");
|
||||
sb.append(getString(R.string.nsprofileview_ic_label));
|
||||
|
@ -251,7 +254,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
|
|||
sb.append("</h4> " + circadianPercentageProfilePlugin.isfString());
|
||||
profileView.setText(Html.fromHtml(sb.toString()));
|
||||
|
||||
baseprofileBasal.setText(Html.fromHtml("<h3>" + getString(R.string.base_profile_label) + "</h3>" +
|
||||
baseprofileBasal.setText(Html.fromHtml("<h3>" + getString(R.string.base_profile_label) + " ( ∑" + DecimalFormatter.to2Decimal(circadianPercentageProfilePlugin.baseBasalSum()) + "U )</h3>" +
|
||||
"<h4>" + getString(R.string.nsprofileview_basal_label) + "</h4>" + circadianPercentageProfilePlugin.baseBasalString()));
|
||||
baseprofileIC.setText(Html.fromHtml("<h4>" + getString(R.string.nsprofileview_ic_label) + "</h4>" + circadianPercentageProfilePlugin.baseIcString()));
|
||||
baseprofileISF.setText(Html.fromHtml("<h4>" + getString(R.string.nsprofileview_isf_label) + "</h4>" + circadianPercentageProfilePlugin.baseIsfString()));
|
||||
|
|
|
@ -207,11 +207,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
|||
JSONObject profile = new JSONObject();
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
double sum = 0d;
|
||||
for (int i = 0; i < 24; i++) {
|
||||
sum += basebasal[i];
|
||||
}
|
||||
stringBuilder.append(DecimalFormatter.to2Decimal(sum));
|
||||
stringBuilder.append(DecimalFormatter.to2Decimal(sum(basebasal)));
|
||||
stringBuilder.append("U@");
|
||||
stringBuilder.append(percentage);
|
||||
stringBuilder.append("%>");
|
||||
|
@ -298,6 +294,27 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
|||
|
||||
String baseBasalString() {return profileString(basebasal, 0, 100, true);}
|
||||
|
||||
public double baseBasalSum(){
|
||||
return sum(basebasal);
|
||||
}
|
||||
|
||||
public double percentageBasalSum(){
|
||||
double result = 0;
|
||||
for (int i = 0; i < basebasal.length; i++) {
|
||||
result += SafeParse.stringToDouble(DecimalFormatter.to2Decimal(basebasal[i] * percentage / 100d));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static double sum(double values[]){
|
||||
double result = 0;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
result += values[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static String profileString(double[] values, int timeshift, int percentage, boolean inc) {
|
||||
timeshift = -(timeshift % 24) + 24;
|
||||
|
|
Loading…
Reference in a new issue