Skip to content

Commit

Permalink
Commit working changes before merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Nov 2, 2016
1 parent 344661d commit 1b6f5da
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,12 @@ public double ageAdjustedFiltered(){
}
}

// ignores calibration checkins for speed
public double ageAdjustedFiltered_fast() {
// adjust the filtered_data with the same factor as the age adjusted raw value
return filtered_data * (age_adjusted_raw_value / raw_data);
}

// the input of this function is a string. each char can be g(=good) or b(=bad) or s(=skip, point unmissed).
static List<BgReading> createlatestTest(String input, Long now) {
Random randomGenerator = new Random();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.text.Html;
import android.text.SpannableString;
import android.text.style.StrikethroughSpan;
import android.text.style.UnderlineSpan;
import android.widget.TextView;

import com.eveningoutpost.dexdrip.BestGlucose;
import com.eveningoutpost.dexdrip.Models.JoH;
import com.eveningoutpost.dexdrip.Models.UserError.Log;

Expand Down Expand Up @@ -72,13 +78,16 @@ public class Notifications extends IntentService {
public static boolean smart_snoozing;
public static boolean smart_alerting;
private final static String TAG = AlertPlayer.class.getSimpleName();
private static final boolean use_best_glucose = true;

private static String last_noise_string = "Startup";


Context mContext;
PendingIntent wakeIntent;
private static Handler mHandler = new Handler(Looper.getMainLooper());

private BestGlucose.DisplayGlucose dg;
int currentVolume;
AudioManager manager;
Bitmap iconBitmap;
Expand Down Expand Up @@ -170,21 +179,36 @@ private void FileBasedNotifications(Context context) {
ReadPerfs(context);
Sensor sensor = Sensor.currentSensor();

BgReading bgReading = BgReading.last(Home.get_follower());
final BgReading bgReading = BgReading.last();
if (bgReading == null) {
// Sensor is stopped, or there is not enough data
AlertPlayer.getPlayer().stopAlert(context, true, false);
return;
}

Log.d(TAG, "FileBasedNotifications called bgReading.calculated_value = " + bgReading.calculated_value);
final double calculated_value;
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);


// TODO: tzachi what is the time of this last bgReading
// If the last reading does not have a sensor, or that sensor was stopped.
// or the sensor was started, but the 2 hours did not still pass? or there is no calibrations.
// In all this cases, bgReading.calculated_value should be 0.
if (((sensor != null) || (Home.get_follower())) && bgReading != null && bgReading.calculated_value != 0) {
AlertType newAlert = AlertType.get_highest_active_alert(context, bgReading.calculated_value);
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");
Expand All @@ -198,7 +222,7 @@ private void FileBasedNotifications(Context context) {
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);
AlertPlayer.getPlayer().startAlert(context, trendingToAlertEnd, newAlert, EditAlertActivity.unitsConvert2Disp(doMgdl, bgReading.calculated_value));
AlertPlayer.getPlayer().startAlert(context, trendingToAlertEnd, newAlert, EditAlertActivity.unitsConvert2Disp(doMgdl, calculated_value));
return;
}

Expand All @@ -217,7 +241,7 @@ private void FileBasedNotifications(Context context) {

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);
AlertPlayer.getPlayer().ClockTick(context, trendingToAlertEnd, EditAlertActivity.unitsConvert2Disp(doMgdl, bgReading.calculated_value));
AlertPlayer.getPlayer().ClockTick(context, trendingToAlertEnd, EditAlertActivity.unitsConvert2Disp(doMgdl, calculated_value));
return;
}
// Currently the ui blocks having two alerts with the same alert value.
Expand Down Expand Up @@ -252,7 +276,7 @@ private void FileBasedNotifications(Context context) {
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);
AlertPlayer.getPlayer().startAlert(context, trendingToAlertEnd, newAlert, EditAlertActivity.unitsConvert2Disp(doMgdl, bgReading.calculated_value));
AlertPlayer.getPlayer().startAlert(context, trendingToAlertEnd, newAlert, EditAlertActivity.unitsConvert2Disp(doMgdl, calculated_value));
} else {
AlertPlayer.getPlayer().stopAlert(context, true, false);
}
Expand Down Expand Up @@ -467,14 +491,24 @@ public synchronized Notification createOngoingNotification(BgGraphBuilder bgGrap
NotificationCompat.Builder b = new NotificationCompat.Builder(mContext);
//b.setOngoing(true);
b.setCategory(NotificationCompat.CATEGORY_STATUS);
String titleString = lastReading == null ? "BG Reading Unavailable" : (lastReading.displayValue(mContext) + " " + lastReading.slopeArrow());
final BestGlucose.DisplayGlucose dg = (use_best_glucose) ? BestGlucose.getDisplayGlucose() : null;
final SpannableString titleString = new SpannableString(lastReading == null ? "BG Reading Unavailable" : (dg != null) ? dg.unitized + " " + dg.delta_arrow
: (lastReading.displayValue(mContext) + " " + lastReading.slopeArrow()));
b.setContentTitle(titleString)
.setContentText("xDrip Data collection service is running.")
.setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
.setUsesChronometer(false);
if (lastReading != null) {

b.setWhen(lastReading.timestamp);
String deltaString = "Delta: " + bgGraphBuilder.unitizedDeltaString(true, true);
final SpannableString deltaString = new SpannableString("Delta: " + ((dg != null) ? dg.unitized_delta + (dg.from_plugin ? " "+context.getString(R.string.p_in_circle) : "")
: bgGraphBuilder.unitizedDeltaString(true, true)));

if ((dg != null) && (dg.stale)) {
deltaString.setSpan(new StrikethroughSpan(), 0, deltaString.length(), 0);
titleString.setSpan(new StrikethroughSpan(), 0, titleString.length(), 0); // reference updatable
}

b.setContentText(deltaString);
iconBitmap = new BgSparklineBuilder(mContext)
.setHeight(64)
Expand Down

0 comments on commit 1b6f5da

Please sign in to comment.