All Downloads are FREE. Search and download functionalities are using the official Maven repository.

decodes.tsdb.test.WriteTimeSeries Maven / Gradle / Ivy

Go to download

A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.

The newest version!
/*
*  $Id$
*/
package decodes.tsdb.test;

import java.util.Date;
import java.util.StringTokenizer;

import opendcs.dai.TimeSeriesDAI;

import ilex.cmdline.*;
import ilex.var.TimedVariable;

import decodes.util.CmdLineArgs;
import decodes.sql.DbKey;
import decodes.tsdb.*;

/**
Writes some test data to a time series in the database.
*/
public class WriteTimeSeries extends TestProg
{
	private StringToken outArg;
	private IntegerToken periodArg;
	private IntegerToken numSamplesArg;
	private BooleanToken lineArg;

	public WriteTimeSeries()
	{
		super(null);
	}

	/**
	 * Overrides to add test-specific arguments.
	 */
	protected void addCustomArgs(CmdLineArgs cmdLineArgs)
	{
		lineArg = new BooleanToken("L", "Ascending Line", "", 
			TokenOptions.optSwitch, false);
		periodArg = new IntegerToken("S", "sample period in seconds", "", 
			TokenOptions.optSwitch, 3600);
		numSamplesArg = new IntegerToken("N", "Number of Samples", "", 
			TokenOptions.optSwitch, 24);
		outArg = new StringToken("", "sdi:intv:tabsel:modid", "", 
			TokenOptions.optArgument|TokenOptions.optRequired, "");
		cmdLineArgs.addToken(lineArg);
		cmdLineArgs.addToken(periodArg);
		cmdLineArgs.addToken(numSamplesArg);
		cmdLineArgs.addToken(outArg);
	}

	public static void main(String args[])
		throws Exception
	{
		TestProg tp = new WriteTimeSeries();
		tp.execute(args);
	}

	protected void runTest()
		throws Exception
	{
		String outTS = outArg.getValue();

		CTimeSeries ts = makeTimeSeries(outTS);
		ts.setComputationId(DbKey.createDbKey(1));

		long periodMsec = periodArg.getValue() * 1000L;
		int num = numSamplesArg.getValue();

		// Build a time series with 1 day's worth of hourly stage values.
		long t = System.currentTimeMillis();
		// Truncate to even period
		t = (t / periodMsec) * periodMsec;
		t -= (periodMsec * (num-1));
		for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy