Merge remote-tracking branch 'origin/dev' into rs

This commit is contained in:
Milos Kozak 2020-04-21 10:57:04 +02:00
commit b3db476533
10 changed files with 72 additions and 8 deletions

View file

@ -80,12 +80,13 @@ interface AppComponent : AndroidInjector<MainApp> {
fun injectObjective1(objective1: Objective1)
fun injectObjective2(objective2: Objective2)
fun injectObjective3(objective3: Objective3)
fun injectObjective3(objective4: Objective4)
fun injectObjective4(objective4: Objective4)
fun injectObjective5(objective5: Objective5)
fun injectObjective6(objective6: Objective6)
fun injectObjective6(objective7: Objective7)
fun injectObjective6(objective8: Objective8)
fun injectObjective6(objective9: Objective9)
fun injectObjective7(objective7: Objective7)
fun injectObjective8(objective8: Objective8)
fun injectObjective9(objective9: Objective9)
fun injectObjective10(objective10: Objective10)
fun injectAutomationEvent(automationEvent: AutomationEvent)

View file

@ -161,6 +161,7 @@ open class AppModule {
@ContributesAndroidInjector fun objective7Injector(): Objective7
@ContributesAndroidInjector fun objective8Injector(): Objective8
@ContributesAndroidInjector fun objective9Injector(): Objective9
@ContributesAndroidInjector fun objective10Injector(): Objective10
@ContributesAndroidInjector fun automationEventInjector(): AutomationEvent

View file

@ -76,4 +76,9 @@ interface ConstraintsInterface {
fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> {
return maxIob
}
@JvmDefault
fun isAutomationEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
return value
}
}

View file

@ -54,6 +54,9 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
fun getMaxIOBAllowed(): Constraint<Double> =
applyMaxIOBConstraints(Constraint(Constants.REALLYHIGHIOB))
fun isAutomationEnabled(): Constraint<Boolean> =
isAutomationEnabled(Constraint(true))
override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
for (p in constraintsPlugins) {
@ -193,4 +196,14 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug
}
return maxIob
}
override fun isAutomationEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
for (p in constraintsPlugins) {
val constraint = p as ConstraintsInterface
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
constraint.isAutomationEnabled(value)
}
return value
}
}

View file

@ -161,7 +161,7 @@ class ObjectivesFragment : DaggerFragment() {
holder.accomplished.visibility = View.GONE
holder.unFinish.visibility = View.GONE
holder.unStart.visibility = View.GONE
if (position == 0 || objectivesPlugin.objectives[position - 1].isAccomplished)
if (position == 0 || objectivesPlugin.allPriorAccomplished(position))
holder.start.visibility = View.VISIBLE
else
holder.start.visibility = View.GONE

View file

@ -50,6 +50,7 @@ class ObjectivesPlugin @Inject constructor(
const val AUTOSENS_OBJECTIVE = 7
const val AMA_OBJECTIVE = 8
const val SMB_OBJECTIVE = 9
const val AUTO_OBJECTIVE = 10
}
public override fun onStart() {
@ -94,6 +95,7 @@ class ObjectivesPlugin @Inject constructor(
objectives.add(Objective7(injector))
objectives.add(Objective8(injector))
objectives.add(Objective9(injector))
objectives.add(Objective10(injector))
}
fun reset() {
@ -133,6 +135,8 @@ class ObjectivesPlugin @Inject constructor(
sp.putLong("Objectives_" + "ama" + "_accomplished", DateUtil.now())
sp.putLong("Objectives_" + "smb" + "_started", DateUtil.now())
sp.putLong("Objectives_" + "smb" + "_accomplished", DateUtil.now())
sp.putLong("Objectives_" + "auto" + "_started", DateUtil.now())
sp.putLong("Objectives_" + "auto" + "_accomplished", DateUtil.now())
setupObjectives()
OKDialog.show(activity, resourceHelper.gs(R.string.objectives), resourceHelper.gs(R.string.codeaccepted))
} else {
@ -140,6 +144,14 @@ class ObjectivesPlugin @Inject constructor(
}
}
fun allPriorAccomplished(position: Int) : Boolean {
var accomplished = true
for (i in 0 until position) {
accomplished = accomplished && objectives[i].isAccomplished
}
return accomplished
}
/**
* Constraints interface
*/
@ -178,4 +190,10 @@ class ObjectivesPlugin @Inject constructor(
maxIob.set(aapsLogger, 0.0, String.format(resourceHelper.gs(R.string.objectivenotfinished), MAXIOB_ZERO_CL_OBJECTIVE + 1), this)
return maxIob
}
override fun isAutomationEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
if (!objectives[AUTO_OBJECTIVE].isStarted)
value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AUTO_OBJECTIVE + 1), this)
return value
}
}

View file

@ -0,0 +1,19 @@
package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
import java.util.List;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.T;
public class Objective10 extends Objective {
public Objective10(HasAndroidInjector injector) {
super(injector, "auto", R.string.objectives_auto_objective, R.string.objectives_auto_gate);
}
@Override
protected void setupTasks(List<Task> tasks) {
tasks.add(new MinimumDurationTask(T.days(28).msecs()));
}
}

View file

@ -184,9 +184,7 @@ class ActionsFragment : DaggerFragment() {
@Synchronized
fun updateGui() {
actions_profileswitch?.visibility =
if (activePlugin.activeProfileInterface.profile != null) View.VISIBLE
else View.GONE
actions_profileswitch?.visibility = (activePlugin.activeProfileInterface.profile != null).toVisibility()
val profile = profileFunction.getProfile()
val pump = activePlugin.activePump

View file

@ -18,6 +18,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.general.automation.actions.*
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui
@ -50,6 +51,7 @@ class AutomationPlugin @Inject constructor(
private val fabricPrivacy: FabricPrivacy,
private val loopPlugin: LoopPlugin,
private val rxBus: RxBusWrapper,
private val constraintChecker: ConstraintChecker,
aapsLogger: AAPSLogger
) : PluginBase(PluginDescription()
.mainType(PluginType.GENERAL)
@ -181,6 +183,11 @@ class AutomationPlugin @Inject constructor(
aapsLogger.debug(LTag.AUTOMATION, "Loop deactivated")
return
}
val enabled = constraintChecker.isAutomationEnabled()
if (!enabled.value()) {
executionLog.add(enabled.getMostLimitedReasons(aapsLogger))
return
}
aapsLogger.debug(LTag.AUTOMATION, "processActions")
for (event in automationEvents) {

View file

@ -32,7 +32,9 @@
<string name="objectives_autosens_gate">1 week successful daytime looping with regular carb entry</string>
<string name="objectives_ama_objective">Enabling additional features for daytime use, such as advanced meal assist</string>
<string name="objectives_smb_objective">Enabling additional features for daytime use, such as SMB</string>
<string name="objectives_auto_objective">Enabling automation</string>
<string name="objectives_smb_gate">You must read the wiki and rise maxIOB to get SMBs working fine! A good start is maxIOB=average mealbolus + 3 x max daily basal</string>
<string name="objectives_auto_gate">Read the wiki how automation works. Setup your first simple rules. Instead of action let AAPS display only notification. When you are sure automation is triggered at the right time replace notification by real action.</string>
<string name="objectives_bgavailableinns">BG available in NS</string>
<string name="objectives_pumpstatusavailableinns">Pump status available in NS</string>
<string name="objectives_manualenacts">Manual enacts</string>