optimize getUnits() & detecting faked extended

This commit is contained in:
Milos Kozak 2017-06-13 12:08:30 +02:00
parent 1de64f06c2
commit afca896f23
26 changed files with 129 additions and 69 deletions

View file

@ -10,6 +10,8 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Iterator;
import info.nightscout.androidaps.Constants;
/**
* Created by mike on 01.06.2017.
*/
@ -17,9 +19,11 @@ import java.util.Iterator;
public class ProfileStore {
private static Logger log = LoggerFactory.getLogger(ProfileStore.class);
private JSONObject json = null;
private String units = Constants.MGDL;
public ProfileStore(JSONObject json) {
this.json = json;
getDefaultProfile(); // initialize units
}
public JSONObject getData() {
@ -33,10 +37,10 @@ public class ProfileStore {
String defaultProfileName = json.getString("defaultProfile");
JSONObject store = json.getJSONObject("store");
if (store.has(defaultProfileName)) {
String units = null;
if (store.has("units"))
units = store.getString("units");
profile = new Profile(store.getJSONObject(defaultProfileName), units);
units = profile.getUnits();
}
} catch (JSONException e) {
e.printStackTrace();
@ -59,6 +63,10 @@ public class ProfileStore {
return defaultProfileName;
}
public String getUnits() {
return units;
}
@Nullable
public Profile getSpecificProfile(String profileName) {
Profile profile = null;

View file

@ -158,7 +158,7 @@ public class BgReading implements DataPointWithLabelInterface {
@Override
public double getY() {
String units = MainApp.getConfigBuilder().getProfile().getUnits();
String units = MainApp.getConfigBuilder().getProfileUnits();
return valueToUnits(units);
}
@ -190,7 +190,7 @@ public class BgReading implements DataPointWithLabelInterface {
@Override
public int getColor() {
String units = MainApp.getConfigBuilder().getProfile().getUnits();
String units = MainApp.getConfigBuilder().getProfileUnits();
Double lowLine = SP.getDouble("low_mark", 0d);
Double highLine = SP.getDouble("high_mark", 0d);
if (lowLine < 1) {

View file

@ -89,7 +89,7 @@ public class CareportalEvent implements DataPointWithLabelInterface {
}
public String age() {
Map<TimeUnit,Long> diff = computeDiff(date, new Date().getTime());
Map<TimeUnit, Long> diff = computeDiff(date, new Date().getTime());
return diff.get(TimeUnit.DAYS) + " " + MainApp.sResources.getString(R.string.days) + " " + diff.get(TimeUnit.HOURS) + " " + MainApp.sResources.getString(R.string.hours);
}
@ -105,17 +105,17 @@ public class CareportalEvent implements DataPointWithLabelInterface {
}
//Map:{DAYS=1, HOURS=3, MINUTES=46, SECONDS=40, MILLISECONDS=0, MICROSECONDS=0, NANOSECONDS=0}
public static Map<TimeUnit,Long> computeDiff(long date1, long date2) {
public static Map<TimeUnit, Long> computeDiff(long date1, long date2) {
long diffInMillies = date2 - date1;
List<TimeUnit> units = new ArrayList<TimeUnit>(EnumSet.allOf(TimeUnit.class));
Collections.reverse(units);
Map<TimeUnit,Long> result = new LinkedHashMap<TimeUnit,Long>();
Map<TimeUnit, Long> result = new LinkedHashMap<TimeUnit, Long>();
long milliesRest = diffInMillies;
for ( TimeUnit unit : units ) {
long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS);
for (TimeUnit unit : units) {
long diff = unit.convert(milliesRest, TimeUnit.MILLISECONDS);
long diffInMilliesForUnit = unit.toMillis(diff);
milliesRest = milliesRest - diffInMilliesForUnit;
result.put(unit,diff);
result.put(unit, diff);
}
return result;
}
@ -131,7 +131,7 @@ public class CareportalEvent implements DataPointWithLabelInterface {
@Override
public double getY() {
Profile profile = MainApp.getConfigBuilder().getProfile();
String units = MainApp.getConfigBuilder().getProfileUnits();
if (eventType.equals(MBG)) {
double mbg = 0d;
try {
@ -140,13 +140,10 @@ public class CareportalEvent implements DataPointWithLabelInterface {
} catch (JSONException e) {
e.printStackTrace();
}
if (profile != null)
return profile.fromMgdlToUnits(mbg, profile.getUnits());
return 0d;
return Profile.fromMgdlToUnits(mbg, units);
}
double glucose = 0d;
String units = Constants.MGDL;
try {
JSONObject object = new JSONObject(json);
if (object.has("glucose")) {
@ -156,7 +153,7 @@ public class CareportalEvent implements DataPointWithLabelInterface {
} catch (JSONException e) {
e.printStackTrace();
}
if (profile != null && glucose != 0d) {
if (glucose != 0d) {
double mmol = 0d;
double mgdl = 0;
if (units.equals(Constants.MGDL)) {
@ -167,7 +164,7 @@ public class CareportalEvent implements DataPointWithLabelInterface {
mmol = glucose;
mgdl = glucose * Constants.MMOLL_TO_MGDL;
}
return profile.toUnits(mgdl, mmol, profile.getUnits());
return Profile.toUnits(mgdl, mmol, units);
}
return yValue;

View file

@ -204,6 +204,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} catch (SQLException e) {
e.printStackTrace();
}
VirtualPumpPlugin.setFakingStatus(true);
scheduleBgChange(); // trigger refresh
scheduleTemporaryBasalChange();
scheduleTreatmentChange();
@ -251,6 +252,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} catch (SQLException e) {
e.printStackTrace();
}
VirtualPumpPlugin.setFakingStatus(false);
scheduleTemporaryBasalChange();
}
@ -817,8 +819,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void createTemptargetFromJsonIfNotExists(JSONObject trJson) {
try {
Profile profile = MainApp.getConfigBuilder().getProfile();
String units = profile.getUnits();
String units = MainApp.getConfigBuilder().getProfileUnits();
TempTarget tempTarget = new TempTarget();
tempTarget.date = trJson.getLong("mills");
tempTarget.durationInMinutes = trJson.getInt("duration");
@ -1070,7 +1071,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
extendedBolus.durationInMinutes = trJson.getInt("duration");
extendedBolus.insulin = trJson.getDouble("originalExtendedAmount");
extendedBolus._id = trJson.getString("_id");
VirtualPumpPlugin.fromNSAreCommingFakedExtendedBoluses = true;
if (!VirtualPumpPlugin.getFakingStatus()) {
VirtualPumpPlugin.setFakingStatus(true);
updateEarliestDataChange(0);
scheduleTemporaryBasalChange();
}
createOrUpdate(extendedBolus);
} else if (trJson.has("isFakedTempBasal")) { // extended bolus end uploaded as temp basal end
ExtendedBolus extendedBolus = new ExtendedBolus();
@ -1080,7 +1085,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
extendedBolus.durationInMinutes = 0;
extendedBolus.insulin = 0;
extendedBolus._id = trJson.getString("_id");
VirtualPumpPlugin.fromNSAreCommingFakedExtendedBoluses = true;
if (!VirtualPumpPlugin.getFakingStatus()) {
VirtualPumpPlugin.setFakingStatus(true);
updateEarliestDataChange(0);
scheduleTemporaryBasalChange();
}
createOrUpdate(extendedBolus);
} else {
TemporaryBasal tempBasal = new TemporaryBasal();

View file

@ -10,5 +10,6 @@ import info.nightscout.androidaps.data.ProfileStore;
public interface ProfileInterface {
@Nullable
ProfileStore getProfile();
String getUnits();
String getProfileName();
}

View file

@ -231,7 +231,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
profile = MainApp.getConfigBuilder().getProfile();
profileStore = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile();
ArrayList<CharSequence> profileList;
units = Constants.MGDL;
units = profile.getUnits();
profileList = profileStore.getProfileList();
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(),

View file

@ -1008,6 +1008,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
return getProfile(new Date().getTime());
}
public String getProfileUnits() {
return activeProfile.getUnits();
}
public Profile getProfile(long time) {
//log.debug("Profile for: " + new Date(time).toLocaleString() + " : " + getProfileName(time));
ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time);

View file

@ -345,6 +345,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
return iobTotal;
}
@Nullable
private static Long findPreviousTimeFromBucketedData(long time) {
if (bucketed_data == null)
return null;
@ -413,6 +414,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
Profile profile = MainApp.getConfigBuilder().getProfile();
// predict IOB out to DIA plus 30m
long time = new Date().getTime();
time = roundUpTime(time);
int len = (int) ((profile.getDia() * 60 + 30) / 5);
IobTotal[] array = new IobTotal[len];
int pos = 0;

View file

@ -156,6 +156,7 @@ public class NSClientService extends Service {
ev.isChanged(R.string.key_nsclientinternal_api_secret) ||
ev.isChanged(R.string.key_nsclientinternal_paused)
) {
latestDateInReceivedData = 0;
destroy();
initialize();
}
@ -164,6 +165,7 @@ public class NSClientService extends Service {
@Subscribe
public void onStatusEvent(EventConfigBuilderChange ev) {
if (nsEnabled != MainApp.getSpecificPlugin(NSClientInternalPlugin.class).isEnabled(PluginBase.GENERAL)) {
latestDateInReceivedData = 0;
destroy();
initialize();
}

View file

@ -60,14 +60,10 @@ public class CalibrationDialog extends DialogFragment implements View.OnClickLis
okButton = (Button) view.findViewById(R.id.overview_calibration_okbutton);
okButton.setOnClickListener(this);
Profile profile = MainApp.getConfigBuilder().getProfile();
Double bg = profile != null ? Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile.getUnits()) : 0d;
String units = MainApp.getConfigBuilder().getProfileUnits();
Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units);
String units = Constants.MGDL;
if (profile != null)
units = profile.getUnits();
if (units.equals(Constants.MMOL))
if (units.equals(Constants.MMOL))
bgText = new PlusMinusEditText(view, R.id.overview_calibration_bg, R.id.overview_calibration_bg_plus, R.id.overview_calibration_bg_minus, bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false);
else
bgText = new PlusMinusEditText(view, R.id.overview_calibration_bg, R.id.overview_calibration_bg_plus, R.id.overview_calibration_bg_minus, bg, 0d, 500d, 1d, new DecimalFormat("0"), false);

View file

@ -916,6 +916,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
PumpInterface pump = MainApp.getConfigBuilder();
Profile profile = MainApp.getConfigBuilder().getProfile();
String units = profile.getUnits();
// open loop mode
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
@ -958,13 +959,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground));
tempTargetView.setVisibility(View.VISIBLE);
if (tempTarget.low == tempTarget.high)
tempTargetView.setText(Profile.toUnitsString(tempTarget.low, Profile.fromMgdlToUnits(tempTarget.low, profile.getUnits()), profile.getUnits()));
tempTargetView.setText(Profile.toUnitsString(tempTarget.low, Profile.fromMgdlToUnits(tempTarget.low, units), units));
else
tempTargetView.setText(Profile.toUnitsString(tempTarget.low, Profile.fromMgdlToUnits(tempTarget.low, profile.getUnits()), profile.getUnits()) + " - " + Profile.toUnitsString(tempTarget.high, Profile.fromMgdlToUnits(tempTarget.high, profile.getUnits()), profile.getUnits()));
tempTargetView.setText(Profile.toUnitsString(tempTarget.low, Profile.fromMgdlToUnits(tempTarget.low, units), units) + " - " + Profile.toUnitsString(tempTarget.high, Profile.fromMgdlToUnits(tempTarget.high, units), units));
} else {
Double maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
Double minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
if (!profile.getUnits().equals(Constants.MGDL)) {
if (!units.equals(Constants.MGDL)) {
maxBgDefault = Constants.MAX_BG_DEFAULT_MMOL;
minBgDefault = Constants.MIN_BG_DEFAULT_MMOL;
}
@ -1062,7 +1063,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
quickWizardButton.setVisibility(View.VISIBLE);
String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
BolusWizard wizard = new BolusWizard();
wizard.doCalc(profile, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(profile.getUnits()), 0d, true, true, false, false);
wizard.doCalc(profile, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(units), 0d, true, true, false, false);
text += " " + DecimalFormatter.to2Decimal(wizard.calculatedTotalInsulin) + "U";
quickWizardButton.setText(text);
if (wizard.calculatedTotalInsulin <= 0)
@ -1079,8 +1080,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
treatmentButton.setVisibility(View.GONE);
}
String units = profile.getUnits();
Double lowLine = SP.getDouble("low_mark", 0d);
Double highLine = SP.getDouble("high_mark", 0d);
if (lowLine < 1) {
@ -1097,7 +1096,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
color = MainApp.sResources.getColor(R.color.low);
else if (lastBG.valueToUnits(units) > highLine)
color = MainApp.sResources.getColor(R.color.high);
bgView.setText(lastBG.valueToUnitsToString(profile.getUnits()));
bgView.setText(lastBG.valueToUnitsToString(units));
arrowView.setText(lastBG.directionToSymbol());
bgView.setTextColor(color);
arrowView.setTextColor(color);
@ -1156,7 +1155,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
// ****** GRAPH *******
//log.debug("updateGUI checkpoint 1");
log.debug("updateGUI checkpoint 1");
// allign to hours
Calendar calendar = Calendar.getInstance();
@ -1287,7 +1286,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
absoluteBasalsLineSeries.setCustomPaint(absolutePaint);
}
//log.debug("updateGUI checkpoint 2");
log.debug("updateGUI checkpoint 2");
// **** IOB COB DEV graph ****
class DeviationDataPoint extends DataPoint {
@ -1405,12 +1404,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} else {
iobGraph.setVisibility(View.GONE);
}
//log.debug("updateGUI checkpoint 3");
log.debug("updateGUI checkpoint 3");
// remove old data from graph
bgGraph.getSecondScale().getSeries().clear();
bgGraph.getSeries().clear();
//log.debug("updateGUI checkpoint 4");
log.debug("updateGUI checkpoint 4");
// **** Area ****
DoubleDataPoint[] areaDataPoints = new DoubleDataPoint[]{
@ -1586,11 +1585,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
public double getNearestBg(long date, List<BgReading> bgReadingsArray) {
double bg = 0;
Profile profile = MainApp.getConfigBuilder().getProfile();
String units = MainApp.getConfigBuilder().getProfileUnits();
for (int r = bgReadingsArray.size() - 1; r >= 0; r--) {
BgReading reading = bgReadingsArray.get(r);
if (reading.date > date) continue;
bg = Profile.fromMgdlToUnits(reading.value, profile.getUnits());
bg = Profile.fromMgdlToUnits(reading.value, units);
break;
}
return bg;

View file

@ -118,17 +118,17 @@ public class PersistentNotificationPlugin implements PluginBase {
String line1 = ctx.getString(R.string.noprofile);
Profile profile = MainApp.getConfigBuilder().getProfile();
String units = MainApp.getConfigBuilder().getProfileUnits();
BgReading lastBG = DatabaseHelper.lastBg();
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
if (profile != null && lastBG != null) {
line1 = lastBG.valueToUnitsToString(profile.getUnits());
if (lastBG != null) {
line1 = lastBG.valueToUnitsToString(units);
if (glucoseStatus != null) {
line1 += " Δ" + deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, profile.getUnits())
+ " avgΔ" + deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, profile.getUnits());
line1 += " Δ" + deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units)
+ " avgΔ" + deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, units);
} else {
line1 += " " +
ctx.getString(R.string.old_data) +

View file

@ -213,6 +213,11 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
return convertedProfile;
}
@Override
public String getUnits() {
return mgdl ? Constants.MGDL : Constants.MMOL;
}
@Override
public String getProfileName() {
performLimitCheck();

View file

@ -240,6 +240,11 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
return convertedProfile;
}
@Override
public String getUnits() {
return mgdl ? Constants.MGDL : Constants.MMOL;
}
@Override
public String getProfileName() {
return convertedProfileName;

View file

@ -153,6 +153,11 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
return profile;
}
@Override
public String getUnits() {
return profile.getUnits();
}
@Override
public String getProfileName() {
return profile.getDefaultProfileName();

View file

@ -201,6 +201,11 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface {
return convertedProfile;
}
@Override
public String getUnits() {
return mgdl ? Constants.MGDL : Constants.MMOL;
}
@Override
public String getProfileName() {
return "SimpleProfile";

View file

@ -798,6 +798,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
return pump.createConvertedProfile();
}
@Override
public String getUnits() {
return pump.getUnits();
}
@Override
public String getProfileName() {
return pump.createConvertedProfileName();

View file

@ -132,6 +132,10 @@ public class DanaRPump {
public double maxBolus;
public double maxBasal;
public String getUnits() {
return units == UNITS_MGDL ? Constants.MGDL : Constants.MMOL;
}
public ProfileStore createConvertedProfile() {
JSONObject json = new JSONObject();
JSONObject store = new JSONObject();

View file

@ -46,12 +46,6 @@ public class DanaRNSHistorySync {
public void sync(int what) {
try {
ConfigBuilderPlugin ConfigBuilderPlugin = MainApp.getConfigBuilder();
Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.noprofile));
return;
}
Calendar cal = Calendar.getInstance();
long records = historyRecords.size();
long processing = 0;
@ -179,7 +173,7 @@ public class DanaRNSHistorySync {
log.debug("Syncing glucose record " + record.recordValue + " " + DateUtil.toISOString(record.recordDate));
nsrec.put(DANARSIGNATURE, record.bytes);
nsrec.put("eventType", "BG Check");
nsrec.put("glucose", Profile.fromMgdlToUnits(record.recordValue, profile.getUnits()));
nsrec.put("glucose", Profile.fromMgdlToUnits(record.recordValue, MainApp.getConfigBuilder().getProfileUnits()));
nsrec.put("glucoseType", "Finger");
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name));

View file

@ -802,6 +802,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
return pump.createConvertedProfile();
}
@Override
public String getUnits() {
return pump.getUnits();
}
@Override
public String getProfileName() {
return pump.createConvertedProfileName();

View file

@ -715,6 +715,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
return pump.createConvertedProfile();
}
@Override
public String getUnits() {
return pump.getUnits();
}
@Override
public String getProfileName() {
return pump.createConvertedProfileName();

View file

@ -28,6 +28,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProg
import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP;
/**
* Created by mike on 05.08.2016.
@ -45,12 +46,26 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
boolean fragmentEnabled = true;
boolean fragmentVisible = true;
public static boolean fromNSAreCommingFakedExtendedBoluses = false;
private static boolean fromNSAreCommingFakedExtendedBoluses = false;
PumpDescription pumpDescription = new PumpDescription();
static void loadFakingStatus() {
fromNSAreCommingFakedExtendedBoluses = SP.getBoolean("fromNSAreCommingFakedExtendedBoluses", false);
}
public static void setFakingStatus(boolean newStatus) {
fromNSAreCommingFakedExtendedBoluses = newStatus;
SP.putBoolean("fromNSAreCommingFakedExtendedBoluses", fromNSAreCommingFakedExtendedBoluses);
}
public static boolean getFakingStatus() {
return fromNSAreCommingFakedExtendedBoluses;
}
static VirtualPumpPlugin instance = null;
public static VirtualPumpPlugin getInstance() {
loadFakingStatus();
if (instance == null)
instance = new VirtualPumpPlugin();
return instance;

View file

@ -238,8 +238,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
BgReading actualBG = DatabaseHelper.actualBg();
BgReading lastBG = DatabaseHelper.lastBg();
Profile profile = MainApp.getConfigBuilder().getProfile();
String units = profile.getUnits();
String units = MainApp.getConfigBuilder().getProfileUnits();
if (actualBG != null) {
reply = MainApp.sResources.getString(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", ";

View file

@ -62,16 +62,15 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
@Override
public void onBindViewHolder(TempTargetsViewHolder holder, int position) {
Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null) return;
String units = MainApp.getConfigBuilder().getProfileUnits();
TempTarget tempTarget = tempTargetList.getReversed(position);
holder.ph.setVisibility(tempTarget.source == Source.PUMP ? View.VISIBLE : View.GONE);
holder.ns.setVisibility(tempTarget._id != null ? View.VISIBLE : View.GONE);
if (!tempTarget.isEndingEvent()) {
holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date) + " - " + DateUtil.timeString(tempTarget.originalEnd()));
holder.duration.setText(DecimalFormatter.to0Decimal(tempTarget.durationInMinutes) + " min");
holder.low.setText(tempTarget.lowValueToUnitsToString(profile.getUnits()));
holder.high.setText(tempTarget.highValueToUnitsToString(profile.getUnits()));
holder.low.setText(tempTarget.lowValueToUnitsToString(units));
holder.high.setText(tempTarget.highValueToUnitsToString(units));
holder.reason.setText(tempTarget.reason);
} else {
holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date));

View file

@ -209,14 +209,13 @@ public class WatchUpdaterService extends WearableListenerService implements
}
private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) {
Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null) return null;
String units = MainApp.getConfigBuilder().getProfileUnits();
Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0"));
Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0"));
//convert to mg/dl
if (!profile.getUnits().equals(Constants.MGDL)) {
if (!units.equals(Constants.MGDL)) {
lowLine *= Constants.MMOLL_TO_MGDL;
highLine *= Constants.MMOLL_TO_MGDL;
@ -239,7 +238,7 @@ public class WatchUpdaterService extends WearableListenerService implements
DataMap dataMap = new DataMap();
int battery = getBatteryLevel(getApplicationContext());
dataMap.putString("sgvString", lastBG.valueToUnitsToString(profile.getUnits()));
dataMap.putString("sgvString", lastBG.valueToUnitsToString(units));
dataMap.putDouble("timestamp", lastBG.date);
if (glucoseStatus == null) {
dataMap.putString("slopeArrow", "");
@ -247,8 +246,8 @@ public class WatchUpdaterService extends WearableListenerService implements
dataMap.putString("avgDelta", "");
} else {
dataMap.putString("slopeArrow", slopeArrow(glucoseStatus.delta));
dataMap.putString("delta", deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, profile.getUnits()));
dataMap.putString("avgDelta", deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, profile.getUnits()));
dataMap.putString("delta", deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units));
dataMap.putString("avgDelta", deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, units));
}
dataMap.putString("battery", "" + battery);
dataMap.putLong("sgvLevel", sgvLevel);

View file

@ -44,12 +44,10 @@ public class XdripCalibrations {
}
public static boolean sendIntent(Double bg) {
final Profile profile = MainApp.getConfigBuilder().getProfile();
Context context = MainApp.instance().getApplicationContext();
Bundle bundle = new Bundle();
bundle.putDouble("glucose_number", bg);
bundle.putString("units", profile.getUnits().equals(Constants.MGDL) ? "mgdl" : "mmol");
bundle.putString("units", MainApp.getConfigBuilder().getProfileUnits().equals(Constants.MGDL) ? "mgdl" : "mmol");
bundle.putLong("timestamp", new Date().getTime());
Intent intent = new Intent(Intents.ACTION_REMOTE_CALIBRATION);
intent.putExtras(bundle);