
/*
 *  Copyright (C) 2004  The Concord Consortium, Inc.,
 *  10 Concord Crossing, Concord, MA 01741
 *
 *  Web Site: http://www.concord.org
 *  Email: info@concord.org
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/*
 * Created on Jan 26, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.concord.sensor.impl;

import org.concord.framework.data.stream.DataChannelDescription;
import org.concord.framework.data.stream.DataStreamDescription;
import org.concord.sensor.ExperimentConfig;
import org.concord.sensor.ExperimentRequest;
import org.concord.sensor.SensorConfig;
import org.concord.sensor.SensorRequest;

/**
 * @author scott
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class DataStreamDescUtil 
{
	/**
	 * The result can be null. 
	 * 
	 * @param dDesc
	 * @param request
	 * @param result
	 */
	public static void setupDescription(DataStreamDescription dDesc,
			ExperimentRequest request, 
			ExperimentConfig result)
	{
		SensorConfig [] sensConfigs = null;
		SensorRequest [] sensRequests = request.getSensorRequests();		
		int firstValueChannelIndex = 0;
		
		if(result != null) {
			sensConfigs = result.getSensorConfigs();
		}
		
		dDesc.setChannelsPerSample(sensRequests.length);
		
		if(result != null) {
			dDesc.setDt(result.getPeriod());
			if(result.getExactPeriod()) {
				dDesc.setDataType(DataStreamDescription.DATA_SEQUENCE);
			} else {
				dDesc.setDataType(DataStreamDescription.DATA_SERIES);
				DataChannelDescription chDescrip = new DataChannelDescription();
				chDescrip.setName("time");
				chDescrip.setUnit(new SensorUnit("s"));
				chDescrip.setPrecision(-2);
				chDescrip.setNumericData(true);
				dDesc.setChannelDescription(chDescrip, 0);				
				firstValueChannelIndex = 1;
				dDesc.setChannelsPerSample(sensRequests.length+1);
			}
		} else {
			dDesc.setDt(request.getPeriod());			
		}
		
		for(int i=0; i<sensRequests.length; i++) {
			DataChannelDescription chDescrip = new DataChannelDescription();
			if(result != null) {
				chDescrip.setName(sensConfigs[i].getName());
			}
			chDescrip.setUnit(sensRequests[i].getUnit());
			
			chDescrip.setPrecision(sensRequests[i].getDisplayPrecision());			
			chDescrip.setNumericData(true);
			dDesc.setChannelDescription(chDescrip, i+firstValueChannelIndex);
		}		
	}
}

@@ -2163,175 +2163,20 @@
 ));%0A
-%09%09%09if(result.getExactPeriod()) %7B%0A%09%09%09%09dDesc.setDataType(DataStreamDescription.DATA_SEQUENCE);%0A%09%09%09%7D else %7B%0A%09%09%09%09dDesc.setDataType(DataStreamDescription.DATA_SERIES);%0A%09%09%09%09
+            
 Data
@@ -2236,20 +2236,28 @@
 tion();%0A
-%09%09%09%09
+            
 chDescri
@@ -2275,20 +2275,28 @@
 time%22);%0A
-%09%09%09%09
+            
 chDescri
@@ -2327,20 +2327,28 @@
 (%22s%22));%0A
-%09%09%09%09
+            
 chDescri
@@ -2367,20 +2367,28 @@
 on(-2);%0A
-%09%09%09%09
+            
 chDescri
@@ -2411,16 +2411,237 @@
 (true);%0A
+%09%09%09if(result.getExactPeriod()) %7B%0A%09%09%09%09dDesc.setDataType(DataStreamDescription.DATA_SEQUENCE);%0A                dDesc.setDtChannelDescription(chDescrip);%0A%09%09%09%7D else %7B%0A%09%09%09%09dDesc.setDataType(DataStreamDescription.DATA_SERIES);%0A
 %09%09%09%09dDes

Modified the setup of the channel description so the dt channel description is setup correctly.