mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-23 22:19:13 +00:00
Merge branch 'racecommittee_integrated' of ssh://sapsailing.com/home/trac/git into racecommittee_integrated
This commit is contained in:
@@ -1,25 +1,48 @@
|
||||
#!/bin/bash
|
||||
set -o functrace
|
||||
|
||||
find_project_home ()
|
||||
{
|
||||
if [[ $1 == '/' ]] || [[ $1 == "" ]]; then
|
||||
echo ""
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ ! -d "$1/.git" ]; then
|
||||
PARENT_DIR=`cd $1/..;pwd | sed -e 's/\/cygdrive\/\([a-zA-Z]\)/\1:/'`
|
||||
echo $(find_project_home $PARENT_DIR)
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo $1
|
||||
}
|
||||
|
||||
# this holds for default installation
|
||||
USER_HOME=~
|
||||
START_DIR=`pwd`
|
||||
|
||||
if [ "$PROJECT_HOME" = "" ]; then
|
||||
PROJECT_HOME=$USER_HOME/git
|
||||
PROJECT_HOME=$(find_project_home $START_DIR)
|
||||
fi
|
||||
|
||||
if [ ! -d $PROJECT_HOME/.git ]; then
|
||||
echo "Could not identify $PROJECT_HOME as git repository. Please make sure to set PROJECT_HOME to the right one."
|
||||
exit
|
||||
# if project_home is still empty we could not determine any suitable directory
|
||||
if [[ $PROJECT_HOME == "" ]]; then
|
||||
echo "Could neither determine nor get PROJECT_HOME. Please provide it by setting an environment variable with this name."
|
||||
exit
|
||||
fi
|
||||
|
||||
echo PROJECT_HOME is $PROJECT_HOME
|
||||
SERVERS_HOME=$USER_HOME/servers
|
||||
if [ "$SERVERS_HOME" = "" ]; then
|
||||
SERVERS_HOME=`echo "$USER_HOME/servers" | sed -e 's/\/cygdrive\/\([a-zA-Z]\)/\1:/'`
|
||||
fi
|
||||
|
||||
# x86 or x86_64 should work for most cases
|
||||
ARCH=x86_64
|
||||
START_DIR=`pwd`
|
||||
|
||||
# needed for maven to work correctly
|
||||
source $USER_HOME/.bash_profile
|
||||
# needed for maven on sapsailing.com to work correctly
|
||||
if [ -f $USER_HOME/.bash_profile ]; then
|
||||
source $USER_HOME/.bash_profile
|
||||
fi
|
||||
|
||||
cd $PROJECT_HOME
|
||||
active_branch=$(git symbolic-ref -q HEAD)
|
||||
@@ -30,6 +53,8 @@ ACDIR=$SERVERS_HOME/$active_branch
|
||||
MAVEN_SETTINGS=$PROJECT_HOME/configuration/maven-settings.xml
|
||||
MAVEN_SETTINGS_PROXY=$PROJECT_HOME/configuration/maven-settings-proxy.xml
|
||||
|
||||
p2PluginRepository=$PROJECT_HOME/java/com.sap.sailing.feature.p2build/bin/products/raceanalysis.product.id/linux/gtk/$ARCH
|
||||
|
||||
gwtcompile=1
|
||||
testing=1
|
||||
clean="clean"
|
||||
@@ -38,23 +63,34 @@ proxy=0
|
||||
extra=''
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "buildAndUpdateProduct [-g -t -o -c] [build|install|all]"
|
||||
echo ""
|
||||
echo "Active branch is $active_branch"
|
||||
echo "buildAndUpdateProduct [-g -t -o -c -m <config> -n <package> -l <port>] [build|install|all|hot-deploy]"
|
||||
echo ""
|
||||
echo "-g Disable GWT compile, no gwt files will be generated, old ones will be preserved."
|
||||
echo "-t Disable tests"
|
||||
echo "-o Enable offline mode (does not work for tycho surefire plugin)"
|
||||
echo "-c Disable cleaning (use only if you are sure that no java file has changed)"
|
||||
echo "-p Enable proxy mode"
|
||||
echo "-p Enable proxy mode (overwrites file specified by -m)"
|
||||
echo "-m <path to file> Specify alternate maven configuration (possibly has side effect on proxy setting)"
|
||||
echo "-n <package name> Name of the bundle you want to hot deploy. Needs fully qualified name like"
|
||||
echo " com.sap.sailing.monitoring. Only works if there is a fully built server available."
|
||||
echo "-l <telnet port> Telnet port the OSGi server is running. Optional but enables fully automatic hot-deploy."
|
||||
echo ""
|
||||
echo "build: builds the server code using Maven to $PROJECT_HOME (log to $START_DIR/build.log)"
|
||||
echo "install: installs product and configuration to $SERVERS_HOME/$active_branch. Overwrites any configuration by using config from branch."
|
||||
echo "all: calls build and then install"
|
||||
echo "hot-deploy: performs hot deployment of named bundle into OSGi server"
|
||||
echo ""
|
||||
echo "Active branch is $active_branch"
|
||||
echo "Project home is $PROJECT_HOME"
|
||||
echo "Server home is $SERVERS_HOME"
|
||||
echo "P2 home is $p2PluginRepository"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
options=':gtocp'
|
||||
echo PROJECT_HOME is $PROJECT_HOME
|
||||
echo SERVERS_HOME is $SERVERS_HOME
|
||||
|
||||
options=':gtocpm:n:l:'
|
||||
while getopts $options option
|
||||
do
|
||||
case $option in
|
||||
@@ -63,26 +99,129 @@ do
|
||||
o) offline=1;;
|
||||
c) clean="";;
|
||||
p) proxy=1;;
|
||||
m) MAVEN_SETTINGS=$OPTARG;;
|
||||
n) OSGI_BUNDLE_NAME=$OPTARG;;
|
||||
l) OSGI_TELNET_PORT=$OPTARG;;
|
||||
\?) echo "Invalid option"
|
||||
exit 2;;
|
||||
esac
|
||||
done
|
||||
|
||||
read -s -n1 -p "Currently branch $active_branch is active. Do you want to proceed (y/N): " answer
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if [[ $@ == "" ]]; then
|
||||
echo "You need to specify an action [build|install|all|hot-deploy]"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ "$@" == "hot-deploy" ]]; then
|
||||
# check parameters
|
||||
if [[ $OSGI_BUNDLE_NAME == "" ]]; then
|
||||
echo "You need to provide -n parameter with bundle name."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# locate old bundle
|
||||
BUNDLE_COUNT=`find $SERVERS_HOME/$active_branch/plugins -maxdepth 1 -name "${OSGI_BUNDLE_NAME}_*.jar" | wc -l`
|
||||
OLD_BUNDLE=`find $SERVERS_HOME/$active_branch/plugins -maxdepth 1 -name "${OSGI_BUNDLE_NAME}_*.jar"`
|
||||
if [[ $OLD_BUNDLE == "" ]] || [[ $BUNDLE_COUNT -ne 1 ]]; then
|
||||
echo "ERROR: Could not find any bundle named $OSGI_BUNDLE_NAME ($BUNDLE_COUNT). Perhaps your name is misspelled or you have no build?"
|
||||
exit
|
||||
fi
|
||||
|
||||
OLD_BUNDLE_BASENAME=`basename $OLD_BUNDLE .jar`
|
||||
OLD_BUNDLE_VERSION=${OLD_BUNDLE_BASENAME#*_}
|
||||
|
||||
echo "OLD bundle is $OSGI_BUNDLE_NAME with version $OLD_BUNDLE_VERSION"
|
||||
|
||||
# locate new bundle
|
||||
NEW_BUNDLE=`find $p2PluginRepository/plugins -maxdepth 1 -name "${OSGI_BUNDLE_NAME}_*.jar"`
|
||||
NEW_BUNDLE_BASENAME=`basename $NEW_BUNDLE .jar`
|
||||
NEW_BUNDLE_VERSION=${NEW_BUNDLE_BASENAME#*_}
|
||||
echo "NEW bundle is $OSGI_BUNDLE_NAME with version $NEW_BUNDLE_VERSION"
|
||||
|
||||
if [[ $NEW_BUNDLE_VERSION == $OLD_BUNDLE_VERSION ]]; then
|
||||
echo ""
|
||||
echo "WARNING: Bundle versions do not differ. Update not needed."
|
||||
fi
|
||||
|
||||
read -s -n1 -p "Do you really want to hot-deploy bundle $OSGI_BUNDLE_NAME to $PROJECT_HOME/$active_branch? (y/N): " answer
|
||||
case $answer in
|
||||
"Y" | "y") echo "Continuing";;
|
||||
*) echo "Aborting..."
|
||||
exit;;
|
||||
esac
|
||||
|
||||
# deploy new bundle physically
|
||||
mkdir -p $SERVERS_HOME/$active_branch/plugins/deploy
|
||||
cp $NEW_BUNDLE $SERVERS_HOME/$active_branch/plugins/deploy
|
||||
echo "Copied ${NEW_BUNDLE_BASENAME}.jar to $SERVERS_HOME/$active_branch/plugins/deploy"
|
||||
|
||||
# check telnet port connection
|
||||
TELNET_ACTIVE=`netstat -tlnp 2>/dev/null | grep ":$OSGI_TELNET_PORT"`
|
||||
if [[ $OSGI_TELNET_PORT == "" ]] || [[ $TELNET_ACTIVE == "" ]]; then
|
||||
echo ""
|
||||
echo "ERROR: Could not find any process running on port $OSGI_TELNET_PORT. Make sure your server has been started with -console $OSGI_TELNET_PORT"
|
||||
echo "I've already deployed bundle to $SERVERS_HOME/$active_branch/plugins/deploy/${NEW_BUNDLE_BASENAME}.jar"
|
||||
echo "You can now install it yourself by issuing the following commands:"
|
||||
echo ""
|
||||
echo "osgi> ss $OSGI_BUNDLE_NAME"
|
||||
echo "21 ACTIVE $OLD_BUNDLE_BASENAME"
|
||||
echo "osgi> stop 21"
|
||||
echo "osgi> uninstall 21"
|
||||
echo "osgi> install file://$SERVERS_HOME/$active_branch/plugins/deploy/${NEW_BUNDLE_BASENAME}.jar"
|
||||
echo "osgi> ss $OSGI_BUNDLE_NAME"
|
||||
echo "71 INSTALLED $NEW_BUNDLE_BASENAME"
|
||||
echo "osgi> start 71"
|
||||
exit
|
||||
fi
|
||||
|
||||
# first get bundle ID
|
||||
NC_CMD="nc -t 127.0.0.1 $OSGI_TELNET_PORT"
|
||||
OLD_BUNDLE_INFORMATION=`echo -n ss | $NC_CMD | grep $OSGI_BUNDLE_NAME`
|
||||
BUNDLE_ID=`echo $OLD_BUNDLE_INFORMATION | cut -d " " -f 1`
|
||||
OLD_ACTIVATED_NAME=`echo $OLD_BUNDLE_INFORMATION | cut -d " " -f 3`
|
||||
echo "Could identify bundle-id $BUNDLE_ID for $OLD_ACTIVATED_NAME"
|
||||
|
||||
# stop and uninstall
|
||||
echo -n stop $BUNDLE_ID | $NC_CMD > /dev/null
|
||||
echo -n uninstall $BUNDLE_ID | $NC_CMD > /dev/null
|
||||
|
||||
# make sure bundle is removed
|
||||
UNINSTALL_INFORMATION=`echo -n ss | $NC_CMD | grep $OSGI_BUNDLE_NAME`
|
||||
if [[ $UNINSTALL_INFORMATION == "" ]]; then
|
||||
echo "Uninstall procedure sucessful!"
|
||||
else
|
||||
echo "Something went wrong during uninstall. Please check error logs."
|
||||
exit
|
||||
fi
|
||||
|
||||
# now reinstall bundle
|
||||
NEW_BUNDLE_ID=`echo -n install file://$SERVERS_HOME/$active_branch/plugins/deploy/${NEW_BUNDLE_BASENAME}.jar | $NC_CMD`
|
||||
NEW_BUNDLE_INFORMATION=`echo -n ss | $NC_CMD | grep $OSGI_BUNDLE_NAME`
|
||||
NEW_BUNDLE_ID=`echo $NEW_BUNDLE_INFORMATION | cut -d " " -f 1`
|
||||
echo "Installed new bundle file://$SERVERS_HOME/$active_branch/plugins/deploy/${NEW_BUNDLE_BASENAME}.jar with id $NEW_BUNDLE_ID"
|
||||
|
||||
# and start
|
||||
echo -n start $NEW_BUNDLE_ID | $NC_CMD > /dev/null && sleep 1
|
||||
NEW_BUNDLE_STATUS=`echo -n ss | $NC_CMD | grep $OSGI_BUNDLE_NAME | grep ACTIVE`
|
||||
if [[ $NEW_BUNDLE_STATUS == "" ]]; then
|
||||
echo "ERROR: Something went wrong with start of bundle. Please check if everything went ok."
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "Everything seems to be ok. Bundle hot-deployed to server with new id $NEW_BUNDLE_ID"
|
||||
exit
|
||||
fi
|
||||
|
||||
read -s -n1 -p "Currently branch $active_branch is active. Do you want to proceed with $@ (y/N): " answer
|
||||
case $answer in
|
||||
"Y" | "y") echo "Continuing";;
|
||||
*) echo "Aborting..."
|
||||
exit;;
|
||||
esac
|
||||
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if [[ $@ == "" ]]; then
|
||||
echo "You need to specify an action [build|install|all]"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo "Starting $@ of server..."
|
||||
echo "Starting $@ of server (maven configuration set to $MAVEN_SETTINGS)..."
|
||||
|
||||
if [[ "$@" == "build" ]] || [[ "$@" == "all" ]]; then
|
||||
# yield build so that we get updated product
|
||||
@@ -122,6 +261,11 @@ fi
|
||||
|
||||
if [[ "$@" == "install" ]] || [[ "$@" == "all" ]]; then
|
||||
|
||||
if [ ! -d $ACDIR ]; then
|
||||
echo "Could not find directory $ACDIR - perhaps you are on a wrong branch?"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ! -d "$ACDIR/plugins" ]; then
|
||||
mkdir $ACDIR/plugins
|
||||
fi
|
||||
@@ -130,18 +274,12 @@ if [[ "$@" == "install" ]] || [[ "$@" == "all" ]]; then
|
||||
mkdir $ACDIR/configuration
|
||||
fi
|
||||
|
||||
if [ ! -d $ACDIR ]; then
|
||||
echo "Could not find directory $ACDIR - perhaps you are on a wrong branch?"
|
||||
exit
|
||||
fi
|
||||
|
||||
cd $ACDIR
|
||||
|
||||
rm -rf $ACDIR/plugins/*.*
|
||||
rm -rf $ACDIR/org.eclipse.*
|
||||
rm -rf $ACDIR/configuration/org.eclipse.*
|
||||
|
||||
p2PluginRepository=$PROJECT_HOME/java/com.sap.sailing.feature.p2build/bin/products/raceanalysis.product.id/linux/gtk/$ARCH
|
||||
cp -v $p2PluginRepository/configuration/config.ini configuration/
|
||||
cp -r -v $p2PluginRepository/configuration/org.eclipse.equinox.simpleconfigurator configuration/
|
||||
cp -v $p2PluginRepository/plugins/*.jar plugins/
|
||||
|
||||
+2
@@ -7,6 +7,7 @@ import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.ManeuverType;
|
||||
@@ -24,6 +25,7 @@ public abstract class AbstractManeuverDetectionTestCase extends OnlineTracTracBa
|
||||
public AbstractManeuverDetectionTestCase() throws MalformedURLException, URISyntaxException {
|
||||
super();
|
||||
dateFormat = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss");
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+2")); // will result in CEST
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Regular → Executable
-2
@@ -6,7 +6,6 @@ import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
@@ -44,7 +43,6 @@ public class ManeuverAnalysis505Test extends AbstractManeuverDetectionTestCase {
|
||||
getTrackedRace().recordWind(
|
||||
new WindImpl(/* position */null, MillisecondsTimePoint.now(), new KnotSpeedWithBearingImpl(12,
|
||||
new DegreeBearingImpl(65))), new WindSourceImpl(WindSourceType.WEB));
|
||||
dateFormat = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Regular → Executable
+1
@@ -1717,6 +1717,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
return raceTimesInfos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoursePositionsDTO getCoursePositions(RegattaAndRaceIdentifier raceIdentifier, Date date) {
|
||||
CoursePositionsDTO result = new CoursePositionsDTO();
|
||||
if (date != null) {
|
||||
|
||||
+81
-37
@@ -34,6 +34,9 @@ import com.sap.sailing.server.gateway.AbstractCSVHttpServlet;
|
||||
public class ESS40ResultsAsCSVServlet extends AbstractCSVHttpServlet {
|
||||
private static final long serialVersionUID = -3975664653148197608L;
|
||||
private static final String PARAM_NAME_LEADERBOARDNAME = "leaderboardName";
|
||||
private static final String PARAM_NAME_RESULTSTATE = "resultState";
|
||||
private enum ResultStates { Live, Preliminary, Final };
|
||||
private final ResultStates DEFAULT_RESULT_STATE = ResultStates.Final;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
@@ -56,54 +59,66 @@ public class ESS40ResultsAsCSVServlet extends AbstractCSVHttpServlet {
|
||||
|
||||
setCSVResponseHeader(response, fileName);
|
||||
|
||||
TimePoint timePoint = MillisecondsTimePoint.now();
|
||||
ResultStates resultState = resolveRequestedResultState(request.getParameter(PARAM_NAME_RESULTSTATE));
|
||||
TimePoint requestTimePoint = MillisecondsTimePoint.now();
|
||||
TimePoint resultTimePoint = calculateTimePointForResultState(leaderboard, resultState);
|
||||
|
||||
// competitors are ordered according to total rank
|
||||
List<Competitor> suppressedCompetitors = new ArrayList<Competitor>();
|
||||
for (Competitor c : leaderboard.getSuppressedCompetitors()) {
|
||||
suppressedCompetitors.add(c);
|
||||
}
|
||||
List<Competitor> competitorsFromBestToWorst = leaderboard.getCompetitorsFromBestToWorst(timePoint);
|
||||
List<Competitor> competitorsFromBestToWorst = leaderboard.getCompetitorsFromBestToWorst(resultTimePoint != null ? resultTimePoint : requestTimePoint);
|
||||
Map<RaceColumn, List<Competitor>> rankedCompetitorsPerColumn = new HashMap<RaceColumn, List<Competitor>>();
|
||||
Iterable<RaceColumn> raceColumns = leaderboard.getRaceColumns();
|
||||
|
||||
for (Competitor competitor : competitorsFromBestToWorst) {
|
||||
if (!suppressedCompetitors.contains(competitor)) {
|
||||
// int totalRank = competitorsFromBestToWorst.indexOf(competitor) + 1;
|
||||
Double totalPoints = leaderboard.getTotalPoints(competitor, timePoint);
|
||||
if (leaderboard.hasCarriedPoints(competitor)) {
|
||||
Double carriedPoints = leaderboard.getCarriedPoints(competitor);
|
||||
if (carriedPoints != null) {
|
||||
totalPoints = totalPoints != null ? totalPoints += carriedPoints : carriedPoints;
|
||||
}
|
||||
}
|
||||
|
||||
List<Object> csvLine = new ArrayList<Object>();
|
||||
csvLine.add(competitor.getName());
|
||||
csv.add(csvLine);
|
||||
|
||||
// TODO: we should only export complete races where all competitors have valid totalPoints for a race
|
||||
for (RaceColumn raceColumn : raceColumns) {
|
||||
List<Competitor> rankedCompetitorsForColumn = rankedCompetitorsPerColumn.get(raceColumn);
|
||||
if (rankedCompetitorsForColumn == null) {
|
||||
rankedCompetitorsForColumn = leaderboard.getCompetitorsFromBestToWorst(raceColumn,
|
||||
timePoint);
|
||||
rankedCompetitorsPerColumn.put(raceColumn, rankedCompetitorsForColumn);
|
||||
}
|
||||
// Double netRacePoints = leaderboard.getNetPoints(competitor, raceColumn, timePoint);
|
||||
Double totalRacePoints = leaderboard.getTotalPoints(competitor, raceColumn, timePoint);
|
||||
MaxPointsReason maxPointsReason = leaderboard.getMaxPointsReason(competitor, raceColumn, timePoint);
|
||||
int rank = rankedCompetitorsForColumn.indexOf(competitor)+1;
|
||||
if(totalRacePoints != null) {
|
||||
if (maxPointsReason == null || maxPointsReason == MaxPointsReason.NONE) {
|
||||
csvLine.add(rank);
|
||||
csvLine.add(totalRacePoints);
|
||||
|
||||
} else {
|
||||
csvLine.add(maxPointsReason.name());
|
||||
csvLine.add(totalRacePoints);
|
||||
if(resultTimePoint != null) {
|
||||
for (Competitor competitor : competitorsFromBestToWorst) {
|
||||
if (!suppressedCompetitors.contains(competitor)) {
|
||||
// int totalRank = competitorsFromBestToWorst.indexOf(competitor) + 1;
|
||||
Double totalPoints = leaderboard.getTotalPoints(competitor, resultTimePoint);
|
||||
if (leaderboard.hasCarriedPoints(competitor)) {
|
||||
Double carriedPoints = leaderboard.getCarriedPoints(competitor);
|
||||
if (carriedPoints != null) {
|
||||
totalPoints = totalPoints != null ? totalPoints += carriedPoints : carriedPoints;
|
||||
}
|
||||
}
|
||||
|
||||
List<Object> csvLine = new ArrayList<Object>();
|
||||
csvLine.add(competitor.getName());
|
||||
csv.add(csvLine);
|
||||
|
||||
// TODO: we should only export complete races where all competitors have valid totalPoints for a race
|
||||
for (RaceColumn raceColumn : raceColumns) {
|
||||
List<Competitor> rankedCompetitorsForColumn = rankedCompetitorsPerColumn.get(raceColumn);
|
||||
if (rankedCompetitorsForColumn == null) {
|
||||
rankedCompetitorsForColumn = leaderboard.getCompetitorsFromBestToWorst(raceColumn,
|
||||
resultTimePoint);
|
||||
rankedCompetitorsPerColumn.put(raceColumn, rankedCompetitorsForColumn);
|
||||
}
|
||||
// Double netRacePoints = leaderboard.getNetPoints(competitor, raceColumn, timePoint);
|
||||
Double totalRacePoints = leaderboard.getTotalPoints(competitor, raceColumn, resultTimePoint);
|
||||
MaxPointsReason maxPointsReason = leaderboard.getMaxPointsReason(competitor, raceColumn, resultTimePoint);
|
||||
int rank = rankedCompetitorsForColumn.indexOf(competitor)+1;
|
||||
if(totalRacePoints != null) {
|
||||
if (maxPointsReason == null || maxPointsReason == MaxPointsReason.NONE) {
|
||||
csvLine.add(rank);
|
||||
csvLine.add(totalRacePoints);
|
||||
|
||||
} else {
|
||||
csvLine.add(maxPointsReason.name());
|
||||
csvLine.add(totalRacePoints);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (Competitor competitor : competitorsFromBestToWorst) {
|
||||
if (!suppressedCompetitors.contains(competitor)) {
|
||||
List<Object> csvLine = new ArrayList<Object>();
|
||||
csvLine.add(competitor.getName());
|
||||
csv.add(csvLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,4 +158,33 @@ public class ESS40ResultsAsCSVServlet extends AbstractCSVHttpServlet {
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
private ResultStates resolveRequestedResultState(String resultStateParam) {
|
||||
ResultStates result = DEFAULT_RESULT_STATE;
|
||||
if(resultStateParam != null) {
|
||||
for(ResultStates state: ResultStates.values()) {
|
||||
if(state.name().equalsIgnoreCase(resultStateParam)) {
|
||||
result = state;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private TimePoint calculateTimePointForResultState(Leaderboard leaderboard, ResultStates resultState) {
|
||||
TimePoint result = null;
|
||||
switch (resultState) {
|
||||
case Live:
|
||||
result = MillisecondsTimePoint.now();
|
||||
break;
|
||||
case Preliminary:
|
||||
case Final:
|
||||
if(leaderboard.getScoreCorrection() != null) {
|
||||
result = leaderboard.getScoreCorrection().getTimePointOfLastCorrectionsValidity();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+100
-29
@@ -25,13 +25,22 @@ import com.sap.sailing.domain.leaderboard.SettableScoreCorrection;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
import com.sap.sailing.server.gateway.AbstractJsonHttpServlet;
|
||||
|
||||
/**
|
||||
* Exports a leaderboard to the JSON format
|
||||
* @author Frank
|
||||
*
|
||||
*/
|
||||
public class LeaderboardJsonExportServlet extends AbstractJsonHttpServlet {
|
||||
private static final long serialVersionUID = -2460691283231361152L;
|
||||
private static final String PARAM_NAME_LEADERBOARDNAME = "leaderboardName";
|
||||
private static final String PARAM_NAME_RESULTSTATE = "resultState";
|
||||
private enum ResultStates { Live, Preliminary, Final };
|
||||
|
||||
// for backward compatibility the default result state is live
|
||||
private final ResultStates DEFAULT_RESULT_STATE = ResultStates.Live;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
TimePoint timePoint = MillisecondsTimePoint.now();
|
||||
String leaderboardName = req.getParameter(PARAM_NAME_LEADERBOARDNAME);
|
||||
if (leaderboardName == null) {
|
||||
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Need to specify a leaderboard name using the "+
|
||||
@@ -42,12 +51,22 @@ public class LeaderboardJsonExportServlet extends AbstractJsonHttpServlet {
|
||||
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Leaderboard "+leaderboardName+" not found");
|
||||
} else {
|
||||
try {
|
||||
ResultStates resultState = resolveRequestedResultState(req.getParameter(PARAM_NAME_RESULTSTATE));
|
||||
TimePoint requestTimePoint = MillisecondsTimePoint.now();
|
||||
TimePoint resultTimePoint = calculateTimePointForResultState(leaderboard, resultState);
|
||||
|
||||
List<Competitor> competitorsFromBestToWorstAccordingToTotalRank = leaderboard
|
||||
.getCompetitorsFromBestToWorst(timePoint);
|
||||
.getCompetitorsFromBestToWorst(resultTimePoint != null ? resultTimePoint : requestTimePoint);
|
||||
Map<RaceColumn, List<Competitor>> rankedCompetitorsPerColumn = new HashMap<RaceColumn, List<Competitor>>();
|
||||
JSONObject jsonLeaderboard = new JSONObject();
|
||||
jsonLeaderboard.put("name", leaderboard.getName());
|
||||
jsonLeaderboard.put("timepoint", timePoint.toString());
|
||||
|
||||
// for backward compatibility
|
||||
jsonLeaderboard.put("timepoint", resultTimePoint != null ? resultTimePoint.toString() : requestTimePoint.toString());
|
||||
|
||||
jsonLeaderboard.put("resultTimepoint", resultTimePoint != null ? resultTimePoint.toString() : null);
|
||||
jsonLeaderboard.put("requestTimepoint", requestTimePoint.toString());
|
||||
jsonLeaderboard.put("resultState", resultState.name());
|
||||
|
||||
SettableScoreCorrection scoreCorrection = leaderboard.getScoreCorrection();
|
||||
if (scoreCorrection != null) {
|
||||
@@ -76,34 +95,56 @@ public class LeaderboardJsonExportServlet extends AbstractJsonHttpServlet {
|
||||
Nationality nationality = competitor.getTeam().getNationality();
|
||||
jsonCompetitor.put("nationality", nationality != null ? nationality.getThreeLetterIOCAcronym(): null);
|
||||
jsonCompetitor.put("countryCode", nationality != null ? nationality.getCountryCode().getTwoLetterISOCode(): null);
|
||||
jsonCompetitor.put("rank",
|
||||
competitorsFromBestToWorstAccordingToTotalRank.indexOf(competitor) + 1);
|
||||
jsonCompetitor.put("carriedPoints", leaderboard.getCarriedPoints(competitor));
|
||||
jsonCompetitor.put("totalPoints", leaderboard.getTotalPoints(competitor, timePoint));
|
||||
jsonCompetitorEntries.add(jsonCompetitor);
|
||||
JSONObject jsonRaceColumns = new JSONObject();
|
||||
jsonCompetitor.put("raceScores", jsonRaceColumns);
|
||||
for (RaceColumn raceColumn : leaderboard.getRaceColumns()) {
|
||||
List<Competitor> rankedCompetitorsForColumn = rankedCompetitorsPerColumn.get(raceColumn);
|
||||
if (rankedCompetitorsForColumn == null) {
|
||||
rankedCompetitorsForColumn = leaderboard.getCompetitorsFromBestToWorst(raceColumn, timePoint);
|
||||
rankedCompetitorsPerColumn.put(raceColumn, rankedCompetitorsForColumn);
|
||||
|
||||
// only add results if we have a valid resultTimePoint
|
||||
if(resultTimePoint != null) {
|
||||
jsonCompetitor.put("rank", competitorsFromBestToWorstAccordingToTotalRank.indexOf(competitor) + 1);
|
||||
jsonCompetitor.put("carriedPoints", leaderboard.getCarriedPoints(competitor));
|
||||
jsonCompetitor.put("totalPoints", leaderboard.getTotalPoints(competitor, resultTimePoint));
|
||||
jsonCompetitorEntries.add(jsonCompetitor);
|
||||
JSONObject jsonRaceColumns = new JSONObject();
|
||||
jsonCompetitor.put("raceScores", jsonRaceColumns);
|
||||
for (RaceColumn raceColumn : leaderboard.getRaceColumns()) {
|
||||
List<Competitor> rankedCompetitorsForColumn = rankedCompetitorsPerColumn.get(raceColumn);
|
||||
if (rankedCompetitorsForColumn == null) {
|
||||
rankedCompetitorsForColumn = leaderboard.getCompetitorsFromBestToWorst(raceColumn, resultTimePoint);
|
||||
rankedCompetitorsPerColumn.put(raceColumn, rankedCompetitorsForColumn);
|
||||
}
|
||||
JSONObject jsonEntry = new JSONObject();
|
||||
jsonRaceColumns.put(raceColumn.getName(), jsonEntry);
|
||||
final Fleet fleetOfCompetitor = raceColumn.getFleetOfCompetitor(competitor);
|
||||
jsonEntry.put("fleet", fleetOfCompetitor==null?"":fleetOfCompetitor.getName());
|
||||
jsonEntry.put("netPoints", leaderboard.getNetPoints(competitor, raceColumn, resultTimePoint));
|
||||
jsonEntry.put("totalPoints", leaderboard.getTotalPoints(competitor, raceColumn, resultTimePoint));
|
||||
MaxPointsReason maxPointsReason = leaderboard.getMaxPointsReason(competitor, raceColumn, resultTimePoint);
|
||||
jsonEntry.put("maxPointsReason", maxPointsReason != null ? maxPointsReason.toString(): null);
|
||||
jsonEntry.put("rank", rankedCompetitorsForColumn.indexOf(competitor)+1);
|
||||
final TrackedRace trackedRace = raceColumn.getTrackedRace(competitor);
|
||||
if (trackedRace != null) {
|
||||
jsonEntry.put("raceRank", trackedRace.getRank(competitor, resultTimePoint));
|
||||
}
|
||||
jsonEntry.put("isDiscarded", leaderboard.isDiscarded(competitor, raceColumn, resultTimePoint));
|
||||
jsonEntry.put("isCorrected", leaderboard.getScoreCorrection().isScoreCorrected(competitor, raceColumn));
|
||||
}
|
||||
JSONObject jsonEntry = new JSONObject();
|
||||
jsonRaceColumns.put(raceColumn.getName(), jsonEntry);
|
||||
final Fleet fleetOfCompetitor = raceColumn.getFleetOfCompetitor(competitor);
|
||||
jsonEntry.put("fleet", fleetOfCompetitor==null?"":fleetOfCompetitor.getName());
|
||||
jsonEntry.put("netPoints", leaderboard.getNetPoints(competitor, raceColumn, timePoint));
|
||||
jsonEntry.put("totalPoints", leaderboard.getTotalPoints(competitor, raceColumn, timePoint));
|
||||
MaxPointsReason maxPointsReason = leaderboard.getMaxPointsReason(competitor, raceColumn, timePoint);
|
||||
jsonEntry.put("maxPointsReason", maxPointsReason != null ? maxPointsReason.toString(): null);
|
||||
jsonEntry.put("rank", rankedCompetitorsForColumn.indexOf(competitor)+1);
|
||||
final TrackedRace trackedRace = raceColumn.getTrackedRace(competitor);
|
||||
if (trackedRace != null) {
|
||||
jsonEntry.put("raceRank", trackedRace.getRank(competitor, timePoint));
|
||||
} else {
|
||||
jsonCompetitor.put("rank", 0);
|
||||
jsonCompetitor.put("carriedPoints", null);
|
||||
jsonCompetitor.put("totalPoints", null);
|
||||
jsonCompetitorEntries.add(jsonCompetitor);
|
||||
JSONObject jsonRaceColumns = new JSONObject();
|
||||
jsonCompetitor.put("raceScores", jsonRaceColumns);
|
||||
for (RaceColumn raceColumn : leaderboard.getRaceColumns()) {
|
||||
JSONObject jsonEntry = new JSONObject();
|
||||
jsonRaceColumns.put(raceColumn.getName(), jsonEntry);
|
||||
final Fleet fleetOfCompetitor = raceColumn.getFleetOfCompetitor(competitor);
|
||||
jsonEntry.put("fleet", fleetOfCompetitor==null?"":fleetOfCompetitor.getName());
|
||||
jsonEntry.put("netPoints", null);
|
||||
jsonEntry.put("totalPoints", null);
|
||||
jsonEntry.put("maxPointsReason", "");
|
||||
jsonEntry.put("rank", 0);
|
||||
jsonEntry.put("isDiscarded", false);
|
||||
jsonEntry.put("isCorrected", false);
|
||||
}
|
||||
jsonEntry.put("isDiscarded", leaderboard.isDiscarded(competitor, raceColumn, timePoint));
|
||||
jsonEntry.put("isCorrected", leaderboard.getScoreCorrection().isScoreCorrected(competitor, raceColumn));
|
||||
}
|
||||
}
|
||||
setJsonResponseHeader(resp);
|
||||
@@ -114,4 +155,34 @@ public class LeaderboardJsonExportServlet extends AbstractJsonHttpServlet {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ResultStates resolveRequestedResultState(String resultStateParam) {
|
||||
ResultStates result = DEFAULT_RESULT_STATE;
|
||||
if(resultStateParam != null) {
|
||||
for(ResultStates state: ResultStates.values()) {
|
||||
if(state.name().equalsIgnoreCase(resultStateParam)) {
|
||||
result = state;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private TimePoint calculateTimePointForResultState(Leaderboard leaderboard, ResultStates resultState) {
|
||||
TimePoint result = null;
|
||||
switch (resultState) {
|
||||
case Live:
|
||||
result = MillisecondsTimePoint.now();
|
||||
break;
|
||||
case Preliminary:
|
||||
case Final:
|
||||
if(leaderboard.getScoreCorrection() != null) {
|
||||
result = leaderboard.getScoreCorrection().getTimePointOfLastCorrectionsValidity();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user