Merge pull request #2297 from MilosKozak/maintenance/cleanups

small cleanups
This commit is contained in:
Milos Kozak 2019-12-21 10:16:12 +01:00 committed by GitHub
commit b946326c2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 43 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

@ -39,8 +39,7 @@ public class SingleFragmentActivity extends AppCompatActivity {
if (item.getItemId() == android.R.id.home) { if (item.getItemId() == android.R.id.home) {
finish(); finish();
return true; return true;
} } else if (item.getItemId() == R.id.nav_plugin_preferences) {
else if (item.getItemId() == R.id.nav_plugin_preferences) {
PasswordProtection.QueryPassword(this, R.string.settings_password, "settings_password", () -> { PasswordProtection.QueryPassword(this, R.string.settings_password, "settings_password", () -> {
Intent i = new Intent(this, PreferencesActivity.class); Intent i = new Intent(this, PreferencesActivity.class);
i.putExtra("id", plugin.getPreferencesId()); i.putExtra("id", plugin.getPreferencesId());

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

@ -4,25 +4,21 @@ import android.os.Bundle
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.FirebaseDatabase import com.google.firebase.database.FirebaseDatabase
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.defaultProfile.DefaultProfile import info.nightscout.androidaps.data.defaultProfile.DefaultProfile
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin 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.plugins.treatments.fragments.ProfileViewerDialog import info.nightscout.androidaps.plugins.treatments.fragments.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
import java.util.*
class SurveyActivity : NoSplashAppCompatActivity() { class SurveyActivity : NoSplashAppCompatActivity() {
private val log = LoggerFactory.getLogger(SurveyActivity::class.java) private val log = LoggerFactory.getLogger(SurveyActivity::class.java)
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()
@ -88,7 +84,7 @@ class SurveyActivity : NoSplashAppCompatActivity() {
.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)

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

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)