fix doubled percentage when comming from NS
This commit is contained in:
parent
248d3d1697
commit
2bb37a4bfc
3 changed files with 44 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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%)"));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue