OVERVIEW & NOTIFICATION logging cleanup

This commit is contained in:
Milos Kozak 2018-07-27 14:01:56 +02:00
parent 6a058f5036
commit 9141e0f66d
9 changed files with 167 additions and 157 deletions

View file

@ -37,6 +37,8 @@ public class Config {
public static final boolean logEvents = false;
public static final boolean logQueue = true;
public static final boolean logBgSource = true;
public static final boolean logOverview = true;
public static final boolean logNotification = true;
// DanaR specific
public static final boolean logDanaBTComm = true;

View file

@ -73,4 +73,6 @@ public class Constants {
public static final String EVENTS = "EVENTS";
public static final String QUEUE = "QUEUE";
public static final String BGSOURCE = "BGSOURCE";
public static final String OVERVIEW = "OVERVIEW";
public static final String NOTIFICATION = "NOTIFICATION";
}

View file

@ -126,7 +126,7 @@ import info.nightscout.utils.ToastUtils;
import static info.nightscout.utils.DateUtil.now;
public class OverviewFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener {
private static Logger log = LoggerFactory.getLogger(OverviewFragment.class);
private static Logger log = LoggerFactory.getLogger(Constants.OVERVIEW);
TextView timeView;
TextView bgView;
@ -201,143 +201,136 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
//check screen width
final DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
int screen_width = dm.widthPixels;
int screen_height = dm.heightPixels;
smallWidth = screen_width <= Constants.SMALL_WIDTH;
smallHeight = screen_height <= Constants.SMALL_HEIGHT;
boolean landscape = screen_height < screen_width;
//check screen width
final DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
int screen_width = dm.widthPixels;
int screen_height = dm.heightPixels;
smallWidth = screen_width <= Constants.SMALL_WIDTH;
smallHeight = screen_height <= Constants.SMALL_HEIGHT;
boolean landscape = screen_height < screen_width;
View view;
View view;
if (MainApp.sResources.getBoolean(R.bool.isTablet) && (Config.NSCLIENT || Config.G5UPLOADER)) {
view = inflater.inflate(R.layout.overview_fragment_nsclient_tablet, container, false);
} else if (Config.NSCLIENT || Config.G5UPLOADER) {
view = inflater.inflate(R.layout.overview_fragment_nsclient, container, false);
shorttextmode = true;
} else if (smallHeight || landscape) {
view = inflater.inflate(R.layout.overview_fragment_smallheight, container, false);
} else {
view = inflater.inflate(R.layout.overview_fragment, container, false);
}
timeView = (TextView) view.findViewById(R.id.overview_time);
bgView = (TextView) view.findViewById(R.id.overview_bg);
arrowView = (TextView) view.findViewById(R.id.overview_arrow);
if (smallWidth) {
arrowView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 35);
}
sensitivityView = (TextView) view.findViewById(R.id.overview_sensitivity);
timeAgoView = (TextView) view.findViewById(R.id.overview_timeago);
timeAgoShortView = (TextView) view.findViewById(R.id.overview_timeagoshort);
deltaView = (TextView) view.findViewById(R.id.overview_delta);
deltaShortView = (TextView) view.findViewById(R.id.overview_deltashort);
avgdeltaView = (TextView) view.findViewById(R.id.overview_avgdelta);
baseBasalView = (TextView) view.findViewById(R.id.overview_basebasal);
extendedBolusView = (TextView) view.findViewById(R.id.overview_extendedbolus);
activeProfileView = (TextView) view.findViewById(R.id.overview_activeprofile);
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
pumpDeviceStatusView = (TextView) view.findViewById(R.id.overview_pump);
openapsDeviceStatusView = (TextView) view.findViewById(R.id.overview_openaps);
uploaderDeviceStatusView = (TextView) view.findViewById(R.id.overview_uploader);
iobCalculationProgressView = (TextView) view.findViewById(R.id.overview_iobcalculationprogess);
loopStatusLayout = (LinearLayout) view.findViewById(R.id.overview_looplayout);
pumpStatusLayout = (LinearLayout) view.findViewById(R.id.overview_pumpstatuslayout);
pumpStatusView.setBackgroundColor(MainApp.gc(R.color.colorInitializingBorder));
iobView = (TextView) view.findViewById(R.id.overview_iob);
cobView = (TextView) view.findViewById(R.id.overview_cob);
apsModeView = (TextView) view.findViewById(R.id.overview_apsmode);
tempTargetView = (TextView) view.findViewById(R.id.overview_temptarget);
iage = (TextView) view.findViewById(R.id.careportal_insulinage);
cage = (TextView) view.findViewById(R.id.careportal_canulaage);
sage = (TextView) view.findViewById(R.id.careportal_sensorage);
pbage = (TextView) view.findViewById(R.id.careportal_pbage);
bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph);
treatmentButton = (SingleClickButton) view.findViewById(R.id.overview_treatmentbutton);
treatmentButton.setOnClickListener(this);
wizardButton = (SingleClickButton) view.findViewById(R.id.overview_wizardbutton);
wizardButton.setOnClickListener(this);
insulinButton = (SingleClickButton) view.findViewById(R.id.overview_insulinbutton);
if (insulinButton != null)
insulinButton.setOnClickListener(this);
carbsButton = (SingleClickButton) view.findViewById(R.id.overview_carbsbutton);
if (carbsButton != null)
carbsButton.setOnClickListener(this);
acceptTempButton = (SingleClickButton) view.findViewById(R.id.overview_accepttempbutton);
if (acceptTempButton != null)
acceptTempButton.setOnClickListener(this);
quickWizardButton = (SingleClickButton) view.findViewById(R.id.overview_quickwizardbutton);
quickWizardButton.setOnClickListener(this);
quickWizardButton.setOnLongClickListener(this);
calibrationButton = (SingleClickButton) view.findViewById(R.id.overview_calibrationbutton);
if (calibrationButton != null)
calibrationButton.setOnClickListener(this);
cgmButton = (SingleClickButton) view.findViewById(R.id.overview_cgmbutton);
if (cgmButton != null)
cgmButton.setOnClickListener(this);
acceptTempLayout = (LinearLayout) view.findViewById(R.id.overview_accepttemplayout);
notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications);
notificationsView.setHasFixedSize(false);
llm = new LinearLayoutManager(view.getContext());
notificationsView.setLayoutManager(llm);
int axisWidth = 50;
if (dm.densityDpi <= 120)
axisWidth = 3;
else if (dm.densityDpi <= 160)
axisWidth = 10;
else if (dm.densityDpi <= 320)
axisWidth = 35;
else if (dm.densityDpi <= 420)
axisWidth = 50;
else if (dm.densityDpi <= 560)
axisWidth = 70;
else
axisWidth = 80;
bgGraph.getGridLabelRenderer().setGridColor(MainApp.gc(R.color.graphgrid));
bgGraph.getGridLabelRenderer().reloadStyles();
iobGraph.getGridLabelRenderer().setGridColor(MainApp.gc(R.color.graphgrid));
iobGraph.getGridLabelRenderer().reloadStyles();
iobGraph.getGridLabelRenderer().setHorizontalLabelsVisible(false);
bgGraph.getGridLabelRenderer().setLabelVerticalWidth(axisWidth);
iobGraph.getGridLabelRenderer().setLabelVerticalWidth(axisWidth);
iobGraph.getGridLabelRenderer().setNumVerticalLabels(3);
rangeToDisplay = SP.getInt(R.string.key_rangetodisplay, 6);
bgGraph.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
rangeToDisplay += 6;
rangeToDisplay = rangeToDisplay > 24 ? 6 : rangeToDisplay;
SP.putInt(R.string.key_rangetodisplay, rangeToDisplay);
updateGUI("rangeChange");
return false;
}
});
setupChartMenu(view);
return view;
} catch (Exception e) {
FabricPrivacy.logException(e);
log.debug("Runtime Exception", e);
if (MainApp.sResources.getBoolean(R.bool.isTablet) && (Config.NSCLIENT || Config.G5UPLOADER)) {
view = inflater.inflate(R.layout.overview_fragment_nsclient_tablet, container, false);
} else if (Config.NSCLIENT || Config.G5UPLOADER) {
view = inflater.inflate(R.layout.overview_fragment_nsclient, container, false);
shorttextmode = true;
} else if (smallHeight || landscape) {
view = inflater.inflate(R.layout.overview_fragment_smallheight, container, false);
} else {
view = inflater.inflate(R.layout.overview_fragment, container, false);
}
return null;
timeView = (TextView) view.findViewById(R.id.overview_time);
bgView = (TextView) view.findViewById(R.id.overview_bg);
arrowView = (TextView) view.findViewById(R.id.overview_arrow);
if (smallWidth) {
arrowView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 35);
}
sensitivityView = (TextView) view.findViewById(R.id.overview_sensitivity);
timeAgoView = (TextView) view.findViewById(R.id.overview_timeago);
timeAgoShortView = (TextView) view.findViewById(R.id.overview_timeagoshort);
deltaView = (TextView) view.findViewById(R.id.overview_delta);
deltaShortView = (TextView) view.findViewById(R.id.overview_deltashort);
avgdeltaView = (TextView) view.findViewById(R.id.overview_avgdelta);
baseBasalView = (TextView) view.findViewById(R.id.overview_basebasal);
extendedBolusView = (TextView) view.findViewById(R.id.overview_extendedbolus);
activeProfileView = (TextView) view.findViewById(R.id.overview_activeprofile);
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
pumpDeviceStatusView = (TextView) view.findViewById(R.id.overview_pump);
openapsDeviceStatusView = (TextView) view.findViewById(R.id.overview_openaps);
uploaderDeviceStatusView = (TextView) view.findViewById(R.id.overview_uploader);
iobCalculationProgressView = (TextView) view.findViewById(R.id.overview_iobcalculationprogess);
loopStatusLayout = (LinearLayout) view.findViewById(R.id.overview_looplayout);
pumpStatusLayout = (LinearLayout) view.findViewById(R.id.overview_pumpstatuslayout);
pumpStatusView.setBackgroundColor(MainApp.gc(R.color.colorInitializingBorder));
iobView = (TextView) view.findViewById(R.id.overview_iob);
cobView = (TextView) view.findViewById(R.id.overview_cob);
apsModeView = (TextView) view.findViewById(R.id.overview_apsmode);
tempTargetView = (TextView) view.findViewById(R.id.overview_temptarget);
iage = (TextView) view.findViewById(R.id.careportal_insulinage);
cage = (TextView) view.findViewById(R.id.careportal_canulaage);
sage = (TextView) view.findViewById(R.id.careportal_sensorage);
pbage = (TextView) view.findViewById(R.id.careportal_pbage);
bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph);
treatmentButton = (SingleClickButton) view.findViewById(R.id.overview_treatmentbutton);
treatmentButton.setOnClickListener(this);
wizardButton = (SingleClickButton) view.findViewById(R.id.overview_wizardbutton);
wizardButton.setOnClickListener(this);
insulinButton = (SingleClickButton) view.findViewById(R.id.overview_insulinbutton);
if (insulinButton != null)
insulinButton.setOnClickListener(this);
carbsButton = (SingleClickButton) view.findViewById(R.id.overview_carbsbutton);
if (carbsButton != null)
carbsButton.setOnClickListener(this);
acceptTempButton = (SingleClickButton) view.findViewById(R.id.overview_accepttempbutton);
if (acceptTempButton != null)
acceptTempButton.setOnClickListener(this);
quickWizardButton = (SingleClickButton) view.findViewById(R.id.overview_quickwizardbutton);
quickWizardButton.setOnClickListener(this);
quickWizardButton.setOnLongClickListener(this);
calibrationButton = (SingleClickButton) view.findViewById(R.id.overview_calibrationbutton);
if (calibrationButton != null)
calibrationButton.setOnClickListener(this);
cgmButton = (SingleClickButton) view.findViewById(R.id.overview_cgmbutton);
if (cgmButton != null)
cgmButton.setOnClickListener(this);
acceptTempLayout = (LinearLayout) view.findViewById(R.id.overview_accepttemplayout);
notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications);
notificationsView.setHasFixedSize(false);
llm = new LinearLayoutManager(view.getContext());
notificationsView.setLayoutManager(llm);
int axisWidth = 50;
if (dm.densityDpi <= 120)
axisWidth = 3;
else if (dm.densityDpi <= 160)
axisWidth = 10;
else if (dm.densityDpi <= 320)
axisWidth = 35;
else if (dm.densityDpi <= 420)
axisWidth = 50;
else if (dm.densityDpi <= 560)
axisWidth = 70;
else
axisWidth = 80;
bgGraph.getGridLabelRenderer().setGridColor(MainApp.gc(R.color.graphgrid));
bgGraph.getGridLabelRenderer().reloadStyles();
iobGraph.getGridLabelRenderer().setGridColor(MainApp.gc(R.color.graphgrid));
iobGraph.getGridLabelRenderer().reloadStyles();
iobGraph.getGridLabelRenderer().setHorizontalLabelsVisible(false);
bgGraph.getGridLabelRenderer().setLabelVerticalWidth(axisWidth);
iobGraph.getGridLabelRenderer().setLabelVerticalWidth(axisWidth);
iobGraph.getGridLabelRenderer().setNumVerticalLabels(3);
rangeToDisplay = SP.getInt(R.string.key_rangetodisplay, 6);
bgGraph.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
rangeToDisplay += 6;
rangeToDisplay = rangeToDisplay > 24 ? 6 : rangeToDisplay;
SP.putInt(R.string.key_rangetodisplay, rangeToDisplay);
updateGUI("rangeChange");
return false;
}
});
setupChartMenu(view);
return view;
}
private void setupChartMenu(View view) {
@ -833,7 +826,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
synchronized (builder) {
if (accepted) {
log.debug("guarding: already accepted");
if (Config.logOverview)
log.debug("guarding: already accepted");
return;
}
accepted = true;
@ -1038,7 +1032,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
@SuppressLint("SetTextI18n")
public void updateGUI(final String from) {
log.debug("updateGUI entered from: " + from);
if (Config.logOverview)
log.debug("updateGUI entered from: " + from);
final Date updateGUIStart = new Date();
if (getActivity() == null)
@ -1433,7 +1428,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final long now = System.currentTimeMillis();
// ------------------ 1st graph
Profiler.log(log, from + " - 1st graph - START", updateGUIStart);
if (Config.logOverview)
Profiler.log(log, from + " - 1st graph - START", updateGUIStart);
final GraphData graphData = new GraphData(bgGraph, IobCobCalculatorPlugin.getPlugin());
@ -1465,7 +1461,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
graphData.addNowLine(now);
// ------------------ 2nd graph
Profiler.log(log, from + " - 2nd graph - START", updateGUIStart);
if (Config.logOverview)
Profiler.log(log, from + " - 2nd graph - START", updateGUIStart);
final GraphData secondGraphData = new GraphData(iobGraph, IobCobCalculatorPlugin.getPlugin());
@ -1519,12 +1516,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// finally enforce drawing of graphs
graphData.performUpdate();
secondGraphData.performUpdate();
Profiler.log(log, from + " - onDataChanged", updateGUIStart);
if (Config.logOverview)
Profiler.log(log, from + " - onDataChanged", updateGUIStart);
});
}
}).start();
Profiler.log(log, from, updateGUIStart);
if (Config.logOverview)
Profiler.log(log, from, updateGUIStart);
}
//Notifications

