ProfileHelper

This commit is contained in:
Milos Kozak 2020-07-06 21:14:00 +02:00
parent b91f8e668a
commit 2c884821e0
13 changed files with 201 additions and 14 deletions

View file

@ -68,6 +68,7 @@
<activity android:name=".plugins.general.maintenance.activities.PrefImportListActivity" /> <activity android:name=".plugins.general.maintenance.activities.PrefImportListActivity" />
<activity android:name=".historyBrowser.HistoryBrowseActivity" /> <activity android:name=".historyBrowser.HistoryBrowseActivity" />
<activity android:name=".activities.SurveyActivity" /> <activity android:name=".activities.SurveyActivity" />
<activity android:name=".activities.ProfileHelperActivity" />
<activity android:name=".activities.StatsActivity" /> <activity android:name=".activities.StatsActivity" />
<!-- Receive new BG readings from other local apps --> <!-- Receive new BG readings from other local apps -->

View file

@ -27,6 +27,7 @@ import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import com.joanzapata.iconify.Iconify import com.joanzapata.iconify.Iconify
import com.joanzapata.iconify.fonts.FontAwesomeModule import com.joanzapata.iconify.fonts.FontAwesomeModule
import info.nightscout.androidaps.activities.ProfileHelperActivity
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.activities.PreferencesActivity import info.nightscout.androidaps.activities.PreferencesActivity
import info.nightscout.androidaps.activities.SingleFragmentActivity import info.nightscout.androidaps.activities.SingleFragmentActivity
@ -49,10 +50,10 @@ import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicato
import info.nightscout.androidaps.setupwizard.SetupWizardActivity import info.nightscout.androidaps.setupwizard.SetupWizardActivity
import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.AndroidPermission
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.locale.LocaleHelper
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.extensions.isRunningRealPumpTest import info.nightscout.androidaps.utils.extensions.isRunningRealPumpTest
import info.nightscout.androidaps.utils.locale.LocaleHelper
import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.protection.ProtectionCheck
import info.nightscout.androidaps.utils.resources.IconsProvider import info.nightscout.androidaps.utils.resources.IconsProvider
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -324,6 +325,11 @@ class MainActivity : NoSplashAppCompatActivity() {
return true return true
} }
*/ */
R.id.nav_defaultprofile -> {
startActivity(Intent(this, ProfileHelperActivity::class.java))
return true
}
R.id.nav_stats -> { R.id.nav_stats -> {
startActivity(Intent(this, StatsActivity::class.java)) startActivity(Intent(this, StatsActivity::class.java))
return true return true

View file

@ -0,0 +1,66 @@
package info.nightscout.androidaps.activities
import android.os.Bundle
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.defaultProfile.DefaultProfile
import info.nightscout.androidaps.dialogs.ProfileViewerDialog
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.stats.TddCalculator
import kotlinx.android.synthetic.main.activity_profilehelper.*
import java.text.DecimalFormat
import javax.inject.Inject
class ProfileHelperActivity : NoSplashAppCompatActivity() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var tddCalculator: TddCalculator
@Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var defaultProfile: DefaultProfile
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_profilehelper)
profilehelper_age.setParams(15.0, 1.0, 80.0, 1.0, DecimalFormat("0"), false, null)
profilehelper_weight.setParams(50.0, 5.0, 150.0, 1.0, DecimalFormat("0"), false, null)
profilehelper_tdd.setParams(50.0, 3.0, 200.0, 1.0, DecimalFormat("0"), false, null)
profilehelper_tdds.text = tddCalculator.stats()
profilehelper_profile.setOnClickListener {
val age = profilehelper_age.value
val weight = profilehelper_weight.value
val tdd = profilehelper_tdd.value
if (age < 1 || age > 120) {
ToastUtils.showToastInUiThread(this, R.string.invalidage)
return@setOnClickListener
}
if ((weight < 5 || weight > 150) && tdd == 0.0) {
ToastUtils.showToastInUiThread(this, R.string.invalidweight)
return@setOnClickListener
}
if ((tdd < 5 || tdd > 150) && weight == 0.0) {
ToastUtils.showToastInUiThread(this, R.string.invalidweight)
return@setOnClickListener
}
profileFunction.getProfile()?.let { runningProfile ->
val profile = defaultProfile.profile(age, tdd, weight, profileFunction.getUnits())
ProfileViewerDialog().also { pvd ->
pvd.arguments = Bundle().also {
it.putLong("time", DateUtil.now())
it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal)
it.putString("customProfile", runningProfile.data.toString())
it.putString("customProfile2", profile.data.toString())
it.putString("customProfileUnits", profile.units)
it.putString("customProfileName", "Age: $age TDD: $tdd Weight: $weight")
}
}.show(supportFragmentManager, "ProfileViewDialog")
}
}
}
}

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.stats.TddCalculator import info.nightscout.androidaps.utils.stats.TddCalculator
import info.nightscout.androidaps.utils.stats.TirCalculator import info.nightscout.androidaps.utils.stats.TirCalculator
import kotlinx.android.synthetic.main.survey_activity.* import kotlinx.android.synthetic.main.activity_survey.*
import javax.inject.Inject import javax.inject.Inject
class SurveyActivity : NoSplashAppCompatActivity() { class SurveyActivity : NoSplashAppCompatActivity() {
@ -34,7 +34,7 @@ class SurveyActivity : NoSplashAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.survey_activity) setContentView(R.layout.activity_survey)
survey_id.text = InstanceId.instanceId() survey_id.text = InstanceId.instanceId()

View file

@ -38,5 +38,6 @@ abstract class ActivitiesModule {
@ContributesAndroidInjector abstract fun contributesSmsCommunicatorOtpActivity(): SmsCommunicatorOtpActivity @ContributesAndroidInjector abstract fun contributesSmsCommunicatorOtpActivity(): SmsCommunicatorOtpActivity
@ContributesAndroidInjector abstract fun contributesStatsActivity(): StatsActivity @ContributesAndroidInjector abstract fun contributesStatsActivity(): StatsActivity
@ContributesAndroidInjector abstract fun contributesSurveyActivity(): SurveyActivity @ContributesAndroidInjector abstract fun contributesSurveyActivity(): SurveyActivity
@ContributesAndroidInjector abstract fun contributesDefaultProfileActivity(): ProfileHelperActivity
@ContributesAndroidInjector abstract fun contributesPrefImportListActivity(): PrefImportListActivity @ContributesAndroidInjector abstract fun contributesPrefImportListActivity(): PrefImportListActivity
} }

