Merge branch 'dev' into dialogs

This commit is contained in:
Milos Kozak 2019-12-22 23:04:21 +01:00
commit 3a6f29d1dc
9 changed files with 73 additions and 45 deletions

View file

@ -82,4 +82,11 @@ public class Constants {
public static final double LOWMARK = 76.0; public static final double LOWMARK = 76.0;
public static final double HIGHMARK = 180.0; public static final double HIGHMARK = 180.0;
// STATISTICS
public static final double STATS_TARGET_LOW_MMOL = 3.9;
public static final double STATS_TARGET_HIGH_MMOL = 7.8;
public static final double STATS_RANGE_LOW_MMOL = 3.9;
public static final double STATS_RANGE_HIGH_MMOL = 10.0;
} }

View file

@ -9,7 +9,6 @@ import info.nightscout.androidaps.utils.TddCalculator
import info.nightscout.androidaps.utils.TirCalculator import info.nightscout.androidaps.utils.TirCalculator
import kotlinx.android.synthetic.main.stats_activity.* import kotlinx.android.synthetic.main.stats_activity.*
class StatsActivity : NoSplashAppCompatActivity() { class StatsActivity : NoSplashAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {

View file

@ -10,7 +10,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.dialogs.ProfileViewerDialog
import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.*
import kotlinx.android.synthetic.main.survey_fragment.* import kotlinx.android.synthetic.main.survey_activity.*
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
class SurveyActivity : NoSplashAppCompatActivity() { class SurveyActivity : NoSplashAppCompatActivity() {
@ -18,7 +18,7 @@ class SurveyActivity : NoSplashAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.survey_fragment) setContentView(R.layout.survey_activity)
survey_id.text = InstanceId.instanceId() survey_id.text = InstanceId.instanceId()
@ -81,21 +81,21 @@ class SurveyActivity : NoSplashAppCompatActivity() {
val auth = FirebaseAuth.getInstance() val auth = FirebaseAuth.getInstance()
auth.signInAnonymously() auth.signInAnonymously()
.addOnCompleteListener(this) { task -> .addOnCompleteListener(this) { task ->
if (task.isSuccessful) { if (task.isSuccessful) {
log.debug("signInAnonymously:success") log.debug("signInAnonymously:success")
val user = auth.currentUser val user = auth.currentUser // TODO: do we need this, seems unused?
val database = FirebaseDatabase.getInstance().reference val database = FirebaseDatabase.getInstance().reference
database.child("survey").child(r.id).setValue(r) database.child("survey").child(r.id).setValue(r)
} else { } else {
log.error("signInAnonymously:failure", task.exception) log.error("signInAnonymously:failure", task.exception)
ToastUtils.showToastInUiThread(this, "Authentication failed.") ToastUtils.showToastInUiThread(this, "Authentication failed.")
//updateUI(null) //updateUI(null)
}
// ...
} }
// ...
}
finish() finish()
} }
} }

View file

