V1_0.java [src/java/m/cfa/timeseries15min] Revision:   Date:
package m.cfa.timeseries15min;

import csip.ModelDataService;
import csip.api.server.PayloadParameter;
import csip.api.server.PayloadResults;
import csip.annotations.Description;
import csip.annotations.Name;
import csip.annotations.VersionInfo;
import java.io.File;
import javax.ws.rs.Path;

@Name("timeseries15min")
@Description("Time Series: 15-minute Statistics and Data Visualization")
@VersionInfo("1.0")
@Path("m/cfa/timeseries15min/1.0")
public class V1_0 extends ModelDataService {

    gui15minTimeseries_Model model = new gui15minTimeseries_Model();
    
    @Override
    protected void preProcess() throws Exception {
        model.setDirectory(workspace().getDir().toString());
        
        PayloadParameter inputPayload = parameter();
        model.setDatabase(inputPayload.getString("database"));
        model.setStationId(inputPayload.getString("station_id"));
        model.setStationName(inputPayload.getString("station_name"));
        model.setStartDate(inputPayload.getString("begin_date", ""));
        model.setEndDate(inputPayload.getString("end_date", ""));
        model.setMergeDatasets(inputPayload.getBoolean("merge_datasets", false));
        model.setMergeMethod(inputPayload.getString("merge_method", "user"));
        model.setUserData(inputPayload.getString("user_data", ""));
    }

    @Override
    protected void doProcess() throws Exception {
        model.run();
    }
    
    @Override
    protected void postProcess() throws Exception {
        PayloadResults resultPayload = results();
        // files
        File wd = workspace().getDir();
        resultPayload.put(new File(wd, model.getGraph()),
                  model.getOutputSummary(),
                  //Below are the result graph files for use by JHighCharts on eRAMS for duplicating the above graphs
                  model.getTimeseriesOutput());

        // values
        resultPayload.put("len", model.getLen());
        resultPayload.put("start", model.getStart());
        resultPayload.put("end", model.getEnd());
        resultPayload.put("units", model.getUnits());
        resultPayload.put("data_source", model.getDataSource());
        //Get all data results
        resultPayload.put("max", model.getMax(), null, "cfs");
        resultPayload.put("min", model.getMin(), null, "cfs");
        resultPayload.put("range", model.getRange(), null, "cfs");
        resultPayload.put("mean", model.getMean(), null, "cfs");
        resultPayload.put("standardDeviation", model.getStandardDeviation(), null, "cfs");
        //Get other results
        resultPayload.put("graph", model.getGraph());
        resultPayload.put("resultSummary", model.getOutputSummary().getName());
        
        //Get result files for JSHighCharts
        String graphDataFiles = model.getTimeseriesOutput().getName();
        resultPayload.put("graph_data_files", graphDataFiles);
    }
}