View file

@ -54,6 +54,7 @@ class TddCalculator @Inject constructor(
val midnight = MidnightTime.calc(t.date) val midnight = MidnightTime.calc(t.date)
val tdd = result[midnight] ?: TDD(midnight, 0.0, 0.0, 0.0) val tdd = result[midnight] ?: TDD(midnight, 0.0, 0.0, 0.0)
tdd.bolus += t.insulin tdd.bolus += t.insulin
tdd.carbs += t.carbs
result.put(midnight, tdd) result.put(midnight, tdd)
} }
@ -81,10 +82,12 @@ class TddCalculator @Inject constructor(
totalTdd.basal += tdd.basal totalTdd.basal += tdd.basal
totalTdd.bolus += tdd.bolus totalTdd.bolus += tdd.bolus
totalTdd.total += tdd.total totalTdd.total += tdd.total
totalTdd.carbs += tdd.carbs
} }
totalTdd.basal /= tdds.size().toDouble() totalTdd.basal /= tdds.size().toDouble()
totalTdd.bolus /= tdds.size().toDouble() totalTdd.bolus /= tdds.size().toDouble()
totalTdd.total /= tdds.size().toDouble() totalTdd.total /= tdds.size().toDouble()
totalTdd.carbs /= tdds.size().toDouble()
return totalTdd return totalTdd
} }
@ -93,16 +96,16 @@ class TddCalculator @Inject constructor(
val averageTdd = averageTDD(tdds) val averageTdd = averageTDD(tdds)
return HtmlHelper.fromHtml( return HtmlHelper.fromHtml(
"<b>" + resourceHelper.gs(R.string.tdd) + ":</b><br>" + "<b>" + resourceHelper.gs(R.string.tdd) + ":</b><br>" +
toText(tdds) + toText(tdds, true) +
"<b>" + resourceHelper.gs(R.string.average) + ":</b><br>" + "<b>" + resourceHelper.gs(R.string.average) + ":</b><br>" +
averageTdd.toText(resourceHelper, tdds.size()) averageTdd.toText(resourceHelper, tdds.size(), true)
) )
} }
private fun toText(tdds: LongSparseArray<TDD>): String { private fun toText(tdds: LongSparseArray<TDD>, includeCarbs: Boolean): String {
var t = "" var t = ""
for (i in 0 until tdds.size()) { for (i in 0 until tdds.size()) {
t += "${tdds.valueAt(i).toText(resourceHelper, dateUtil)}<br>" t += "${tdds.valueAt(i).toText(resourceHelper, dateUtil, includeCarbs)}<br>"
} }
return t return t
} }

View file

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.SurveyActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/profilehelper_age_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:labelFor="@+id/profilehelper_age"
android:text="@string/age"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<info.nightscout.androidaps.utils.NumberPicker
android:id="@+id/profilehelper_age"
android:layout_width="130dp"
android:layout_height="40dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/profilehelper_weigth_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:labelFor="@+id/profilehelper_weight"
android:text="@string/weight_label"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<info.nightscout.androidaps.utils.NumberPicker
android:id="@+id/profilehelper_weight"
android:layout_width="130dp"
android:layout_height="40dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/profilehelper_tdd_label"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:labelFor="@+id/profilehelper_weight"
android:text="@string/tdd_total"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<info.nightscout.androidaps.utils.NumberPicker
android:id="@+id/profilehelper_tdd"
android:layout_width="130dp"
android:layout_height="40dp" />
</TableRow>
</TableLayout>
<TextView
android:id="@+id/profilehelper_tdds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
<Button
android:id="@+id/profilehelper_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/comapareprofile" />
</LinearLayout>
</ScrollView>

