Merge pull request #1540 from jotomo/upstream-1480
Profile switch name mangling for NS up/download
This commit is contained in:
commit
8110bef68f
3 changed files with 19 additions and 17 deletions
|
@ -101,6 +101,11 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
|||
return profile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: the name returned here is used as the PS name when uploading to NS. When such a PS is retrieved
|
||||
* again from NS, the added parts must be removed again, see
|
||||
* {@link info.nightscout.utils.PercentageSplitter#pureName}
|
||||
*/
|
||||
public String getCustomizedName() {
|
||||
String name = profileName;
|
||||
if(LocalProfilePlugin.LOCAL_PROFILE.equals(name)){
|
||||
|
|
|
@ -8,23 +8,15 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
|
||||
public class PercentageSplitter {
|
||||
// "Profile name (200%,2h)"
|
||||
private static final Pattern percentagePattern = Pattern.compile("(.+)\\(\\d+%,\\d+h\\)");
|
||||
// "Profile name (200%)"
|
||||
private static final Pattern percentageShiftPattern = Pattern.compile("(.+)\\(\\d+%\\)");
|
||||
// Matches "Profile name (200%,-2h)", "Profile name (50%)
|
||||
private static final Pattern splitPattern = Pattern.compile("(.+)\\(\\d+%(,-?\\d+h)?\\)");
|
||||
|
||||
/** Removes the suffix for percentage and timeshift from a profile name. */
|
||||
/** Removes the suffix for percentage and timeshift from a profile name. This is the inverse of what
|
||||
* {@link info.nightscout.androidaps.db.ProfileSwitch#getCustomizedName()} does.
|
||||
* Since the customized name is used for the PS upload to NS, this is needed get the original profile name
|
||||
* when retrieving the PS from NS again. */
|
||||
public static String pureName(String name) {
|
||||
Matcher percentageMatch = percentagePattern.matcher(name);
|
||||
if (percentageMatch.find()) {
|
||||
return percentageMatch.group(1).trim();
|
||||
}
|
||||
|
||||
Matcher percentageShiftMatch = percentageShiftPattern.matcher(name);
|
||||
if (percentageShiftMatch.find()) {
|
||||
return percentageShiftMatch.group(1).trim();
|
||||
}
|
||||
|
||||
return name;
|
||||
Matcher percentageMatch = splitPattern.matcher(name);
|
||||
return percentageMatch.find() ? percentageMatch.group(1).trim() : name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,12 @@ public class PercentageSplitterTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void pureNameTestPercentageAndShift() {
|
||||
public void pureNameTestPercentageAndPositiveTimeShift() {
|
||||
assertEquals("Fiasp", PercentageSplitter.pureName("Fiasp (101%,2h)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pureNameTestPercentageAndNegtiveTimeShift() {
|
||||
assertEquals("Fiasp", PercentageSplitter.pureName("Fiasp (50%,-2h)"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue