fix doubled percentage when comming from NS

This commit is contained in:
Milos Kozak 2017-12-22 21:03:36 +01:00
parent 248d3d1697
commit 2bb37a4bfc
3 changed files with 44 additions and 0 deletions

View file

@ -46,6 +46,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData;
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
import info.nightscout.utils.PercentageSplitter;
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static Logger log = LoggerFactory.getLogger(DatabaseHelper.class);
@ -1598,6 +1599,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
}
}
// look for already added percentage from NS
profileSwitch.profileName = PercentageSplitter.pureName(profileSwitch.profileName);
getDaoProfileSwitch().create(profileSwitch);
log.debug("PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " + profileSwitch.toString());
scheduleProfileSwitchChange();

View file

@ -0,0 +1,21 @@
package info.nightscout.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by mike on 22.12.2017.
*/
public class PercentageSplitter {
public static String pureName(String name) {
String newName = name;
String s = "(.*)\\((\\d+)\\%\\)";
Pattern r = Pattern.compile(s);
Matcher m = r.matcher(name);
if (m.find()) {
newName = m.group(1);
}
return newName;
}
}

View file

@ -0,0 +1,20 @@
package info.nightscout.utils;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Created by mike on 22.12.2017.
*/
public class PercentageSplitterTest {
public PercentageSplitterTest() {
super();
}
@Test
public void pureNameTest() throws Exception {
assertEquals("Fiasp", PercentageSplitter.pureName("Fiasp(101%)"));
}
}