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

com.datastax.data.exploration.service.chart.impl.CrosstabServiceImpl Maven / Gradle / Ivy

package com.datastax.data.exploration.service.chart.impl;

import com.datastax.data.exploration.biz.datatable.DataTable;
import com.datastax.data.exploration.biz.datatable.column.NomialColumn;
import com.datastax.data.exploration.biz.stat.Cross;
import com.datastax.data.exploration.common.File2DataTable;
import com.datastax.data.exploration.dto.dataChart.stackedBar.Crosstab;
import com.datastax.data.exploration.service.chart.CrosstabService;
import com.datastax.data.exploration.util.Consts;
import org.javatuples.Pair;
import org.springframework.stereotype.Service;

import java.util.*;


/**
 * 交叉分组表
 *
 * @author songfu 2018/01/30
 */
@Service("crosstabService")
public class CrosstabServiceImpl implements CrosstabService {
    private static final String EMPTY = "";

    /**
     * 获取交叉分组表
     *
     * @param id    数据集 id
     * @param group 交叉表 行
     * @param stack 交叉表 列
     * @return 返回的是交叉分组表展示数据
     */
    @Override
    public Crosstab crosstabData(String id, String group, String stack) {
        if (Consts.NONE.equals(group) || Consts.NONE.equals(stack)) {
            return new Crosstab();
        }
        DataTable table = File2DataTable.exactTable(id);
        List groupSubs = ((NomialColumn) table.getColumns().getColumn(group)).distinct();
        List stackSubs = ((NomialColumn) table.getColumns().getColumn(stack)).distinct();

        Pair>, List> pair = Cross.getCount(table, group, stack); //获取每分组的count数据,以及分组的count总和
        List> groupCounts = pair.getValue0(); //获取每分组的count数据
        Pair> pairTotal = Cross.getCountTotals(groupCounts); //获取 count总和 和 合计中的count值
        Map map = Cross.getFuncs(group, stack); //获取计算因子

        String[] summary = Cross.getSummary(id);
        Crosstab.ModuleData contentModule = Cross.getContentModule(map, group, groupSubs, pair, pairTotal);
        Crosstab.GroupData totalModule = Cross.getTotalModule(map, pairTotal.getValue1(), pairTotal.getValue0());
        List chiSquares = Cross.getChiSquare(groupCounts, pairTotal.getValue0());

        if (group.equals(stack)) {
            stackSubs = stackSubs.subList(0, 1);
        }
        stackSubs.add("合计");
        Crosstab crosstab = new Crosstab
                .Builder()
                .summary(summary)
                .stack(stack)
                .stackSubs(stackSubs)
                .content(contentModule)
                .total(totalModule)
                .chiSquare(chiSquares)
                .build();
        return crosstab;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy