Skip to content

Commit

Permalink
v1.24
Browse files Browse the repository at this point in the history
 - added min and max aggregation functions to the filter and transform expression library
  • Loading branch information
matsfunk committed Dec 7, 2021
1 parent 013bfd0 commit 6e54932
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
Binary file modified server/dist/OOCSI_server.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion server/src/nl/tue/id/oocsi/server/OOCSIServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 41 additions & 7 deletions server/src/nl/tue/id/oocsi/server/model/FunctionClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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<String> vars = e.getUsedVariables();
for (String key : vars) {
Expand Down Expand Up @@ -267,6 +277,30 @@ private double mean(Queue<BigDecimal> queue) {
}
}

class MinOverWindowFunction extends WindowFunction {

protected MinOverWindowFunction() {
super("emin", 2);
}

@Override
public BigDecimal evalQueue(Queue<BigDecimal> 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<BigDecimal> queue) {
return queue.stream().max((a, b) -> a.compareTo(b)).orElse(new BigDecimal(0));
}
}

class AbstractTransform extends AbstractLazyFunction {

private Message message;
Expand Down

0 comments on commit 6e54932

Please sign in to comment.