View file

@ -7,6 +7,7 @@ import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
@ -24,7 +25,7 @@ import info.nightscout.utils.SP;
* Created by mike on 05.08.2016.
*/
public class OverviewPlugin extends PluginBase {
private static Logger log = LoggerFactory.getLogger(OverviewPlugin.class);
private static Logger log = LoggerFactory.getLogger(Constants.OVERVIEW);
private static OverviewPlugin overviewPlugin = new OverviewPlugin();

View file

@ -7,7 +7,6 @@ import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.androidaps.events.Event;
public class EventOverviewBolusProgress extends Event {
private static Logger log = LoggerFactory.getLogger(EventOverviewBolusProgress.class);
public String status = "";
public Treatment t = null;
public int percent = 0;

View file

@ -18,6 +18,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -50,7 +51,7 @@ import info.nightscout.utils.Round;
*/
public class GraphData {
private static Logger log = LoggerFactory.getLogger(GraphData.class);
private static Logger log = LoggerFactory.getLogger(Constants.OVERVIEW);
private GraphView graph;
public double maxY = Double.MIN_VALUE;
@ -74,7 +75,8 @@ public class GraphData {
List<DataPointWithLabelInterface> bgListArray = new ArrayList<>();
if (bgReadingsArray == null || bgReadingsArray.size() == 0) {
log.debug("No BG data.");
if (Config.logOverview)
log.debug("No BG data.");
return;
}

View file

@ -20,8 +20,6 @@ import info.nightscout.utils.SP;
*/
public class Notification {
private static Logger log = LoggerFactory.getLogger(Notification.class);
public static final int URGENT = 0;
public static final int NORMAL = 1;
public static final int LOW = 2;

View file

@ -15,6 +15,8 @@ import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastAckAlarm;
@ -24,7 +26,7 @@ import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP;
public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter<NotificationRecyclerViewAdapter.NotificationsViewHolder> {
private static Logger log = LoggerFactory.getLogger(NotificationRecyclerViewAdapter.class);
private static Logger log = LoggerFactory.getLogger(Constants.NOTIFICATION);
private List<Notification> notificationsList;
@ -96,11 +98,13 @@ public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter<Notifi
BroadcastAckAlarm.handleClearAlarm(notification.nsAlarm, MainApp.instance().getApplicationContext(), 60 * 60 * 1000L);
}
// Adding current time to snooze if we got staleData
log.debug("Notification text is: " + notification.text);
if (Config.logNotification)
log.debug("Notification text is: " + notification.text);
if (notification.text.equals(MainApp.gs(R.string.nsalarm_staledata))) {
NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore;
long msToSnooze = SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L;
log.debug("snooze nsalarm_staledatavalue in minutes is " + SP.getInt("nsalarm_staledatavalue", 15) + "\n in ms is: " + msToSnooze + " currentTimeMillis is: " + System.currentTimeMillis());
if (Config.logNotification)
log.debug("snooze nsalarm_staledatavalue in minutes is " + SP.getInt("nsalarm_staledatavalue", 15) + "\n in ms is: " + msToSnooze + " currentTimeMillis is: " + System.currentTimeMillis());
nstore.snoozeTo(System.currentTimeMillis() + (SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L));
}
if (notification instanceof NotificationWithAction) {

View file

@ -22,6 +22,7 @@ import java.util.Comparator;
import java.util.List;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.AlarmSoundService;
@ -33,11 +34,10 @@ import info.nightscout.utils.SP;
public class NotificationStore {
public static final String CHANNEL_ID = "AndroidAPS-Overview";
private static final String CHANNEL_ID = "AndroidAPS-Overview";
private static Logger log = LoggerFactory.getLogger(NotificationStore.class);
public List<Notification> store = new ArrayList<Notification>();
public long snoozedUntil = 0L;
private static Logger log = LoggerFactory.getLogger(Constants.NOTIFICATION);
public List<Notification> store = new ArrayList<>();
private boolean usesChannels;
public NotificationStore() {
@ -52,7 +52,8 @@ public class NotificationStore {
}
public synchronized boolean add(Notification n) {
log.info("Notification received: " + n.text);
if (Config.logNotification)
log.debug("Notification received: " + n.text);
for (Notification storeNotification : store) {
if (storeNotification.id == n.id) {
storeNotification.date = n.date;
@ -107,7 +108,8 @@ public class NotificationStore {
}
public void snoozeTo(long timeToSnooze) {
log.debug("Snoozing alarm until: " + timeToSnooze);
if (Config.logNotification)
log.debug("Snoozing alarm until: " + timeToSnooze);
SP.putLong("snoozedTo", timeToSnooze);
}
@ -116,7 +118,8 @@ public class NotificationStore {
Notification notification = new Notification(Notification.NSALARM, MainApp.gs(R.string.nsalarm_staledata), Notification.URGENT);
SP.putLong("snoozedTo", System.currentTimeMillis());
add(notification);
log.debug("Snoozed to current time and added back notification!");
if (Config.logNotification)
log.debug("Snoozed to current time and added back notification!");
}
}
@ -125,7 +128,7 @@ public class NotificationStore {
NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.blueowl);
int smallIcon = R.drawable.ic_notification;
if (Config.NSCLIENT || Config.G5UPLOADER){
if (Config.NSCLIENT || Config.G5UPLOADER) {
largeIcon = BitmapFactory.decodeResource(MainApp.instance().getResources(), R.mipmap.yellowowl);
smallIcon = R.drawable.nsclient_smallicon;
}