package com.jxy.marketall.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.jxy.common.core.text.Convert;
import com.jxy.common.core.utils.DateUtils;
import com.jxy.common.core.utils.StringUtils;
import com.jxy.common.core.web.Result.AjaxResult;
import com.jxy.common.security.utils.SecurityUtils;
import com.jxy.marketall.dto.DateBigDecimalDto;
import com.jxy.marketall.dto.DateStrBigDecimalDto;
import com.jxy.marketall.dto.DateStrStringDto;
import com.jxy.marketall.entity.ExchangeBalance;
import com.jxy.marketall.enums.BTCRedisName;
import com.jxy.marketall.vo.*;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description
 * @Date 2022/5/30 9:34
 * @Author 杜懿
 */
public class Test {

    public static void main(String[] args) {

        String s = SecurityUtils.encryptPassword("jxys2024@!");
        System.out.println(s);
    }

    public static List<DateBigDecimalDto> getSMA(List<DateBigDecimalDto> list,int day) {

        if (list.size()< day){
            return new ArrayList<>();
        }
        if(list.size() < 1){
            return list;
        }

        BigDecimal total = BigDecimal.ZERO;
        BigDecimal divideNumber = new BigDecimal(day);
        for(int i = 0 ; i < day ;i++){
            total =  list.get(i).getValue().add(total);
        }
        BigDecimal startY = total.divide(divideNumber, 8, BigDecimal.ROUND_HALF_UP);
        DateBigDecimalDto startDto = new DateBigDecimalDto();
        startDto.setDate(list.get(day-1).getDate());
        startDto.setValue(startY.stripTrailingZeros());

        List<DateBigDecimalDto> returnList = new ArrayList<>();
        returnList.add(startDto);
        for (int i = day; i < list.size(); i++) {

            total = total.add(list.get(i).getValue()).subtract(list.get(i-day).getValue());

            startY = total.divide(divideNumber,8,BigDecimal.ROUND_HALF_UP);

            DateBigDecimalDto dto = new DateBigDecimalDto();
            dto.setDate(list.get(i).getDate());
            dto.setValue(startY.stripTrailingZeros());

            returnList.add(dto);
        }
        return returnList;
    }
}




