| | |
| | | |
| | | public abstract class AbstractGetDataJob implements Runnable { |
| | | public static volatile boolean first = true; |
| | | protected static Logger logger = LoggerFactory.getLogger(StockGetDataJob.class); |
| | | protected static Logger logger = LoggerFactory.getLogger(AbstractGetDataJob.class); |
| | | /** |
| | | * 数据接口调用间隔时长(毫秒) |
| | | */ |
| | |
| | | } |
| | | Integer frequency = AdjustmentValueCache.getFrequency().get(symbol); |
| | | if (frequency == null) { |
| | | frequency = (int) Arith.div(Arith.mul(delayValue.getSecond(), 1000.0D), this.interval); |
| | | double rawFrequency = Arith.div(Arith.mul(delayValue.getSecond(), 1000.0D), this.interval); |
| | | // 判断是否有小数部分 |
| | | if (rawFrequency > (int) rawFrequency) { |
| | | // 有小数(如333.333)→ +1 |
| | | frequency = (int) rawFrequency + 1; |
| | | } else { |
| | | // 无小数(如500.0)→ 不+1 |
| | | frequency = (int) rawFrequency; |
| | | } |
| | | AdjustmentValueCache.getFrequency().put(symbol, frequency); |
| | | } |
| | | if (frequency <= 1) { |
| | |
| | | if (adjustments == null) { |
| | | adjustments = new ArrayList<>(); |
| | | } |
| | | adjustments.addAll(generateRandomAdjustments(result.get(i), frequency / 10, decimal)); |
| | | int count = frequency / nums; |
| | | if (i == result.size() - 1) { |
| | | count += frequency % nums; |
| | | } |
| | | adjustments.addAll(generateRandomAdjustments(result.get(i), count, decimal)); |
| | | } |
| | | currentIndex = 0; |
| | | AdjustmentValueCache.getPreAllocatedAdjustments().put(symbol, adjustments); |
| | |
| | | public static void main(String[] args) { |
| | | AbstractGetDataJob abstractGetDataJob = new CryptosGetDataJob(); |
| | | List<BigDecimal> list = new ArrayList<>(); |
| | | int frequency = 166; |
| | | int frequency = 334; |
| | | int decimal = 4; |
| | | //分几段执行 |
| | | int nums = Math.max(10, frequency / 10); |
| | | List<BigDecimal> result = RandomNumbersGenerator.generateNumbers(BigDecimal.valueOf(0.0026), nums, decimal + 4); |
| | | System.out.println(nums); |
| | | List<BigDecimal> result = RandomNumbersGenerator.generateNumbers(BigDecimal.valueOf(0.02), nums, decimal + 4); |
| | | System.out.println(result); |
| | | for (int i = 0; i < result.size(); i++) { |
| | | List<BigDecimal> numbers = abstractGetDataJob.generateRandomAdjustments(result.get(i), frequency / 10, decimal); |
| | | int count = frequency / nums; |
| | | if (i == result.size() - 1) { |
| | | count += frequency % nums; |
| | | } |
| | | List<BigDecimal> numbers = abstractGetDataJob.generateRandomAdjustments(result.get(i), count, decimal); |
| | | System.out.println(numbers); |
| | | list.addAll(numbers); |
| | | } |
| | | |
| | |
| | | |
| | | numd = numd.add(list.get(i)); |
| | | num++; |
| | | if (num == 20) { |
| | | if (num == 33) { |
| | | System.out.println(dmt+"ddd" + numd); |
| | | dmt++; |
| | | num=0; |