com.datastax.data.exploration.service.chart.impl.PieServiceImpl Maven / Gradle / Ivy
package com.datastax.data.exploration.service.chart.impl;
import com.alibaba.fastjson.JSONObject;
import com.datastax.data.exploration.biz.datatable.column.math.Function;
import com.datastax.data.exploration.biz.stat.Pie;
import com.datastax.data.exploration.common.DataTypeHandler;
import com.datastax.data.exploration.common.File2DataTable;
import com.datastax.data.exploration.service.chart.PieService;
import com.datastax.data.exploration.util.Consts;
import org.javatuples.Pair;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* 饼图
*
* @author songfu 2017/12/12
*/
@Service("pieService")
public class PieServiceImpl implements PieService {
// private static final Logger logger = LogManager.getLogger(PieServiceImpl.class);
/**
* 获取饼图初始化数据
*
* @param id 数据集id
* @return 返回的是饼图初始化数据
*/
@Override
public JSONObject pieInit(String id) {
Pair, List> pair = DataTypeHandler.continuousDiscrete(File2DataTable.tableSchema(id));
List listVal = pair.getValue0();
List listProp = pair.getValue1();
if (listProp.size() == 0) {
listProp.add(Consts.NONE);
}
if (listVal.size() == 0) {
listVal.add(Consts.NONE);
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("prop", listProp);
jsonObject.put("val", listVal);
jsonObject.put("func", Function.getFunctions());
return jsonObject;
}
/**
* 返回饼图的展示数据
*
* @param id 数据集id
* @param group 聚合属性
* @param val 取值属性
* @param func 聚合函数
* @return 返回的是饼图的展示数据
*/
@Override
public List pieSelect(String id, String group, String val, String func) {
List listValue = new ArrayList<>();
if (Consts.NONE.equals(group)) {
return listValue;
}
return Pie.operator(id, group, val, func);
}
}