Merge pull request #787 from jotomo/revert-770

Revert "Merge pull request #770 from jotomo/new-bg-processing"
This commit is contained in:
Milos Kozak 2018-03-21 10:42:01 +01:00 committed by GitHub
commit 9c71bacd7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 27 additions and 47 deletions

View file

@ -192,7 +192,7 @@ public class DataService extends IntentService {
bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP);
bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW);
MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP", xDripEnabled);
MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP");
}
private void handleNewDataFromGlimp(Intent intent) {
@ -206,7 +206,7 @@ public class DataService extends IntentService {
bgReading.date = bundle.getLong("myTimestamp");
bgReading.raw = 0;
MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP", glimpEnabled);
MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP");
}
private void handleNewDataFromDexcomG5(Intent intent) {
@ -229,7 +229,7 @@ public class DataService extends IntentService {
bgReading.direction = json.getString("m_trend");
bgReading.date = json.getLong("m_time") * 1000L;
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)) {
NSUpload.uploadBg(bgReading);
}
@ -268,7 +268,7 @@ public class DataService extends IntentService {
bgReading.date = json_object.getLong("date");
bgReading.raw = json_object.getDouble("sgv");
MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g", mm640gEnabled);
MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g");
break;
default:
log.debug("Unknown entries type: " + type);
@ -425,7 +425,7 @@ public class DataService extends IntentService {
JSONObject sgvJson = new JSONObject(sgvstring);
NSSgv nsSgv = new NSSgv(sgvJson);
BgReading bgReading = new BgReading(nsSgv);
MainApp.getDbHelper().createIfNotExists(bgReading, "NS", nsClientEnabled);
MainApp.getDbHelper().createIfNotExists(bgReading, "NS");
}
if (bundles.containsKey("sgvs")) {
@ -435,7 +435,7 @@ public class DataService extends IntentService {
JSONObject sgvJson = jsonArray.getJSONObject(i);
NSSgv nsSgv = new NSSgv(sgvJson);
BgReading bgReading = new BgReading(nsSgv);
MainApp.getDbHelper().createIfNotExists(bgReading, "NS", nsClientEnabled);
MainApp.getDbHelper().createIfNotExists(bgReading, "NS");
}
}
} catch (Exception e) {

View file

@ -8,6 +8,7 @@ import android.support.annotation.Nullable;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.CloseableIterator;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.Where;
@ -240,7 +241,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
log.error("Unhandled exception", e);
}
VirtualPumpPlugin.setFakingStatus(true);
scheduleBgChange(null, false, false); // trigger refresh
scheduleBgChange(null); // trigger refresh
scheduleTemporaryBasalChange();
scheduleTreatmentChange(null);
scheduleExtendedBolusChange();
@ -366,14 +367,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
// ------------------- BgReading handling -----------------------
public boolean createIfNotExists(BgReading bgReading, String from, boolean isFromActiveBgSource) {
public boolean createIfNotExists(BgReading bgReading, String from) {
try {
bgReading.date = roundDateToSec(bgReading.date);
BgReading old = getDaoBgReadings().queryForId(bgReading.date);
if (old == null) {
getDaoBgReadings().create(bgReading);
log.debug("BG: New record from: " + from + " " + bgReading.toString());
scheduleBgChange(bgReading, true, isFromActiveBgSource);
scheduleBgChange(bgReading);
return true;
}
if (!old.isEqual(bgReading)) {
@ -381,7 +382,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
old.copyFrom(bgReading);
getDaoBgReadings().update(old);
log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
scheduleBgChange(bgReading, false, isFromActiveBgSource);
scheduleBgChange(bgReading);
return false;
}
} 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 {
public void run() {
log.debug("Firing EventNewBg");
MainApp.bus().post(new EventNewBG(bgReading, isNew, isFromActiveBgSource));
MainApp.bus().post(new EventNewBG(bgReading));
scheduledBgPost = null;
}
}

View file

@ -10,17 +10,8 @@ import info.nightscout.androidaps.db.BgReading;
public class EventNewBG extends EventLoop {
@Nullable
public final BgReading bgReading;
public final boolean isNew;
public final boolean isFromActiveBgSource;
/** Whether the BgReading is current (enough to use for treatment decisions). */
public boolean isCurrent() {
return bgReading != null && bgReading.date + 9 * 60 * 1000 > System.currentTimeMillis();
}
public EventNewBG(@Nullable BgReading bgReading, boolean isNew, boolean isFromActiveBgSource) {
public EventNewBG(BgReading bgReading) {
this.bgReading = bgReading;
this.isNew = isNew;
this.isFromActiveBgSource = isFromActiveBgSource;
}
}

View file

@ -531,8 +531,6 @@ public class IobCobCalculatorPlugin implements PluginBase {
@Subscribe
public void onEventNewBG(EventNewBG ev) {
if (!ev.isFromActiveBgSource)
return;
if (this != getPlugin()) {
log.debug("Ignoring event for non default instance");
return;

View file

@ -23,7 +23,6 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.APSInterface;
@ -160,12 +159,8 @@ public class LoopPlugin implements PluginBase {
@Subscribe
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
if (!(ev.cause instanceof EventNewBG))
return;
EventNewBG bgEv = (EventNewBG) ev.cause;
if (bgEv.isNew && bgEv.isFromActiveBgSource && bgEv.isCurrent()) {
invoke("New BG", true);
if (ev.cause instanceof EventNewBG) {
invoke(ev.getClass().getSimpleName() + "(" + ev.cause.getClass().getSimpleName() + ")", true);
}
}

View file

@ -142,16 +142,14 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
@Subscribe
public void onStatusEvent(final EventNewBG e) {
if (e.isFromActiveBgSource && e.isNew && e.isCurrent()) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
calculateInsulin();
}
});
}
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
calculateInsulin();
}
});
}
@Subscribe

View file

@ -255,8 +255,7 @@ public class PersistentNotificationPlugin implements PluginBase {
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent())
updateNotification();
updateNotification();
}
@Subscribe

View file

@ -182,8 +182,7 @@ public class WearPlugin implements PluginBase {
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
if (ev.isFromActiveBgSource)
sendDataToWatch(true, true, true);
sendDataToWatch(true, true, true);
}
@Subscribe

View file

@ -235,8 +235,7 @@ public class StatuslinePlugin implements PluginBase {
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent())
sendStatus();
sendStatus();
}
@Subscribe