mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-18 18:20:58 +00:00
MetaColumn factors are now imported with MasterDataImport
see bug #1605 also added an assert to the according OverallLeaderboard test case
This commit is contained in:
1 parent
b3c65ee93a
commit
967e3de29e
5 files changed
+68
-12
No files matched your search
+15
-1
@@ -1,8 +1,10 @@
|
||||
package com.sap.sailing.server.gateway.deserialization.masterdata.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
@@ -102,7 +104,19 @@ public class LeaderboardGroupMasterDataJsonDeserializer implements JsonDeseriali
|
||||
}
|
||||
ScoringScheme overallLeaderboardScoringScheme = !hasOverallLeaderboard ? null : LeaderboardMasterDataJsonDeserializer.deserializeScoringScheme((JSONObject) object.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_OVERALL_LEADERBOARD_SCORING_SCHEME), domainFactory);
|
||||
int[] overallLeaderboardResultDiscardingThresholds = !hasOverallLeaderboard ? null : LeaderboardMasterDataJsonDeserializer.deserializeResultDesicardingRule((JSONObject) object.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_OVERALL_LEADERBOARD_DISCARDING_THRESHOLDS));
|
||||
return new LeaderboardGroupMasterData(name, description, displayGroupsReverse, hasOverallLeaderboard, overallLeaderboardScoringScheme, overallLeaderboardResultDiscardingThresholds, leaderboards, events, regattas);
|
||||
Map<String, Double> metaColumnsWithFactors = !hasOverallLeaderboard ? null : deserializeMetaColumnsWithFactor((JSONArray) object.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_OVERALL_LEADERBOARD_META_COLUMNS));
|
||||
return new LeaderboardGroupMasterData(name, description, displayGroupsReverse, hasOverallLeaderboard, overallLeaderboardScoringScheme, overallLeaderboardResultDiscardingThresholds, metaColumnsWithFactors, leaderboards, events, regattas);
|
||||
}
|
||||
|
||||
private Map<String, Double> deserializeMetaColumnsWithFactor(JSONArray jsonArray) {
|
||||
Map<String, Double> metaColumnsWithFactors = new HashMap<String, Double>();
|
||||
for (Object obj : jsonArray) {
|
||||
JSONObject jsonObj = (JSONObject) obj;
|
||||
String name = (String) jsonObj.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_NAME);
|
||||
Double explicitFactor = (Double) jsonObj.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_EXPLICIT_FACTOR);
|
||||
metaColumnsWithFactors.put(name, explicitFactor);
|
||||
}
|
||||
return metaColumnsWithFactors;
|
||||
}
|
||||
|
||||
}
|
||||
+20
-4
@@ -15,6 +15,7 @@ import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.domain.common.Color;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
|
||||
import com.sap.sailing.domain.leaderboard.meta.LeaderboardGroupMetaLeaderboard;
|
||||
import com.sap.sailing.domain.racelog.RaceLogEvent;
|
||||
import com.sap.sailing.server.gateway.serialization.JsonSerializer;
|
||||
import com.sap.sailing.server.gateway.serialization.impl.BoatClassJsonSerializer;
|
||||
@@ -36,6 +37,8 @@ public class LeaderboardGroupMasterDataJsonSerializer implements JsonSerializer<
|
||||
public static final String FIELD_DISPLAY_GROUPS_REVERSE = "displayGroupsReverse";
|
||||
public static final String FIELD_EVENTS = "events";
|
||||
public static final String FIELD_REGATTAS = "regattas";
|
||||
public static final String FIELD_OVERALL_LEADERBOARD_META_COLUMNS = "overallLeaderboardMetaColumns";
|
||||
public static final String FIELD_EXPLICIT_FACTOR = "explicitFactor";
|
||||
private final LeaderboardMasterDataJsonSerializer leadboardSerializer;
|
||||
private final Iterable<Event> allEvents;
|
||||
private final JsonSerializer<Event> eventSerializer;
|
||||
@@ -71,12 +74,14 @@ public class LeaderboardGroupMasterDataJsonSerializer implements JsonSerializer<
|
||||
jsonLeaderboardGroup.put(FIELD_DESCRIPTION, leaderboardGroup.getDescription());
|
||||
jsonLeaderboardGroup.put(FIELD_HAS_OVERALL_LEADERBOARD, leaderboardGroup.getOverallLeaderboard() != null);
|
||||
if (leaderboardGroup.getOverallLeaderboard() != null) {
|
||||
LeaderboardGroupMetaLeaderboard metaLeader = (LeaderboardGroupMetaLeaderboard) leaderboardGroup
|
||||
.getOverallLeaderboard();
|
||||
jsonLeaderboardGroup.put(FIELD_OVERALL_LEADERBOARD_DISCARDING_THRESHOLDS,
|
||||
LeaderboardMasterDataJsonSerializer.createJsonForResultDiscardingRule(leaderboardGroup
|
||||
.getOverallLeaderboard().getResultDiscardingRule()));
|
||||
LeaderboardMasterDataJsonSerializer.createJsonForResultDiscardingRule(metaLeader
|
||||
.getResultDiscardingRule()));
|
||||
jsonLeaderboardGroup.put(FIELD_OVERALL_LEADERBOARD_SCORING_SCHEME,
|
||||
LeaderboardMasterDataJsonSerializer.createJsonForScoringScheme(leaderboardGroup
|
||||
.getOverallLeaderboard().getScoringScheme()));
|
||||
LeaderboardMasterDataJsonSerializer.createJsonForScoringScheme(metaLeader.getScoringScheme()));
|
||||
jsonLeaderboardGroup.put(FIELD_OVERALL_LEADERBOARD_META_COLUMNS, createJsonArrayForMetaColumns(metaLeader));
|
||||
}
|
||||
jsonLeaderboardGroup.put(FIELD_LEADERBOARDS, createJsonArrayForLeaderboards(leaderboardGroup.getLeaderboards()));
|
||||
jsonLeaderboardGroup.put(FIELD_DISPLAY_GROUPS_REVERSE, leaderboardGroup.isDisplayGroupsInReverseOrder());
|
||||
@@ -88,6 +93,17 @@ public class LeaderboardGroupMasterDataJsonSerializer implements JsonSerializer<
|
||||
return jsonLeaderboardGroup;
|
||||
}
|
||||
|
||||
private JSONArray createJsonArrayForMetaColumns(LeaderboardGroupMetaLeaderboard metaLeader) {
|
||||
JSONArray array = new JSONArray();
|
||||
for (RaceColumn column : metaLeader.getRaceColumns()) {
|
||||
JSONObject metaColumn = new JSONObject();
|
||||
metaColumn.put(FIELD_NAME, column.getName());
|
||||
metaColumn.put(FIELD_EXPLICIT_FACTOR, column.getExplicitFactor());
|
||||
array.add(metaColumn);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private JSONArray createJsonArrayForRegattas() {
|
||||
JSONArray array = new JSONArray();
|
||||
Iterable<Regatta> regattas = leadboardSerializer.getRegattas();
|
||||
|
||||
Reference in new issue
Block a user