1 package org.simantics.history.examples;
5 import org.simantics.databoard.Bindings;
6 import org.simantics.databoard.Datatypes;
7 import org.simantics.databoard.accessor.StreamAccessor;
8 import org.simantics.databoard.accessor.error.AccessorException;
9 import org.simantics.databoard.binding.RecordBinding;
10 import org.simantics.databoard.binding.error.BindingException;
11 import org.simantics.databoard.type.RecordType;
12 import org.simantics.databoard.util.Bean;
13 import org.simantics.history.Collector;
14 import org.simantics.history.History;
15 import org.simantics.history.HistoryAndCollectorItem;
16 import org.simantics.history.HistoryException;
17 import org.simantics.history.HistoryItem;
18 import org.simantics.history.HistoryManager;
19 import org.simantics.history.impl.FlushPolicy;
21 public class CollectorExample2 {
23 public static void main(String[] args) throws HistoryException, BindingException, AccessorException {
25 /// Example2: Record variable "MyVariable" to two history
26 /// items "MyVariable-interval=0.5" and "MyVariable-deadband=5"
28 // Create History Manager
29 HistoryManager history = History.createMemoryHistory();
31 // Create a sample format
32 RecordType sampleFormat = new RecordType();
33 sampleFormat.addComponent("time", Datatypes.DOUBLE );
34 sampleFormat.addComponent("value", Datatypes.DOUBLE );
35 sampleFormat.addComponent("quality", Datatypes.BYTE );
37 // Create two History Item and Collector Item configurations
38 HistoryAndCollectorItem i1 = new HistoryAndCollectorItem();
39 i1.id = "MyVariable-interval=0.5";
40 i1.format = sampleFormat;
42 i1.variableId = "MyVariable";
44 HistoryAndCollectorItem i2 = new HistoryAndCollectorItem();
45 i2.id = "MyVariable-deadband=5";
46 i2.format = sampleFormat;
48 i2.variableId = "MyVariable";
50 // Create the item in the history
51 history.create( i1, i2 );
54 Collector collector = History.createCollector(history, FlushPolicy.NoFlush);
56 // Initialize Collector (Items)
57 collector.addItem( i1 );
58 collector.addItem( i2 );
62 for ( int i = 0; i<100; i++ ) {
64 // Our "simulation" results
65 double time = i * 0.1;
66 double myItemValue = -20 + i*0.1;
68 // Begin collector writing step
69 collector.beginStep(Bindings.DOUBLE, time);
71 // Enter values for one variable.
72 collector.setValue("MyVariable", Bindings.DOUBLE, myItemValue);
74 // End collector step - MyVariable is written to two HistoryItems