Merge branch 'master' into koreandanar

This commit is contained in:
Milos Kozak 2016-12-06 23:18:02 +01:00
commit be8003da4b
15 changed files with 338 additions and 23 deletions

View file

@ -22,7 +22,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
}
var bg = glucose_status.glucose;
if (bg < 30) { //Dexcom is in ??? mode or calibrating, do nothing. Asked @benwest for raw data in iter_glucose
if (bg < 38) { //Dexcom is in ??? mode or calibrating, do nothing. Asked @benwest for raw data in iter_glucose
rT.error = "CGM is calibrating or in ??? state";
return rT;
}

View file

@ -159,6 +159,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
queryBuilder.orderBy("timeIndex", false);
queryBuilder.limit(1L);
queryBuilder.where().gt("value", 38);
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
bgList = daoBgReadings.query(preparedQuery);
@ -196,6 +197,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
queryBuilder.orderBy("timeIndex", true);
Where where = queryBuilder.where();
where.ge("timeIndex", mills);
queryBuilder.where().gt("value", 38);
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
bgReadings = daoBgreadings.query(preparedQuery);
return bgReadings;
@ -281,6 +283,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
List<BgReading> bgReadings;
QueryBuilder<BgReading, Long> queryBuilder = daoBgreadings.queryBuilder();
queryBuilder.orderBy("timeIndex", false);
queryBuilder.where().gt("value", 38);
queryBuilder.limit(4l);
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
bgReadings = daoBgreadings.query(preparedQuery);
@ -300,13 +303,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
BgReading last = bgReadings.get(sizeRecords - 3);
BgReading last1 = bgReadings.get(sizeRecords - 2);
BgReading last2 = bgReadings.get(sizeRecords - 1);
if (last2.value > 30) {
if (last2.value > 38) {
minutes = (now.timeIndex - last2.timeIndex)/(60d*1000);
change = now.value - last2.value;
} else if (last1.value > 30) {
} else if (last1.value > 38) {
minutes = (now.timeIndex - last1.timeIndex)/(60d*1000);;
change = now.value - last1.value;
} else if (last.value > 30) {
} else if (last.value > 38) {
minutes = (now.timeIndex - last.timeIndex)/(60d*1000);
change = now.value - last.value;
} else {

View file

@ -128,21 +128,21 @@ public class DanaRPump {
profile.put("dia", dia);
JSONArray carbratios = new JSONArray();
carbratios.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCF));
carbratios.put(new JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCF));
carbratios.put(new JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCF));
carbratios.put(new JSONObject().put("time", "14:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCF));
carbratios.put(new JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCF));
carbratios.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCIR));
carbratios.put(new JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCIR));
carbratios.put(new JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCIR));
carbratios.put(new JSONObject().put("time", "14:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCIR));
carbratios.put(new JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCIR));
profile.put("carbratio", carbratios);
profile.put("carbs_hr", car);
JSONArray sens = new JSONArray();
sens.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCIR));
sens.put(new JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCIR));
sens.put(new JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCIR));
sens.put(new JSONObject().put("time", "17:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCIR));
sens.put(new JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCIR));
sens.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCF));
sens.put(new JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCF));
sens.put(new JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCF));
sens.put(new JSONObject().put("time", "17:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCF));
sens.put(new JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCF));
profile.put("sens", sens);
JSONArray basals = new JSONArray();

View file

@ -295,7 +295,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
bgDiff = lastBgValue - targetBGHigh;
}
bg.setText(lastBg.valueToUnitsToString(units) + " ISF: " + DecimalFormatter.to0Decimal(sens));
bg.setText(lastBg.valueToUnitsToString(units) + " ISF: " + DecimalFormatter.to1Decimal(sens));
bgInsulin.setText(DecimalFormatter.to2Decimal(bgDiff / sens) + "U");
bgInput.removeTextChangedListener(textWatcher);
//bgInput.setText(lastBg.valueToUnitsToString(units));
@ -368,10 +368,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
BolusWizard wizard = new BolusWizard();
wizard.doCalc(specificProfile, carbsAfterConstraint, c_bg, corrAfterConstraint, bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked());
bg.setText(c_bg + " ISF: " + DecimalFormatter.to0Decimal(wizard.sens));
bg.setText(c_bg + " ISF: " + DecimalFormatter.to1Decimal(wizard.sens));
bgInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromBG) + "U");
carbs.setText(DecimalFormatter.to0Decimal(c_carbs) + "g IC: " + DecimalFormatter.to0Decimal(wizard.ic));
carbs.setText(DecimalFormatter.to0Decimal(c_carbs) + "g IC: " + DecimalFormatter.to1Decimal(wizard.ic));
carbsInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromCarbs) + "U");
bolusIobInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulingFromBolusIOB) + "U");

View file

