diff --git a/server/dist/OOCSI_server.jar b/server/dist/OOCSI_server.jar index d92f06f..65d3633 100644 Binary files a/server/dist/OOCSI_server.jar and b/server/dist/OOCSI_server.jar differ diff --git a/server/src/nl/tue/id/oocsi/server/OOCSIServer.java b/server/src/nl/tue/id/oocsi/server/OOCSIServer.java index 884d3c4..25f88fb 100644 --- a/server/src/nl/tue/id/oocsi/server/OOCSIServer.java +++ b/server/src/nl/tue/id/oocsi/server/OOCSIServer.java @@ -29,7 +29,7 @@ public class OOCSIServer extends Server { // constants - public static final String VERSION = "1.23"; + public static final String VERSION = "1.24"; // defaults for different services private int maxClients = 100; diff --git a/server/src/nl/tue/id/oocsi/server/model/FunctionClient.java b/server/src/nl/tue/id/oocsi/server/model/FunctionClient.java index 583c2ea..445a57f 100644 --- a/server/src/nl/tue/id/oocsi/server/model/FunctionClient.java +++ b/server/src/nl/tue/id/oocsi/server/model/FunctionClient.java @@ -28,6 +28,8 @@ public class FunctionClient extends Client { private WindowFunction sumFct = new SumOverWindowFunction(); private WindowFunction meanFct = new MeanOverWindowFunction(); private WindowFunction stdevFct = new StandardDeviationOverWindowFunction(); + private WindowFunction minFct = new MinOverWindowFunction(); + private WindowFunction maxFct = new MaxOverWindowFunction(); public FunctionClient(Client delegateClient, String token, String functionString, ChangeListener presence) { super(token, presence); @@ -68,12 +70,16 @@ public void send(Message message) { // apply expression try { final Expression e = loadExpression(expression, message, true); - if (expression.contains("sum(")) + if (expression.contains("sum(") || expression.contains("SUM(")) e.addFunction(sumFct); - if (expression.contains("mean(")) + if (expression.contains("mean(") || expression.contains("MEAN(")) e.addFunction(meanFct); - if (expression.contains("stdev(")) + if (expression.contains("stdev(") || expression.contains("STDEV(")) e.addFunction(stdevFct); + if (expression.contains("emin(") || expression.contains("EMIN(")) + e.addFunction(minFct); + if (expression.contains("emax(") || expression.contains("EMAX(")) + e.addFunction(maxFct); BigDecimal bd = e.eval(); if (bd.intValue() == 0) { return; @@ -88,12 +94,16 @@ public void send(Message message) { for (String expression : transformExpression) { try { Expression e = loadExpression(expression, message, false); - if (expression.contains("sum(")) + if (expression.contains("sum(") || expression.contains("SUM(")) e.addFunction(sumFct); - if (expression.contains("mean(")) + if (expression.contains("mean(") || expression.contains("MEAN(")) e.addFunction(meanFct); - if (expression.contains("stdev(")) + if (expression.contains("stdev(") || expression.contains("STDEV(")) e.addFunction(stdevFct); + if (expression.contains("emin(") || expression.contains("EMIN(")) + e.addFunction(minFct); + if (expression.contains("emax(") || expression.contains("EMAX(")) + e.addFunction(maxFct); e.addLazyFunction(new AbstractTransform(message)); e.eval(); } catch (Exception ex) { @@ -118,7 +128,7 @@ public void send(Message message) { * @param abortOnMissing * @return */ - private static Expression loadExpression(final String expression, Message message, boolean abortOnMissing) { + private Expression loadExpression(final String expression, Message message, boolean abortOnMissing) { final Expression e = new Expression(expression); List vars = e.getUsedVariables(); for (String key : vars) { @@ -267,6 +277,30 @@ private double mean(Queue queue) { } } + class MinOverWindowFunction extends WindowFunction { + + protected MinOverWindowFunction() { + super("emin", 2); + } + + @Override + public BigDecimal evalQueue(Queue queue) { + return queue.stream().min((a, b) -> a.compareTo(b)).orElse(new BigDecimal(0)); + } + } + + class MaxOverWindowFunction extends WindowFunction { + + protected MaxOverWindowFunction() { + super("emax", 2); + } + + @Override + public BigDecimal evalQueue(Queue queue) { + return queue.stream().max((a, b) -> a.compareTo(b)).orElse(new BigDecimal(0)); + } + } + class AbstractTransform extends AbstractLazyFunction { private Message message;