use of com.eveningoutpost.dexdrip.Models.BgReading in project xDrip by NightscoutFoundation.
the class BgReadingTable method getData.
/*@Override
public void onNavigationDrawerItemSelected(int position) {
mNavigationDrawerFragment.swapContext(position);
}*/
private void getData() {
// 3 days
final long startTime = new Date().getTime() - (60000 * 60 * 24 * 3);
final List<BgReading> latest = BgReading.latestForGraph(216, startTime);
ListAdapter adapter = new BgReadingAdapter(this, latest);
this.setListAdapter(adapter);
String msg = "";
int size = 0;
if (latest != null)
size = latest.size();
if (size == 0) {
msg = getResources().getString(R.string.notify_table_size, "BgReading", size);
JoH.static_toast(xdrip.getAppContext(), msg, Toast.LENGTH_SHORT);
}
}
use of com.eveningoutpost.dexdrip.Models.BgReading in project xDrip by NightscoutFoundation.
the class BgSendQueue method resendData.
// KS start from WatchUpdaterService
public static void resendData(Context context, int battery) {
// KS
Log.d("BgSendQueue", "resendData enter battery=" + battery);
long startTime = new Date().getTime() - (60000 * 60 * 24);
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", "ACTION_G5BG");
BgReading last_bg = BgReading.last();
if (last_bg != null) {
Log.d("BgSendQueue", "resendData last_bg.timestamp:" + JoH.dateTimeText(last_bg.timestamp));
}
List<BgReading> graph_bgs = BgReading.latestForGraph(60, startTime);
BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context.getApplicationContext());
if (!graph_bgs.isEmpty()) {
Log.d("BgSendQueue", "resendData graph_bgs size=" + graph_bgs.size());
final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
DataMap entries = dataMap(last_bg, sharedPrefs, bgGraphBuilder, context, battery);
for (BgReading bg : graph_bgs) {
dataMaps.add(dataMap(bg, sharedPrefs, bgGraphBuilder, context, battery));
}
entries.putDataMapArrayList("entries", dataMaps);
if (sharedPrefs.getBoolean("extra_status_line", false)) {
// messageIntent.putExtra("extra_status_line", extraStatusLine(sharedPrefs));
entries.putString("extra_status_line", extraStatusLine(sharedPrefs));
}
Log.d("BgSendQueue", "resendData entries=" + entries);
messageIntent.putExtra("data", entries.toBundle());
DataMap stepsDataMap = getSensorSteps(sharedPrefs);
if (stepsDataMap != null) {
messageIntent.putExtra("steps", stepsDataMap.toBundle());
}
LocalBroadcastManager.getInstance(context).sendBroadcast(messageIntent);
}
}
use of com.eveningoutpost.dexdrip.Models.BgReading in project xDrip by NightscoutFoundation.
the class Notifications method FileBasedNotifications.
/*
* *************************************************************************************************************
* Function for new notifications
*/
private void FileBasedNotifications(Context context) {
ReadPerfs(context);
Sensor sensor = Sensor.currentSensor();
final BgReading bgReading = BgReading.last();
if (bgReading == null) {
// Sensor is stopped, or there is not enough data
AlertPlayer.getPlayer().stopAlert(context, true, false);
return;
}
final double calculated_value;
/* KS TODO BestGlucose
if (use_best_glucose) {
this.dg = BestGlucose.getDisplayGlucose();
if (dg != null) {
bgReading.calculated_value = dg.mgdl;
calculated_value = dg.mgdl;
} else {
calculated_value = bgReading.calculated_value;
Log.wtf(TAG, "Could not obtain best glucose value!");
}
} else {*/
calculated_value = bgReading.calculated_value;
// }
Log.d(TAG, "FileBasedNotifications called bgReading.calculated_value = " + bgReading.calculated_value + " calculated value: " + calculated_value);
// In all this cases, bgReading.calculated_value should be 0.
if (((sensor != null) || (Home.get_follower())) && calculated_value != 0) {
AlertType newAlert = AlertType.get_highest_active_alert(context, calculated_value);
if (newAlert == null) {
Log.d(TAG, "FileBasedNotifications - No active notifcation exists, stopping all alerts");
// No alert should work, Stop all alerts, but keep the snoozing...
AlertPlayer.getPlayer().stopAlert(context, false, true);
return;
}
AlertType activeBgAlert = ActiveBgAlert.alertTypegetOnly();
if (activeBgAlert == null) {
Log.d(TAG, "FileBasedNotifications we have a new alert, starting to play it... " + newAlert.name);
// We need to create a new alert and start playing
boolean trendingToAlertEnd = trendingToAlertEnd(context, true, newAlert);
// KS EditAlertActivity.
AlertPlayer.getPlayer().startAlert(context, trendingToAlertEnd, newAlert, unitsConvert2Disp(doMgdl, calculated_value));
return;
}
if (activeBgAlert.uuid.equals(newAlert.uuid)) {
// disable alert on stale data
if (prefs.getBoolean("disable_alerts_stale_data", false)) {
int minutes = Integer.parseInt(prefs.getString("disable_alerts_stale_data_minutes", "15")) + 2;
if ((new Date().getTime()) - (60000 * minutes) - BgReading.lastNoSenssor().timestamp > 0) {
Log.d(TAG, "FileBasedNotifications : active alert found but not replaying it because more than three readings missed : " + newAlert.name);
return;
}
}
Log.d(TAG, "FileBasedNotifications we have found an active alert, checking if we need to play it " + newAlert.name);
boolean trendingToAlertEnd = trendingToAlertEnd(context, false, newAlert);
// KS EditAlertActivity
AlertPlayer.getPlayer().ClockTick(context, trendingToAlertEnd, unitsConvert2Disp(doMgdl, calculated_value));
return;
}
// Currently the ui blocks having two alerts with the same alert value.
boolean alertSnoozeOver = ActiveBgAlert.alertSnoozeOver();
if (alertSnoozeOver) {
Log.d(TAG, "FileBasedNotifications we had two alerts, the snoozed one is over, we fall down to deleting the snoozed and staring the new");
// in such case it is not important which is higher.
} else {
// we have a new alert. If it is more important than the previous one. we need to stop
// the older one and start a new one (We need to play even if we were snoozed).
// If it is a lower level alert, we should keep being snoozed.
// Example, if we have two alerts one for 90 and the other for 80. and we were already alerting for the 80
// and we were snoozed. Now bg is 85, the alert for 80 is cleared, but we are alerting for 90.
// We should not do anything if we are snoozed for the 80...
// If one allert was high and the second one is low however, we alarm in any case (snoozing ignored).
boolean opositeDirection = AlertType.OpositeDirection(activeBgAlert, newAlert);
if (!opositeDirection) {
AlertType newHigherAlert = AlertType.HigherAlert(activeBgAlert, newAlert);
if ((newHigherAlert == activeBgAlert)) {
// the existing (snoozed) alert is the higher, No need to play it since it is snoozed.
Log.d(TAG, "FileBasedNotifications The new alert has the same direcotion, it is lower than the one snoozed, not playing it." + " newHigherAlert = " + newHigherAlert.name + "activeBgAlert = " + activeBgAlert.name);
return;
}
}
}
// For now, we are stopping the old alert and starting a new one.
Log.d(TAG, "Found a new alert, that is higher than the previous one will play it. " + newAlert.name);
AlertPlayer.getPlayer().stopAlert(context, true, false);
boolean trendingToAlertEnd = trendingToAlertEnd(context, true, newAlert);
// KS EditAlertActivity
AlertPlayer.getPlayer().startAlert(context, trendingToAlertEnd, newAlert, unitsConvert2Disp(doMgdl, calculated_value));
} else {
AlertPlayer.getPlayer().stopAlert(context, true, false);
}
}
use of com.eveningoutpost.dexdrip.Models.BgReading in project xDrip-plus by jamorham.
the class Ob1G5StateMachine method processNewTransmitterData.
// Save/process the data in xDrip style
private static synchronized void processNewTransmitterData(int raw_data, int filtered_data, int sensor_battery_level, long captureTime) {
final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_level, captureTime);
if (transmitterData == null) {
UserError.Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
return;
} else {
UserError.Log.d(TAG, "Created transmitter data " + transmitterData.uuid + " " + JoH.dateTimeText(transmitterData.timestamp));
// TODO timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
}
Sensor sensor = Sensor.currentSensor();
if (sensor == null) {
UserError.Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
return;
}
// TODO : LOG if unfiltered or filtered values are zero
Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
if (d)
UserError.Log.i(TAG, "timestamp create: " + Long.toString(transmitterData.timestamp));
BgReading bgreading = BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
// KS
UserError.Log.d(TAG, "Dex raw_data " + Double.toString(transmitterData.raw_data));
// KS
UserError.Log.d(TAG, "Dex filtered_data " + Double.toString(transmitterData.filtered_data));
// KS
UserError.Log.d(TAG, "Dex sensor_battery_level " + Double.toString(transmitterData.sensor_battery_level));
// KS
UserError.Log.d(TAG, "Dex timestamp " + JoH.dateTimeText(transmitterData.timestamp));
UserError.Log.d(TAG, "BgReading created: " + bgreading.uuid + " " + JoH.dateTimeText(bgreading.timestamp));
// TODO static_last_timestamp = transmitterData.timestamp;
}
use of com.eveningoutpost.dexdrip.Models.BgReading in project xDrip-plus by jamorham.
the class DexShareCollectionService method setRetryTimer.
public void setRetryTimer() {
if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
BgReading bgReading = BgReading.last();
long retry_in;
if (bgReading != null) {
retry_in = Math.min(Math.max((1000 * 30), (1000 * 60 * 5) - (new Date().getTime() - bgReading.timestamp) + (1000 * 5)), (1000 * 60 * 5));
} else {
retry_in = (1000 * 20);
}
Log.d(TAG, "Restarting in: " + (retry_in / (60 * 1000)) + " minutes");
Calendar calendar = Calendar.getInstance();
AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
if (pendingIntent != null)
alarm.cancel(pendingIntent);
long wakeTime = calendar.getTimeInMillis() + retry_in;
pendingIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()), 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarm.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarm.setExact(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
} else
alarm.set(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
}
}
Aggregations