Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statistics Customization 1 #3707

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.eveningoutpost.dexdrip.stats;

import static android.app.PendingIntent.getActivity;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.eveningoutpost.dexdrip.databinding.StatsGeneralBinding;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.models.UserError.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -19,6 +19,7 @@

import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants;
import com.eveningoutpost.dexdrip.R;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;

import java.text.DecimalFormat;
import java.util.ArrayList;
Expand All @@ -28,6 +29,7 @@
* Created by adrian on 30/06/15.
*/
public class FirstPageFragment extends Fragment {
private final static String TAG = FirstPageFragment.class.getSimpleName();

private View myView;

Expand All @@ -36,8 +38,9 @@ public class FirstPageFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Log.d("DrawStats", "FirstPageFragment onCreateView");

myView = inflater.inflate(
R.layout.stats_general, container, false);
StatsGeneralBinding binding = DataBindingUtil.inflate(inflater, R.layout.stats_general, container, false);
myView = binding.getRoot();
binding.setStatsview(new ViewStats());

myView.setTag(0);

Expand All @@ -52,6 +55,56 @@ public View getView() {
return myView;
}

public class ViewStats { // Linking to stats_general layout
public boolean viewAbsolutes() { // Show absolute numbers
return Pref.getBoolean("show_statistics_absolutes", false);
}

public boolean viewMedianBG() { // Show BG median
return Pref.getBoolean("show_statistics_median", false);
}

public boolean viewA1C() { // Show estimated A1C
return Pref.getBoolean("show_statistics_a1cestimate", false);
}

public boolean viewSD() { // Show standard deviation
return Pref.getBoolean("show_statistics_sd", false);
}

public boolean viewRelSD() { // Show relative standard deviation
return Pref.getBoolean("show_statistics_relsd", false);
}

public boolean viewGviLine() { // Show the GVI line, including GVI and PGS
return Pref.getBoolean("show_statistics_gvi", false) || Pref.getBoolean("show_statistics_pgs", false);
}
}

public static void defineDefaults () { // This is where the defaults are defined.
defineDefault("show_statistics_absolutes", true); // Show absolute values
defineDefault("show_statistics_median", true); // Show median by default
defineDefault("show_statistics_a1cestimate", true); // Show estimated A1C
defineDefault("show_statistics_sd", true); // Show standard deviation
defineDefault("show_statistics_relsd", true); // Show relative standard deviation
defineDefault("show_statistics_pgs", true); // Show PGS
defineDefault("show_statistics_gvi", true); // Show GVI
}

public static void defineDefault (String pref, Boolean def) {
if (!Pref.isPreferenceSet(pref)) { // If the value (of pref) has never been changed
try {
if (!def) { // If the default is false
// There is no need to take any action if the default is false
} else if (def) { // If the default is true
Pref.setBoolean(pref, true); // Enable the setting
}
} catch (Exception e) {
UserError.Log.wtf(TAG, "incorrect arguments");
}
}
}

private class CalculationThread extends Thread {

private final View localView;
Expand All @@ -75,7 +128,7 @@ public void run() {
return;
}

//Ranges
// Ranges
long aboveRange = DBSearchUtil.noReadingsAboveRange(context);
long belowRange = DBSearchUtil.noReadingsBelowRange(context);
long inRange = DBSearchUtil.noReadingsInRange(context);
Expand All @@ -96,7 +149,7 @@ public void run() {
double stats_high = Double.parseDouble(settings.getString("highValue", "170"));
double stats_low = Double.parseDouble(settings.getString("lowValue", "70"));
TextView rangeView = (TextView) localView.findViewById(R.id.textView_stats_range_set);
//update stats_high/low
// update stats_high/low
if (!mgdl) {
updateText(localView, rangeView, (Math.round(stats_low * 10) / 10d) + " - " + (Math.round(stats_high * 10) / 10d) + " mmol/l");
} else {
Expand Down Expand Up @@ -127,14 +180,14 @@ public void run() {
}

TextView meanView = (TextView) localView.findViewById(R.id.textView_mean);
//update mean
// update mean
if (mgdl) {
updateText(localView, meanView, (Math.round(mean * 10) / 10d) + " mg/dl");
} else {
updateText(localView, meanView, (Math.round(mean * Dex_Constants.MG_DL_TO_MMOL_L * 100) / 100d) + " mmol/l");

}
//update A1c
// update A1c
TextView a1cView = (TextView) localView.findViewById(R.id.textView_a1c);
int a1c_ifcc = (int) Math.round(((mean + 46.7) / 28.7 - 2.15) * 10.929);
double a1c_dcct = Math.round(10 * (mean + 46.7) / 28.7) / 10d;
Expand All @@ -156,7 +209,7 @@ public void run() {
updateText(localView, coefficientOfVariation, Math.round(1000d*stdev/mean)/10d + "%");


//calculate BGI / PGS
// calculate GVI / PGS
// https://github.com/nightscout/cgm-remote-monitor/blob/master/lib/report_plugins/glucosedistribution.js#L150
List<BgReadingStats> bgListByTime = DBSearchUtil.getFilteredReadingsWithFallback(false);

Expand Down Expand Up @@ -193,7 +246,13 @@ public void run() {
Log.d("DrawStats", "NormalReadingspct=" + normalReadingspct + " glucoseMean=" + glucoseMean + " tirMultiplier=" + tirMultiplier + " PGS=" + PGS);
TextView gviView = (TextView) localView.findViewById(R.id.textView_gvi);
DecimalFormat df = new DecimalFormat("#.00");
updateText(localView, gviView, df.format(gvi) + " PGS: " + df.format(PGS));
if (Pref.getBoolean("show_statistics_pgs", false) && Pref.getBoolean("show_statistics_gvi", true)) { // Show both GVI and PGS
updateText(localView, gviView, "GVI: " + df.format(gvi) + " PGS: " + df.format(PGS));
} else if (Pref.getBoolean("show_statistics_gvi", true)) { // Show only GVI
updateText(localView, gviView, "GVI: " + df.format(gvi));
} else if (Pref.getBoolean("show_statistics_pgs", false)) { // Show only PGS
updateText(localView, gviView, "PGS: " + df.format(PGS));
}

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,25 @@ public class StatsActivity extends ActivityWithMenu {
private Button button90d;
MenuItem menuItem;
MenuItem menuItem2;
MenuItem menuItem3;
MenuItem menuItem4;
MenuItem menuItem5;
MenuItem menuItem6;
MenuItem menuItem7;
MenuItem menuItem8;
MenuItem menuItem9;
private View decorView;
private String stateString;
private final static int MY_PERMISSIONS_REQUEST_STORAGE_SCREENSHOT = 106;
private static final String SHOW_STATISTICS_FULL_SCREEN = "show_statistics_full_screen";
public static final String SHOW_STATISTICS_PRINT_COLOR = "show_statistics_print_color";
public static final String SHOW_STATISTICS_Absolutes = "show_statistics_absolutes";
public static final String SHOW_STATISTICS_Median_BG = "show_statistics_median";
public static final String SHOW_STATISTICS_A1C = "show_statistics_a1cestimate";
public static final String SHOW_STATISTICS_SD = "show_statistics_sd";
public static final String SHOW_STATISTICS_Rel_SD = "show_statistics_relsd";
public static final String SHOW_STATISTICS_GVI = "show_statistics_gvi";
public static final String SHOW_STATISTICS_PGS = "show_statistics_pgs";
private static final String TAG = "Statistics";

@Override
Expand Down Expand Up @@ -265,6 +279,13 @@ public boolean onCreateOptionsMenu(Menu menu) {

menuItem = menu.findItem(R.id.action_toggle_fullscreen);
menuItem2 = menu.findItem(R.id.action_toggle_printing);
menuItem3 = menu.findItem(R.id.action_show_absolutes);
menuItem4 = menu.findItem(R.id.action_show_median);
menuItem5 = menu.findItem(R.id.action_show_a1cestimate);
menuItem6 = menu.findItem(R.id.action_show_sd);
menuItem7 = menu.findItem(R.id.action_show_relsd);
menuItem8 = menu.findItem(R.id.action_show_gvi);
menuItem9 = menu.findItem(R.id.action_show_pgs);

updateMenuChecked();

Expand All @@ -282,6 +303,13 @@ public void onWindowFocusChanged(boolean hasFocus) {
private void updateMenuChecked() {
menuItem.setChecked(Pref.getBoolean(SHOW_STATISTICS_FULL_SCREEN, false));
menuItem2.setChecked(Pref.getBoolean(SHOW_STATISTICS_PRINT_COLOR, false));
menuItem3.setChecked(Pref.getBoolean(SHOW_STATISTICS_Absolutes, false));
menuItem4.setChecked(Pref.getBoolean(SHOW_STATISTICS_Median_BG, false));
menuItem5.setChecked(Pref.getBoolean(SHOW_STATISTICS_A1C, false));
menuItem6.setChecked(Pref.getBoolean(SHOW_STATISTICS_SD, false));
menuItem7.setChecked(Pref.getBoolean(SHOW_STATISTICS_Rel_SD, false));
menuItem8.setChecked(Pref.getBoolean(SHOW_STATISTICS_GVI, false));
menuItem9.setChecked(Pref.getBoolean(SHOW_STATISTICS_PGS, false));
}

private void evaluateColors(boolean recreate) {
Expand Down Expand Up @@ -311,6 +339,56 @@ public void toggleStatisticsPrintingMode(MenuItem m)
evaluateColors(true);
updateMenuChecked();
}

public void toggleStatisticsShowAbsolutes(MenuItem m) // Toggle visibility of absolute numbers
{
Pref.toggleBoolean(SHOW_STATISTICS_Absolutes);
evaluateColors(true);
updateMenuChecked();
}

public void toggleStatisticsShowMedianBG(MenuItem m) // Toggle visibility of median
{
Pref.toggleBoolean(SHOW_STATISTICS_Median_BG);
evaluateColors(true);
updateMenuChecked();
}

public void toggleStatisticsShowA1C(MenuItem m) // Toggle visibility of estimated A1C
{
Pref.toggleBoolean(SHOW_STATISTICS_A1C);
evaluateColors(true);
updateMenuChecked();
}

public void toggleStatisticsShowSD(MenuItem m) // Toggle visibility of standard deviation
{
Pref.toggleBoolean(SHOW_STATISTICS_SD);
evaluateColors(true);
updateMenuChecked();
}

public void toggleStatisticsShowRelSD(MenuItem m) // Toggle visibility of relative standard deviation
{
Pref.toggleBoolean(SHOW_STATISTICS_Rel_SD);
evaluateColors(true);
updateMenuChecked();
}

public void toggleStatisticsShowGVI(MenuItem m) // Toggle visibility of GVI
{
Pref.toggleBoolean(SHOW_STATISTICS_GVI);
evaluateColors(true);
updateMenuChecked();
}

public void toggleStatisticsShowPGS(MenuItem m) // Toggle visibility of PGS
{
Pref.toggleBoolean(SHOW_STATISTICS_PGS);
evaluateColors(true);
updateMenuChecked();
}

public void statisticsDisableFullScreen(View v)
{
toggleStatisticsFullScreenMode(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.eveningoutpost.dexdrip.models.UserNotification;
import com.eveningoutpost.dexdrip.R;
import com.eveningoutpost.dexdrip.SnoozeActivity;
import com.eveningoutpost.dexdrip.stats.FirstPageFragment;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -60,6 +61,7 @@ public void performAll() {
IncompatibleApps.notifyAboutIncompatibleApps();
CompatibleApps.notifyAboutCompatibleApps();
legacySettingsMoveLanguageFromNoToNb();
FirstPageFragment.defineDefaults(); // Define the statistics page visibility defaults.

}

Expand Down
Loading
Loading