Skip to content

Commit

Permalink
修正了时间窗口为永久,提取时间窗口数据为null的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
junxworks committed Jul 22, 2018
1 parent d3fc70a commit 944a84a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.github.junxworks.junx.stat.StatContext;
import io.github.junxworks.junx.stat.StatDefinition;
import io.github.junxworks.junx.stat.datawindow.DataBundle;
import io.github.junxworks.junx.stat.datawindow.timewindow.TimeUnit;
import io.github.junxworks.junx.stat.function.FuncDef;

/**
Expand Down Expand Up @@ -245,4 +246,26 @@ public void rang_dist() throws Exception {
System.out.println(so.getValue(ctx));
}

/**
* 无尽窗口
* @throws Exception
*/
@Test
public void eternalTest() throws Exception {
StatDefinition model = createStatModel(FuncDef.SNAPSHOT);
model.setDataWindowTimeUnit(TimeUnit.eternal.toString());
Stat so = Stat.create(model);
long timestamp = System.currentTimeMillis();
so.compose(new DataBundle(timestamp, 50f));
so.compose(new DataBundle(timestamp + 70000, 200));
so.compose(new DataBundle(timestamp + 70001, 250));
so.compose(new DataBundle(timestamp + 200000, 350f));
so.compose(new DataBundle(timestamp + 300000, 10));
so.compose(new DataBundle(timestamp + 400000, 300));
StatContext ctx = new StatContext();
ctx.setTimestamp(timestamp + 500000);
ctx.setValue(1);
System.out.println(so.getValue(ctx));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.github.junxworks.junx.stat.Stat;
import io.github.junxworks.junx.stat.StatDefinition;
import io.github.junxworks.junx.stat.datawindow.DataBundle;
import io.github.junxworks.junx.stat.datawindow.DataWindowConstants;
import io.github.junxworks.junx.stat.datawindow.timewindow.TimeUnit;

public class StatTest {
Expand Down Expand Up @@ -48,34 +47,11 @@ protected StatDefinition createStatModel(String func) {
* @return the statistics
*/
protected StatDefinition createStatModel(String func, int winNum) {
StatDefinition statModel = new StatDefinition() {

@Override
public int getDataWindowType() {
return DataWindowConstants.WIN_TYPE_TIME;
}

@Override
public int getDataWindowSize() {
return winNum;
}

@Override
public String getStatFunction() {
return func;
}

@Override
public String getDataWindowTimeUnit() {
return TimeUnit.minute.toString();
}

@Override
public String getStatFunctionAddition() {
return "num:$~100|100~200|200~300|300~$";
}

};
StatDefinition statModel = new StatDefinition();
statModel.setDataWindowSize(winNum);
statModel.setStatFunction(func);
statModel.setDataWindowTimeUnit(TimeUnit.minute.toString());
statModel.setStatFunctionAddition("num:$~100|100~200|200~300|300~$");
return statModel;
}

Expand Down
2 changes: 2 additions & 0 deletions junx-stat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
<version>1.0.1</version>
</parent>
<artifactId>junx-stat</artifactId>
<version>1.0.1.1</version>
<dependencies>
<dependency>
<groupId>io.github.junxworks</groupId>
<artifactId>junx-core</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ public Collection<?> extractData(StatContext ctx) throws Exception {
if (ctx == null) {
throw new NullParameterException("Parameter can not be null. ");
}
if (TimeUnit.eternal == this.definition.getUnit()) {
//如果是永久时间窗口,则直接返回当前数据集
if (!blocks.isEmpty()) {
return blocks.getFirst().getData();
}
return new ArrayList<>();
}
long timestamp = ctx.getTimestamp();
if (!blocks.isEmpty()) {
List<SlicedBlock> _blocks = new LinkedList<>();
Expand Down

0 comments on commit 944a84a

Please sign in to comment.