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