use of org.eevolution.engine.forecast.DataSet in project adempiere by adempiere.
the class ForecastRunCreate method createForecastRunResult.
/**
* Create the Forecast Result
*
* @param M_Warehouse_ID
* @return no records processed
*/
private int createForecastRunResult(int M_Warehouse_ID) {
// total record processed
int records = 0;
ForecastEngine engine = ForecastFactory.getForecastEngine(getAD_Client_ID());
// Generate ForecastEntry based on forecast rule
for (MPPForecastRunMaster master : MPPForecastRunMaster.getLines(getCtx(), p_PP_ForecastRun_ID, get_TrxName())) {
DataSet series = new DataSet();
series.setPeriods(m_run.getPeriodHistory());
MProduct product = MProduct.get(getCtx(), master.getM_Product_ID());
List<MPPForecastRunDetail> details = MPPForecastRunMaster.getDetails(getCtx(), master.get_ID(), get_TrxName());
for (MPPForecastRunDetail detail : details) {
MPPPeriod period = (MPPPeriod) detail.getPP_Period();
DataElement data = new DataElement(master.get_ID(), period.getPeriodNo(), detail.getQtyCalculated(), null);
series.addDataElement(data);
}
DataSet results = engine.getForecast(m_forecast_rule.getCalculationClass(), master.get_ID(), series, master.getFactorAlpha().doubleValue(), master.getFactorGamma().doubleValue(), master.getFactorBeta().doubleValue(), master.getFactorMultiplier().doubleValue(), master.getFactorScale().doubleValue(), master.getFactorUser().doubleValue());
Enumeration<DataElement> elements = results.getDataElements();
while (elements.hasMoreElements()) {
DataElement element = elements.nextElement();
MUOM uom = (MUOM) product.getC_UOM();
MPPForecastRunResult result = new MPPForecastRunResult(getCtx(), 0, get_TrxName());
result.setPP_ForecastRun_ID(m_run.get_ID());
result.setPP_ForecastRunMaster_ID(element.getKey());
result.setDescription(element.getDescription());
BigDecimal qty = (BigDecimal) element.getValue();
result.setQtyCalculated(qty);
result.setQtyPlan(uom.round(qty, true));
result.setIsActive(true);
result.setPP_Period_ID(MPPPeriod.getIDByPeriodNo(m_period_definition_target, element.getPeriodNo()));
result.setPeriodNo(element.getPeriodNo());
result.saveEx();
records++;
}
}
// m_run.saveEx();
return records;
}
Aggregations