Search in sources :

Example 1 with BbTsaMaCoefficients

use of com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients in project bamboobsc by billchen198318.

the class TimeSeriesAnalysisUtils method getForecastNext.

public static double[] getForecastNext(TsaVO tsa, double[] observations) throws ServiceException, Exception {
    if (null == observations || observations.length < 1) {
        throw new IllegalArgumentException("observations array cannot zero size");
    }
    List<BbTsaMaCoefficients> coefficients = getCoefficients(tsa);
    if (coefficients == null || coefficients.size() != 3) {
        throw new IllegalStateException("Ma coefficients data error");
    }
    DefaultArimaProcess arimaProcess = new DefaultArimaProcess();
    arimaProcess.setMaCoefficients(coefficients.get(0).getSeqValue(), coefficients.get(1).getSeqValue(), coefficients.get(2).getSeqValue());
    arimaProcess.setIntegrationOrder(tsa.getIntegrationOrder());
    ArimaForecaster arimaForecaster = new DefaultArimaForecaster(arimaProcess, observations);
    double[] forecast = arimaForecaster.next(tsa.getForecastNext());
    return forecast;
}
Also used : DefaultArimaForecaster(org.espy.arima.DefaultArimaForecaster) DefaultArimaProcess(org.espy.arima.DefaultArimaProcess) BbTsaMaCoefficients(com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients) DefaultArimaForecaster(org.espy.arima.DefaultArimaForecaster) ArimaForecaster(org.espy.arima.ArimaForecaster)

Example 2 with BbTsaMaCoefficients

use of com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients in project bamboobsc by billchen198318.

the class TimeSeriesAnalysisUtils method getResultForExcel.

public static String getResultForExcel(String tsaOid, String visionOid, String startDate, String endDate, String startYearDate, String endYearDate, String frequency, String dataFor, String measureDataOrganizationOid, String measureDataEmployeeOid) throws ServiceException, Exception {
    Map<String, Object> dataMap = getResultWithVision(tsaOid, visionOid, startDate, endDate, startYearDate, endYearDate, frequency, dataFor, measureDataOrganizationOid, measureDataEmployeeOid);
    List<TimeSeriesAnalysisResult> tsaResults = (List<TimeSeriesAnalysisResult>) dataMap.get("result");
    VisionVO vision = (VisionVO) dataMap.get("vision");
    TsaVO tsa = getParam(tsaOid);
    List<BbTsaMaCoefficients> coefficients = getCoefficients(tsa);
    Context context = new ContextBase();
    context.put("tsaResults", tsaResults);
    context.put("tsa", tsa);
    context.put("coefficients", coefficients);
    // for show only.
    context.put("visionName", vision.getTitle());
    if (BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency)) {
        context.put("date1", startYearDate);
        context.put("date2", endYearDate);
    } else {
        context.put("date1", startDate);
        context.put("date2", endDate);
    }
    context.put("frequencyName", BscMeasureDataFrequency.getFrequencyMap(false).get(frequency));
    context.put("dataFor", dataFor);
    context.put("organizationName", "");
    context.put("employeeName", "");
    if (!Constants.HTML_SELECT_NO_SELECT_ID.equals(measureDataOrganizationOid) && !StringUtils.isBlank(measureDataOrganizationOid)) {
        context.put("organizationName", BscBaseLogicServiceCommonSupport.findOrganizationData(organizationService, measureDataOrganizationOid).getName());
    }
    if (!Constants.HTML_SELECT_NO_SELECT_ID.equals(measureDataEmployeeOid) && !StringUtils.isBlank(measureDataEmployeeOid)) {
        context.put("employeeName", BscBaseLogicServiceCommonSupport.findEmployeeData(employeeService, measureDataEmployeeOid).getFullName());
    }
    SimpleChain chain = new SimpleChain();
    ChainResultObj resultObj = chain.getResultFromResource("timeSeriesAnalysisExcelCommandContentChain", context);
    if (!(resultObj.getValue() instanceof String)) {
        throw new java.lang.IllegalStateException("timeSeriesAnalysisExcelCommandContentChain error!");
    }
    return (String) resultObj.getValue();
}
Also used : AppContext(com.netsteadfast.greenstep.base.AppContext) Context(org.apache.commons.chain.Context) SimpleChain(com.netsteadfast.greenstep.base.chain.SimpleChain) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) TsaVO(com.netsteadfast.greenstep.vo.TsaVO) BbTsaMaCoefficients(com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients) TimeSeriesAnalysisResult(com.netsteadfast.greenstep.bsc.model.TimeSeriesAnalysisResult) ChainResultObj(com.netsteadfast.greenstep.base.model.ChainResultObj) ArrayList(java.util.ArrayList) List(java.util.List) ContextBase(org.apache.commons.chain.impl.ContextBase)

