提交 53d7550f authored 作者: Matrix's avatar Matrix

first commit

上级
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
差异被折叠。
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% ^
%JVM_CONFIG_MAVEN_PROPS% ^
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %WRAPPER_JAR% ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%"=="on" pause
if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
cmd /C exit /B %ERROR_CODE%
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>pt</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>pt</name>
<description>pt</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.12</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.example.pt;
import com.example.pt.collectors.DataRecord;
import com.example.pt.collectors.DataRecordService;
import javafx.application.Application;
import javafx.collections.ListChangeListener;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* ChartApp.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2023/3/21 at 18:07
* Suffering is the most powerful teacher of life.
*/
@SpringBootApplication
public class ChartApp extends Application {
private static final int RID_FENG_GE = 9999;
private static final int RID_DA_SI_MA = 606118;
private ConfigurableApplicationContext springContext;
@Resource
private DataRecordService dataRecordService;
private LineChart<String, Number> lineChart;
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void init() {
springContext = SpringApplication.run(ChartApp.class);
dataRecordService = springContext.getBean(DataRecordService.class);
}
@Override
public void start(Stage primaryStage) {
// 获取初始数据
List<DataRecord> dataRecords = dataRecordService.list();
// 过滤 rid 为 9999 和 606118 的记录
Map<Integer, List<DataRecord>> ridToDataRecordsMap = dataRecords.stream().filter(record -> record.getRid() == RID_FENG_GE || record.getRid() == RID_DA_SI_MA).collect(Collectors.groupingBy(DataRecord::getRid));
// 创建折线图
CategoryAxis xAxis = new CategoryAxis();
xAxis.setStyle("-fx-font-size: 1px;");
NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("时间 (HH:mm)");
yAxis.setLabel("票数增长量");
lineChart = new LineChart<>(xAxis, yAxis);
lineChart.setTitle("票数增长量统计");
// 添加时间区间下拉框和按钮
ComboBox<Integer> intervalComboBox = new ComboBox<>();
intervalComboBox.getItems().addAll(1, 5, 10, 30, 60);
intervalComboBox.getSelectionModel().selectFirst();
Button updateButton = new Button("更新");
updateButton.setOnAction(event -> updateChartData(ridToDataRecordsMap, intervalComboBox.getValue()));
HBox hbox = new HBox(10, intervalComboBox, updateButton);
hbox.setAlignment(Pos.CENTER);
// 设置场景并显示图表
BorderPane root = new BorderPane(lineChart);
root.setTop(hbox);
Scene scene = new Scene(root, 800, 600);
primaryStage.setScene(scene);
primaryStage.setTitle("票数增长量统计");
primaryStage.show();
// 初始化图表数据
updateChartData(ridToDataRecordsMap, intervalComboBox.getValue());
}
private void updateChartData(Map<Integer, List<DataRecord>> ridToDataRecordsMap, int intervalInMinutes) {
lineChart.getData().clear();
for (Map.Entry<Integer, List<DataRecord>> entry : ridToDataRecordsMap.entrySet()) {
Integer rid = entry.getKey();
List<DataRecord> records = entry.getValue();
// 按时间排序
List<DataRecord> sortedRecords = new ArrayList<>(records);
sortedRecords.sort(Comparator.comparing(DataRecord::getTimestamp));
// 计算票数增长量
List<DataRecord> aggregatedData = new ArrayList<>();
DataRecord previousRecord = null;
LocalDateTime currentIntervalStart = sortedRecords.get(0).getTimestamp();
int maxScInCurrentInterval = sortedRecords.get(0).getSc();
for (DataRecord record : sortedRecords) {
if (record.getTimestamp().isAfter(currentIntervalStart.plus(intervalInMinutes, ChronoUnit.MINUTES))) {
// 当前记录超出当前时间区间,将之前的数据添加到折线图
int scGrowth = previousRecord == null ? maxScInCurrentInterval : maxScInCurrentInterval - previousRecord.getSc();
aggregatedData.add(new DataRecord(null, rid, scGrowth, currentIntervalStart));
// 更新时间区间和最大票数
previousRecord = new DataRecord(null, rid, maxScInCurrentInterval, currentIntervalStart);
currentIntervalStart = currentIntervalStart.plus(intervalInMinutes, ChronoUnit.MINUTES);
maxScInCurrentInterval = record.getSc();
} else {
// 更新当前时间区间的最大票数
maxScInCurrentInterval = Math.max(maxScInCurrentInterval, record.getSc());
}
}
// 添加最后一个时间区间的数据
int lastScGrowth = previousRecord == null ? maxScInCurrentInterval : maxScInCurrentInterval - previousRecord.getSc();
aggregatedData.add(new DataRecord(null, rid, lastScGrowth, currentIntervalStart));
// 将数据添加到折线图
XYChart.Series<String, Number> series = new XYChart.Series<>();
series.setName(rid == RID_FENG_GE ? "峰哥" : "大司马");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
boolean isFirstDataPoint = true;
for (DataRecord record : aggregatedData) {
if (!isFirstDataPoint) {
String formattedTimestamp = record.getTimestamp().format(formatter);
XYChart.Data<String, Number> dataPoint = new XYChart.Data<>(formattedTimestamp, record.getSc());
series.getData().add(dataPoint);
dataPoint.nodeProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
newValue.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
String tooltipText = "时间: " + formattedTimestamp + "\n票数增长量: " + dataPoint.getYValue();
Alert alert = new Alert(Alert.AlertType.INFORMATION, tooltipText, ButtonType.OK);
alert.setHeaderText(null);
alert.setTitle("票数增长详情");
alert.show();
});
}
});
// dataPoint.nodeProperty().addListener((observable, oldValue, newValue) -> {
// if (newValue != null) {
// StackPane stackPane = (StackPane) newValue;
// Label label = new Label(String.valueOf(dataPoint.getYValue()));
// stackPane.getChildren().add(label);
// }
// });
} else {
isFirstDataPoint = false;
}
}
lineChart.getData().add(series);
}
}
@Override
public void stop() {
springContext.close();
}
}
package com.example.pt.collectors;
import cn.hutool.core.date.DateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
/**
* DataRecord.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2023/3/21 at 11:43
* Suffering is the most powerful teacher of life.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DataRecord implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private Integer rid;
private Integer sc;
private LocalDateTime timestamp;
}
package com.example.pt.collectors;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* DataRecordService.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2023/3/21 at 11:48
* Suffering is the most powerful teacher of life.
*/
public interface DataRecordService extends IService<DataRecord> {
}
package com.example.pt.collectors;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.pt.collectors.mapper.DataRecordMapper;
import org.springframework.stereotype.Service;
/**
* DataRecordServiceImpl.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2023/3/21 at 11:48
* Suffering is the most powerful teacher of life.
*/
@Service
public class DataRecordServiceImpl extends ServiceImpl<DataRecordMapper,DataRecord> implements DataRecordService {
}
package com.example.pt.collectors.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.pt.collectors.DataRecord;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
/**
* DataRecordMapper.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2023/3/21 at 11:47
* Suffering is the most powerful teacher of life.
*/
@Repository
@Mapper
public interface DataRecordMapper extends BaseMapper<DataRecord> {
}
server.port= 9998
spring.datasource.url=jdbc:mysql://localhost:3306/fgnb?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=ldf3291369
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
mybatis-plus.mapper-locations=classpath*:com/example/pt/**/mapping/*.xml, classpath:/META-INF/modeler-mybatis-mappings/*.xml
mybatis-plus.configuration.map-underscore-to-camel-case=true
mybatis-plus.configuration.cache-enabled=true
mybatis-plus.configuration.lazy-loading-enabled=true
mybatis-plus.configuration.multiple-result-sets-enabled=true
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.nologging.NoLoggingImpl
package com.example.pt;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class PtApplicationTests {
@Test
void contextLoads() {
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论