@ -0,0 +1,20 @@
package info.nightscout.androidaps.plugins.Overview;
import java.util.Date;
/**
* Created by mike on 03.12.2016.
*/
public class Notification {
public static final int URGENT = 0;
public static final int NORMAL = 1;
public static final int LOW = 2;
public static final int INFO = 3;
public int id;
Date date;
String text;
Date validTo = new Date(0);
int level;
}

View file

@ -0,0 +1,60 @@
package info.nightscout.androidaps.plugins.Overview;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
/**
* Created by mike on 03.12.2016.
*/
public class NotificationStore {
public List<Notification> store = new ArrayList<Notification>();
public NotificationStore() {
}
public class NotificationComparator implements Comparator<Notification> {
@Override
public int compare(Notification o1, Notification o2) {
return o1.level - o2.level;
}
}
public Notification get(int index) {
return store.get(index);
}
public void add(Notification n) {
for (int i = 0; i < store.size(); i++) {
if (get(i).id == n.id) {
get(i).date = n.date;
get(i).validTo = n.validTo;
return;
}
}
store.add(n);
Collections.sort(store, new NotificationComparator());
}
public void remove(int id) {
for (int i = 0; i < store.size(); i++) {
if (get(i).id == id) {
store.remove(i);
return;
}
}
}
public void removeExpired() {
for (int i = 0; i < store.size(); i++) {
Notification n = get(i);
if (n.validTo.getTime() != 0 && n.validTo.getTime() < new Date().getTime()) {
store.remove(i);
}
}
}
}

View file

@ -14,6 +14,9 @@ import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.View;
@ -35,6 +38,7 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
@ -69,6 +73,8 @@ import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
import info.nightscout.androidaps.plugins.Overview.GraphSeriesExtension.PointsWithLabelGraphSeries;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
@ -98,6 +104,9 @@ public class OverviewFragment extends Fragment {
TextView apsModeView;
GraphView bgGraph;
RecyclerView notificationsView;
LinearLayoutManager llm;
LinearLayout cancelTempLayout;
LinearLayout acceptTempLayout;
LinearLayout quickWizardLayout;
@ -148,6 +157,11 @@ public class OverviewFragment extends Fragment {
quickWizardButton = (Button) view.findViewById(R.id.overview_quickwizard);
quickWizardLayout = (LinearLayout) view.findViewById(R.id.overview_quickwizardlayout);
notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications);
notificationsView.setHasFixedSize(true);
llm = new LinearLayoutManager(view.getContext());
notificationsView.setLayoutManager(llm);
treatmentButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -383,6 +397,12 @@ public class OverviewFragment extends Fragment {
@Subscribe
public void onStatusEvent(final EventNewBasalProfile ev) { updateGUIIfVisible(); }
@Subscribe
public void onStatusEvent(final EventNewNotification n) { updateNotifications(); }
@Subscribe
public void onStatusEvent(final EventDismissNotification n) { updateNotifications(); }
private void hideTempRecommendation() {
Activity activity = getActivity();
if (activity != null)
@ -407,6 +427,7 @@ public class OverviewFragment extends Fragment {
@SuppressLint("SetTextI18n")
public void updateGUI() {
updateNotifications();
BgReading actualBG = MainApp.getDbHelper().actualBg();
BgReading lastBG = MainApp.getDbHelper().lastBg();
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
@ -758,4 +779,95 @@ public class OverviewFragment extends Fragment {
}
//Notifications
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.NotificationsViewHolder> {
List<Notification> notificationsList;
RecyclerViewAdapter(List<Notification> notificationsList) {
this.notificationsList = notificationsList;
}
@Override
public NotificationsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_notification_item, viewGroup, false);
NotificationsViewHolder notificationsViewHolder = new NotificationsViewHolder(v);
return notificationsViewHolder;
}
@Override
public void onBindViewHolder(NotificationsViewHolder holder, int position) {
DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
Notification notification = notificationsList.get(position);
holder.dismiss.setTag(notification);
holder.text.setText(notification.text);
holder.time.setText(df.format(notification.date));
if (notification.level == Notification.URGENT)
holder.cv.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.notificationUrgent));
else if (notification.level == Notification.NORMAL)
holder.cv.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.notificationNormal));
else if (notification.level == Notification.LOW)
holder.cv.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.notificationLow));
else if (notification.level == Notification.INFO)
holder.cv.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.notificationInfo));
}
@Override
public int getItemCount() {
return notificationsList.size();
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
CardView cv;
TextView time;
TextView text;
Button dismiss;
NotificationsViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.notification_cardview);
time = (TextView) itemView.findViewById(R.id.notification_time);
text = (TextView) itemView.findViewById(R.id.notification_text);
dismiss = (Button) itemView.findViewById(R.id.notification_dismiss);
dismiss.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Notification notification = (Notification) v.getTag();
switch (v.getId()) {
case R.id.notification_dismiss:
MainApp.bus().post(new EventDismissNotification(notification.id));
break;
}
}
}
}
void updateNotifications() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
NotificationStore nstore = getPlugin().notificationStore;
nstore.removeExpired();
if (nstore.store.size() > 0) {
RecyclerViewAdapter adapter = new RecyclerViewAdapter(nstore.store);
notificationsView.setAdapter(adapter);
notificationsView.setVisibility(View.VISIBLE);
} else {
notificationsView.setVisibility(View.GONE);
}
}
});
}
}

