feat: Automatically calculate last record

This commit is contained in:
JZITNIK-github 2024-07-07 19:20:05 +02:00
parent ea5a1c1a5d
commit c78b310232
Signed by: jzitnik
GPG Key ID: C577A802A6AF4EF3
2 changed files with 48 additions and 28 deletions

32
pom.xml
View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>cz.jzitnik</groupId> <groupId>cz.jzitnik</groupId>
<artifactId>fit</artifactId> <artifactId>fit</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<properties> <properties>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target> <maven.compiler.target>17</maven.compiler.target>
@ -20,6 +20,34 @@
<version>21.141.0</version> <version>21.141.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<mainClass>cz.jzitnik.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> </project>

View File

@ -17,36 +17,28 @@ class CustomFitListener implements MesgListener {
} }
public void modifyData() { public void modifyData() {
DateTime latestTime = null;
for (int i = 0; i < messages.size(); i++) {
Mesg mesg = messages.get(i);
if (mesg.getNum() == MesgNum.RECORD) {
RecordMesg recordMesg = new RecordMesg(mesg);
DateTime time = recordMesg.getTimestamp();
if (latestTime == null || time.compareTo(latestTime) > 0) {
latestTime = time;
}
}
}
for (int i = 0; i < messages.size(); i++) { for (int i = 0; i < messages.size(); i++) {
Mesg mesg = messages.get(i); Mesg mesg = messages.get(i);
if (mesg.getNum() == MesgNum.EVENT) { if (mesg.getNum() == MesgNum.EVENT) {
EventMesg eventMesg = new EventMesg(mesg); EventMesg eventMesg = new EventMesg(mesg);
if (eventMesg.getEventType() == EventType.STOP_ALL) { if (eventMesg.getEventType() == EventType.STOP_ALL) {
Scanner scanner = new Scanner(System.in); eventMesg.setTimestamp(latestTime);
System.out.print("Rok: ");
int year = Integer.parseInt(scanner.nextLine());
System.out.print("Měsíc: ");
int month = Integer.parseInt(scanner.nextLine()) - 1;
System.out.print("Den: ");
int day = Integer.parseInt(scanner.nextLine());
System.out.print("Hodina: ");
int hour = Integer.parseInt(scanner.nextLine());
System.out.print("Minuta: ");
int minute = Integer.parseInt(scanner.nextLine());
System.out.print("Sekunda: ");
int second = Integer.parseInt(scanner.nextLine());
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day, hour, minute, second);
Date date = calendar.getTime();
DateTime dateTime = new DateTime(date);
eventMesg.setTimestamp(dateTime);
messages.set(i, eventMesg); messages.set(i, eventMesg);
} }
} }