This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
quickstart [2019/05/09 18:48]
quickstart [2019/10/31 19:30]
Line 1: Line 1:
 ====== Quickstart ====== ====== Quickstart ======
-Use the TimEL facade ​to compile and run a program:+To use TimEL you need to import the following dependecy:
-<code java+//Maven// 
-// Assemble the evaluation interval as [now, now + 1 second) +  ​<dependency
-Instant now = Instant.now(); +      <​groupId>​net.vleo.timel<​/groupId>​ 
-Interval interval = Interval.of(now, now.plus(1, ChronoUnit.SECONDS));​+      <​artifactId>​timel-core<​/artifactId>​ 
 +      <​version>​0.9.3</​version>​ 
 +  </​dependency>​
-// Compile the expression 1 + 1 +//Gradle// 
-Expression expression = TimEL +  ​implementation 'net.vleo.timel:​timel-core:​0.9.3'
-         .parse("​1 + 1") +
-         .compile();+
-// Iterate through the results +\\
-TimeIterator<​Integer>​ itor = TimEL +
-        .evaluate(expression,​ interval);+
-// Since 1+is constant we'll have a single sample for the whole interval +Now you're ready to go! Let's count how many days passed since (unix) epoch: 
-int v itor.next().getValue();+ 
 +<code java> 
 +// Compile the expression 
 +Expression<?>​ expression = TimEL 
 +        .parse("​scale(scale(uniform(1.0), every(1, \"​DAY_OF_YEAR\",​ \"​UTC\"​)))"​) 
 +        .compile();​ 
 +// 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());
 </​code>​ </​code>​
-Note that all the job is done through the TimEL facade, first compiling the expression and then executing it.+===== Adding a variable =====
-The following example shows how to provide ​non constant values to TimEL using *variable*+Now let's try something a bit more complex, where we provide ​an input time-serie variable. As TimEL is streaming api, it will pull values out of the variable ​when it needs themIn this case we are going to use a TreeMapVariable,​ which is a Variable backed by a regular in memory TreeMap:
 <code java> <code java>
Line 30: Line 37:
 TreeMap<​Interval,​ Integer> values = variable.getTreeMap();​ TreeMap<​Interval,​ Integer> values = variable.getTreeMap();​
-// Add some values to the variable:+// Add some values to the variable
 Instant now = Instant.now();​ Instant now = Instant.now();​
-for(int[] i : new int[][] {{0, 1, 1}, {1, 2, 2} /* Gap */{2, 3, 4}})+for(int[] i : new int[][] { 
 +        // start, end, value 
 +        ​{0, 1, 1}, 
 +        ​{1, 2, 2}
 +        ​// gap between 2nd and 3rd minute 
 +        ​{3, 4, 4} 
 + }) {
     values.put(Interval.of(     values.put(Interval.of(
             now.plus(i[0],​ ChronoUnit.MINUTES),​             now.plus(i[0],​ ChronoUnit.MINUTES),​
             now.plus(i[1],​ ChronoUnit.MINUTES)             now.plus(i[1],​ ChronoUnit.MINUTES)
     ), i[2]);     ), i[2]);
-// Compile "a * a" +// Compile "a * a" ​without type requirement 
-Expression expression = TimEL+Expression<?> ​expression = TimEL
         .parse("​a * a")         .parse("​a * a")
         .withVariable("​a",​ new IntegerType(),​ variable) // Declare '​a'​ as a int         .withVariable("​a",​ new IntegerType(),​ variable) // Declare '​a'​ as a int
Line 45: Line 59:
 // Evaluate the expression in the interval [now, now + 5 minutes) // Evaluate the expression in the interval [now, now + 5 minutes)
-TimeIterator<​Double> itor = TimEL+TimeIterator<​?> itor = TimEL
         .evaluate(expression,​ Interval.of(now,​ now.plus(5, ChronoUnit.MINUTES)));​         .evaluate(expression,​ Interval.of(now,​ now.plus(5, ChronoUnit.MINUTES)));​
Line 54: Line 68:
 </​code>​ </​code>​
-Note that TimEL works in a streaming way, that is it pulls values from input and computes the result as soon as the output iterator is advanced. This way allows the library to work incrementally,​ thus the whole dataset is not required to fit in memory (imagine having various year of samples at a second resolution!) but can be instead streamed when needed. +That'​s ​it!
- +
-To provide values to a TimEL program or expression the followings steps are needed, as shown above: +
- +
-  - The variable needs to be declared at compile time with its relative type; +
-  - An instance of the variable needs to be bounded at execution time. +
- +
-TimEL is agnostic to data storage and requires the user to implement the **Variable** interface to allow read and write operations. Note that reading an interval in both directions is required. +
- +
-The commodity **TreeMapVariable** class is a **Variable** implementation backed by a TreeMap can be used when the dataset is not large. +
- +
-===== Stability ===== +
- +
-**Please consider the API not mature yet and subject to change**. Although no major changes are expected in the TimEL facade, the type mechanism is still prototypal an might be subject to changes. +
- +
-Anything in the impl package is to be considered private, and therefore, unstable.+
  • quickstart.txt
  • Last modified: 2019/10/31 19:30
  • by a.leofreddi