@ -47,7 +47,7 @@ class ProfileStore(val data: JSONObject) {
if (profile == null) { if (profile == null) {
JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject -> JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject ->
// take units from profile and if N/A from store // take units from profile and if N/A from store
JsonHelper.safeGetStringAllowNull(profileObject, "units", JsonHelper.safeGetString(store, "units"))?.let { units -> JsonHelper.safeGetStringAllowNull(profileObject, "units", JsonHelper.safeGetString(data, "units"))?.let { units ->
profile = Profile(profileObject, units) profile = Profile(profileObject, units)
cachedObjects[profileName] = profile cachedObjects[profileName] = profile
} }

View file

@ -1602,15 +1602,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
queryBuilder.limit(100L); queryBuilder.limit(100L);
Where where = queryBuilder.where(); Where where = queryBuilder.where();
where.ge("date", from); where.ge("date", from);
queryBuilder.setCountOf(true);
PreparedQuery<ProfileSwitch> preparedQuery = queryBuilder.prepare(); PreparedQuery<ProfileSwitch> preparedQuery = queryBuilder.prepare();
long count = daoProfileSwitch.countOf(preparedQuery);
// now do query of count + 1
queryBuilder = daoProfileSwitch.queryBuilder();
queryBuilder.orderBy("date", ascending);
queryBuilder.limit(count + 1);
preparedQuery = queryBuilder.prepare();
profileSwitches = daoProfileSwitch.query(preparedQuery); profileSwitches = daoProfileSwitch.query(preparedQuery);
//add last one without duration
ProfileSwitch last = getLastProfileSwitchWithoutDuration();
if (last != null) {
if (!profileSwitches.contains(last))
profileSwitches.add(last);
}
return profileSwitches; return profileSwitches;
} catch (SQLException e) { } catch (SQLException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
@ -1618,6 +1617,28 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return new ArrayList<>(); return new ArrayList<>();
} }
@Nullable
private ProfileSwitch getLastProfileSwitchWithoutDuration() {
try {
Dao<ProfileSwitch, Long> daoProfileSwitch = getDaoProfileSwitch();
List<ProfileSwitch> profileSwitches;
QueryBuilder<ProfileSwitch, Long> queryBuilder = daoProfileSwitch.queryBuilder();
queryBuilder.orderBy("date", false);
queryBuilder.limit(1L);
Where where = queryBuilder.where();
where.eq("durationInMinutes", 0);
PreparedQuery<ProfileSwitch> preparedQuery = queryBuilder.prepare();
profileSwitches = daoProfileSwitch.query(preparedQuery);
if (profileSwitches.size() > 0)
return profileSwitches.get(0);
else
return null;
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return null;
}
public List<ProfileSwitch> getProfileSwitchEventsFromTime(long mills, boolean ascending) { public List<ProfileSwitch> getProfileSwitchEventsFromTime(long mills, boolean ascending) {
try { try {
Dao<ProfileSwitch, Long> daoProfileSwitch = getDaoProfileSwitch(); Dao<ProfileSwitch, Long> daoProfileSwitch = getDaoProfileSwitch();

View file

@ -62,7 +62,7 @@ object ActivityMonitor : Application.ActivityLifecycleCallbacks {
return result return result
} }
fun stats() :Spanned { fun stats(): Spanned {
return HtmlHelper.fromHtml("<br><b>" + MainApp.gs(R.string.activitymonitor) + ":</b><br>" + toText()) return HtmlHelper.fromHtml("<br><b>" + MainApp.gs(R.string.activitymonitor) + ":</b><br>" + toText())
} }

View file

@ -19,7 +19,6 @@ object TddCalculator : TreatmentsPlugin() {
val endTime = MidnightTime.calc(DateUtil.now()) val endTime = MidnightTime.calc(DateUtil.now())
initializeData(range) initializeData(range)
val result = LongSparseArray<TDD>() val result = LongSparseArray<TDD>()
for (t in treatmentsFromHistory) { for (t in treatmentsFromHistory) {
if (!t.isValid) continue if (!t.isValid) continue
@ -65,10 +64,10 @@ object TddCalculator : TreatmentsPlugin() {
val tdds = calculate(7) val tdds = calculate(7)
val averageTdd = averageTDD(tdds) val averageTdd = averageTDD(tdds)
return HtmlHelper.fromHtml( return HtmlHelper.fromHtml(
"<b>" + MainApp.gs(R.string.tdd) + ":</b><br>" + "<b>" + MainApp.gs(R.string.tdd) + ":</b><br>" +
toText(tdds) + toText(tdds) +
"<b>" + MainApp.gs(R.string.average) + ":</b><br>" + "<b>" + MainApp.gs(R.string.average) + ":</b><br>" +
averageTdd.toText(tdds.size()) averageTdd.toText(tdds.size())
) )
} }

View file

@ -32,9 +32,11 @@ object TirCalculator {
} }
fun averageTIR(tirs: LongSparseArray<TIR>): TIR { fun averageTIR(tirs: LongSparseArray<TIR>): TIR {
val totalTir = val totalTir = if (tirs.size() > 0) {
if (tirs.size() > 0) TIR(tirs.valueAt(0).date, tirs.valueAt(0).lowThreshold, tirs.valueAt(0).highThreshold) TIR(tirs.valueAt(0).date, tirs.valueAt(0).lowThreshold, tirs.valueAt(0).highThreshold)
else TIR(7, 70.0, 180.0) } else {
TIR(7, 70.0, 180.0)
}
for (i in 0 until tirs.size()) { for (i in 0 until tirs.size()) {
val tir = tirs.valueAt(i) val tir = tirs.valueAt(i)
totalTir.below += tir.below totalTir.below += tir.below
@ -47,10 +49,10 @@ object TirCalculator {
} }
fun stats(): Spanned { fun stats(): Spanned {
val lowTirMgdl = 3.9 * Constants.MMOLL_TO_MGDL val lowTirMgdl = Constants.STATS_RANGE_LOW_MMOL * Constants.MMOLL_TO_MGDL
val highTirMgdl = 10.0 * Constants.MMOLL_TO_MGDL val highTirMgdl = Constants.STATS_RANGE_HIGH_MMOL * Constants.MMOLL_TO_MGDL
val lowTitMgdl = 3.9 * Constants.MMOLL_TO_MGDL val lowTitMgdl = Constants.STATS_TARGET_LOW_MMOL * Constants.MMOLL_TO_MGDL
val highTitMgdl = 7.8 * Constants.MMOLL_TO_MGDL val highTitMgdl = Constants.STATS_TARGET_HIGH_MMOL * Constants.MMOLL_TO_MGDL
val tir7 = calculate(7, lowTirMgdl, highTirMgdl) val tir7 = calculate(7, lowTirMgdl, highTirMgdl)
val averageTir7 = averageTIR(tir7) val averageTir7 = averageTIR(tir7)
@ -61,14 +63,14 @@ object TirCalculator {
val tit30 = calculate(30, lowTitMgdl, highTitMgdl) val tit30 = calculate(30, lowTitMgdl, highTitMgdl)
val averageTit30 = averageTIR(tit30) val averageTit30 = averageTIR(tit30)
return HtmlHelper.fromHtml( return HtmlHelper.fromHtml(
"<br><b>" + MainApp.gs(R.string.tir) + ":</b><br>" + "<br><b>" + MainApp.gs(R.string.tir) + ":</b><br>" +
toText(tir7) + toText(tir7) +
"<br><b>" + MainApp.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTirMgdl) + "-" + Profile.toCurrentUnitsString(highTirMgdl) + "):</b><br>" + "<br><b>" + MainApp.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTirMgdl) + "-" + Profile.toCurrentUnitsString(highTirMgdl) + "):</b><br>" +
averageTir7.toText(tir7.size()) + "<br>" + averageTir7.toText(tir7.size()) + "<br>" +
averageTir30.toText(tir30.size()) + averageTir30.toText(tir30.size()) +
"<br><b>" + MainApp.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTitMgdl) + "-" + Profile.toCurrentUnitsString(highTitMgdl) + "):</b><br>" + "<br><b>" + MainApp.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTitMgdl) + "-" + Profile.toCurrentUnitsString(highTitMgdl) + "):</b><br>" +
averageTit7.toText(tit7.size()) + "<br>" + averageTit7.toText(tit7.size()) + "<br>" +
averageTit30.toText(tit30.size()) averageTit30.toText(tit30.size())
) )
} }