View file

@ -27,6 +27,10 @@
app:showAsAction="never" app:showAsAction="never"
android:title="@string/nav_survey" /> android:title="@string/nav_survey" />
--> -->
<item
android:id="@+id/nav_defaultprofile"
app:showAsAction="never"
android:title="@string/nav_profilehelper" />
<item <item
android:id="@+id/nav_about" android:id="@+id/nav_about"
app:showAsAction="never" app:showAsAction="never"

View file

@ -1708,5 +1708,7 @@
<string name="omnipod_bolus_failed_uncertain">Unable to verify whether the bolus succeeded. Please verify that your Pod is bolusing or cancel the bolus.</string> <string name="omnipod_bolus_failed_uncertain">Unable to verify whether the bolus succeeded. Please verify that your Pod is bolusing or cancel the bolus.</string>
<string name="omnipod_rl_stats">RL Stats</string> <string name="omnipod_rl_stats">RL Stats</string>
<string name="omnipod_read_pulse_log_short">Pulse Log</string> <string name="omnipod_read_pulse_log_short">Pulse Log</string>
<string name="comapareprofile">Compare with current profile</string>
<string name="nav_profilehelper">Profile helper</string>
</resources> </resources>

View file

@ -126,7 +126,7 @@ class DefaultProfile @Inject constructor(val injector: HasAndroidInjector) {
return res return res
} }
fun arrayToJson(b: Array<Double>): JSONArray { private fun arrayToJson(b: Array<Double>): JSONArray {
val basals = JSONArray() val basals = JSONArray()
for (i in 0..23) { for (i in 0..23) {
val time = String.format(Locale.ENGLISH, "%02d:00", i) val time = String.format(Locale.ENGLISH, "%02d:00", i)
@ -135,7 +135,7 @@ class DefaultProfile @Inject constructor(val injector: HasAndroidInjector) {
return basals return basals
} }
fun singleValueArray(value: Double, sample: Array<Double>): JSONArray { private fun singleValueArray(value: Double, sample: Array<Double>): JSONArray {
val array = JSONArray() val array = JSONArray()
array.put(JSONObject().put("time", "00:00").put("value", value + sample[0])) array.put(JSONObject().put("time", "00:00").put("value", value + sample[0]))
array.put(JSONObject().put("time", "06:00").put("value", value + sample[1])) array.put(JSONObject().put("time", "06:00").put("value", value + sample[1]))

View file

@ -29,6 +29,7 @@ public class TDD {
@DatabaseField @DatabaseField
public double total; public double total;
public double carbs;
public double getTotal() { public double getTotal() {
return (total > 0d) ? total : (bolus + basal); return (total > 0d) ? total : (bolus + basal);
@ -56,11 +57,17 @@ public class TDD {
']'; ']';
} }
public String toText(ResourceHelper resourceHelper, DateUtil dateUtil) { public String toText(ResourceHelper resourceHelper, DateUtil dateUtil, boolean includeCarbs) {
return resourceHelper.gs(R.string.tddformat, dateUtil.dateStringShort(date), total, bolus, basal); if (includeCarbs)
return resourceHelper.gs(R.string.tddwithcarbsformat, dateUtil.dateStringShort(date), total, bolus, basal, carbs);
else
return resourceHelper.gs(R.string.tddformat, dateUtil.dateStringShort(date), total, bolus, basal);
} }
public String toText(ResourceHelper resourceHelper, int days) { public String toText(ResourceHelper resourceHelper, int days, boolean includeCarbs) {
return resourceHelper.gs(R.string.tddformat, String.format(Locale.getDefault(), "%d ", days) + resourceHelper.gs(R.string.days), total, bolus, basal); if (includeCarbs)
return resourceHelper.gs(R.string.tddwithcarbsformat, String.format(Locale.getDefault(), "%d ", days) + resourceHelper.gs(R.string.days), total, bolus, basal, carbs);
else
return resourceHelper.gs(R.string.tddformat, String.format(Locale.getDefault(), "%d ", days) + resourceHelper.gs(R.string.days), total, bolus, basal);
} }
} }

View file

@ -156,7 +156,8 @@
<string name="mins">%1$dmin</string> <string name="mins">%1$dmin</string>
<!-- TDD--> <!-- TDD-->
<string name="tddformat"><![CDATA[<b>%1$s:</b> ∑: <b>%2$.2f</b> Bol: <b>%3$.2f</b> Bas: <b>%4$.2f</b>]]></string> <string name="tddformat"><![CDATA[<b>%1$s:</b> ∑: <b>%2$.2fU</b> Bol: <b>%3$.2fU</b> Bas: <b>%4$.2fU</b>]]></string>
<string name="tddwithcarbsformat"><![CDATA[<b>%1$s:</b> ∑: <b>%2$.2fU</b> Bol: <b>%3$.2fU</b> Bas: <b>%4$.2fU</b> Carbs: <b>%5$.0fg</b>]]></string>
<!-- Translator--> <!-- Translator-->
<string name="careportal_bgcheck">BG Check</string> <string name="careportal_bgcheck">BG Check</string>