Measure activity
This commit is contained in:
parent
00cd2ba343
commit
a9e08bd08d
|
@ -41,6 +41,8 @@ class SurveyActivity : NoSplashAppCompatActivity() {
|
||||||
val averageTir = TirCalculator.averageTIR(tirs)
|
val averageTir = TirCalculator.averageTIR(tirs)
|
||||||
survey_tir.text = "\n" + MainApp.gs(R.string.tir) + ":\n" + TirCalculator.toText(tirs) + MainApp.gs(R.string.average) + ":\n" + averageTir.toText()
|
survey_tir.text = "\n" + MainApp.gs(R.string.tir) + ":\n" + TirCalculator.toText(tirs) + MainApp.gs(R.string.average) + ":\n" + averageTir.toText()
|
||||||
|
|
||||||
|
survey_activity.text = "\n" + MainApp.gs(R.string.activitymonitor) + ":\n" + ActivityMonitor.toText()
|
||||||
|
|
||||||
survey_profile.setOnClickListener {
|
survey_profile.setOnClickListener {
|
||||||
val age = SafeParse.stringToDouble(survey_age.text.toString())
|
val age = SafeParse.stringToDouble(survey_age.text.toString())
|
||||||
val weight = SafeParse.stringToDouble(survey_weight.text.toString())
|
val weight = SafeParse.stringToDouble(survey_weight.text.toString())
|
||||||
|
|
|
@ -9,30 +9,63 @@ import org.slf4j.LoggerFactory
|
||||||
object ActivityMonitor : Application.ActivityLifecycleCallbacks {
|
object ActivityMonitor : Application.ActivityLifecycleCallbacks {
|
||||||
private val log = LoggerFactory.getLogger(L.CORE)
|
private val log = LoggerFactory.getLogger(L.CORE)
|
||||||
override fun onActivityPaused(activity: Activity?) {
|
override fun onActivityPaused(activity: Activity?) {
|
||||||
log.debug("onActivityPaused " + activity?.localClassName)
|
val name = activity?.javaClass?.simpleName ?: return
|
||||||
|
val resumed = SP.getLong("Monitor_" + name + "_" + "resumed", 0)
|
||||||
|
if (resumed == 0L) {
|
||||||
|
log.debug("onActivityPaused: $name resumed == 0")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val elapsed = DateUtil.now() - resumed
|
||||||
|
val total = SP.getLong("Monitor_" + name + "_total", 0)
|
||||||
|
if (total == 0L) {
|
||||||
|
SP.putLong("Monitor_" + name + "_start", DateUtil.now())
|
||||||
|
}
|
||||||
|
SP.putLong("Monitor_" + name + "_total", total + elapsed)
|
||||||
|
log.debug("onActivityPaused: $name elapsed=$elapsed total=${total + elapsed}")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResumed(activity: Activity?) {
|
override fun onActivityResumed(activity: Activity?) {
|
||||||
log.debug("onActivityResumed " + activity?.localClassName)
|
val name = activity?.javaClass?.simpleName ?: return
|
||||||
|
log.debug("onActivityResumed: $name")
|
||||||
|
SP.putLong("Monitor_" + name + "_" + "resumed", DateUtil.now())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityStarted(activity: Activity?) {
|
override fun onActivityStarted(activity: Activity?) {
|
||||||
log.debug("onActivityStarted " + activity?.localClassName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityDestroyed(activity: Activity?) {
|
override fun onActivityDestroyed(activity: Activity?) {
|
||||||
log.debug("onActivityDestroyed " + activity?.localClassName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) {
|
override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) {
|
||||||
log.debug("onActivitySaveInstanceState " + activity?.localClassName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityStopped(activity: Activity?) {
|
override fun onActivityStopped(activity: Activity?) {
|
||||||
log.debug("onActivityStopped " + activity?.localClassName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {
|
override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {
|
||||||
log.debug("onActivityCreated " + activity?.localClassName)
|
}
|
||||||
|
|
||||||
|
fun toText(): String {
|
||||||
|
val keys: Map<String, *> = SP.getAll()
|
||||||
|
var result = ""
|
||||||
|
for ((key, value) in keys)
|
||||||
|
if (key.startsWith("Monitor") && key.endsWith("total")) {
|
||||||
|
val activity = key.split("_")[1]
|
||||||
|
val seconds = value as Long / 1000
|
||||||
|
val start = SP.getLong(key.replace("total", "start"), 0)
|
||||||
|
val days = T.msecs(DateUtil.now() - start).days()
|
||||||
|
result += "$activity: $seconds s in $days days\n"
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
fun reset() {
|
||||||
|
val keys: Map<String, *> = SP.getAll()
|
||||||
|
for ((key, _) in keys)
|
||||||
|
if (key.startsWith("Monitor") && key.endsWith("total")) {
|
||||||
|
SP.remove(key)
|
||||||
|
SP.remove(key.replace("total", "start"))
|
||||||
|
SP.remove(key.replace("total", "resumed"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,8 @@ package info.nightscout.androidaps.utils;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +14,10 @@ import info.nightscout.androidaps.MainApp;
|
||||||
public class SP {
|
public class SP {
|
||||||
private static SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
private static SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||||
|
|
||||||
|
static public Map<String, ?> getAll() {
|
||||||
|
return sharedPreferences.getAll();
|
||||||
|
}
|
||||||
|
|
||||||
static public void clear() {
|
static public void clear() {
|
||||||
sharedPreferences.edit().clear().apply();
|
sharedPreferences.edit().clear().apply();
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,6 +150,13 @@
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/survey_activity"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/survey_submit"
|
android:id="@+id/survey_submit"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -1676,5 +1676,6 @@
|
||||||
<string name="average">Average</string>
|
<string name="average">Average</string>
|
||||||
<string name="tdd">TDD</string>
|
<string name="tdd">TDD</string>
|
||||||
<string name="tir">TIR</string>
|
<string name="tir">TIR</string>
|
||||||
|
<string name="activitymonitor">Activity monitor</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue