]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.history/src/org/simantics/history/impl/CollectorState.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.history / src / org / simantics / history / impl / CollectorState.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.history.impl;\r
13 \r
14 import java.util.Map;\r
15 \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
26 \r
27 /**\r
28  * This is the state that s persisted.\r
29  *  \r
30  * @author toni.kalajainen\r
31  */\r
32 public class CollectorState extends Bean {\r
33 \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
36         \r
37         public @Identifier String id;\r
38         \r
39         /** Last known time value */\r
40         public MutableVariant time;\r
41 \r
42         /** Time stepped between the two last collector steps. Used for time stamp epsilon calculations. */\r
43         public double dT = 1.0;\r
44 \r
45         /** Last known values for each variable */\r
46         public Map<String, VariableState> values;\r
47          \r
48         /** Item states - corresponds to subscription.items */\r
49         public Map<String, Item> itemStates;\r
50 \r
51         public static class VariableState {\r
52                 \r
53                 /** The actual value, type is Void is no value */\r
54                 public MutableVariant value;\r
55                 \r
56                 /** Set to true if is valid value */\r
57                 public boolean isValid; \r
58                 \r
59                 /** True, if double or float and is NaN */\r
60                 public boolean isNan;\r
61         }\r
62         \r
63         public static class Item extends Bean {\r
64                 \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
70                 /** Dataformat */\r
71                 public Datatype format;\r
72                 /** Deadband */\r
73                 public double deadband = Double.NaN;\r
74                 /** Interval */\r
75                 public double interval = Double.NaN;\r
76                 /** Gain */\r
77                 public double gain = 1.0;\r
78                 /** Bias */\r
79                 public double bias = 0.0;\r
80                 /** Enabled */\r
81                 public boolean enabled = true;\r
82                 /** Format id, group id */\r
83                 public String groupId = "", groupItemId = "", formatId = "";\r
84                 \r
85                 // - Valueband  \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
99                 public double sum;\r
100                 /** Sample Count of acquired samples in current band */\r
101                 public int count;\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
110                 \r
111                 /** Median values of the value band */\r
112                 public WeightedMedian median;\r
113                 \r
114                 /**\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
119                  */     \r
120                 //public @Optional ClassDistribution intervalDistribution;\r
121                 \r
122                 /**\r
123                  * Value distribution contains clasification of values. \r
124                  */\r
125                 //public @Optional ClassDistribution valueDistribution;\r
126 \r
127         }\r
128         \r
129         public CollectorState() {\r
130                 super(BINDING);\r
131         }\r
132         \r
133         static {\r
134         Bindings.classBindingFactory.addFactory( MedianBindingProvider.INSTANCE );\r
135         \r
136                 try {\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
140                 \r
141                 br = new BindingRequest( CollectorState.class ); \r
142                 datatypeBinding = Bindings.getBinding( br );\r
143                 Bindings.typeClassFactory.getRepository().put(datatypeBinding.type(), br);\r
144                 \r
145                 } catch (BindingConstructionException e) {\r
146                         System.err.println(e);\r
147                 }\r
148         }\r
149         \r
150 }\r