Search in sources :

Example 6 with LabelIndexModel

use of org.sagacity.sqltoy.config.model.LabelIndexModel in project sagacity-sqltoy by chenrenfei.

the class ResultUtils method wrapLabelIndexMap.

/**
 * @TODO 建立列名称跟列index的对应关系
 * @param fields
 * @return
 */
private static LabelIndexModel wrapLabelIndexMap(String[] fields) {
    LabelIndexModel result = new LabelIndexModel();
    if (fields != null && fields.length > 0) {
        String realLabelName;
        int index;
        for (int i = 0, n = fields.length; i < n; i++) {
            realLabelName = fields[i].toLowerCase();
            index = realLabelName.indexOf(":");
            if (index != -1) {
                realLabelName = realLabelName.substring(index + 1).trim();
            }
            result.put(realLabelName, i);
        }
    }
    return result;
}
Also used : LabelIndexModel(org.sagacity.sqltoy.config.model.LabelIndexModel)

Example 7 with LabelIndexModel

use of org.sagacity.sqltoy.config.model.LabelIndexModel in project sagacity-sqltoy by chenrenfei.

the class ChainRelativeTest method testColsChainRelative.

@Test
public void testColsChainRelative() {
    // |------- 1月-------|------- 2月 ------|------ 3月--------|
    // |交易笔 | 金额 | 收入 |交易笔 | 金额 | 收入 |交易笔 | 金额 | 收入 |
    Object[][] values = { { "香蕉", 10, 2000, 20000, 12, 2400, 27000, 13, 2300, 27000 }, { "苹果", 12, 2000, 24000, 11, 1900, 26000, 13, 2000, 25000 } };
    List result = CollectionUtil.arrayToDeepList(values);
    ColsChainRelativeModel colsRelative = new ColsChainRelativeModel();
    colsRelative.setGroupSize(3);
    colsRelative.setReduceOne(false);
    colsRelative.setRelativeIndexs(new Integer[] { 1, 2 });
    colsRelative.setFormat("#.00%");
    colsRelative.setStartColumn("1");
    LabelIndexModel labelIndexMap = new LabelIndexModel();
    ColsChainRelative.process(colsRelative, labelIndexMap, result);
    System.out.println(JSON.toJSONString(result));
}
Also used : ColsChainRelativeModel(org.sagacity.sqltoy.config.model.ColsChainRelativeModel) List(java.util.List) LabelIndexModel(org.sagacity.sqltoy.config.model.LabelIndexModel) Test(org.junit.jupiter.api.Test)

Example 8 with LabelIndexModel

use of org.sagacity.sqltoy.config.model.LabelIndexModel in project sagacity-sqltoy by chenrenfei.

the class ChainRelativeTest method testRowsChainRelative.

@Test
public void testRowsChainRelative() {
    // |月份 | 产品 |交易笔数 | 环比 | 金额 | 环比 | 收入 | 环比 |
    // | 5月 | 香蕉 | 2000 | 环比 | 金额 | 环比 | 收入 | 环比 |
    // | 5月 | 苹果 | 2000 | 环比 | 金额 | 环比 | 收入 | 环比 |
    // | 4月 | 香蕉 | 2000 | 环比 | 金额 | 环比 | 收入 | 环比 |0
    // | 4月 | 苹果 | 2000 | 环比 | 金额 | 环比 | 收入 | 环比 |1
    // | 3月 | 香蕉 | 2000 | 环比 | 金额 | 环比 | 收入 | 环比 |
    // | 3月 | 苹果 | 2000 | 环比 | 金额 | 环比 | 收入 | 环比 |
    Object[][] values = { { "5月", "香蕉", 2000 }, { "5月", "苹果", 1900 }, { "4月", "香蕉", 1800 }, { "4月", "苹果", 1800 }, { "3月", "香蕉", 1600 }, { "3月", "苹果", 1700 } };
    List result = CollectionUtil.arrayToDeepList(values);
    RowsChainRelativeModel rowsRelative = new RowsChainRelativeModel();
    rowsRelative.setGroupColumn("1");
    rowsRelative.setReduceOne(false);
    rowsRelative.setRelativeColumns(new String[] { "2" });
    rowsRelative.setFormat("#.00%");
    rowsRelative.setReverse(true);
    LabelIndexModel labelIndexMap = new LabelIndexModel();
    RowsChainRelative.process(rowsRelative, labelIndexMap, result);
    for (int i = 0; i < result.size(); i++) {
        System.out.println(JSON.toJSONString(result.get(i)));
    }
}
Also used : RowsChainRelativeModel(org.sagacity.sqltoy.config.model.RowsChainRelativeModel) List(java.util.List) LabelIndexModel(org.sagacity.sqltoy.config.model.LabelIndexModel) Test(org.junit.jupiter.api.Test)

Aggregations

LabelIndexModel (org.sagacity.sqltoy.config.model.LabelIndexModel)8 List (java.util.List)6 Test (org.junit.jupiter.api.Test)6 UnpivotModel (org.sagacity.sqltoy.config.model.UnpivotModel)4 UnpivotList (org.sagacity.sqltoy.plugins.calculator.UnpivotList)4 DataSetResult (org.sagacity.sqltoy.model.inner.DataSetResult)3 ColsChainRelativeModel (org.sagacity.sqltoy.config.model.ColsChainRelativeModel)2 RowsChainRelativeModel (org.sagacity.sqltoy.config.model.RowsChainRelativeModel)2 ArrayList (java.util.ArrayList)1 FormatModel (org.sagacity.sqltoy.config.model.FormatModel)1 PivotModel (org.sagacity.sqltoy.config.model.PivotModel)1 ReverseModel (org.sagacity.sqltoy.config.model.ReverseModel)1 SecureMask (org.sagacity.sqltoy.config.model.SecureMask)1 SummaryModel (org.sagacity.sqltoy.config.model.SummaryModel)1 ReverseList (org.sagacity.sqltoy.plugins.calculator.ReverseList)1