Example 3 with BbTsaMaCoefficients

use of com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients in project bamboobsc by billchen198318.

the class TsaQueryForecastAction method fillLineChartData.

private void fillLineChartData(List<TimeSeriesAnalysisResult> results) throws Exception {
    this.tsa = TimeSeriesAnalysisUtils.getParam(this.getFields().get("tsaOid"));
    List<BbTsaMaCoefficients> coefficientsList = TimeSeriesAnalysisUtils.getCoefficients(this.tsa);
    for (BbTsaMaCoefficients maCoefficients : coefficientsList) {
        Map<String, String> dataMap = new HashMap<String, String>();
        dataMap.put("seq", String.valueOf(maCoefficients.getSeq()));
        dataMap.put("seqValue", String.valueOf(maCoefficients.getSeqValue()));
        this.coefficients.add(dataMap);
    }
    // ==============================================================================
    // 產生 categories 資料
    KpiVO firstKpi = results.get(0).getKpi();
    for (DateRangeScoreVO dateRangeScore : firstKpi.getDateRangeScores()) {
        this.categories.add(dateRangeScore.getDate());
    }
    List<Double> firstForecastNext = results.get(0).getForecastNext();
    for (int i = 0; i < firstForecastNext.size(); i++) {
        this.categories.add("next(" + (i + 1) + ")");
    }
    // 產生 series 資料
    for (int i = 0; results != null && i < results.size(); i++) {
        KpiVO kpi = results.get(i).getKpi();
        List<Double> forecastNext = results.get(i).getForecastNext();
        Map<String, Object> mapData = new HashMap<String, Object>();
        List<Float> rangeScore = new LinkedList<Float>();
        for (DateRangeScoreVO dateRangeScore : kpi.getDateRangeScores()) {
            rangeScore.add(dateRangeScore.getScore());
        }
        for (int j = 0; j < forecastNext.size(); j++) {
            rangeScore.add(Float.parseFloat(Double.toString(forecastNext.get(j))));
        }
        mapData.put("name", kpi.getName());
        mapData.put("data", rangeScore);
        this.series.add(mapData);
    }
// ==============================================================================
}
Also used : HashMap(java.util.HashMap) KpiVO(com.netsteadfast.greenstep.vo.KpiVO) DateRangeScoreVO(com.netsteadfast.greenstep.vo.DateRangeScoreVO) BbTsaMaCoefficients(com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients) LinkedList(java.util.LinkedList)

Example 4 with BbTsaMaCoefficients

use of com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients in project bamboobsc by billchen198318.

the class TimeSeriesAnalysisExcelCommand method putTables.