View file

@ -3,12 +3,16 @@ package info.nightscout.androidaps.plugins.Overview;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.squareup.otto.Subscribe;
import org.json.JSONArray;
import org.json.JSONException;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
/**
* Created by mike on 05.08.2016.
@ -20,6 +24,8 @@ public class OverviewPlugin implements PluginBase {
public QuickWizard quickWizard = new QuickWizard();
public NotificationStore notificationStore = new NotificationStore();
public OverviewPlugin() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
String storedData = preferences.getString("QuickWizard", "[]");
@ -28,6 +34,7 @@ public class OverviewPlugin implements PluginBase {
} catch (JSONException e) {
e.printStackTrace();
}
MainApp.bus().register(this);
}
@Override
@ -71,4 +78,14 @@ public class OverviewPlugin implements PluginBase {
}
@Subscribe
public void onStatusEvent(final EventNewNotification n) {
notificationStore.add(n.notification);
}
@Subscribe
public void onStatusEvent(final EventDismissNotification n) {
notificationStore.remove(n.id);
}
}

View file

@ -0,0 +1,14 @@
package info.nightscout.androidaps.plugins.Overview.events;
/**
* Created by mike on 03.12.2016.
*/
public class EventDismissNotification {
public int id;
public EventDismissNotification(int did) {
id = did;
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.Overview.events;
import info.nightscout.androidaps.plugins.Overview.Notification;
/**
* Created by mike on 03.12.2016.
*/
public class EventNewNotification {
public Notification notification;
public EventNewNotification(Notification n) {
notification = n;
}
}

View file

@ -35,6 +35,7 @@ import info.nightscout.androidaps.plugins.Wear.WearPlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;
public class WatchUpdaterService extends WearableListenerService implements
GoogleApiClient.ConnectionCallbacks,
@ -139,7 +140,7 @@ public class WatchUpdaterService extends WearableListenerService implements
}
}
public void sendData() {
private void sendData() {
BgReading lastBG = MainApp.getDbHelper().lastBg();
if (lastBG != null) {
@ -147,14 +148,21 @@ public class WatchUpdaterService extends WearableListenerService implements
if(googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); }
if (wear_integration) {
new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(dataMapSingleBG(lastBG, glucoseStatus));
final DataMap dataMap = dataMapSingleBG(lastBG, glucoseStatus);
if(dataMap==null) {
ToastUtils.showToastInUiThread(this, getString(R.string.noprofile));
return;
}
new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(dataMap);
}
}
}
private DataMap dataMapSingleBG(BgReading lastBG, DatabaseHelper.GlucoseStatus glucoseStatus) {
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
if(profile == null) return null;
Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0"));
Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0"));
@ -251,9 +259,16 @@ public class WatchUpdaterService extends WearableListenerService implements
if (!graph_bgs.isEmpty()) {
DataMap entries = dataMapSingleBG(last_bg, glucoseStatus);
if(entries==null) {
ToastUtils.showToastInUiThread(this, getString(R.string.noprofile));
return;
}
final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
for (BgReading bg : graph_bgs) {
dataMaps.add(dataMapSingleBG(bg, glucoseStatus));
DataMap dataMap = dataMapSingleBG(bg, glucoseStatus);
if(dataMap != null) {
dataMaps.add(dataMap);
}
}
entries.putDataMapArrayList("entries", dataMaps);
new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(entries);
@ -276,7 +291,9 @@ public class WatchUpdaterService extends WearableListenerService implements
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
if( profile == null) return;
if(profile==null) {
return;
}
long beginBasalSegmentTime = startTimeWindow;
long runningTime = startTimeWindow;

View file

@ -13,6 +13,13 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/overview_notifications"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/notification_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
card_view:cardBackgroundColor="@color/cardColorBackground"
card_view:cardCornerRadius="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:text="Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/notification_time"
android:layout_weight="0.1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/notification_text"
android:layout_weight="1"
android:text="Notification text" />
<Button
android:text="Dismiss"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:id="@+id/notification_dismiss"
android:layout_weight="0.2" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

View file

@ -24,4 +24,9 @@
<color name="colorPumpLabel">#779ECB</color>
<color name="cardItemLabel">#FF478EFF</color>
<color name="notificationUrgent">#ff0400</color>
<color name="notificationNormal">#ff5e55</color>
<color name="notificationLow">#ff827c</color>
<color name="notificationInfo">#009705</color>
</resources>

View file

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files