mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 01:31:01 +00:00
Added functionality to clean up names
This commit is contained in:
1 parent
cb634175ef
commit
ce6b4878ad
2 files changed
+43
-2
No files matched your search
+41
@@ -5,6 +5,8 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
@@ -26,7 +28,9 @@ import org.jdom.output.DOMOutputter;
|
||||
import org.jdom.output.Format;
|
||||
import org.jdom.output.XMLOutputter;
|
||||
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.Fleet;
|
||||
import com.sap.sailing.domain.base.Nationality;
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
@@ -65,6 +69,43 @@ public abstract class ExportAction {
|
||||
}
|
||||
return leaderboard;
|
||||
}
|
||||
|
||||
protected String cleanRaceName(String raceName) {
|
||||
String newRaceName = raceName;
|
||||
if (raceName.matches("[A-Za-z ]*\\d")) {
|
||||
Pattern regex = Pattern.compile("([A-Za-z ]*)(\\d)");
|
||||
Matcher matcher = regex.matcher(raceName);
|
||||
String raceNameFirstPart = matcher.replaceAll("$1");
|
||||
String raceNumber = matcher.replaceAll("$2");
|
||||
try {
|
||||
if (Integer.parseInt(raceNumber) < 10) {
|
||||
raceNumber = "0" + raceNumber;
|
||||
newRaceName = raceNameFirstPart + raceNumber;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return newRaceName;
|
||||
}
|
||||
|
||||
protected String cleanSailId(String sailId, Competitor competitor) {
|
||||
if (sailId.matches("^[A-Z]{3}\\s[0-9]*")) {
|
||||
Pattern regex = Pattern.compile("(^[A-Z]{3})\\s([0-9]*)");
|
||||
Matcher regexMatcher = regex.matcher(sailId);
|
||||
try {
|
||||
return regexMatcher.replaceAll("$1$2");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (sailId.matches("^[A-Z]{3}\\S[0-9]*")) {
|
||||
return sailId;
|
||||
} else if (sailId.matches("[0-9]*")){
|
||||
Nationality nationality = competitor.getTeam().getNationality();
|
||||
return (nationality==null ? "" : nationality.getThreeLetterIOCAcronym() + sailId);
|
||||
}
|
||||
return sailId;
|
||||
}
|
||||
|
||||
public void sendDocument(Document doc, String fileName) {
|
||||
ServletOutputStream stream = null;
|
||||
|
||||
+2
-2
@@ -125,7 +125,7 @@ public class LeaderboardData extends ExportAction {
|
||||
private Element createRaceXML(TrackedRace race, Fleet fleet, List<Element> legs, RaceColumn column, Leaderboard leaderboard) throws NoWindException {
|
||||
// TODO: Plausibility checks (race has start time, ...)
|
||||
Element raceElement = new Element("race");
|
||||
addNamedElementWithValue(raceElement, "name", race.getRace().getName());
|
||||
addNamedElementWithValue(raceElement, "name", cleanRaceName(race.getRace().getName()));
|
||||
addNamedElementWithValue(raceElement, "fleet_name", fleet.getName());
|
||||
|
||||
addNamedElementWithValue(raceElement, "delay_to_live_in_millis", race.getDelayToLiveInMillis());
|
||||
@@ -182,7 +182,7 @@ public class LeaderboardData extends ExportAction {
|
||||
addNamedElementWithValue(competitorElement, "name", competitor.getName());
|
||||
addNamedElementWithValue(competitorElement, "nationality_name", competitor.getTeam().getNationality().getName());
|
||||
addNamedElementWithValue(competitorElement, "nationality_ioc", competitor.getTeam().getNationality().getThreeLetterIOCAcronym());
|
||||
addNamedElementWithValue(competitorElement, "sail_id", competitor.getBoat().getSailID());
|
||||
addNamedElementWithValue(competitorElement, "sail_id", cleanSailId(competitor.getBoat().getSailID(), competitor));
|
||||
addNamedElementWithValue(competitorElement, "boat_name", competitor.getBoat().getName());
|
||||
addNamedElementWithValue(competitorElement, "boat_class", competitor.getBoat().getBoatClass().getName());
|
||||
|
||||
|
||||
Reference in new issue
Block a user