private void putTables(XSSFWorkbook wb, XSSFSheet sh, Context context) throws Exception {
    TsaVO tsa = (TsaVO) context.get("tsa");
    @SuppressWarnings("unchecked") List<BbTsaMaCoefficients> coefficients = (List<BbTsaMaCoefficients>) context.get("coefficients");
    @SuppressWarnings("unchecked") List<TimeSeriesAnalysisResult> tsaResults = (List<TimeSeriesAnalysisResult>) context.get("tsaResults");
    XSSFFont cellHeadFont = wb.createFont();
    cellHeadFont.setBold(true);
    XSSFCellStyle cellHeadStyle = wb.createCellStyle();
    cellHeadStyle.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#f5f5f5")));
    cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cellHeadStyle.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle.setBorderTop(BorderStyle.THIN);
    cellHeadStyle.setBorderRight(BorderStyle.THIN);
    cellHeadStyle.setBorderLeft(BorderStyle.THIN);
    cellHeadStyle.setFont(cellHeadFont);
    XSSFCellStyle cellHeadStyleBlank = wb.createCellStyle();
    cellHeadStyleBlank.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#ffffff")));
    cellHeadStyleBlank.setFont(cellHeadFont);
    XSSFCellStyle cellHeadStyle2 = wb.createCellStyle();
    cellHeadStyle2.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#ffffff")));
    cellHeadStyle2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cellHeadStyle2.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle2.setBorderTop(BorderStyle.THIN);
    cellHeadStyle2.setBorderRight(BorderStyle.THIN);
    cellHeadStyle2.setBorderLeft(BorderStyle.THIN);
    sh.setColumnWidth(0, 12000);
    int row = 0;
    // ==============================================================
    Row nowRow = sh.createRow(row);
    Cell cellTitle = nowRow.createCell(0);
    cellTitle.setCellStyle(cellHeadStyleBlank);
    cellTitle.setCellValue("Forecast analysis - " + context.get("visionName"));
    row++;
    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell0a = nowRow.createCell(0);
    cell0a.setCellStyle(cellHeadStyleBlank);
    cell0a.setCellValue("Frequency: " + context.get("frequencyName") + " , Date range: " + context.get("date1") + " - " + context.get("date2") + " , " + "Measure data type for: " + context.get("dataFor") + " , " + context.get("organizationName") + context.get("employeeName"));
    row++;
    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell0b = nowRow.createCell(0);
    cell0b.setCellStyle(cellHeadStyleBlank);
    cell0b.setCellValue("");
    row++;
    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell1 = nowRow.createCell(0);
    cell1.setCellStyle(cellHeadStyleBlank);
    cell1.setCellValue("Param infornation");
    row++;
    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell2_a = nowRow.createCell(0);
    cell2_a.setCellStyle(cellHeadStyle);
    cell2_a.setCellValue("Item");
    Cell cell2_b = nowRow.createCell(1);
    cell2_b.setCellStyle(cellHeadStyle);
    cell2_b.setCellValue("Value");
    row++;
    // ==============================================================	
    nowRow = sh.createRow(row);
    Cell cell3_a = nowRow.createCell(0);
    cell3_a.setCellStyle(cellHeadStyle2);
    cell3_a.setCellValue("Param name");
    Cell cell3_b = nowRow.createCell(1);
    cell3_b.setCellStyle(cellHeadStyle2);
    cell3_b.setCellValue(tsa.getName());
    row++;
    // ==============================================================	
    nowRow = sh.createRow(row);
    Cell cell4_a = nowRow.createCell(0);
    cell4_a.setCellStyle(cellHeadStyle2);
    cell4_a.setCellValue("Integration order");
    Cell cell4_b = nowRow.createCell(1);
    cell4_b.setCellStyle(cellHeadStyle2);
    cell4_b.setCellValue(tsa.getIntegrationOrder());
    row++;
    // ==============================================================	
    nowRow = sh.createRow(row);
    Cell cell5_a = nowRow.createCell(0);
    cell5_a.setCellStyle(cellHeadStyle2);
    cell5_a.setCellValue("Forecast next");
    Cell cell5_b = nowRow.createCell(1);
    cell5_b.setCellStyle(cellHeadStyle2);
    cell5_b.setCellValue(tsa.getForecastNext());
    row++;
    // ==============================================================	
    nowRow = sh.createRow(row);
    Cell cell6_a = nowRow.createCell(0);
    cell6_a.setCellStyle(cellHeadStyle2);
    cell6_a.setCellValue("Description");
    Cell cell6_b = nowRow.createCell(1);
    cell6_b.setCellStyle(cellHeadStyle2);
    cell6_b.setCellValue(StringUtils.defaultString(tsa.getDescription()).trim());
    row++;
    // ==============================================================
    for (int i = 0; coefficients != null && i < coefficients.size(); i++) {
        BbTsaMaCoefficients coefficient = coefficients.get(i);
        nowRow = sh.createRow(row);
        Cell cell7x_a = nowRow.createCell(0);
        cell7x_a.setCellStyle(cellHeadStyle2);
        cell7x_a.setCellValue("Coefficient (" + (i + 1) + ")");
        Cell cell7x_b = nowRow.createCell(1);
        cell7x_b.setCellStyle(cellHeadStyle2);
        cell7x_b.setCellValue(String.valueOf(coefficient.getSeqValue()));
        row++;
    }
    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cellTitle3a = nowRow.createCell(0);
    cellTitle3a.setCellStyle(cellHeadStyleBlank);
    cellTitle3a.setCellValue("");
    row++;
    // 填寫標題
    nowRow = sh.createRow(row);
    Cell cellTitle2a = nowRow.createCell(0);
    cellTitle2a.setCellStyle(cellHeadStyle);
    cellTitle2a.setCellValue("KPIs");
    int j = 1;
    TimeSeriesAnalysisResult firstResult = tsaResults.get(0);
    for (int i = 0; i < firstResult.getKpi().getDateRangeScores().size(); i++) {
        DateRangeScoreVO dateRangeScore = firstResult.getKpi().getDateRangeScores().get(i);
        Cell cellTitle2a_dateRange = nowRow.createCell(j);
        j++;
        cellTitle2a_dateRange.setCellStyle(cellHeadStyle);
        cellTitle2a_dateRange.setCellValue(dateRangeScore.getDate());
    }
    for (int i = 0; i < firstResult.getForecastNext().size(); i++) {
        Cell cellTitle2a_dateRange = nowRow.createCell(j);
        j++;
        cellTitle2a_dateRange.setCellStyle(cellHeadStyle);
        cellTitle2a_dateRange.setCellValue("next(" + (i + 1) + ")");
    }
    row++;
    // 填寫 Date Range score 與 Forecast next score
    for (int i = 0; i < tsaResults.size(); i++) {
        nowRow = sh.createRow(row);
        j = 0;
        TimeSeriesAnalysisResult resultModel = tsaResults.get(i);
        Cell cell_kpi = nowRow.createCell(j);
        cell_kpi.setCellStyle(cellHeadStyle);
        cell_kpi.setCellValue(resultModel.getKpi().getName());
        j++;
        for (int n = 0; n < resultModel.getKpi().getDateRangeScores().size(); n++) {
            DateRangeScoreVO dateRangeScore = resultModel.getKpi().getDateRangeScores().get(n);
            Cell cell_dateRangeScore = nowRow.createCell(j);
            cell_dateRangeScore.setCellStyle(cellHeadStyle2);
            cell_dateRangeScore.setCellValue(dateRangeScore.getScore());
            j++;
        }
        for (int n = 0; n < resultModel.getForecastNext().size(); n++) {
            double forecastScore = resultModel.getForecastNext().get(n);
            Cell cell_forecastScore = nowRow.createCell(j);
            cell_forecastScore.setCellStyle(cellHeadStyle2);
            cell_forecastScore.setCellValue(forecastScore);
            j++;
        }
        row++;
    }
}
Also used : DateRangeScoreVO(com.netsteadfast.greenstep.vo.DateRangeScoreVO) TsaVO(com.netsteadfast.greenstep.vo.TsaVO) BbTsaMaCoefficients(com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients) TimeSeriesAnalysisResult(com.netsteadfast.greenstep.bsc.model.TimeSeriesAnalysisResult) XSSFColor(org.apache.poi.xssf.usermodel.XSSFColor) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) List(java.util.List) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Example 5 with BbTsaMaCoefficients

