]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.trend/src/org/simantics/trend/configuration/TrendSamplingFormats.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.trend / src / org / simantics / trend / configuration / TrendSamplingFormats.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.trend.configuration;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 import org.simantics.databoard.Datatypes;
18 import org.simantics.databoard.type.RecordType;
19 import org.simantics.history.util.subscription.SamplingFormat;
20
21 public class TrendSamplingFormats {
22
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;
27         
28         public final static String all="all", _100ms="100ms", _1s="1s", _10s="10s", _60s="60s", minmax="minmax"; 
29         
30         /**
31          * Create a list of sampling formats for trend's needs 
32          * 
33          * @param interval
34          * @param deadband
35          * @return
36          */
37         public static List<SamplingFormat> createAnalogSamplingFormats( double interval, double deadband, String unit )
38         {
39                 ArrayList<SamplingFormat> result = new ArrayList<SamplingFormat>( 6 );
40                 
41                 result.add( analog_minmax );
42                 
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) );
49                         return result;
50                 } 
51
52                 // Format for ]0,1 .. 1[
53                 if (interval < 0.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) );
59                         return result;
60                 }
61                 
62                 // Format for ]0 .. 1[
63                 if (interval < 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) );
68                         return result;
69                 }
70
71                 // Format for [1 .. 10[
72                 if (interval < 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) );
76                         return result;
77                 }
78
79                 // Format for [10 .. 60[
80                 if (interval < 60.) {
81                         result.add( analog_10s.clone( interval, deadband).setUnit(unit) );
82                         result.add( analog_60s.clone( 60, deadband).setUnit(unit) );
83                         return result;
84                 }
85
86                 // Format for >60s
87                 result.add( analog_60s.clone( interval, deadband).setUnit(unit) );
88                 return result;
89         }
90
91         /**
92          * Create a list of sampling formats for trend's needs 
93          * 
94          * @param interval
95          * @return
96          */
97         public static List<SamplingFormat> createBinarySamplingFormats( double interval )
98         {
99                 ArrayList<SamplingFormat> result = new ArrayList<SamplingFormat>( 5 );
100                 
101                 if (interval==0.) {
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 );
107                         return result;
108                 } 
109
110                 // Format for ]0,1 .. 1[
111                 if (interval < 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 );
117                         return result;
118                 }
119                 
120                 // Format for ]0 .. 1[
121                 if (interval < 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 );
126                         return result;
127                 }
128
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 );
134                         return result;
135                 }
136
137                 // Format for [10 .. 60[
138                 if (interval < 60.) {
139                         result.add( binary_10s.clone( interval, Double.NaN) );
140                         result.add( binary_60s );
141                         return result;
142                 }
143
144                 // Format for >60s
145                 result.add( binary_60s.clone( interval, Double.NaN) );
146                 return result;
147         }
148         
149         static {
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;
157
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;
167                 
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;                
182                 
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);
186
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;
197                 
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;
208                 
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;                
220                 
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);
224         }
225         
226         
227 }