mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-10 14:20:55 +00:00
Merge branch 'master' into bug1825
This commit is contained in:
commit
e7c21b0235
11 files changed
+62
-90
No files matched your search
+2
-13
@@ -16,12 +16,11 @@ import com.sap.sailing.domain.igtimiadapter.impl.FixFactory;
|
||||
|
||||
public class LatestDatumTest {
|
||||
|
||||
private final String sample1 = "{\"latest_data\":[{\"latest_datum\":{\"serial_number\":\"DD-EE-AAGA\",\"resource_id\":1012353,\"c1\":0.5556,\"timestamp\":1384091813000.0}},{\"latest_datum\":{\"serial_number\":\"DD-EE-AAHG\",\"resource_id\":1012356,\"c1\":0.3704,\"timestamp\":1384078160000.0}}]}";
|
||||
private final String sample2 = "{\"latest_data\":[{\"latest_datum\":{\"serial_number\":\"DD-EE-AAHG\",\"resource_id\":1012356,\"c1\":4.0744,\"timestamp\":1384078157500.0}}]}";
|
||||
private final String sample1 = "{\"DD-EE-AAGA\":{\"9\":{\"t\":[1.384091813E12],\"resource_id\":1012353,\"1\":[0.5556]}},\"DD-EE-AAHG\":{\"9\":{\"t\":[1.386186319E12],\"resource_id\":1012677,\"1\":[0.0]}}}";
|
||||
|
||||
@Test
|
||||
public void testFixProductionFromSample1() throws ParseException {
|
||||
Iterable<Fix> fixes = new FixFactory().createFixesFromLastDatum((JSONObject) new JSONParser().parse(sample1), Type.SOG);
|
||||
Iterable<Fix> fixes = new FixFactory().createFixes((JSONObject) new JSONParser().parse(sample1));
|
||||
assertEquals(2, Util.size(fixes));
|
||||
Iterator<Fix> i = fixes.iterator();
|
||||
Fix fix1 = i.next();
|
||||
@@ -31,14 +30,4 @@ public class LatestDatumTest {
|
||||
assertEquals("DD-EE-AAHG", fix2.getSensor().getDeviceSerialNumber());
|
||||
assertEquals(Type.SOG, fix2.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFixProductionFromSample2() throws ParseException {
|
||||
Iterable<Fix> fixes = new FixFactory().createFixesFromLastDatum((JSONObject) new JSONParser().parse(sample2), Type.AWS);
|
||||
assertEquals(1, Util.size(fixes));
|
||||
Iterator<Fix> i = fixes.iterator();
|
||||
Fix fix1 = i.next();
|
||||
assertEquals("DD-EE-AAHG", fix1.getSensor().getDeviceSerialNumber());
|
||||
assertEquals(Type.AWS, fix1.getType());
|
||||
}
|
||||
}
|
||||
+29
-48
@@ -15,6 +15,7 @@ import org.json.simple.JSONObject;
|
||||
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util;
|
||||
import com.sap.sailing.domain.igtimiadapter.Sensor;
|
||||
import com.sap.sailing.domain.igtimiadapter.datatypes.Fix;
|
||||
import com.sap.sailing.domain.igtimiadapter.datatypes.Type;
|
||||
@@ -27,60 +28,40 @@ public class FixFactory {
|
||||
for (Entry<Object, Object> e : sensorsJson.entrySet()) {
|
||||
String deviceSerialNumber = (String) e.getKey();
|
||||
JSONObject typesJson = (JSONObject) e.getValue();
|
||||
for (Entry<Object, Object> fixTypeAndFixesJson : typesJson.entrySet()) {
|
||||
final String fixTypeAndOptionalSensorId = (String) fixTypeAndFixesJson.getKey();
|
||||
final String[] fixTypeAndOptionalColonSeparatedSensorsSubId = fixTypeAndOptionalSensorId.split(":");
|
||||
int fixType = Integer.valueOf(fixTypeAndOptionalColonSeparatedSensorsSubId[0]);
|
||||
JSONObject fixesJson = (JSONObject) fixTypeAndFixesJson.getValue();
|
||||
JSONArray timePointsMillis = (JSONArray) fixesJson.get("t");
|
||||
int fixIndex = 0;
|
||||
for (Object timePointMillis : timePointsMillis) {
|
||||
TimePoint timePoint = new MillisecondsTimePoint(((Number) timePointMillis).longValue());
|
||||
Map<Integer, Object> valuesPerSubindex = new HashMap<>();
|
||||
int i=1;
|
||||
JSONArray values;
|
||||
while ((values=(JSONArray) fixesJson.get(""+i)) != null) {
|
||||
valuesPerSubindex.put(i, (Number) values.get(fixIndex));
|
||||
i++;
|
||||
}
|
||||
Sensor sensor = new SensorImpl(deviceSerialNumber,
|
||||
fixTypeAndOptionalColonSeparatedSensorsSubId.length < 2 ? 0
|
||||
: Long.valueOf(fixTypeAndOptionalColonSeparatedSensorsSubId[1]));
|
||||
Fix fix = createFix(sensor, Type.valueOf(fixType), timePoint, valuesPerSubindex);
|
||||
result.add(fix);
|
||||
fixIndex++;
|
||||
Util.addAll(createFixesForTypes(deviceSerialNumber, typesJson), result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Iterable<Fix> createFixesForTypes(String deviceSerialNumber, JSONObject typesJson) {
|
||||
final List<Fix> result = new ArrayList<>();
|
||||
for (Entry<Object, Object> fixTypeAndFixesJson : typesJson.entrySet()) {
|
||||
final String fixTypeAndOptionalSensorId = (String) fixTypeAndFixesJson.getKey();
|
||||
final String[] fixTypeAndOptionalColonSeparatedSensorsSubId = fixTypeAndOptionalSensorId.split(":");
|
||||
int fixType = Integer.valueOf(fixTypeAndOptionalColonSeparatedSensorsSubId[0]);
|
||||
JSONObject fixesJson = (JSONObject) fixTypeAndFixesJson.getValue();
|
||||
JSONArray timePointsMillis = (JSONArray) fixesJson.get("t");
|
||||
int fixIndex = 0;
|
||||
for (Object timePointMillis : timePointsMillis) {
|
||||
TimePoint timePoint = new MillisecondsTimePoint(((Number) timePointMillis).longValue());
|
||||
Map<Integer, Object> valuesPerSubindex = new HashMap<>();
|
||||
int i=1;
|
||||
JSONArray values;
|
||||
while ((values=(JSONArray) fixesJson.get(""+i)) != null) {
|
||||
valuesPerSubindex.put(i, (Number) values.get(fixIndex));
|
||||
i++;
|
||||
}
|
||||
Sensor sensor = new SensorImpl(deviceSerialNumber,
|
||||
fixTypeAndOptionalColonSeparatedSensorsSubId.length < 2 ? 0
|
||||
: Long.valueOf(fixTypeAndOptionalColonSeparatedSensorsSubId[1]));
|
||||
Fix fix = createFix(sensor, Type.valueOf(fixType), timePoint, valuesPerSubindex);
|
||||
result.add(fix);
|
||||
fixIndex++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lastDataJson expected to use "c1", "c2", ... instead of "1" and "2" for the sensor parameters, and
|
||||
* "timestamp" instead of "t" for the timestamp. The values are not provided as arrays but as single values.
|
||||
*/
|
||||
public Iterable<Fix> createFixesFromLastDatum(JSONObject lastDataJson, Type type) {
|
||||
List<Fix> result = new ArrayList<>();
|
||||
JSONArray latestDataArray = (JSONArray) lastDataJson.get("latest_data");
|
||||
for (Object d : latestDataArray) {
|
||||
JSONObject latestDatum = (JSONObject) ((JSONObject) d).get("latest_datum");
|
||||
String serialNumber = (String) latestDatum.get("serial_number");
|
||||
// there is a field called "resource_id" but we're currently ignoring it because not all fixes have one and we currently
|
||||
// don't have a use for it
|
||||
Map<Integer, Object> valuesPerSubindex = new HashMap<>();
|
||||
int i=1;
|
||||
Object c_i;
|
||||
while ((c_i=latestDatum.get("c"+i)) != null) {
|
||||
valuesPerSubindex.put(i, c_i);
|
||||
i++;
|
||||
}
|
||||
Sensor sensor = new SensorImpl(serialNumber, /* sensor ID */ 0); // Note: the sensor ID isn't obvious from neither the URL nor the response; using 0 as default
|
||||
TimePoint timestamp = new MillisecondsTimePoint(((Number) latestDatum.get("timestamp")).longValue());
|
||||
result.add(createFix(sensor, type, timestamp, valuesPerSubindex));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Fix createFix(Sensor sensor, Type fixType, TimePoint timePoint, Map<Integer, Object> valuesPerSubindex) {
|
||||
try {
|
||||
Constructor<? extends Fix> constructor = fixType.getFixClass().getConstructor(TimePoint.class, Sensor.class, Map.class);
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ public class IgtimiConnectionImpl implements IgtimiConnection {
|
||||
HttpClient client = connectionFactory.getHttpClient();
|
||||
HttpGet getLatestData = new HttpGet(connectionFactory.getLatestDatumUrl(deviceSerialNumbers, type, account));
|
||||
JSONObject latestDataJson = ConnectivityUtils.getJsonFromResponse(client.execute(getLatestData));
|
||||
return new FixFactory().createFixesFromLastDatum(latestDataJson, type);
|
||||
return new FixFactory().createFixes(latestDataJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ public class TopLevelMasterData implements Serializable {
|
||||
Map<RegattaIdentifier, Set<String>> raceIdStringsForRegatta = new HashMap<RegattaIdentifier, Set<String>>();
|
||||
for (Entry<String, Regatta> entry : regattaForRaceIdString.entrySet()) {
|
||||
Regatta regatta = entry.getValue();
|
||||
Set<String> raceIds = raceIdStringsForRegatta.get(regatta);
|
||||
Set<String> raceIds = raceIdStringsForRegatta.get(regatta.getRegattaIdentifier());
|
||||
if (raceIds == null) {
|
||||
raceIds = new HashSet<String>();
|
||||
raceIdStringsForRegatta.put(regatta.getRegattaIdentifier(), raceIds);
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="com.google.gwt.eclipse.core.moduleClasspathProvider"/>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.google.gwt.dev.DevMode"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-war "${project_loc:com.sap.sailing.gwt.ui}" -noserver -remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -logLevel INFO -codeServerPort 9997 -startupUrl /gwt/AdminConsole.html com.sap.sailing.gwt.ui.AdminConsole -startupUrl /gwt/LeaderboardEditing.html com.sap.sailing.gwt.ui.LeaderboardEditing -startupUrl /gwt/UserManagement.html com.sap.sailing.gwt.ui.UserManagement -startupUrl /gwt/Leaderboard.html com.sap.sailing.gwt.ui.Leaderboard -startupUrl /gwt/Spectator.html com.sap.sailing.gwt.ui.Spectator -startupUrl /gwt/RaceBoard.html com.sap.sailing.gwt.ui.RaceBoard -startupUrl /gwt/TvView.html com.sap.sailing.gwt.ui.TvView -startupUrl /gwt/PolarSheets.html com.sap.sailing.gwt.ui.PolarSheets -startupUrl /gwt/RegattaOverview.html com.sap.sailing.gwt.ui.RegattaOverview -startupUrl /gwt/Simulator.html com.sap.sailing.gwt.ui.VideoPopup"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-war "${project_loc:com.sap.sailing.gwt.ui}" -noserver -remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -logLevel INFO -codeServerPort 9997 -startupUrl /gwt/AdminConsole.html com.sap.sailing.gwt.ui.AdminConsole -startupUrl /gwt/LeaderboardEditing.html com.sap.sailing.gwt.ui.LeaderboardEditing -startupUrl /gwt/UserManagement.html com.sap.sailing.gwt.ui.UserManagement -startupUrl /gwt/Leaderboard.html com.sap.sailing.gwt.ui.Leaderboard -startupUrl /gwt/Spectator.html com.sap.sailing.gwt.ui.Spectator -startupUrl /gwt/RaceBoard.html com.sap.sailing.gwt.ui.RaceBoard -startupUrl /gwt/TvView.html com.sap.sailing.gwt.ui.TvView -startupUrl /gwt/PolarSheets.html com.sap.sailing.gwt.ui.PolarSheets -startupUrl /gwt/RegattaOverview.html com.sap.sailing.gwt.ui.VideoPopup"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.sap.sailing.gwt.ui"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx2048m -XX:MaxPermSize=512m"/>
|
||||
</launchConfiguration>
|
||||
+1
@@ -67,6 +67,7 @@ public class TestStoringAndRetrievingLeaderboardGroups extends AbstractMongoDBTe
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DomainFactory.INSTANCE.getCompetitorStore().clear();
|
||||
mongoObjectFactory = new MongoObjectFactoryImpl(db);
|
||||
domainObjectFactory = new DomainObjectFactoryImpl(db, DomainFactory.INSTANCE);
|
||||
}
|
||||
|
||||
+6
@@ -9,6 +9,7 @@ import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mongodb.MongoException;
|
||||
@@ -44,6 +45,11 @@ public class TestStoringAndRetrievingLeaderboards extends AbstractMongoDBTest {
|
||||
public TestStoringAndRetrievingLeaderboards() throws UnknownHostException, MongoException {
|
||||
super();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void clearCompetitorStore() {
|
||||
DomainFactory.INSTANCE.getCompetitorStore().clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreAndRetrieveSimpleLeaderboardWithSpecificColumnFactors() {
|
||||
|
||||
+3
-4
@@ -1518,10 +1518,8 @@ public class MasterDataImportTest {
|
||||
TrackedRace trackedRace = new DummyTrackedRace(competitors, regatta, null);
|
||||
|
||||
raceColumn.setTrackedRace(testFleet1, trackedRace);
|
||||
Set<String> raceIds = new HashSet<String>();
|
||||
raceIds.add("dummy");
|
||||
|
||||
sourceService.setPersistentRegattaForRaceIDs(regatta, raceIds, false);
|
||||
sourceService.setRegattaForRace(regatta, "dummy");
|
||||
sourceService.setRegattaForRace(regatta, "dummy2");
|
||||
|
||||
// Set log event
|
||||
RaceLogEventFactory factory = new RaceLogEventFactoryImpl();
|
||||
@@ -1596,6 +1594,7 @@ public class MasterDataImportTest {
|
||||
// Check if dummy race id has been imported to destination service
|
||||
ConcurrentHashMap<String, Regatta> map = destService.getPersistentRegattasForRaceIDs();
|
||||
Assert.assertEquals(regattaOnTarget, map.get("dummy"));
|
||||
Assert.assertEquals(regattaOnTarget, map.get("dummy2"));
|
||||
|
||||
// Check if persistent regatta for race id has been persisted
|
||||
RacingEventServiceImplMock destService2 = new RacingEventServiceImplMock(new DataImportProgressImpl(randomUUID));
|
||||
|
||||
@@ -443,13 +443,9 @@ public interface RacingEventService extends TrackedRegattaRegistry, RegattaFetch
|
||||
* {@link #setRegattaForRace(Regatta, RaceDefinition)}. It helps remember the connection between races and regattas.
|
||||
*/
|
||||
ConcurrentHashMap<String, Regatta> getPersistentRegattasForRaceIDs();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param override If set to true, the mthod will override any existing connection
|
||||
*/
|
||||
void setPersistentRegattaForRaceIDs(Regatta regatta, Iterable<String> raceIdStrings, boolean override);
|
||||
|
||||
void setRegattaForRace(Regatta regatta, String raceIdAsString);
|
||||
|
||||
Event createEventWithoutReplication(String eventName, String venue, String publicationUrl, boolean isPublic,
|
||||
UUID id);
|
||||
|
||||
|
||||
+7
-15
@@ -1994,8 +1994,13 @@ public class RacingEventServiceImpl implements RacingEventServiceWithTestSupport
|
||||
* <code>regatta</code> will be returned.
|
||||
*/
|
||||
private void setRegattaForRace(Regatta regatta, RaceDefinition race) {
|
||||
persistentRegattasForRaceIDs.put(race.getId().toString(), regatta);
|
||||
mongoObjectFactory.storeRegattaForRaceID(race.getId().toString(), regatta);
|
||||
setRegattaForRace(regatta, race.getId().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRegattaForRace(Regatta regatta, String raceIdAsString) {
|
||||
persistentRegattasForRaceIDs.put(raceIdAsString, regatta);
|
||||
mongoObjectFactory.storeRegattaForRaceID(raceIdAsString, regatta);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2149,19 +2154,6 @@ public class RacingEventServiceImpl implements RacingEventServiceWithTestSupport
|
||||
return persistentRegattasForRaceIDs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPersistentRegattaForRaceIDs(Regatta regatta, Iterable<String> raceIdStrings, boolean override) {
|
||||
for (String raceIdAsString : raceIdStrings) {
|
||||
if (!override && persistentRegattasForRaceIDs.contains(raceIdAsString)) {
|
||||
logger.info(String.format(
|
||||
"Persistent regatta wasn't set for race id %1$s, because override was not turned on.",
|
||||
raceIdAsString));
|
||||
} else {
|
||||
persistentRegattasForRaceIDs.put(raceIdAsString, regatta);
|
||||
mongoObjectFactory.storeRegattaForRaceID(raceIdAsString, regatta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WindStore getWindStore() {
|
||||
|
||||
+9
-1
@@ -350,7 +350,15 @@ public class ImportMasterDataOperation extends
|
||||
createdRegatta.setRegattaConfiguration(regatta.getRegattaConfiguration());
|
||||
Set<String> raceIdStrings = masterData.getRaceIdStringsForRegatta().get(regatta.getRegattaIdentifier());
|
||||
if (raceIdStrings != null) {
|
||||
toState.setPersistentRegattaForRaceIDs(createdRegatta, raceIdStrings, override);
|
||||
for (String raceIdAsString : raceIdStrings) {
|
||||
if (!override && toState.getRememberedRegattaForRace(raceIdAsString) != null) {
|
||||
logger.info(String
|
||||
.format("Persistent regatta wasn't set for race id %1$s, because override was not turned on.",
|
||||
raceIdAsString));
|
||||
} else {
|
||||
toState.setRegattaForRace(createdRegatta, raceIdAsString);
|
||||
}
|
||||
}
|
||||
}
|
||||
creationCount.addOneRegatta(createdRegatta.getId().toString());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user