Java Code Examples for net.sourceforge.openforecast.DataSet#getTimeVariable()

The following examples show how to use net.sourceforge.openforecast.DataSet#getTimeVariable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTimeBasedModel.java    From OpenForecast with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Initializes the time variable from the given data set. If the data set
 * does not have a time variable explicitly defined, then provided there
 * is only one independent variable defined for the data set that is used
 * as the time variable. If more than one independent variable is defined
 * for the data set, then it is not possible to take an educated guess at
 * which one is the time variable. In this case, an
 * IllegalArgumentException will be thrown.
 * @param dataSet the data set to use to initialize the time variable.
 * @throws IllegalArgumentException If more than one independent variable
 * is defined for the data set and no time variable has been specified. To
 * correct this, be sure to explicitly specify the time variable in the
 * data set passed to {@link #init}.
 */
protected void initTimeVariable( DataSet dataSet )
    throws IllegalArgumentException
{
    if ( timeVariable == null )
        {
            // Time variable not set, so look at independent variables
            timeVariable = dataSet.getTimeVariable();
            if ( timeVariable == null )
                {
                    String[] independentVars
                        = dataSet.getIndependentVariables();
                    
                    if ( independentVars.length != 1 )
                        throw new IllegalArgumentException("Unable to determine the independent time variable for the data set passed to init for "+toString()+". Please use DataSet.setTimeVariable before invoking model.init.");
                    
                    timeVariable = independentVars[0];
                }
        }
}
 
Example 2
Source File: TimeSeriesOutputter.java    From OpenForecast with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Adds a DataSet - a collection of DataPoints - to the current TimeSeries.
 * The DataSet should contain all DataPoints to be output.
 * @param dataSet the DataSet to be output to the current TimeSeries.
 */
public void output( DataSet dataSet )
    throws InstantiationException, IllegalAccessException,
    InvocationTargetException, InstantiationException
{
    String timeVariable = dataSet.getTimeVariable();
    
    Iterator<DataPoint> it = dataSet.iterator();
    while ( it.hasNext() )
        {
            DataPoint dataPoint = it.next();
            output( dataPoint, timeVariable );
        }
}