From edcc95a5bc58393e6c5a4ddf0720172b3411d25e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 25 Apr 2020 17:20:12 +0200 Subject: [PATCH] Refactor deprecated --- .../androidaps/SetupWizardActivityTest.kt | 6 ++--- .../aps/openAPSAMA/OpenAPSAMAPlugin.java | 20 +++++++++----- .../aps/openAPSSMB/OpenAPSSMBPlugin.java | 20 +++++++++----- .../iobCobCalculator/IobCobOref1Thread.java | 7 ++--- .../iob/iobCobCalculator/IobCobThread.java | 6 +++-- .../nightscout/androidaps/utils/Profiler.java | 26 ------------------- .../nightscout/androidaps/utils/Profiler.kt | 15 +++++++++++ .../nightscout/androidaps/db/BgReadingTest.kt | 3 +-- 8 files changed, 52 insertions(+), 51 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/utils/Profiler.java create mode 100644 app/src/main/java/info/nightscout/androidaps/utils/Profiler.kt diff --git a/app/src/androidTest/java/info/nightscout/androidaps/SetupWizardActivityTest.kt b/app/src/androidTest/java/info/nightscout/androidaps/SetupWizardActivityTest.kt index 6b094db210..c082e51018 100644 --- a/app/src/androidTest/java/info/nightscout/androidaps/SetupWizardActivityTest.kt +++ b/app/src/androidTest/java/info/nightscout/androidaps/SetupWizardActivityTest.kt @@ -20,7 +20,6 @@ import androidx.test.rule.GrantPermissionRule import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin @@ -28,7 +27,6 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin import info.nightscout.androidaps.plugins.source.RandomBgPlugin import info.nightscout.androidaps.setupwizard.SetupWizardActivity import info.nightscout.androidaps.utils.HardLimits -import info.nightscout.androidaps.utils.SP import info.nightscout.androidaps.utils.extensions.isRunningTest import org.hamcrest.CoreMatchers.allOf import org.hamcrest.Description @@ -60,7 +58,7 @@ class SetupWizardActivityTest { @Before fun clear() { - SP.clear() + sp.clear() } /* @@ -77,7 +75,7 @@ adb shell settings put global animator_duration_scale 0 & @Test fun setupWizardActivityTest() { - SP.clear() + sp.clear() Assert.assertTrue(isRunningTest()) // Welcome page onView(withId(R.id.next_button)).perform(click()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java index cea65a14d9..42003d1b13 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java @@ -52,6 +52,8 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { private final TreatmentsPlugin treatmentsPlugin; private final IobCobCalculatorPlugin iobCobCalculatorPlugin; private final HardLimits hardLimits; + private final Profiler profiler; + private final FabricPrivacy fabricPrivacy; // last values DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null; @@ -71,7 +73,9 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { ActivePluginProvider activePlugin, TreatmentsPlugin treatmentsPlugin, IobCobCalculatorPlugin iobCobCalculatorPlugin, - HardLimits hardLimits + HardLimits hardLimits, + Profiler profiler, + FabricPrivacy fabricPrivacy ) { super(new PluginDescription() .mainType(PluginType.APS) @@ -92,6 +96,8 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { this.treatmentsPlugin = treatmentsPlugin; this.iobCobCalculatorPlugin = iobCobCalculatorPlugin; this.hardLimits = hardLimits; + this.profiler = profiler; + this.fabricPrivacy = fabricPrivacy; } @Override @@ -161,11 +167,11 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { long start = System.currentTimeMillis(); long startPart = System.currentTimeMillis(); IobTotal[] iobArray = iobCobCalculatorPlugin.calculateIobArrayInDia(profile); - Profiler.log(aapsLogger, LTag.APS, "calculateIobArrayInDia()", startPart); + profiler.log(LTag.APS, "calculateIobArrayInDia()", startPart); startPart = System.currentTimeMillis(); MealData mealData = iobCobCalculatorPlugin.getMealData(); - Profiler.log(aapsLogger, LTag.APS, "getMealData()", startPart); + profiler.log(LTag.APS, "getMealData()", startPart); double maxIob = constraintChecker.getMaxIOBAllowed().value(); @@ -206,8 +212,8 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { lastAutosensResult = new AutosensResult(); lastAutosensResult.sensResult = "autosens disabled"; } - Profiler.log(aapsLogger, LTag.APS, "detectSensitivityandCarbAbsorption()", startPart); - Profiler.log(aapsLogger, LTag.APS, "AMA data gathering", start); + profiler.log(LTag.APS, "detectSensitivityandCarbAbsorption()", startPart); + profiler.log(LTag.APS, "AMA data gathering", start); start = System.currentTimeMillis(); @@ -217,13 +223,13 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { isTempTarget ); } catch (JSONException e) { - FabricPrivacy.getInstance().logException(e); + fabricPrivacy.logException(e); return; } DetermineBasalResultAMA determineBasalResultAMA = determineBasalAdapterAMAJS.invoke(); - Profiler.log(aapsLogger, LTag.APS, "AMA calculation", start); + profiler.log(LTag.APS, "AMA calculation", start); // Fix bug determine basal if (determineBasalResultAMA == null) { aapsLogger.error(LTag.APS, "SMB calculation returned null"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java index 51650891ee..878d260bca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java @@ -54,6 +54,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr private final TreatmentsPlugin treatmentsPlugin; private final IobCobCalculatorPlugin iobCobCalculatorPlugin; private final HardLimits hardLimits; + private final Profiler profiler; + private final FabricPrivacy fabricPrivacy; // last values DetermineBasalAdapterSMBJS lastDetermineBasalAdapterSMBJS = null; @@ -73,7 +75,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr ActivePluginProvider activePlugin, TreatmentsPlugin treatmentsPlugin, IobCobCalculatorPlugin iobCobCalculatorPlugin, - HardLimits hardLimits + HardLimits hardLimits, + Profiler profiler, + FabricPrivacy fabricPrivacy ) { super(new PluginDescription() .mainType(PluginType.APS) @@ -94,6 +98,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr this.treatmentsPlugin = treatmentsPlugin; this.iobCobCalculatorPlugin = iobCobCalculatorPlugin; this.hardLimits = hardLimits; + this.profiler = profiler; + this.fabricPrivacy = fabricPrivacy; } @Override @@ -168,7 +174,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr long startPart = System.currentTimeMillis(); MealData mealData = iobCobCalculatorPlugin.getMealData(); - Profiler.log(getAapsLogger(), LTag.APS, "getMealData()", startPart); + profiler.log(LTag.APS, "getMealData()", startPart); Constraint maxIOBAllowedConstraint = constraintChecker.getMaxIOBAllowed(); inputConstraints.copyReasons(maxIOBAllowedConstraint); @@ -213,7 +219,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr } IobTotal[] iobArray = iobCobCalculatorPlugin.calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget); - Profiler.log(getAapsLogger(), LTag.APS, "calculateIobArrayInDia()", startPart); + profiler.log(LTag.APS, "calculateIobArrayInDia()", startPart); startPart = System.currentTimeMillis(); Constraint smbAllowed = new Constraint<>(!tempBasalFallback); @@ -228,8 +234,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr constraintChecker.isUAMEnabled(uam); inputConstraints.copyReasons(uam); - Profiler.log(getAapsLogger(), LTag.APS, "detectSensitivityandCarbAbsorption()", startPart); - Profiler.log(getAapsLogger(), LTag.APS, "SMB data gathering", start); + profiler.log(LTag.APS, "detectSensitivityandCarbAbsorption()", startPart); + profiler.log(LTag.APS, "SMB data gathering", start); start = System.currentTimeMillis(); try { @@ -241,14 +247,14 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr advancedFiltering.value() ); } catch (JSONException e) { - FabricPrivacy.getInstance().logException(e); + fabricPrivacy.logException(e); return; } long now = System.currentTimeMillis(); DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke(); - Profiler.log(getAapsLogger(), LTag.APS, "SMB calculation", start); + profiler.log(LTag.APS, "SMB calculation", start); if (determineBasalResultSMB == null) { getAapsLogger().error(LTag.APS, "SMB calculation returned null"); lastDetermineBasalAdapterSMBJS = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java index 505b9a799f..9478b9ed73 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java @@ -23,7 +23,6 @@ import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -66,6 +65,8 @@ public class IobCobOref1Thread extends Thread { @Inject SensitivityAAPSPlugin sensitivityAAPSPlugin; @Inject SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin; @Inject BuildHelper buildHelper; + @Inject Profiler profiler; + @Inject FabricPrivacy fabricPrivacy; private final HasAndroidInjector injector; private boolean bgDataReload; @@ -222,7 +223,7 @@ public class IobCobOref1Thread extends Thread { } } catch (Exception e) { aapsLogger.error("Unhandled exception", e); - FabricPrivacy.getInstance().logException(e); + fabricPrivacy.logException(e); aapsLogger.debug(autosensDataTable.toString()); aapsLogger.debug(bucketed_data.toString()); aapsLogger.debug(iobCobCalculatorPlugin.getBgReadings().toString()); @@ -391,7 +392,7 @@ public class IobCobOref1Thread extends Thread { rxBus.send(new EventIobCalculationProgress("")); aapsLogger.debug(LTag.AUTOSENS, "AUTOSENSDATA thread ended: " + from); aapsLogger.debug(LTag.AUTOSENS, "Midnights: " + MidnightTime.log()); - Profiler.log(aapsLogger, LTag.AUTOSENS, "IobCobOref1Thread", start); + profiler.log(LTag.AUTOSENS, "IobCobOref1Thread", start); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java index 6e30d776b2..48b9c2eb0a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java @@ -62,6 +62,8 @@ public class IobCobThread extends Thread { @Inject SensitivityAAPSPlugin sensitivityAAPSPlugin; @Inject SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin; @Inject BuildHelper buildHelper; + @Inject Profiler profiler; + @Inject FabricPrivacy fabricPrivacy; private final HasAndroidInjector injector; private boolean bgDataReload; @@ -218,7 +220,7 @@ public class IobCobThread extends Thread { } } catch (Exception e) { aapsLogger.error("Unhandled exception", e); - FabricPrivacy.getInstance().logException(e); + fabricPrivacy.logException(e); aapsLogger.debug(autosensDataTable.toString()); aapsLogger.debug(bucketed_data.toString()); aapsLogger.debug(iobCobCalculatorPlugin.getBgReadings().toString()); @@ -314,7 +316,7 @@ public class IobCobThread extends Thread { rxBus.send(new EventIobCalculationProgress("")); aapsLogger.debug(LTag.AUTOSENS, "AUTOSENSDATA thread ended: " + from); aapsLogger.debug(LTag.AUTOSENS, "Midnights: " + MidnightTime.log()); - Profiler.log(aapsLogger, LTag.AUTOSENS, "IobCobThread", start); + profiler.log(LTag.AUTOSENS, "IobCobThread", start); } } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/Profiler.java b/app/src/main/java/info/nightscout/androidaps/utils/Profiler.java deleted file mode 100644 index b23f664261..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/utils/Profiler.java +++ /dev/null @@ -1,26 +0,0 @@ -package info.nightscout.androidaps.utils; - -import org.slf4j.Logger; - -import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.LTag; - -/** - * Created by mike on 29.01.2017. - */ - -public class Profiler { - public Profiler() { - } - - @Deprecated - static public void log(Logger log, String function, long start) { - long msec = System.currentTimeMillis() - start; - log.debug(">>> " + function + " <<< executed in " + msec + " miliseconds"); - } - - static public void log(AAPSLogger log, LTag lTag, String function, long start) { - long msec = System.currentTimeMillis() - start; - log.debug(lTag, ">>> " + function + " <<< executed in " + msec + " miliseconds"); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/utils/Profiler.kt b/app/src/main/java/info/nightscout/androidaps/utils/Profiler.kt new file mode 100644 index 0000000000..b3ac2bbe94 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/Profiler.kt @@ -0,0 +1,15 @@ +package info.nightscout.androidaps.utils + +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.LTag +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class Profiler @Inject constructor(val aapsLogger: AAPSLogger) { + + fun log(lTag: LTag, function: String, start: Long) { + val msec = System.currentTimeMillis() - start + aapsLogger.debug(lTag, ">>> $function <<< executed in $msec miliseconds") + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/db/BgReadingTest.kt b/app/src/test/java/info/nightscout/androidaps/db/BgReadingTest.kt index 7f55f458d4..61494f7d8c 100644 --- a/app/src/test/java/info/nightscout/androidaps/db/BgReadingTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/db/BgReadingTest.kt @@ -10,7 +10,6 @@ import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.utils.DefaultValueHelper -import info.nightscout.androidaps.utils.SP import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Before @@ -27,7 +26,7 @@ import java.util.* import java.util.logging.Logger @RunWith(PowerMockRunner::class) -@PrepareForTest(MainApp::class, Logger::class, L::class, SP::class, GlucoseStatus::class) +@PrepareForTest(MainApp::class, Logger::class, L::class, GlucoseStatus::class) class BgReadingTest : TestBase() { @Mock lateinit var defaultValueHelper: DefaultValueHelper