OpenAPS Offline visualization fix
This commit is contained in:
parent
a4b3b7b2e9
commit
de2273836e
3 changed files with 97 additions and 18 deletions
|
@ -24,6 +24,7 @@ import info.nightscout.androidaps.Constants;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.interfaces.Interval;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg;
|
||||
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
|
||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
||||
|
@ -33,7 +34,7 @@ import info.nightscout.utils.T;
|
|||
import info.nightscout.utils.Translator;
|
||||
|
||||
@DatabaseTable(tableName = DatabaseHelper.DATABASE_CAREPORTALEVENTS)
|
||||
public class CareportalEvent implements DataPointWithLabelInterface {
|
||||
public class CareportalEvent implements DataPointWithLabelInterface, Interval {
|
||||
private static Logger log = LoggerFactory.getLogger(CareportalEvent.class);
|
||||
|
||||
@DatabaseField(id = true)
|
||||
|
@ -221,14 +222,7 @@ public class CareportalEvent implements DataPointWithLabelInterface {
|
|||
|
||||
@Override
|
||||
public long getDuration() {
|
||||
try {
|
||||
JSONObject object = new JSONObject(json);
|
||||
if (object.has("duration"))
|
||||
return object.getInt("duration") * 60 * 1000L;
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
return 0;
|
||||
return end() - start();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -267,8 +261,79 @@ public class CareportalEvent implements DataPointWithLabelInterface {
|
|||
if (eventType.equals(EXERCISE))
|
||||
return Color.BLUE;
|
||||
if (eventType.equals(OPENAPSOFFLINE))
|
||||
return Color.GRAY;
|
||||
return Color.GRAY & 0x80FFFFFF;
|
||||
return Color.GRAY;
|
||||
}
|
||||
|
||||
// Interval interface
|
||||
Long cuttedEnd = null;
|
||||
|
||||
@Override
|
||||
public long durationInMsec() {
|
||||
try {
|
||||
JSONObject object = new JSONObject(json);
|
||||
if (object.has("duration"))
|
||||
return object.getInt("duration") * 60 * 1000L;
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long start() {
|
||||
return date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long originalEnd() {
|
||||
return date + durationInMsec();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long end() {
|
||||
if (cuttedEnd != null)
|
||||
return cuttedEnd;
|
||||
return originalEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cutEndTo(long end) {
|
||||
cuttedEnd = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(long time) {
|
||||
if (start() <= time && end() >= time)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean before(long time) {
|
||||
if (end() < time)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean after(long time) {
|
||||
if (start() > time)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInProgress() {
|
||||
return match(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEndingEvent() {
|
||||
return durationInMsec() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return eventType.equals(OPENAPSOFFLINE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.data.OverlappingIntervals;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.data.ProfileStore;
|
||||
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
||||
|
@ -1242,6 +1243,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
where.ge("date", mills);
|
||||
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
|
||||
careportalEvents = getDaoCareportalEvents().query(preparedQuery);
|
||||
preprocessOpenAPSOfflineEvents(careportalEvents);
|
||||
return careportalEvents;
|
||||
} catch (SQLException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
|
@ -1249,6 +1251,16 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public void preprocessOpenAPSOfflineEvents(List<CareportalEvent> list) {
|
||||
OverlappingIntervals offlineEvents = new OverlappingIntervals();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
CareportalEvent event = list.get(i);
|
||||
if (!event.eventType.equals(CareportalEvent.OPENAPSOFFLINE)) continue;
|
||||
offlineEvents.add(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<CareportalEvent> getCareportalEventsFromTime(long mills, String type, boolean ascending) {
|
||||
try {
|
||||
List<CareportalEvent> careportalEvents;
|
||||
|
@ -1258,6 +1270,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
where.ge("date", mills).and().eq("eventType", type);
|
||||
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
|
||||
careportalEvents = getDaoCareportalEvents().query(preparedQuery);
|
||||
preprocessOpenAPSOfflineEvents(careportalEvents);
|
||||
return careportalEvents;
|
||||
} catch (SQLException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
|
@ -1272,6 +1285,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
queryBuilder.orderBy("date", ascending);
|
||||
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
|
||||
careportalEvents = getDaoCareportalEvents().query(preparedQuery);
|
||||
preprocessOpenAPSOfflineEvents(careportalEvents);
|
||||
return careportalEvents;
|
||||
} catch (SQLException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
|
|
|
@ -312,20 +312,20 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
|
|||
mPaint.setStrokeWidth(5);
|
||||
canvas.drawRect(px - 3, bounds.top + py - 3, xpluslength + 3, bounds.bottom + py + 3, mPaint);
|
||||
}
|
||||
} else if (value.getShape() == Shape.OPENAPSOFFLINE) {
|
||||
} else if (value.getShape() == Shape.OPENAPSOFFLINE && value.getDuration() != 0) {
|
||||
mPaint.setStrokeWidth(0);
|
||||
if (value.getLabel() != null) {
|
||||
mPaint.setStrokeWidth(0);
|
||||
mPaint.setTextSize(scaledTextSize);
|
||||
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
|
||||
//mPaint.setStrokeWidth(0);
|
||||
//mPaint.setTextSize(scaledTextSize);
|
||||
//mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
|
||||
Rect bounds = new Rect();
|
||||
mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds);
|
||||
mPaint.setStyle(Paint.Style.STROKE);
|
||||
//mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds);
|
||||
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||
float px = endX;
|
||||
float py = graphTop + 50;
|
||||
canvas.drawText(value.getLabel(), px, py, mPaint);
|
||||
//canvas.drawText(value.getLabel(), px, py, mPaint);
|
||||
mPaint.setStrokeWidth(5);
|
||||
canvas.drawRect(px - 3, bounds.top + py - 3, xpluslength + 3, bounds.bottom + py + 3, mPaint);
|
||||
canvas.drawRect(px - 3, graphTop, xpluslength + 3, graphTop + graphHeight, mPaint);
|
||||
}
|
||||
} else if (value.getShape() == Shape.GENERALWITHDURATION) {
|
||||
mPaint.setStrokeWidth(0);
|
||||
|
|
Loading…
Reference in a new issue