To use TimEL you need to import the following dependecy:




implementation 'net.vleo.timel:timel-core:0.9.3'

Now you're ready to go! Let's count how many days passed since (unix) epoch:

// Compile the expression
Expression<?> expression = TimEL
        .parse("scale(scale(uniform(1.0), every(1, \"DAY_OF_YEAR\", \"UTC\")))")
// Evaluate and print the number of days from epoch
Interval interval = Interval.of(Instant.ofEpochMilli(0), Instant.now());
System.out.println(TimEL.evaluate(expression, interval).next());

Now let's try something a bit more complex, where we provide an input time-serie variable. As TimEL is a streaming api, it will pull values out of the variable when it needs them. In this case we are going to use a TreeMapVariable, which is a Variable backed by a regular in memory TreeMap:

// Create a new variable backed by a TreeMap
TreeMapVariable<Integer> variable = new TreeMapVariable<>();
TreeMap<Interval, Integer> values = variable.getTreeMap();
// Add some values to the variable
Instant now = Instant.now();
for(int[] i : new int[][] {
        // start, end, value
        {0, 1, 1},
        {1, 2, 2},
        // gap between 2nd and 3rd minute
        {3, 4, 4}
 }) {
            now.plus(i[0], ChronoUnit.MINUTES),
            now.plus(i[1], ChronoUnit.MINUTES)
    ), i[2]);
// Compile "a * a" without type requirement
Expression<?> expression = TimEL
        .parse("a * a")
        .withVariable("a", new IntegerType(), variable) // Declare 'a' as a int
// Evaluate the expression in the interval [now, now + 5 minutes)
TimeIterator<?> itor = TimEL
        .evaluate(expression, Interval.of(now, now.plus(5, ChronoUnit.MINUTES)));
// Pull the results, effectively evaluating the expression.
// This will print 3 lines, one for each interval, with the value 1, 4 and 16.
    System.out.println("\t" + itor.next());

That's it!

  • quickstart.txt
  • Last modified: 2019/10/31 19:30
  • by a.leofreddi