2、FlashTsDB时序数据库-SDT算法(Java)实现

2024-03-15 18:10

本文主要是介绍2、FlashTsDB时序数据库-SDT算法(Java)实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

FlashTsDB时序数据库-SDT算法(Java)实现

FLashDB基于开源模式开发,地址:https://github.com/amon1991/flashdb

1、SDT原理

在这里插入图片描述

2、压缩算法

Point对象

public class Point implements Comparable<Point> {private long x;     // 时间戳private double y; // 测点值// ... 此处省略set,get方法
}

SdtPeriod对象

public class SdtPeriod {private long bgTime;     // 压缩段开始时间private double bgValue; // 压缩段开始值private long endTime;    // 压缩段结束时间private double endValue;// 压缩段结束值private double gradient; // 梯度// ... 此处省略set,get方法}

压缩算法

/*** SDT algorithm compress function** @param originPoints 待压缩的点集* @param accuracyE    旋转门大小* @return*/
public List<SdtPeriod> sdtCompress(List<Point> originPoints, double accuracyE) {List<SdtPeriod> sdtPeriodList = new ArrayList<>();if (null != originPoints && originPoints.size() > 0) {SdtPoints sdtPoints = new SdtPoints();double upGate = -Double.MAX_VALUE;double downGate = Double.MAX_VALUE;for (int i = 0, size = originPoints.size(); i < size; i++) {Point currentPoint = originPoints.get(i);if (i == 0) {sdtPoints.setLastPoint(currentPoint);sdtPoints.setBeginPoint(currentPoint);} else {double nowUpGate = (currentPoint.getY() - sdtPoints.getBeginPoint().getY() - accuracyE) /(currentPoint.getX() - sdtPoints.getBeginPoint().getX());if (nowUpGate > upGate) {upGate = nowUpGate;}double nowDownGate = (currentPoint.getY() - sdtPoints.getBeginPoint().getY() + accuracyE) /(currentPoint.getX() - sdtPoints.getBeginPoint().getX());if (nowDownGate < downGate) {downGate = nowDownGate;}if (upGate > downGate) {// create new SdtPeriod(one)sdtPeriodList.add(structSdtPeriod(sdtPoints));// update gatesupGate = (currentPoint.getY() - sdtPoints.getLastPoint().getY() - accuracyE) /(currentPoint.getX() - sdtPoints.getLastPoint().getX());downGate = (currentPoint.getY() - sdtPoints.getLastPoint().getY() + accuracyE) /(currentPoint.getX() - sdtPoints.getLastPoint().getX());sdtPoints.setBeginPoint(sdtPoints.getLastPoint());}sdtPoints.setLastPoint(currentPoint);}if (i == size - 1) {// save last periodsdtPeriodList.add(structSdtPeriod(sdtPoints));}}}return sdtPeriodList;
}

3、解压算法

/*** SDT algorithm uncompress function** @param sdtPeriodList 压缩段集合* @param bgTime        返回点集开始时间* @param endTime       返回点集结束时间* @param interval      返回点集2点间隔* @return*/
public List<Point> sdtUnCompress(List<SdtPeriod> sdtPeriodList, long bgTime, long endTime, long interval) {List<Point> pointList = new ArrayList<>();if (null != sdtPeriodList && sdtPeriodList.size() > 0) {// recalculate bgTime and endTimelong globalBgTime = sdtPeriodList.get(0).getBgTime();long globalEndTime = sdtPeriodList.get(sdtPeriodList.size() - 1).getEndTime();if (bgTime > globalEndTime || endTime < globalBgTime) {return pointList;}if (bgTime < globalBgTime && endTime < globalEndTime) {while (bgTime < globalBgTime) {bgTime += interval;}}if (globalBgTime < bgTime && globalEndTime < endTime) {long tempEndTime = bgTime;while (tempEndTime < globalEndTime) {tempEndTime += interval;}endTime = tempEndTime - interval;}if (bgTime < globalBgTime && endTime > globalEndTime) {while (bgTime < globalBgTime) {bgTime += interval;}long tempEndTime = bgTime;while (tempEndTime < globalEndTime) {tempEndTime += interval;}endTime = tempEndTime - interval;}// final checkif (bgTime > globalEndTime || endTime < globalBgTime) {return pointList;}long interpolatingTime = bgTime;for (SdtPeriod sdtPeriod : sdtPeriodList) {long periodBgTime = sdtPeriod.getBgTime();double periodBgValue = sdtPeriod.getBgValue();long periodEndTime = sdtPeriod.getEndTime();double grad = sdtPeriod.getGradient();if (interpolatingTime >= periodBgTime && interpolatingTime <= periodEndTime) {while (interpolatingTime <= periodEndTime && interpolatingTime <= endTime) {Point point = new Point();point.setX(interpolatingTime);point.setY(periodBgValue + (interpolatingTime - periodBgTime) * grad);pointList.add(point);interpolatingTime += interval;}}if (interpolatingTime > endTime) {break;}}}return pointList;
}

这篇关于2、FlashTsDB时序数据库-SDT算法(Java)实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/812818

相关文章

Spring Boot集成/输出/日志级别控制/持久化开发实践

《SpringBoot集成/输出/日志级别控制/持久化开发实践》SpringBoot默认集成Logback,支持灵活日志级别配置(INFO/DEBUG等),输出包含时间戳、级别、类名等信息,并可通过... 目录一、日志概述1.1、Spring Boot日志简介1.2、日志框架与默认配置1.3、日志的核心作用

Python使用Tenacity一行代码实现自动重试详解

《Python使用Tenacity一行代码实现自动重试详解》tenacity是一个专为Python设计的通用重试库,它的核心理念就是用简单、清晰的方式,为任何可能失败的操作添加重试能力,下面我们就来看... 目录一切始于一个简单的 API 调用Tenacity 入门:一行代码实现优雅重试精细控制:让重试按我

破茧 JDBC:MyBatis 在 Spring Boot 中的轻量实践指南

《破茧JDBC:MyBatis在SpringBoot中的轻量实践指南》MyBatis是持久层框架,简化JDBC开发,通过接口+XML/注解实现数据访问,动态代理生成实现类,支持增删改查及参数... 目录一、什么是 MyBATis二、 MyBatis 入门2.1、创建项目2.2、配置数据库连接字符串2.3、入

Springboot项目启动失败提示找不到dao类的解决

《Springboot项目启动失败提示找不到dao类的解决》SpringBoot启动失败,因ProductServiceImpl未正确注入ProductDao,原因:Dao未注册为Bean,解决:在启... 目录错误描述原因解决方法总结***************************APPLICA编

深度解析Spring Security 中的 SecurityFilterChain核心功能

《深度解析SpringSecurity中的SecurityFilterChain核心功能》SecurityFilterChain通过组件化配置、类型安全路径匹配、多链协同三大特性,重构了Spri... 目录Spring Security 中的SecurityFilterChain深度解析一、Security

Redis客户端连接机制的实现方案

《Redis客户端连接机制的实现方案》本文主要介绍了Redis客户端连接机制的实现方案,包括事件驱动模型、非阻塞I/O处理、连接池应用及配置优化,具有一定的参考价值,感兴趣的可以了解一下... 目录1. Redis连接模型概述2. 连接建立过程详解2.1 连php接初始化流程2.2 关键配置参数3. 最大连

SpringBoot多环境配置数据读取方式

《SpringBoot多环境配置数据读取方式》SpringBoot通过环境隔离机制,支持properties/yaml/yml多格式配置,结合@Value、Environment和@Configura... 目录一、多环境配置的核心思路二、3种配置文件格式详解2.1 properties格式(传统格式)1.

Apache Ignite 与 Spring Boot 集成详细指南

《ApacheIgnite与SpringBoot集成详细指南》ApacheIgnite官方指南详解如何通过SpringBootStarter扩展实现自动配置,支持厚/轻客户端模式,简化Ign... 目录 一、背景:为什么需要这个集成? 二、两种集成方式(对应两种客户端模型) 三、方式一:自动配置 Thick

Python实现网格交易策略的过程

《Python实现网格交易策略的过程》本文讲解Python网格交易策略,利用ccxt获取加密货币数据及backtrader回测,通过设定网格节点,低买高卖获利,适合震荡行情,下面跟我一起看看我们的第一... 网格交易是一种经典的量化交易策略,其核心思想是在价格上下预设多个“网格”,当价格触发特定网格时执行买

Oracle数据库定时备份脚本方式(Linux)

《Oracle数据库定时备份脚本方式(Linux)》文章介绍Oracle数据库自动备份方案,包含主机备份传输与备机解压导入流程,强调需提前全量删除原库数据避免报错,并需配置无密传输、定时任务及验证脚本... 目录说明主机脚本备机上自动导库脚本整个自动备份oracle数据库的过程(建议全程用root用户)总结