DATA logging & refactor
This commit is contained in:
parent
b8a41e5f5b
commit
a7efa317be
15 changed files with 222 additions and 160 deletions
|
@ -40,6 +40,10 @@ public class Config {
|
|||
public static final boolean logOverview = true;
|
||||
public static final boolean logNotification = true;
|
||||
public static final boolean logAlarm = false;
|
||||
public static final boolean logDataService = true;
|
||||
public static final boolean logDataNS = true;
|
||||
public static final boolean logDataFood = true;
|
||||
public static final boolean logDataTreatments = true;
|
||||
|
||||
// DanaR specific
|
||||
public static final boolean logDanaBTComm = true;
|
||||
|
|
|
@ -76,4 +76,8 @@ public class Constants {
|
|||
public static final String OVERVIEW = "OVERVIEW";
|
||||
public static final String NOTIFICATION = "NOTIFICATION";
|
||||
public static final String ALARM = "ALARM";
|
||||
public static final String DATASERVICE = "DATASERVICE";
|
||||
public static final String DATANS = "DATANS";
|
||||
public static final String DATAFOOD = "DATAFOOD";
|
||||
public static final String DATATREATMENTS = "DATATREATMENTS";
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ import info.nightscout.androidaps.events.EventFeatureRunning;
|
|||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.Food.FoodPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.setupwizard.SetupWizardActivity;
|
||||
import info.nightscout.androidaps.tabs.TabPageAdapter;
|
||||
|
@ -400,7 +400,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
builder.setIcon(R.mipmap.blueowl);
|
||||
String message = "Build: " + BuildConfig.BUILDVERSION + "\n";
|
||||
message += "Flavor: " + BuildConfig.FLAVOR + BuildConfig.BUILD_TYPE + "\n";
|
||||
message += MainApp.gs(R.string.configbuilder_nightscoutversion_label) + " " + ConfigBuilderPlugin.nightscoutVersionName;
|
||||
message += MainApp.gs(R.string.configbuilder_nightscoutversion_label) + " " + NSSettingsStatus.getInstance().nightscoutVersionName;
|
||||
if (MainApp.engineeringMode)
|
||||
message += "\n" + MainApp.gs(R.string.engineering_mode_enabled);
|
||||
message += MainApp.gs(R.string.about_link_urls);
|
||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.Services;
|
|||
|
||||
import android.app.IntentService;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Telephony;
|
||||
|
||||
|
@ -13,18 +12,15 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.CareportalEvent;
|
||||
import info.nightscout.androidaps.events.EventNsFood;
|
||||
import info.nightscout.androidaps.events.EventNsTreatment;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
||||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||
|
@ -43,7 +39,7 @@ import info.nightscout.utils.SP;
|
|||
|
||||
|
||||
public class DataService extends IntentService {
|
||||
private static Logger log = LoggerFactory.getLogger(DataService.class);
|
||||
private Logger log = LoggerFactory.getLogger(Constants.DATASERVICE);
|
||||
|
||||
public DataService() {
|
||||
super("DataService");
|
||||
|
@ -52,8 +48,10 @@ public class DataService extends IntentService {
|
|||
|
||||
@Override
|
||||
protected void onHandleIntent(final Intent intent) {
|
||||
if (Config.logFunctionCalls)
|
||||
if (Config.logDataService) {
|
||||
log.debug("onHandleIntent " + intent);
|
||||
log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras()));
|
||||
}
|
||||
|
||||
boolean acceptNSData = !SP.getBoolean(R.string.key_ns_upload_only, false);
|
||||
Bundle bundles = intent.getExtras();
|
||||
|
@ -78,15 +76,23 @@ public class DataService extends IntentService {
|
|||
} else if (Intents.ACTION_NEW_PROFILE.equals(action)) {
|
||||
// always handle Profile if NSProfile is enabled without looking at nsUploadOnly
|
||||
NSProfilePlugin.getPlugin().handleNewData(intent);
|
||||
} else if (Intents.ACTION_NEW_DEVICESTATUS.equals(action)) {
|
||||
NSDeviceStatus.getInstance().handleNewData(intent);
|
||||
} else if (Intents.ACTION_NEW_STATUS.equals(action)) {
|
||||
NSSettingsStatus.getInstance().handleNewData(intent);
|
||||
} else if (Intents.ACTION_NEW_FOOD.equals(action)) {
|
||||
EventNsFood evt = new EventNsFood(EventNsFood.ADD, bundles);
|
||||
MainApp.bus().post(evt);
|
||||
} else if (Intents.ACTION_CHANGED_FOOD.equals(action)) {
|
||||
EventNsFood evt = new EventNsFood(EventNsFood.UPDATE, bundles);
|
||||
MainApp.bus().post(evt);
|
||||
} else if (Intents.ACTION_REMOVED_FOOD.equals(action)) {
|
||||
EventNsFood evt = new EventNsFood(EventNsFood.REMOVE, bundles);
|
||||
MainApp.bus().post(evt);
|
||||
} else if (acceptNSData &&
|
||||
(Intents.ACTION_NEW_TREATMENT.equals(action) ||
|
||||
Intents.ACTION_CHANGED_TREATMENT.equals(action) ||
|
||||
Intents.ACTION_REMOVED_TREATMENT.equals(action) ||
|
||||
Intents.ACTION_NEW_STATUS.equals(action) ||
|
||||
Intents.ACTION_NEW_DEVICESTATUS.equals(action) ||
|
||||
Intents.ACTION_NEW_FOOD.equals(action) ||
|
||||
Intents.ACTION_CHANGED_FOOD.equals(action) ||
|
||||
Intents.ACTION_REMOVED_FOOD.equals(action) ||
|
||||
Intents.ACTION_NEW_CAL.equals(action) ||
|
||||
Intents.ACTION_NEW_MBG.equals(action))
|
||||
) {
|
||||
|
@ -95,7 +101,7 @@ public class DataService extends IntentService {
|
|||
SmsCommunicatorPlugin.getPlugin().handleNewData(intent);
|
||||
}
|
||||
|
||||
if (Config.logFunctionCalls)
|
||||
if (Config.logDataService)
|
||||
log.debug("onHandleIntent exit " + intent);
|
||||
DataReceiver.completeWakefulIntent(intent);
|
||||
}
|
||||
|
@ -122,79 +128,6 @@ public class DataService extends IntentService {
|
|||
log.debug("Got intent: " + intent.getAction());
|
||||
|
||||
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_STATUS)) {
|
||||
if (bundles.containsKey("nsclientversioncode")) {
|
||||
ConfigBuilderPlugin.nightscoutVersionCode = bundles.getInt("nightscoutversioncode"); // for ver 1.2.3 contains 10203
|
||||
ConfigBuilderPlugin.nightscoutVersionName = bundles.getString("nightscoutversionname");
|
||||
ConfigBuilderPlugin.nsClientVersionCode = bundles.getInt("nsclientversioncode"); // for ver 1.17 contains 117
|
||||
ConfigBuilderPlugin.nsClientVersionName = bundles.getString("nsclientversionname");
|
||||
log.debug("Got versions: NSClient: " + ConfigBuilderPlugin.nsClientVersionName + " Nightscout: " + ConfigBuilderPlugin.nightscoutVersionName);
|
||||
try {
|
||||
if (ConfigBuilderPlugin.nsClientVersionCode < MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode) {
|
||||
Notification notification = new Notification(Notification.OLD_NSCLIENT, MainApp.gs(R.string.unsupportedclientver), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.OLD_NSCLIENT));
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
if (ConfigBuilderPlugin.nightscoutVersionCode < Config.SUPPORTEDNSVERSION) {
|
||||
Notification notification = new Notification(Notification.OLD_NS, MainApp.gs(R.string.unsupportednsversion), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.OLD_NS));
|
||||
}
|
||||
} else {
|
||||
Notification notification = new Notification(Notification.OLD_NSCLIENT, MainApp.gs(R.string.unsupportedclientver), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
}
|
||||
if (bundles.containsKey("status")) {
|
||||
try {
|
||||
JSONObject statusJson = new JSONObject(bundles.getString("status"));
|
||||
NSSettingsStatus.getInstance().setData(statusJson);
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Received status: " + statusJson.toString());
|
||||
Double targetHigh = NSSettingsStatus.getInstance().getThreshold("bgTargetTop");
|
||||
Double targetlow = NSSettingsStatus.getInstance().getThreshold("bgTargetBottom");
|
||||
if (targetHigh != null)
|
||||
OverviewPlugin.bgTargetHigh = targetHigh;
|
||||
if (targetlow != null)
|
||||
OverviewPlugin.bgTargetLow = targetlow;
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_DEVICESTATUS)) {
|
||||
try {
|
||||
if (bundles.containsKey("devicestatus")) {
|
||||
JSONObject devicestatusJson = new JSONObject(bundles.getString("devicestatus"));
|
||||
NSDeviceStatus.getInstance().setData(devicestatusJson);
|
||||
if (devicestatusJson.has("pump")) {
|
||||
// Objectives 0
|
||||
ObjectivesPlugin.pumpStatusIsAvailableInNS = true;
|
||||
ObjectivesPlugin.saveProgress();
|
||||
}
|
||||
}
|
||||
if (bundles.containsKey("devicestatuses")) {
|
||||
String devicestatusesstring = bundles.getString("devicestatuses");
|
||||
JSONArray jsonArray = new JSONArray(devicestatusesstring);
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject devicestatusJson = jsonArray.getJSONObject(i);
|
||||
NSDeviceStatus.getInstance().setData(devicestatusJson);
|
||||
if (devicestatusJson.has("pump")) {
|
||||
// Objectives 0
|
||||
ObjectivesPlugin.pumpStatusIsAvailableInNS = true;
|
||||
ObjectivesPlugin.saveProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT) || intent.getAction().equals(Intents.ACTION_CHANGED_TREATMENT)) {
|
||||
try {
|
||||
if (bundles.containsKey("treatment")) {
|
||||
|
@ -219,7 +152,7 @@ public class DataService extends IntentService {
|
|||
if (bundles.containsKey("treatment")) {
|
||||
String trstring = bundles.getString("treatment");
|
||||
JSONObject json = new JSONObject(trstring);
|
||||
handleTreatmentFromNS(json);
|
||||
handleRemovedTreatmentFromNS(json);
|
||||
}
|
||||
|
||||
if (bundles.containsKey("treatments")) {
|
||||
|
@ -227,7 +160,7 @@ public class DataService extends IntentService {
|
|||
JSONArray jsonArray = new JSONArray(trstring);
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject json = jsonArray.getJSONObject(i);
|
||||
handleTreatmentFromNS(json);
|
||||
handleRemovedTreatmentFromNS(json);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
@ -255,21 +188,9 @@ public class DataService extends IntentService {
|
|||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_FOOD)
|
||||
|| intent.getAction().equals(Intents.ACTION_CHANGED_FOOD)) {
|
||||
int mode = Intents.ACTION_NEW_FOOD.equals(intent.getAction()) ? EventNsFood.ADD : EventNsFood.UPDATE;
|
||||
EventNsFood evt = new EventNsFood(mode, bundles);
|
||||
MainApp.bus().post(evt);
|
||||
}
|
||||
|
||||
if (intent.getAction().equals(Intents.ACTION_REMOVED_FOOD)) {
|
||||
EventNsFood evt = new EventNsFood(EventNsFood.REMOVE, bundles);
|
||||
MainApp.bus().post(evt);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleTreatmentFromNS(JSONObject json) {
|
||||
private void handleRemovedTreatmentFromNS(JSONObject json) {
|
||||
// new DB model
|
||||
EventNsTreatment evtTreatment = new EventNsTreatment(EventNsTreatment.REMOVE, json);
|
||||
MainApp.bus().post(evtTreatment);
|
||||
|
|
|
@ -70,15 +70,9 @@ public class ConfigBuilderPlugin extends PluginBase {
|
|||
private static ProfileInterface activeProfile;
|
||||
private static TreatmentsInterface activeTreatments;
|
||||
private static APSInterface activeAPS;
|
||||
private static LoopPlugin activeLoop;
|
||||
private static InsulinInterface activeInsulin;
|
||||
private static SensitivityInterface activeSensitivity;
|
||||
|
||||
static public String nightscoutVersionName = "";
|
||||
static public Integer nightscoutVersionCode = 0;
|
||||
static public String nsClientVersionName = "";
|
||||
static public Integer nsClientVersionCode = 0;
|
||||
|
||||
private static ArrayList<PluginBase> pluginList;
|
||||
|
||||
private static CommandQueue commandQueue = new CommandQueue();
|
||||
|
@ -337,9 +331,6 @@ public class ConfigBuilderPlugin extends PluginBase {
|
|||
}
|
||||
this.setFragmentVisiblities(((PluginBase) activePump).getName(), pluginsInCategory, PluginType.PUMP);
|
||||
|
||||
// PluginType.LOOP
|
||||
activeLoop = this.determineActivePlugin(PluginType.LOOP);
|
||||
|
||||
// PluginType.TREATMENT
|
||||
activeTreatments = this.determineActivePlugin(PluginType.TREATMENT);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.db.ICallback;
|
||||
|
@ -39,7 +41,7 @@ import info.nightscout.androidaps.events.EventNsFood;
|
|||
*/
|
||||
|
||||
public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||
private static Logger log = LoggerFactory.getLogger(FoodService.class);
|
||||
private Logger log = LoggerFactory.getLogger(Constants.DATAFOOD);
|
||||
|
||||
private static final ScheduledExecutorService foodEventWorker = Executors.newSingleThreadScheduledExecutor();
|
||||
private static ScheduledFuture<?> scheduledFoodEventPost = null;
|
||||
|
@ -110,7 +112,8 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
public void onCreate() {
|
||||
super.onCreate();
|
||||
try {
|
||||
log.info("onCreate");
|
||||
if (Config.logDataFood)
|
||||
log.info("onCreate");
|
||||
TableUtils.createTableIfNotExists(this.getConnectionSource(), Food.class);
|
||||
} catch (SQLException e) {
|
||||
log.error("Can't create database", e);
|
||||
|
@ -122,7 +125,8 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
if (oldVersion == 7 && newVersion == 8) {
|
||||
log.debug("Upgrading database from v7 to v8");
|
||||
} else {
|
||||
log.info("onUpgrade");
|
||||
if (Config.logDataFood)
|
||||
log.info("onUpgrade");
|
||||
// this.resetFood();
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +165,8 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
|
||||
class PostRunnable implements Runnable {
|
||||
public void run() {
|
||||
log.debug("Firing EventFoodChange");
|
||||
if (Config.logDataFood)
|
||||
log.debug("Firing EventFoodChange");
|
||||
MainApp.bus().post(event);
|
||||
callback.setPost(null);
|
||||
}
|
||||
|
@ -271,7 +276,8 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
public void deleteByNSId(String _id) throws SQLException {
|
||||
Food stored = this.findByNSId(_id);
|
||||
if (stored != null) {
|
||||
log.debug("FOOD: Removing Food record from database: " + stored.toString());
|
||||
if (Config.logDataFood)
|
||||
log.debug("Removing Food record from database: " + stored.toString());
|
||||
this.delete(stored);
|
||||
}
|
||||
}
|
||||
|
@ -324,7 +330,8 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
public void createOrUpdate(Food food) {
|
||||
try {
|
||||
this.getDao().createOrUpdate(food);
|
||||
log.debug("FOOD: Created or Updated: " + food.toString());
|
||||
if (Config.logDataFood)
|
||||
log.debug("Created or Updated: " + food.toString());
|
||||
} catch (SQLException e) {
|
||||
log.error("Unable to createOrUpdate Food", e);
|
||||
}
|
||||
|
@ -334,7 +341,8 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
public void create(Food food) {
|
||||
try {
|
||||
this.getDao().create(food);
|
||||
log.debug("FOOD: New record: " + food.toString());
|
||||
if (Config.logDataFood)
|
||||
log.debug("New record: " + food.toString());
|
||||
} catch (SQLException e) {
|
||||
log.error("Unable to create Food", e);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package info.nightscout.androidaps.plugins.NSClientInternal.data;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -12,8 +15,12 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
import info.nightscout.utils.BundleLogger;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.Round;
|
||||
import info.nightscout.utils.SP;
|
||||
|
@ -73,7 +80,7 @@ import info.nightscout.utils.SP;
|
|||
}
|
||||
*/
|
||||
public class NSDeviceStatus {
|
||||
private static Logger log = LoggerFactory.getLogger(NSDeviceStatus.class);
|
||||
private Logger log = LoggerFactory.getLogger(Constants.DATANS);
|
||||
|
||||
private static NSDeviceStatus instance = null;
|
||||
|
||||
|
@ -88,6 +95,41 @@ public class NSDeviceStatus {
|
|||
public NSDeviceStatus() {
|
||||
}
|
||||
|
||||
public void handleNewData(Intent intent) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
if (Config.logDataNS)
|
||||
log.debug("Got NS devicestatus: " + BundleLogger.log(bundle));
|
||||
|
||||
try {
|
||||
if (bundle.containsKey("devicestatus")) {
|
||||
JSONObject devicestatusJson = new JSONObject(bundle.getString("devicestatus"));
|
||||
setData(devicestatusJson);
|
||||
if (devicestatusJson.has("pump")) {
|
||||
// Objectives 0
|
||||
ObjectivesPlugin.pumpStatusIsAvailableInNS = true;
|
||||
ObjectivesPlugin.saveProgress();
|
||||
}
|
||||
}
|
||||
if (bundle.containsKey("devicestatuses")) {
|
||||
String devicestatusesstring = bundle.getString("devicestatuses");
|
||||
JSONArray jsonArray = new JSONArray(devicestatusesstring);
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject devicestatusJson = jsonArray.getJSONObject(i);
|
||||
setData(devicestatusJson);
|
||||
if (devicestatusJson.has("pump")) {
|
||||
// Objectives 0
|
||||
ObjectivesPlugin.pumpStatusIsAvailableInNS = true;
|
||||
ObjectivesPlugin.saveProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public NSDeviceStatus setData(JSONObject obj) {
|
||||
this.data = obj;
|
||||
updatePumpData(obj);
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package info.nightscout.androidaps.plugins.NSClientInternal.data;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
@ -10,6 +13,16 @@ import org.slf4j.LoggerFactory;
|
|||
import java.util.Date;
|
||||
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.Overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||
import info.nightscout.utils.BundleLogger;
|
||||
|
||||
/*
|
||||
{
|
||||
"status": "ok",
|
||||
|
@ -101,7 +114,7 @@ import java.util.Objects;
|
|||
}
|
||||
*/
|
||||
public class NSSettingsStatus {
|
||||
private static Logger log = LoggerFactory.getLogger(NSSettingsStatus.class);
|
||||
private Logger log = LoggerFactory.getLogger(Constants.DATANS);
|
||||
|
||||
private static NSSettingsStatus instance = null;
|
||||
|
||||
|
@ -111,6 +124,8 @@ public class NSSettingsStatus {
|
|||
return instance;
|
||||
}
|
||||
|
||||
public String nightscoutVersionName = "";
|
||||
|
||||
private JSONObject data = null;
|
||||
|
||||
public NSSettingsStatus() {
|
||||
|
@ -121,6 +136,59 @@ public class NSSettingsStatus {
|
|||
return this;
|
||||
}
|
||||
|
||||
public void handleNewData(Intent intent) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
if (Config.logDataNS)
|
||||
log.debug("Got NS status: " + BundleLogger.log(bundle));
|
||||
|
||||
if (bundle.containsKey("nsclientversioncode")) {
|
||||
|
||||
Integer nightscoutVersionCode = bundle.getInt("nightscoutversioncode");
|
||||
nightscoutVersionName = bundle.getString("nightscoutversionname");
|
||||
Integer nsClientVersionCode = bundle.getInt("nsclientversioncode");
|
||||
String nsClientVersionName = bundle.getString("nsclientversionname");
|
||||
if (Config.logDataNS)
|
||||
log.debug("Got versions: NSClient: " + nsClientVersionName + " Nightscout: " + nightscoutVersionName);
|
||||
try {
|
||||
if (nsClientVersionCode < MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode) {
|
||||
Notification notification = new Notification(Notification.OLD_NSCLIENT, MainApp.gs(R.string.unsupportedclientver), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.OLD_NSCLIENT));
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
if (nightscoutVersionCode < Config.SUPPORTEDNSVERSION) {
|
||||
Notification notification = new Notification(Notification.OLD_NS, MainApp.gs(R.string.unsupportednsversion), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.OLD_NS));
|
||||
}
|
||||
} else {
|
||||
Notification notification = new Notification(Notification.OLD_NSCLIENT, MainApp.gs(R.string.unsupportedclientver), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
}
|
||||
if (bundle.containsKey("status")) {
|
||||
try {
|
||||
JSONObject statusJson = new JSONObject(bundle.getString("status"));
|
||||
setData(statusJson);
|
||||
if (Config.logDataNS)
|
||||
log.debug("Received status: " + statusJson.toString());
|
||||
Double targetHigh = getThreshold("bgTargetTop");
|
||||
Double targetlow = getThreshold("bgTargetBottom");
|
||||
if (targetHigh != null)
|
||||
OverviewPlugin.bgTargetHigh = targetHigh;
|
||||
if (targetlow != null)
|
||||
OverviewPlugin.bgTargetLow = targetlow;
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return getStringOrNull("name");
|
||||
}
|
||||
|
@ -134,7 +202,7 @@ public class NSSettingsStatus {
|
|||
}
|
||||
|
||||
public Date getServerTime() {
|
||||
return getDateOrNull("versionNum");
|
||||
return getDateOrNull("serverTime");
|
||||
}
|
||||
|
||||
public boolean getApiEnabled() {
|
||||
|
@ -202,13 +270,11 @@ public class NSSettingsStatus {
|
|||
if (settingsO.has("thresholds")) {
|
||||
JSONObject tObject = settingsO.getJSONObject("thresholds");
|
||||
if (tObject.has(what)) {
|
||||
Double result = tObject.getDouble(what);
|
||||
return result;
|
||||
return tObject.getDouble(what);
|
||||
}
|
||||
}
|
||||
if (settingsO.has("alarmTimeagoWarnMins") && Objects.equals(what, "alarmTimeagoWarnMins")) {
|
||||
Double result = settingsO.getDouble(what);
|
||||
return result;
|
||||
return settingsO.getDouble(what);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
|
|
@ -29,8 +29,6 @@ import info.nightscout.utils.JsonHelper;
|
|||
|
||||
@DatabaseTable(tableName = Treatment.TABLE_TREATMENTS)
|
||||
public class Treatment implements DataPointWithLabelInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(Treatment.class);
|
||||
|
||||
public static final String TABLE_TREATMENTS = "Treatments";
|
||||
|
||||
@DatabaseField(id = true)
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.db.ICallback;
|
||||
|
@ -46,7 +48,7 @@ import info.nightscout.utils.JsonHelper;
|
|||
*/
|
||||
|
||||
public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||
private static Logger log = LoggerFactory.getLogger(TreatmentService.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.DATATREATMENTS);
|
||||
|
||||
private static final ScheduledExecutorService treatmentEventWorker = Executors.newSingleThreadScheduledExecutor();
|
||||
private static ScheduledFuture<?> scheduledTreatmentEventPost = null;
|
||||
|
@ -102,7 +104,8 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
public void onCreate() {
|
||||
super.onCreate();
|
||||
try {
|
||||
log.info("onCreate");
|
||||
if (Config.logDataTreatments)
|
||||
log.info("onCreate");
|
||||
TableUtils.createTableIfNotExists(this.getConnectionSource(), Treatment.class);
|
||||
} catch (SQLException e) {
|
||||
log.error("Can't create database", e);
|
||||
|
@ -121,7 +124,8 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
log.info("onUpgrade");
|
||||
if (Config.logDataTreatments)
|
||||
log.info("onUpgrade");
|
||||
// this.resetFood();
|
||||
}
|
||||
}
|
||||
|
@ -161,10 +165,14 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
|
||||
class PostRunnable implements Runnable {
|
||||
public void run() {
|
||||
log.debug("Firing EventFoodChange");
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("Firing EventReloadTreatmentData");
|
||||
MainApp.bus().post(event);
|
||||
if (DatabaseHelper.earliestDataChange != null)
|
||||
if (DatabaseHelper.earliestDataChange != null) {
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("Firing EventNewHistoryData");
|
||||
MainApp.bus().post(new EventNewHistoryData(DatabaseHelper.earliestDataChange));
|
||||
}
|
||||
DatabaseHelper.earliestDataChange = null;
|
||||
callback.setPost(null);
|
||||
}
|
||||
|
@ -252,13 +260,14 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
if (existingTreatment != null) {
|
||||
boolean equalRePumpHistory = existingTreatment.equalsRePumpHistory(treatment);
|
||||
boolean sameSource = existingTreatment.source == treatment.source;
|
||||
if(!equalRePumpHistory) {
|
||||
if (!equalRePumpHistory) {
|
||||
// another treatment exists. Update it with the treatment coming from the pump
|
||||
log.debug("TREATMENT: Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
|
||||
long oldDate = existingTreatment.date;
|
||||
|
||||
//preserve carbs
|
||||
if(existingTreatment.isValid && existingTreatment.carbs > 0 && treatment.carbs == 0){
|
||||
if (existingTreatment.isValid && existingTreatment.carbs > 0 && treatment.carbs == 0) {
|
||||
treatment.carbs = existingTreatment.carbs;
|
||||
}
|
||||
|
||||
|
@ -278,10 +287,11 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
boolean equalRePumpHistory = existingTreatment.equalsRePumpHistory(treatment);
|
||||
boolean sameSource = existingTreatment.source == treatment.source;
|
||||
long oldDate = existingTreatment.date;
|
||||
log.debug("TREATMENT: Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
|
||||
|
||||
//preserve carbs
|
||||
if(existingTreatment.isValid && existingTreatment.carbs > 0 && treatment.carbs == 0){
|
||||
if (existingTreatment.isValid && existingTreatment.carbs > 0 && treatment.carbs == 0) {
|
||||
treatment.carbs = existingTreatment.carbs;
|
||||
}
|
||||
|
||||
|
@ -294,7 +304,8 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
return new UpdateReturn(equalRePumpHistory || sameSource, false);
|
||||
}
|
||||
getDao().create(treatment);
|
||||
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
DatabaseHelper.updateEarliestDataChange(treatment.date);
|
||||
scheduleTreatmentChange(treatment);
|
||||
return new UpdateReturn(true, true);
|
||||
|
@ -308,7 +319,8 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
getDao().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(treatment);
|
||||
getDao().create(old);
|
||||
log.debug("TREATMENT: Updating record by date from: " + Source.getString(treatment.source) + " " + old.toString());
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("Updating record by date from: " + Source.getString(treatment.source) + " " + old.toString());
|
||||
if (historyChange) {
|
||||
DatabaseHelper.updateEarliestDataChange(oldDate);
|
||||
DatabaseHelper.updateEarliestDataChange(old.date);
|
||||
|
@ -328,7 +340,8 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
getDao().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(treatment);
|
||||
getDao().create(old);
|
||||
log.debug("TREATMENT: Updating record by _id from: " + Source.getString(treatment.source) + " " + old.toString());
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("Updating record by _id from: " + Source.getString(treatment.source) + " " + old.toString());
|
||||
if (historyChange) {
|
||||
DatabaseHelper.updateEarliestDataChange(oldDate);
|
||||
DatabaseHelper.updateEarliestDataChange(old.date);
|
||||
|
@ -339,14 +352,16 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
}
|
||||
}
|
||||
getDao().create(treatment);
|
||||
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
DatabaseHelper.updateEarliestDataChange(treatment.date);
|
||||
scheduleTreatmentChange(treatment);
|
||||
return new UpdateReturn(true, true);
|
||||
}
|
||||
if (treatment.source == Source.USER) {
|
||||
getDao().create(treatment);
|
||||
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
DatabaseHelper.updateEarliestDataChange(treatment.date);
|
||||
scheduleTreatmentChange(treatment);
|
||||
return new UpdateReturn(true, true);
|
||||
|
@ -357,8 +372,10 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
return new UpdateReturn(false, false);
|
||||
}
|
||||
|
||||
/** Returns the record for the given id, null if none, throws RuntimeException
|
||||
* if multiple records with the same pump id exist. */
|
||||
/**
|
||||
* Returns the record for the given id, null if none, throws RuntimeException
|
||||
* if multiple records with the same pump id exist.
|
||||
*/
|
||||
@Nullable
|
||||
public Treatment getPumpRecordById(long pumpId) {
|
||||
try {
|
||||
|
@ -368,9 +385,12 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
PreparedQuery<Treatment> preparedQuery = queryBuilder.prepare();
|
||||
List<Treatment> result = getDao().query(preparedQuery);
|
||||
switch (result.size()) {
|
||||
case 0: return null;
|
||||
case 1: return result.get(0);
|
||||
default: throw new RuntimeException("Multiple records with the same pump id found: " + result.toString());
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return result.get(0);
|
||||
default:
|
||||
throw new RuntimeException("Multiple records with the same pump id found: " + result.toString());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@ -393,7 +413,8 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
private void deleteByNSId(String _id) {
|
||||
Treatment stored = findByNSId(_id);
|
||||
if (stored != null) {
|
||||
log.debug("TREATMENT: Removing Treatment record from database: " + stored.toString());
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("Removing Treatment record from database: " + stored.toString());
|
||||
delete(stored);
|
||||
DatabaseHelper.updateEarliestDataChange(stored.date);
|
||||
scheduleTreatmentChange(null);
|
||||
|
@ -480,10 +501,11 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
}
|
||||
|
||||
public class UpdateReturn {
|
||||
public UpdateReturn(boolean success, boolean newRecord){
|
||||
public UpdateReturn(boolean success, boolean newRecord) {
|
||||
this.success = success;
|
||||
this.newRecord = newRecord;
|
||||
}
|
||||
|
||||
boolean newRecord;
|
||||
boolean success;
|
||||
}
|
||||
|
|
|
@ -27,8 +27,6 @@ import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTempora
|
|||
import info.nightscout.utils.FabricPrivacy;
|
||||
|
||||
public class TreatmentsFragment extends SubscriberFragment implements View.OnClickListener {
|
||||
private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class);
|
||||
|
||||
TextView treatmentsTab;
|
||||
TextView extendedBolusesTab;
|
||||
TextView tempBasalsTab;
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
@ -55,7 +56,7 @@ import info.nightscout.utils.T;
|
|||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(TreatmentsPlugin.class);
|
||||
private Logger log = LoggerFactory.getLogger(Constants.DATATREATMENTS);
|
||||
|
||||
private static TreatmentsPlugin treatmentsPlugin;
|
||||
|
||||
|
@ -109,6 +110,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
}
|
||||
|
||||
private void initializeTreatmentData() {
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("initializeTreatmentData");
|
||||
double dia = Constants.defaultDIA;
|
||||
if (MainApp.getConfigBuilder() != null && MainApp.getConfigBuilder().getProfile() != null)
|
||||
dia = MainApp.getConfigBuilder().getProfile().getDia();
|
||||
|
@ -120,6 +123,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
}
|
||||
|
||||
private void initializeTempBasalData() {
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("initializeTempBasalData");
|
||||
double dia = Constants.defaultDIA;
|
||||
if (MainApp.getConfigBuilder() != null && MainApp.getConfigBuilder().getProfile() != null)
|
||||
dia = MainApp.getConfigBuilder().getProfile().getDia();
|
||||
|
@ -132,6 +137,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
}
|
||||
|
||||
private void initializeExtendedBolusData() {
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("initializeExtendedBolusData");
|
||||
double dia = Constants.defaultDIA;
|
||||
if (MainApp.getConfigBuilder() != null && MainApp.getConfigBuilder().getProfile() != null)
|
||||
dia = MainApp.getConfigBuilder().getProfile().getDia();
|
||||
|
@ -144,6 +151,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
}
|
||||
|
||||
private void initializeTempTargetData() {
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("initializeTempTargetData");
|
||||
synchronized (tempTargets) {
|
||||
long fromMills = System.currentTimeMillis() - 60 * 60 * 1000L * 24;
|
||||
tempTargets.reset().add(MainApp.getDbHelper().getTemptargetsDataFromTime(fromMills, false));
|
||||
|
@ -151,6 +160,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
}
|
||||
|
||||
private void initializeProfileSwitchData() {
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("initializeProfileSwitchData");
|
||||
synchronized (profiles) {
|
||||
profiles.reset().add(MainApp.getDbHelper().getProfileSwitchData(false));
|
||||
}
|
||||
|
@ -294,6 +305,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
last = t.date;
|
||||
}
|
||||
}
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("Last bolus time: " + new Date(last).toLocaleString());
|
||||
return last;
|
||||
}
|
||||
|
@ -322,6 +334,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventReloadTreatmentData ev) {
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("EventReloadTreatmentData");
|
||||
initializeTreatmentData();
|
||||
initializeExtendedBolusData();
|
||||
|
@ -332,6 +345,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
@Subscribe
|
||||
@SuppressWarnings("unused")
|
||||
public void onStatusEvent(final EventReloadTempBasalData ev) {
|
||||
if (Config.logDataTreatments)
|
||||
log.debug("EventReloadTempBasalData");
|
||||
initializeTempBasalData();
|
||||
updateTotalIOBTempBasals();
|
||||
|
|
|
@ -31,8 +31,6 @@ public class ProfileViewerDialog extends DialogFragment {
|
|||
|
||||
private long time;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ProfileViewDialog.class);
|
||||
|
||||
@BindView(R.id.profileview_noprofile)
|
||||
TextView noProfile;
|
||||
@BindView(R.id.profileview_invalidprofile)
|
||||
|
|
|
@ -46,8 +46,6 @@ import info.nightscout.utils.SP;
|
|||
import static info.nightscout.utils.DateUtil.now;
|
||||
|
||||
public class TreatmentsBolusFragment extends SubscriberFragment implements View.OnClickListener {
|
||||
private static Logger log = LoggerFactory.getLogger(TreatmentsBolusFragment.class);
|
||||
|
||||
RecyclerView recyclerView;
|
||||
LinearLayoutManager llm;
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@ import info.nightscout.utils.NSUpload;
|
|||
|
||||
|
||||
public class TreatmentsExtendedBolusesFragment extends SubscriberFragment {
|
||||
private static Logger log = LoggerFactory.getLogger(TreatmentsExtendedBolusesFragment.class);
|
||||
|
||||
RecyclerView recyclerView;
|
||||
LinearLayoutManager llm;
|
||||
|
||||
|
|
Loading…
Reference in a new issue