mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-21 21:25:38 +00:00
bug6096: extract class name
This commit is contained in:
+10
@@ -26,6 +26,8 @@ import com.sap.sailing.resultimport.impl.CompetitorRowImpl;
|
||||
import com.sap.sailing.resultimport.impl.DefaultCompetitorEntryImpl;
|
||||
|
||||
public class SailwaveHtmlParser {
|
||||
static final String CLASS_METADATA = "class";
|
||||
|
||||
private static final Logger logger = Logger.getLogger(SailwaveHtmlParser.class.getName());
|
||||
|
||||
public List<String> getRowContents(BufferedReader br) throws IOException {
|
||||
@@ -122,6 +124,7 @@ public class SailwaveHtmlParser {
|
||||
final List<String> tdContent = getTagContents(row, "td");
|
||||
result.add(createCompetitorRow(tdContent, columnNamesAndStyles, classesCounts));
|
||||
}
|
||||
addMostLikelyClassToMetadata(classesCounts, metadata);
|
||||
return new RegattaResults() {
|
||||
@Override
|
||||
public Map<String, String> getMetadata() {
|
||||
@@ -137,6 +140,13 @@ public class SailwaveHtmlParser {
|
||||
}
|
||||
}
|
||||
|
||||
private void addMostLikelyClassToMetadata(Map<String, Integer> classesCounts, Map<String, String> metadata) {
|
||||
if (!classesCounts.isEmpty()) {
|
||||
// sort descending and pick first:
|
||||
metadata.put(CLASS_METADATA, classesCounts.entrySet().stream().sorted((e1, e2)->Integer.compare(e2.getValue(), e1.getValue())).findFirst().get().getKey());
|
||||
}
|
||||
}
|
||||
|
||||
private void findTableBody(BufferedReader br) throws IOException {
|
||||
String line;
|
||||
while ((line=br.readLine()) != null && !line.contains("<tbody>"))
|
||||
|
||||
+8
-4
@@ -58,12 +58,16 @@ public class ScoreCorrectionProviderImpl extends AbstractResultUrlProvider imple
|
||||
*/
|
||||
private String getBoatClassName(RegattaResults regattaResult) {
|
||||
Map<String, String> metadata = regattaResult.getMetadata();
|
||||
for (String metadatum : metadata.values()) {
|
||||
if (metadatum != null && metadatum.length() > 0) {
|
||||
return metadatum;
|
||||
if (metadata.containsKey(SailwaveHtmlParser.CLASS_METADATA)) {
|
||||
return metadata.get(SailwaveHtmlParser.CLASS_METADATA);
|
||||
} else {
|
||||
for (String metadatum : metadata.values()) {
|
||||
if (metadatum != null && metadatum.length() > 0) {
|
||||
return metadatum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user