package com.njcn.event.utils;

import cn.hutool.core.util.RandomUtil;
import freemarker.template.TemplateException;
import net.sf.json.JSONArray;

import java.io.IOException;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2022年08月25日 08:59
 */
public class TestTemplate {
    public static void main(String[] args) throws IOException, TemplateException {
        HashMap<String, Object> map = new HashMap<>();
        map.put("subtext","区域统计");
        map.put("xname","(区域)");
        List<String> x = Stream.of("江苏省", "浙江省", "福建省").collect(Collectors.toList());
        map.put("area",JSONArray.fromObject(x).toString());
        List<Integer> on = Stream.of(149, 15, 9).collect(Collectors.toList());
        List<Integer> off = Stream.of(24, 2, 1).collect(Collectors.toList());
        map.put("onlineData",JSONArray.fromObject(on).toString());
        map.put("offlineData",JSONArray.fromObject(off).toString());

        List<List<Double>> floatData = new ArrayList<>();
        for (int i = 0; i < 1500; i++) {
            List<Double> sub = new ArrayList<>();
            sub.add( RandomUtil.randomDouble(100.0,3, RoundingMode.UP));
            sub.add( RandomUtil.randomDouble(200.0,3, RoundingMode.UP));
            floatData.add(sub);
        }
        map.put("point",JSONArray.fromObject(floatData).toString());

//        String s = freemarkerUtil.generateString("bar.ftl", "com/njcn/event/template", map);
//        System.out.println(EchartsUtil.generateEchartsBase64(s,"8910"));




//        HashMap<String, Object> datas = new HashMap<>();
//        List<List<Double>> floatData = new ArrayList<>();
//        for (int i = 0; i < 1500; i++) {
//            List<Double> sub = new ArrayList<>();
//            sub.add( RandomUtil.randomDouble(100.0,3, RoundingMode.UP));
//            sub.add( RandomUtil.randomDouble(200.0,3, RoundingMode.UP));
//            floatData.add(sub);
//        }
//        datas.put("bdata", JSONArray.fromObject(floatData).toString());
//        String option = FreemarkerUtil.generateString("test.ftl", "com/njcn/event/template", datas);
//        System.out.println(EchartsUtil.generateEchartsBase64(option, "8910"));
    }


}
