Differences

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:56]
admin
quickstart [2019/10/31 19:30] (current)
a.leofreddi
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// 
-// As we expect an Integer here, we explicitly request an IntegerType +  ​implementation 'net.vleo.timel:​timel-core:​0.9.3'
-// for the sake of type safety, but we can compile generic code as well. +
-Expression<​Integer>​ expression = TimEL +
-        ​.parse("​1 + 1") +
-        ​.compile(new IntegerType());​+
  
-// Iterate through the results +\\
-TimeIterator<​Integer>​ itor = TimEL +
-        .evaluate(expression,​ interval);+
  
-// Since 1+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 (unixepoch:
-int v = itor.next().getValue()+
-</​code>​+
  
-That's it!+<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>​
  
-//+===== Adding a variable =====
  
-Now let's try something a bit more complex, ​so we provide an input time-serie variable. As TimEL is a streaming +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:
-api, it will pull values out of the variable when it needs them. In this simple ​case we are going to use a TreeMapVariable,​ +
-which is a Variable backed by a regular in memory TreeMap:+
  
 <code java> <code java>
Line 38: Line 39:
 // 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 51: 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)));​
  
  • quickstart.1557428180.txt.gz
  • Last modified: 2019/05/09 18:56
  • by admin