move dstPlugin to contraints package

This commit is contained in:
Milos Kozak 2019-03-02 15:13:42 +01:00
parent e27c0c4b8b
commit 987b3d9dd0
3 changed files with 26 additions and 29 deletions

View file

@ -29,12 +29,12 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.DstHelper.DstHelperPlugin;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.constraints.dstHelper.DstHelperPlugin;
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
import info.nightscout.androidaps.plugins.general.actions.ActionsFragment;

View file

@ -1,13 +1,9 @@
package info.nightscout.androidaps.plugins.DstHelper;
package info.nightscout.androidaps.plugins.constraints.dstHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -30,6 +26,7 @@ public class DstHelperPlugin extends PluginBase implements ConstraintsInterface
private int minutesToChange = 0;
static DstHelperPlugin plugin = null;
public static DstHelperPlugin getPlugin() {
if (plugin == null)
plugin = new DstHelperPlugin();
@ -51,7 +48,7 @@ public class DstHelperPlugin extends PluginBase implements ConstraintsInterface
// c = Calendar.getInstance(TimeZone.getTimeZone("Australia/Lord_Howe"));
// c.setTimeInMillis(DateUtil.fromISODateString("2018-10-07T01:00:00Z").getTime());
long zoneOffset = c.get(Calendar.ZONE_OFFSET);
long d1 = c.getTimeInMillis()-zoneOffset;
long d1 = c.getTimeInMillis() - zoneOffset;
c.setTimeInMillis(d1);
int offset1 = c.get(Calendar.DST_OFFSET);
@ -67,20 +64,20 @@ public class DstHelperPlugin extends PluginBase implements ConstraintsInterface
//we have a time change in next 24 hours, but when exactly
// log.debug("Daylight saving time detected between " + startTimeString + " and " + endTimeString);
// log.debug("Diff in hours is: "+diffInHours);
c.setTimeInMillis(d1-zoneOffset);
c.setTimeInMillis(d1 - zoneOffset);
offset1 = c.get(Calendar.DST_OFFSET);
for(int i = 0; i <= diffInHours*4; i++){
for (int i = 0; i <= diffInHours * 4; i++) {
if(offset1 != c.get(Calendar.DST_OFFSET)){
log.debug("Detected offset in "+((i/4)-zoneOffset/T.hours(1).msecs())+" hours value is "+(offset1 - c.get(Calendar.DST_OFFSET))/T.mins(1).msecs()+" minutes");
if (offset1 != c.get(Calendar.DST_OFFSET)) {
log.debug("Detected offset in " + ((i / 4) - zoneOffset / T.hours(1).msecs()) + " hours value is " + (offset1 - c.get(Calendar.DST_OFFSET)) / T.mins(1).msecs() + " minutes");
offsetDetectedTime = c.getTimeInMillis() - d1;
break;
}
c.add(Calendar.MINUTE,15);
c.add(Calendar.MINUTE, 15);
}
}
int minutesLeft = (int) ((offsetDetectedTime/T.mins(1).msecs()));
int minutesLeft = (int) ((offsetDetectedTime / T.mins(1).msecs()));
/*log.debug("zoneoffset(minutes):"+zoneOffset/T.mins(1).msecs());
log.debug("Start offset: "+offset1/T.mins(1).msecs());
log.debug("End offset :" + c.get(Calendar.DST_OFFSET)/T.mins(1).msecs());
@ -94,16 +91,16 @@ public class DstHelperPlugin extends PluginBase implements ConstraintsInterface
//Return false if time to DST change is less than 91 and positive
@Override
public Constraint<Boolean> isLoopInvocationAllowed(Constraint<Boolean> value){
public Constraint<Boolean> isLoopInvocationAllowed(Constraint<Boolean> value) {
try {
this.dstTest(Calendar.getInstance());
} catch (Exception e) {
e.printStackTrace();
}
if ( this.minutesToChange <= 90 && minutesToChange > 0 && value.value()) {
if (this.minutesToChange <= 90 && minutesToChange > 0 && value.value()) {
try {
LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if( loopPlugin.suspendedTo() == 0L) {
if (loopPlugin.suspendedTo() == 0L) {
// loopPlugin.suspendTo(System.currentTimeMillis() + minutesToChange * T.mins(1).msecs());
warnUser(Notification.DST_LOOP_DISABLED, MainApp.gs(R.string.dst_loop_disabled_warning));
} else
@ -120,7 +117,7 @@ public class DstHelperPlugin extends PluginBase implements ConstraintsInterface
}
// display warning
void warnUser(int id, String warningText){
void warnUser(int id, String warningText) {
Notification notification = new Notification(id, warningText, Notification.LOW);
MainApp.bus().post(new EventNewNotification(notification));
}

View file

@ -1,30 +1,30 @@
package info.nightscout.androidaps.plugins.DstHelper;
package info.nightscout.androidaps.plugins.constraints.dstHelper;
import android.content.Context;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import junit.framework.Assert;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP;
import info.nightscout.utils.T;
import org.junit.Test;
import java.util.Calendar;
import java.util.TimeZone;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.SP;
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, SP.class, Context.class})
public class DstHelperPluginTest {
DstHelperPlugin plugin = new DstHelperPlugin();
@Test
public void runTest() throws Exception {
public void runTest() throws Exception {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
// test different time zones