Merge pull request #787 from jotomo/revert-770
Revert "Merge pull request #770 from jotomo/new-bg-processing"
This commit is contained in:
commit
9c71bacd7b
|
@ -192,7 +192,7 @@ public class DataService extends IntentService {
|
||||||
bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP);
|
bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP);
|
||||||
bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW);
|
bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW);
|
||||||
|
|
||||||
MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP", xDripEnabled);
|
MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNewDataFromGlimp(Intent intent) {
|
private void handleNewDataFromGlimp(Intent intent) {
|
||||||
|
@ -206,7 +206,7 @@ public class DataService extends IntentService {
|
||||||
bgReading.date = bundle.getLong("myTimestamp");
|
bgReading.date = bundle.getLong("myTimestamp");
|
||||||
bgReading.raw = 0;
|
bgReading.raw = 0;
|
||||||
|
|
||||||
MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP", glimpEnabled);
|
MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNewDataFromDexcomG5(Intent intent) {
|
private void handleNewDataFromDexcomG5(Intent intent) {
|
||||||
|
@ -229,7 +229,7 @@ public class DataService extends IntentService {
|
||||||
bgReading.direction = json.getString("m_trend");
|
bgReading.direction = json.getString("m_trend");
|
||||||
bgReading.date = json.getLong("m_time") * 1000L;
|
bgReading.date = json.getLong("m_time") * 1000L;
|
||||||
bgReading.raw = 0;
|
bgReading.raw = 0;
|
||||||
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5", dexcomG5Enabled);
|
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
|
||||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
||||||
NSUpload.uploadBg(bgReading);
|
NSUpload.uploadBg(bgReading);
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ public class DataService extends IntentService {
|
||||||
bgReading.date = json_object.getLong("date");
|
bgReading.date = json_object.getLong("date");
|
||||||
bgReading.raw = json_object.getDouble("sgv");
|
bgReading.raw = json_object.getDouble("sgv");
|
||||||
|
|
||||||
MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g", mm640gEnabled);
|
MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log.debug("Unknown entries type: " + type);
|
log.debug("Unknown entries type: " + type);
|
||||||
|
@ -425,7 +425,7 @@ public class DataService extends IntentService {
|
||||||
JSONObject sgvJson = new JSONObject(sgvstring);
|
JSONObject sgvJson = new JSONObject(sgvstring);
|
||||||
NSSgv nsSgv = new NSSgv(sgvJson);
|
NSSgv nsSgv = new NSSgv(sgvJson);
|
||||||
BgReading bgReading = new BgReading(nsSgv);
|
BgReading bgReading = new BgReading(nsSgv);
|
||||||
MainApp.getDbHelper().createIfNotExists(bgReading, "NS", nsClientEnabled);
|
MainApp.getDbHelper().createIfNotExists(bgReading, "NS");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bundles.containsKey("sgvs")) {
|
if (bundles.containsKey("sgvs")) {
|
||||||
|
@ -435,7 +435,7 @@ public class DataService extends IntentService {
|
||||||
JSONObject sgvJson = jsonArray.getJSONObject(i);
|
JSONObject sgvJson = jsonArray.getJSONObject(i);
|
||||||
NSSgv nsSgv = new NSSgv(sgvJson);
|
NSSgv nsSgv = new NSSgv(sgvJson);
|
||||||
BgReading bgReading = new BgReading(nsSgv);
|
BgReading bgReading = new BgReading(nsSgv);
|
||||||
MainApp.getDbHelper().createIfNotExists(bgReading, "NS", nsClientEnabled);
|
MainApp.getDbHelper().createIfNotExists(bgReading, "NS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.support.annotation.Nullable;
|
||||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
|
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
|
||||||
import com.j256.ormlite.dao.CloseableIterator;
|
import com.j256.ormlite.dao.CloseableIterator;
|
||||||
import com.j256.ormlite.dao.Dao;
|
import com.j256.ormlite.dao.Dao;
|
||||||
|
import com.j256.ormlite.dao.DaoManager;
|
||||||
import com.j256.ormlite.stmt.PreparedQuery;
|
import com.j256.ormlite.stmt.PreparedQuery;
|
||||||
import com.j256.ormlite.stmt.QueryBuilder;
|
import com.j256.ormlite.stmt.QueryBuilder;
|
||||||
import com.j256.ormlite.stmt.Where;
|
import com.j256.ormlite.stmt.Where;
|
||||||
|
@ -240,7 +241,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
VirtualPumpPlugin.setFakingStatus(true);
|
VirtualPumpPlugin.setFakingStatus(true);
|
||||||
scheduleBgChange(null, false, false); // trigger refresh
|
scheduleBgChange(null); // trigger refresh
|
||||||
scheduleTemporaryBasalChange();
|
scheduleTemporaryBasalChange();
|
||||||
scheduleTreatmentChange(null);
|
scheduleTreatmentChange(null);
|
||||||
scheduleExtendedBolusChange();
|
scheduleExtendedBolusChange();
|
||||||
|
@ -366,14 +367,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
// ------------------- BgReading handling -----------------------
|
// ------------------- BgReading handling -----------------------
|
||||||
|
|
||||||
public boolean createIfNotExists(BgReading bgReading, String from, boolean isFromActiveBgSource) {
|
public boolean createIfNotExists(BgReading bgReading, String from) {
|
||||||
try {
|
try {
|
||||||
bgReading.date = roundDateToSec(bgReading.date);
|
bgReading.date = roundDateToSec(bgReading.date);
|
||||||
BgReading old = getDaoBgReadings().queryForId(bgReading.date);
|
BgReading old = getDaoBgReadings().queryForId(bgReading.date);
|
||||||
if (old == null) {
|
if (old == null) {
|
||||||
getDaoBgReadings().create(bgReading);
|
getDaoBgReadings().create(bgReading);
|
||||||
log.debug("BG: New record from: " + from + " " + bgReading.toString());
|
log.debug("BG: New record from: " + from + " " + bgReading.toString());
|
||||||
scheduleBgChange(bgReading, true, isFromActiveBgSource);
|
scheduleBgChange(bgReading);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!old.isEqual(bgReading)) {
|
if (!old.isEqual(bgReading)) {
|
||||||
|
@ -381,7 +382,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
old.copyFrom(bgReading);
|
old.copyFrom(bgReading);
|
||||||
getDaoBgReadings().update(old);
|
getDaoBgReadings().update(old);
|
||||||
log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
|
log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
|
||||||
scheduleBgChange(bgReading, false, isFromActiveBgSource);
|
scheduleBgChange(bgReading);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -399,11 +400,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void scheduleBgChange(@Nullable final BgReading bgReading, boolean isNew, boolean isFromActiveBgSource) {
|
private static void scheduleBgChange(@Nullable final BgReading bgReading) {
|
||||||
class PostRunnable implements Runnable {
|
class PostRunnable implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
log.debug("Firing EventNewBg");
|
log.debug("Firing EventNewBg");
|
||||||
MainApp.bus().post(new EventNewBG(bgReading, isNew, isFromActiveBgSource));
|
MainApp.bus().post(new EventNewBG(bgReading));
|
||||||
scheduledBgPost = null;
|
scheduledBgPost = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,17 +10,8 @@ import info.nightscout.androidaps.db.BgReading;
|
||||||
public class EventNewBG extends EventLoop {
|
public class EventNewBG extends EventLoop {
|
||||||
@Nullable
|
@Nullable
|
||||||
public final BgReading bgReading;
|
public final BgReading bgReading;
|
||||||
public final boolean isNew;
|
|
||||||
public final boolean isFromActiveBgSource;
|
|
||||||
|
|
||||||
/** Whether the BgReading is current (enough to use for treatment decisions). */
|
public EventNewBG(BgReading bgReading) {
|
||||||
public boolean isCurrent() {
|
|
||||||
return bgReading != null && bgReading.date + 9 * 60 * 1000 > System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventNewBG(@Nullable BgReading bgReading, boolean isNew, boolean isFromActiveBgSource) {
|
|
||||||
this.bgReading = bgReading;
|
this.bgReading = bgReading;
|
||||||
this.isNew = isNew;
|
|
||||||
this.isFromActiveBgSource = isFromActiveBgSource;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -531,8 +531,6 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEventNewBG(EventNewBG ev) {
|
public void onEventNewBG(EventNewBG ev) {
|
||||||
if (!ev.isFromActiveBgSource)
|
|
||||||
return;
|
|
||||||
if (this != getPlugin()) {
|
if (this != getPlugin()) {
|
||||||
log.debug("Ignoring event for non default instance");
|
log.debug("Ignoring event for non default instance");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -23,7 +23,6 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
|
@ -160,12 +159,8 @@ public class LoopPlugin implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||||
if (!(ev.cause instanceof EventNewBG))
|
if (ev.cause instanceof EventNewBG) {
|
||||||
return;
|
invoke(ev.getClass().getSimpleName() + "(" + ev.cause.getClass().getSimpleName() + ")", true);
|
||||||
|
|
||||||
EventNewBG bgEv = (EventNewBG) ev.cause;
|
|
||||||
if (bgEv.isNew && bgEv.isFromActiveBgSource && bgEv.isCurrent()) {
|
|
||||||
invoke("New BG", true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,16 +142,14 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewBG e) {
|
public void onStatusEvent(final EventNewBG e) {
|
||||||
if (e.isFromActiveBgSource && e.isNew && e.isCurrent()) {
|
Activity activity = getActivity();
|
||||||
Activity activity = getActivity();
|
if (activity != null)
|
||||||
if (activity != null)
|
activity.runOnUiThread(new Runnable() {
|
||||||
activity.runOnUiThread(new Runnable() {
|
@Override
|
||||||
@Override
|
public void run() {
|
||||||
public void run() {
|
calculateInsulin();
|
||||||
calculateInsulin();
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
|
@ -255,8 +255,7 @@ public class PersistentNotificationPlugin implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewBG ev) {
|
public void onStatusEvent(final EventNewBG ev) {
|
||||||
if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent())
|
updateNotification();
|
||||||
updateNotification();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
|
@ -182,8 +182,7 @@ public class WearPlugin implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewBG ev) {
|
public void onStatusEvent(final EventNewBG ev) {
|
||||||
if (ev.isFromActiveBgSource)
|
sendDataToWatch(true, true, true);
|
||||||
sendDataToWatch(true, true, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
|
@ -235,8 +235,7 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewBG ev) {
|
public void onStatusEvent(final EventNewBG ev) {
|
||||||
if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent())
|
sendStatus();
|
||||||
sendStatus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
Loading…
Reference in a new issue