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.trend.configuration;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.simantics.databoard.Datatypes;
18 import org.simantics.databoard.type.RecordType;
19 import org.simantics.history.util.subscription.SamplingFormat;
21 public class TrendSamplingFormats {
23 // Template Sampling formats
24 public final static SamplingFormat analog_all, analog_100ms, analog_1s, analog_10s, analog_60s, analog_minmax;
25 public final static SamplingFormat binary_all, binary_100ms, binary_1s, binary_10s, binary_60s;
26 public final static SamplingFormat time;
28 public final static String all="all", _100ms="100ms", _1s="1s", _10s="10s", _60s="60s", minmax="minmax";
31 * Create a list of sampling formats for trend's needs
37 public static List<SamplingFormat> createAnalogSamplingFormats( double interval, double deadband, String unit )
39 ArrayList<SamplingFormat> result = new ArrayList<SamplingFormat>( 6 );
41 result.add( analog_minmax );
43 if (interval==0. && deadband==0.) {
44 result.add( analog_all.clone().setUnit(unit) );
45 result.add( analog_100ms.clone().setUnit(unit) );
46 result.add( analog_1s.clone().setUnit(unit) );
47 result.add( analog_10s.clone().setUnit(unit) );
48 result.add( analog_60s.clone().setUnit(unit) );
52 // Format for ]0,1 .. 1[
54 result.add( analog_all.clone( interval, deadband ).setUnit(unit) );
55 result.add( analog_100ms.clone( 0.1, deadband ).setUnit(unit) );
56 result.add( analog_1s.clone( 1, deadband).setUnit(unit) );
57 result.add( analog_10s.clone( 10, deadband).setUnit(unit) );
58 result.add( analog_60s.clone( 60, deadband).setUnit(unit) );
62 // Format for ]0 .. 1[
64 result.add( analog_100ms.clone( interval, deadband ).setUnit(unit) );
65 result.add( analog_1s.clone( 1, deadband).setUnit(unit) );
66 result.add( analog_10s.clone( 10, deadband).setUnit(unit) );
67 result.add( analog_60s.clone( 60, deadband).setUnit(unit) );
71 // Format for [1 .. 10[
73 result.add( analog_1s.clone( interval, deadband).setUnit(unit) );
74 result.add( analog_10s.clone( 10, deadband).setUnit(unit) );
75 result.add( analog_60s.clone( 60, deadband).setUnit(unit) );
79 // Format for [10 .. 60[
81 result.add( analog_10s.clone( interval, deadband).setUnit(unit) );
82 result.add( analog_60s.clone( 60, deadband).setUnit(unit) );
87 result.add( analog_60s.clone( interval, deadband).setUnit(unit) );
92 * Create a list of sampling formats for trend's needs
97 public static List<SamplingFormat> createBinarySamplingFormats( double interval )
99 ArrayList<SamplingFormat> result = new ArrayList<SamplingFormat>( 5 );
102 result.add( binary_all );
103 result.add( binary_100ms );
104 result.add( binary_1s );
105 result.add( binary_10s );
106 result.add( binary_60s );
110 // Format for ]0,1 .. 1[
112 result.add( binary_all.clone( interval, Double.NaN ) );
113 result.add( binary_100ms );
114 result.add( binary_1s );
115 result.add( binary_10s );
116 result.add( binary_60s );
120 // Format for ]0 .. 1[
122 result.add( binary_100ms.clone( interval, Double.NaN ) );
123 result.add( binary_1s );
124 result.add( binary_10s );
125 result.add( binary_60s );
129 // Format for [1 .. 10[
130 if (interval < 10.) {
131 result.add( binary_1s.clone( interval, Double.NaN) );
132 result.add( binary_10s );
133 result.add( binary_60s );
137 // Format for [10 .. 60[
138 if (interval < 60.) {
139 result.add( binary_10s.clone( interval, Double.NaN) );
140 result.add( binary_60s );
145 result.add( binary_60s.clone( interval, Double.NaN) );
150 time = new SamplingFormat();
151 RecordType format = (RecordType) (time.format = new RecordType());
152 format.addComponent("time", Datatypes.DOUBLE);
153 format.addComponent("value", Datatypes.DOUBLE);
154 format.addComponent("quality", Datatypes.BYTE);
155 time.interval = Double.NaN;
156 time.deadband = Double.NaN;
158 analog_all = new SamplingFormat();
159 analog_all.formatId = all;
160 format = (RecordType) (analog_all.format = new RecordType());
161 format.addComponent("time", Datatypes.DOUBLE);
162 format.addComponent("endTime", Datatypes.DOUBLE);
163 format.addComponent("value", Datatypes.DOUBLE);
164 format.addComponent("quality", Datatypes.BYTE);
165 analog_all.interval = Double.NaN;
166 analog_all.deadband = Double.NaN;
168 analog_1s = new SamplingFormat();
169 analog_1s.formatId = _1s;
170 analog_1s.format = new RecordType();
171 format = (RecordType) (analog_1s.format = new RecordType());
172 format.addComponent("time", Datatypes.DOUBLE);
173 format.addComponent("endTime", Datatypes.DOUBLE);
174 format.addComponent("value", Datatypes.DOUBLE);
175 format.addComponent("min", Datatypes.DOUBLE);
176 format.addComponent("max", Datatypes.DOUBLE);
177 format.addComponent("avg", Datatypes.DOUBLE);
178 //format.addComponent("median", Datatypes.DOUBLE);
179 format.addComponent("quality", Datatypes.BYTE);
180 analog_1s.interval = 1.0;
181 analog_1s.deadband = Double.NaN;
183 analog_100ms = analog_1s.cloneTo(_100ms, 0.1, Double.NaN);
184 analog_10s = analog_1s.cloneTo(_10s, 10., Double.NaN);
185 analog_60s = analog_10s.cloneTo(_60s, 60., Double.NaN);
187 analog_minmax = new SamplingFormat();
188 analog_minmax.formatId = minmax;
189 format = (RecordType) (analog_minmax.format = new RecordType());
190 format.addComponent("time", Datatypes.DOUBLE);
191 format.addComponent("endTime", Datatypes.DOUBLE);
192 format.addComponent("value", Datatypes.DOUBLE);
193 format.addComponent("min", Datatypes.DOUBLE);
194 format.addComponent("max", Datatypes.DOUBLE);
195 analog_minmax.interval = Double.MAX_VALUE;
196 analog_minmax.deadband = Double.MAX_VALUE;
198 binary_all = new SamplingFormat();
199 binary_all.formatId = all;
200 format = (RecordType) (binary_all.format = new RecordType());
201 format.addComponent("time", Datatypes.DOUBLE);
202 format.addComponent("endTime", Datatypes.DOUBLE);
203 format.addComponent("value", Datatypes.BYTE);
204 format.addComponent("max", Datatypes.BYTE);
205 format.addComponent("quality", Datatypes.BYTE);
206 binary_all.interval = Double.NaN;
207 binary_all.deadband = Double.NaN;
209 binary_1s = new SamplingFormat();
210 binary_1s.formatId = _1s;
211 format = (RecordType) (binary_1s.format = new RecordType());
212 format.addComponent("time", Datatypes.DOUBLE);
213 format.addComponent("endTime", Datatypes.DOUBLE);
214 format.addComponent("value", Datatypes.BYTE);
215 format.addComponent("max", Datatypes.BYTE);
216 //format.addComponent("median", Datatypes.BYTE);
217 format.addComponent("quality", Datatypes.BYTE);
218 binary_1s.interval = 1.0;
219 binary_1s.deadband = Double.NaN;
221 binary_100ms = binary_1s.cloneTo(_100ms, 0.1, Double.NaN);
222 binary_10s = binary_1s.cloneTo(_10s, 10., Double.NaN);
223 binary_60s = binary_1s.cloneTo(_60s, 60., Double.NaN);