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

org.bigml.binding.resources.Forecast Maven / Gradle / Ivy

Go to download

An open source Java client that gives you a simple binding to interact with BigML. You can use it to easily create, retrieve, list, update, and delete BigML resources.

There is a newer version: 2.1.1
Show newest version
package org.bigml.binding.resources;

import org.bigml.binding.BigMLClient;
import org.bigml.binding.utils.CacheManager;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Entry point to create, retrieve, list, update, and delete forecasts.
 *
 * Full API documentation on the API can be found from BigML at:
 * https://bigml.com/api/forecasts
 *
 *
 */
public class Forecast extends AbstractResource {

    // Logging
    Logger logger = LoggerFactory.getLogger(Forecast.class);
    
    /**
     * Constructor
     *
     * @deprecated
     */
	public Forecast() {
		super.init(null, null, null, null, null, 
				FORECAST_RE, FORECAST_PATH);
	}

	/**
	 * Constructor
	 *
	 * @deprecated
	 */
	public Forecast(final String apiUser, final String apiKey) {
		super.init(apiUser, apiKey, null, null, null, 
				FORECAST_RE, FORECAST_PATH);
	}
	
	/**
	 * Constructor
	 *
	 * @deprecated
	 */
	public Forecast(final String apiUser, final String apiKey,
			final CacheManager cacheManager) {
		super.init(apiUser, apiKey, null, null, null, 
				FORECAST_RE, FORECAST_PATH);
	}
	
    /**
     * Constructor
     *
     */
    public Forecast(final BigMLClient bigmlClient,
    				final String apiUser, final String apiKey, 
    				final String project, final String organization,
    				final CacheManager cacheManager) {
    		super.init(bigmlClient, apiUser, apiKey, project, organization,
    				   cacheManager, FORECAST_RE, FORECAST_PATH);
    }

    /**
     * Creates a forecast from a timeseries.
     *
     * POST /andromeda/forecast?username=$BIGML_USERNAME;api_key=$BIGML_API_KEY;
     * HTTP/1.1 Host: bigml.io Content-Type: application/json
     *
     * @param timeSeriesId
     *            a unique identifier in the form timeseries/id where id is a
     *            string of 24 alpha-numeric chars for the timeseries to attach
     *            the forecast.
     * @param inputData
     *            an object with field's id/value pairs representing the
     *            instance you want to create a forecast for.
     * @param args
     *            set of parameters for the new forecast. Optional
     * @param waitTime
     *            time (milliseconds) to wait for next check of FINISHED status
     *            for source before to start to create the forecast.
     *            Optional
     * @param retries
     *            number of times to try the operation. Optional
     *
     */
    public JSONObject create(final String timeSeriesId,
            JSONObject inputData, JSONObject args,
            Integer waitTime, Integer retries) {

        if (timeSeriesId == null || timeSeriesId.length() == 0 ) {
            logger.info("Wrong timeseries id. Id cannot be null");
            return null;
        }

        try {
        	waitForResource(timeSeriesId, "timeSeriesIsReady", waitTime, retries);
        	
            JSONObject requestObject = new JSONObject();
            if (args != null) {
                requestObject = args;
            }

            requestObject.put("timeseries", timeSeriesId);
            requestObject.put("input_data", inputData);

            return createResource(resourceUrl,
            		requestObject.toJSONString());
        } catch (Throwable e) {
            logger.error("Error creating timeseries");
            return null;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy