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.util.subscription;
\r
14 import java.util.Collection;
\r
15 import java.util.Iterator;
\r
17 import org.simantics.databoard.annotations.Identifier;
\r
18 import org.simantics.databoard.type.Datatype;
\r
19 import org.simantics.databoard.util.Bean;
\r
22 * (Utility Class) Item format for HistoryManager, Collector, and meta-data for Simantics subscription configurations.
\r
24 * The items objects the HistoryManager and Collector uses are complete meta-data
\r
25 * descriptions. Different formats are supported and the content is written to disc
\r
26 * completely as is.
\r
28 * The "id" is composed with the following aggregation: [subscriptionId] [variableId] [formatId].
\r
30 * @author toni.kalajainen
\r
32 public class SubscriptionItem extends Bean {
\r
35 * Create HistoryItem descriptions for collecting one variable with multiple
\r
39 * the item to use as a template for the created sampled items
\r
40 * @param groupItemId
\r
41 * the group item id to use with
\r
42 * {@link #composeItemName(String, String, String)}
\r
44 * the group id to use with
\r
45 * {@link #composeItemName(String, String, String)}
\r
47 * the sampling formats to create
\r
48 * @return an array of history items
\r
50 public static SubscriptionItem[] createItems(
\r
51 SubscriptionItem item,
\r
54 Collection<SamplingFormat> formats) {
\r
55 Iterator<SamplingFormat> itr = formats.iterator();
\r
56 SubscriptionItem[] items = new SubscriptionItem[ formats.size() ];
\r
57 for (int i=0; i<formats.size(); i++) {
\r
58 items[i] = createItem( item, groupItemId, groupId, itr.next() );
\r
64 * Create HistoryItem descriptions for collecting one variable with multiple
\r
68 * @param subscriptionId
\r
70 * @return an array of history items
\r
72 public static SubscriptionItem[] createItems(
\r
74 String subscriptionId,
\r
75 SamplingFormat...formats
\r
77 SubscriptionItem[] items = new SubscriptionItem[ formats.length ];
\r
78 for (int i=0; i<formats.length; i++) {
\r
79 items[i] = createItem( variableId, subscriptionId, formats[i] );
\r
85 * Create HistoryItem descriptions for collecting one variable with multiple
\r
88 * @param groupItemId
\r
91 * @return an array of history items
\r
93 public static SubscriptionItem[] createItems(
\r
96 Collection<SamplingFormat> formats) {
\r
97 Iterator<SamplingFormat> itr = formats.iterator();
\r
98 SubscriptionItem[] items = new SubscriptionItem[ formats.size() ];
\r
99 for (int i=0; i<formats.size(); i++) {
\r
100 items[i] = createItem( groupItemId, groupId, itr.next() );
\r
106 * Create HistoryItem description for collecting one variable with one
\r
110 * the subscription item to clone values from
\r
111 * @param groupItemId
\r
112 * the group item id to use with
\r
113 * {@link #composeItemName(String, String, String)}
\r
115 * the group id to use with
\r
116 * {@link #composeItemName(String, String, String)}
\r
118 * @return HistoryItem description.
\r
120 public static SubscriptionItem createItem(
\r
121 SubscriptionItem item,
\r
122 String groupItemId,
\r
124 SamplingFormat format
\r
126 SubscriptionItem hi = new SubscriptionItem();
\r
127 hi.variableId = item.variableId;
\r
128 hi.groupItemId = item.groupItemId;
\r
129 hi.id = composeItemName(groupId, groupItemId, format.formatId);
\r
130 hi.deadband = format.deadband;
\r
131 hi.interval = format.interval;
\r
132 hi.gain = item.gain;
\r
133 hi.bias = item.bias;
\r
134 hi.formatId = format.formatId;
\r
135 hi.format = format.format;
\r
136 hi.groupId = item.groupId;
\r
137 hi.enabled = item.enabled;
\r
142 * Create HistoryItem description for collecting one variable with one
\r
143 * sampling format.
\r
145 * @param groupItemId
\r
146 * the group item id to use with
\r
147 * {@link #composeItemName(String, String, String)}
\r
149 * the group id to use with
\r
150 * {@link #composeItemName(String, String, String)}
\r
152 * @return HistoryItem description.
\r
154 public static SubscriptionItem createItem(
\r
155 String groupItemId,
\r
157 SamplingFormat format
\r
159 SubscriptionItem hi = new SubscriptionItem();
\r
160 hi.variableId = groupItemId;
\r
161 hi.groupItemId = groupItemId;
\r
162 hi.id = composeItemName(groupId, groupItemId, format.formatId);
\r
163 hi.deadband = format.deadband;
\r
164 hi.interval = format.interval;
\r
165 hi.formatId = format.formatId;
\r
166 hi.format = format.format;
\r
167 hi.groupId = groupId;
\r
172 public static String composeItemName(String groupId, String groupItemId, String formatId)
\r
174 return groupId+" "+groupItemId+" "+formatId;
\r
177 /** Item identifier in the HistoryManager */
\r
178 public @Identifier String id;
\r
180 /** Variable Id, Reference of variable in Datasource. This field is used by Collector */
\r
181 public String variableId;
\r
184 * Describes the format of the packed sample. The sample must be a record.
\r
185 * The record must have any combination of the following named fields.
\r
186 * The field types must one of: byte, integer, long, float, double.
\r
188 * time, endTime, value - are mandatory fields.
\r
190 * time - Region start time, the time of the 1st sample included into the band
\r
191 * endTime - Region end time, the time of the last sample included into the band
\r
193 * value - First value in the band
\r
194 * lastValue - Last value in the band
\r
195 * avg - Average value of all included samples
\r
196 * median - Median value of all samples in the band
\r
197 * min - Lowest value in the band
\r
198 * max - Highest value in the band
\r
200 * quality - 0 = Good, -1 = No value
\r
201 * count - The number of included samples in the band
\r
203 public Datatype format;
\r
205 // Subscription parameters
\r
206 public double deadband = Double.NaN;
\r
207 public double interval = Double.NaN;
\r
208 public double gain = 1.0;
\r
209 public double bias = 0.0;
\r
210 public boolean enabled = true;
\r
212 /** Identifier of group or subscription, used by Simantics */
\r
213 public String groupId = "";
\r
215 /** Identifier of the item in the group, used by Simantics */
\r
216 public String groupItemId = "";
\r
218 /** Identifier of the sample format description, used by Simantics */
\r
219 public String formatId = "";
\r