use of com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients in project bamboobsc by billchen198318.

the class TsaLogicServiceImpl method deleteMaCoefficients.

private void deleteMaCoefficients(TsaVO tsa) throws ServiceException, Exception {
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("tsaOid", tsa.getOid());
    List<BbTsaMaCoefficients> maCoefficientsList = this.tsaMaCoefficientsService.findListByParams(paramMap);
    for (BbTsaMaCoefficients maCoefficients : maCoefficientsList) {
        this.tsaMaCoefficientsService.delete(maCoefficients);
    }
}
Also used : HashMap(java.util.HashMap) BbTsaMaCoefficients(com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients)

Aggregations

BbTsaMaCoefficients (com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients)5 TimeSeriesAnalysisResult (com.netsteadfast.greenstep.bsc.model.TimeSeriesAnalysisResult)2 DateRangeScoreVO (com.netsteadfast.greenstep.vo.DateRangeScoreVO)2 TsaVO (com.netsteadfast.greenstep.vo.TsaVO)2 HashMap (java.util.HashMap)2 List (java.util.List)2 AppContext (com.netsteadfast.greenstep.base.AppContext)1 SimpleChain (com.netsteadfast.greenstep.base.chain.SimpleChain)1 ChainResultObj (com.netsteadfast.greenstep.base.model.ChainResultObj)1 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)1 VisionVO (com.netsteadfast.greenstep.vo.VisionVO)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Context (org.apache.commons.chain.Context)1 ContextBase (org.apache.commons.chain.impl.ContextBase)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)1 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)1 XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)1