1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.history.impl;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.databoard.annotations.Identifier;
18 import org.simantics.databoard.binding.Binding;
19 import org.simantics.databoard.binding.error.BindingConstructionException;
20 import org.simantics.databoard.binding.mutable.MutableVariant;
21 import org.simantics.databoard.binding.reflection.BindingRequest;
22 import org.simantics.databoard.type.Datatype;
23 import org.simantics.databoard.util.Bean;
24 import org.simantics.history.util.MedianBindingProvider;
25 import org.simantics.history.util.WeightedMedian;
28 * This is the state that s persisted.
30 * @author toni.kalajainen
32 public class CollectorState extends Bean {
34 public static final Binding BINDING = Bindings.getBindingUnchecked( CollectorState.class );
35 public static final Binding BINDING_ITEM = Bindings.getBindingUnchecked( CollectorState.Item.class );
37 public @Identifier String id;
39 /** Last known time value */
40 public MutableVariant time;
42 /** Time stepped between the two last collector steps. Used for time stamp epsilon calculations. */
43 public double dT = 1.0;
45 /** Last known values for each variable */
46 public Map<String, VariableState> values;
48 /** Item states - corresponds to subscription.items */
49 public Map<String, Item> itemStates;
51 public static class VariableState {
53 /** The actual value, type is Void if no value */
54 public MutableVariant value;
56 /** Set to true if is valid value */
57 public boolean isValid;
59 /** True, if double or float and is NaN */
63 public static class Item extends Bean {
66 /** History item reference */
67 public @Identifier String id;
68 /** Datasource reference */
69 public String variableId;
71 public Datatype format;
73 public double deadband = Double.NaN;
75 public double interval = Double.NaN;
77 public double gain = 1.0;
79 public double bias = 0.0;
81 public boolean enabled = true;
82 /** Format id, group id */
83 public String groupId = "", groupItemId = "", formatId = "";
86 /** Time of the first sample in the value band. NAN, if there is no value */
87 public double firstTime = Double.NaN;
88 /** Value of the first sample in the value band. null, if there is no value */
89 public MutableVariant firstValue;
90 /** Time of the prev added sample. NAN, if there is no value */
91 public double currentTime;
92 /** Value of the prev added sample. null, if there is no value */
93 public MutableVariant currentValue;
94 /** Current value is NaN */
96 /** Current value is valid */
97 public boolean isValid;
98 /** Time weighted sum (area), NAN, if not accumulated */
100 /** Sample Count of acquired samples in current band */
102 /** Out of dead band, set true if a sample has crossed the deadband region in this value band */
103 public boolean ooDeadband = false;
104 /** First time after disabled */
105 public double firstDisabledTime;
106 /** Last time while disabled*/
107 public double lastDisabledTime;
108 /** Is item currently disabled */
109 public boolean isDisabled;
111 /** Median values of the value band */
112 public WeightedMedian median;
115 * Interval is the time between two samples, a step length.
116 * Distribution contains classification of their variation. It is of
117 * interest if the datasource contains varying sizes and a mipmap interval
118 * needs to be decided. Null, if not breakdown is not constructed.
120 //public @Optional ClassDistribution intervalDistribution;
123 * Value distribution contains clasification of values.
125 //public @Optional ClassDistribution valueDistribution;
129 public CollectorState() {
134 Bindings.classBindingFactory.addFactory( MedianBindingProvider.INSTANCE );
137 BindingRequest br = new BindingRequest( CollectorState.Item.class );
138 Binding datatypeBinding = Bindings.getBinding( br );
139 Bindings.typeClassFactory.getRepository().put(datatypeBinding.type(), br);
141 br = new BindingRequest( CollectorState.class );
142 datatypeBinding = Bindings.getBinding( br );
143 Bindings.typeClassFactory.getRepository().put(datatypeBinding.type(), br);
145 } catch (BindingConstructionException e) {
146 System.err.println(e);