-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stuff from defence (zoned attemptInfo, sorted history table, separate…
…d attemptInfo into multiple entities)
- Loading branch information
1 parent
ed3f1c7
commit 3a6cecb
Showing
16 changed files
with
188 additions
and
67 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,50 @@ | ||
package domain; | ||
|
||
|
||
import jakarta.enterprise.inject.spi.CDI; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import ui.TimeZoneBean; | ||
|
||
import java.time.*; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
@Entity | ||
@Table(name = "attempts") | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class AttemptInfo { | ||
@Setter | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
private double x; | ||
private double y; | ||
private double r; | ||
private boolean res; | ||
private String message; | ||
private Duration execTime; | ||
private LocalDateTime currTime; | ||
|
||
@OneToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "coord_id", referencedColumnName = "id") | ||
private CoordInfo coords; | ||
|
||
public AttemptInfo() {} | ||
private AttemptInfo(double x, double y, double r, boolean res, String message, Duration execTime, LocalDateTime currTime) { | ||
this.x=x; | ||
this.y=y; | ||
this.r=r; | ||
this.res=res; | ||
this.message=message; | ||
this.execTime=execTime; | ||
this.currTime=currTime; | ||
} | ||
@OneToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "shot_id", referencedColumnName = "id") | ||
private ShotInfo shot; | ||
|
||
public static AttemptInfo fromHit(Instant startTime, double x, double y, double r, boolean res, String message) { | ||
return new AttemptInfo(x, y, r, res, message, getDiff(startTime), LocalDateTime.now()); | ||
} | ||
private ZonedDateTime currTime; | ||
|
||
public static AttemptInfo empty() { | ||
return new AttemptInfo(0,0,0,false,"",Duration.ZERO,LocalDateTime.MIN); | ||
} | ||
|
||
private static Duration getDiff(Instant start) { | ||
Instant finish = Instant.now(); | ||
return Duration.between(start, finish); | ||
public static AttemptInfo fromHit(CoordInfo coordInfo, ShotInfo shotInfo) { | ||
String timezone = CDI.current().select(TimeZoneBean.class).get().getTimezone(); | ||
return new AttemptInfo(null, coordInfo, shotInfo, ZonedDateTime.now(ZoneId.of(timezone))); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AttemptInfo{" + | ||
"x='" + x + '\'' + | ||
", y='" + y + '\'' + | ||
", r='" + r + '\'' + | ||
", res=" + res + | ||
", message='" + message + '\'' + | ||
", execTime=" + execTime.toNanos() + "ns" + | ||
", currTime=" + currTime.format(DateTimeFormatter.ofPattern("dd.MM.yyyy hh:mm:ss")) + | ||
"id=" + id + | ||
", coordInfo=" + coords + | ||
", shotInfo=" + shot + | ||
", currTime=" + currTime + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Table(name = "coord-attempts") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
public class CoordInfo { | ||
@Setter | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
private double x; | ||
private double y; | ||
private double r; | ||
|
||
@Override | ||
public String toString() { | ||
return "CoordInfo{" + | ||
"id=" + id + | ||
", x=" + x + | ||
", y=" + y + | ||
", r=" + r + | ||
'}'; | ||
} | ||
|
||
public static CoordInfo create(double x, double y, double r) { | ||
return new CoordInfo(null,x,y,r); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
|
||
@Entity | ||
@Table(name = "shot-attempts") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
public class ShotInfo { | ||
@Setter | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
private boolean res; | ||
private String message; | ||
private Duration execTime; | ||
|
||
public static ShotInfo create(boolean res, String message, Instant startTime) { | ||
return new ShotInfo(null,res,message,getDiff(startTime)); | ||
} | ||
|
||
private static Duration getDiff(Instant start) { | ||
Instant finish = Instant.now(); | ||
return Duration.between(start, finish); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ShotInfo{" + | ||
"id=" + id + | ||
", res=" + res + | ||
", message='" + message + '\'' + | ||
", execTime=" + execTime + | ||
'}'; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ui; | ||
|
||
import jakarta.enterprise.context.SessionScoped; | ||
import jakarta.faces.context.FacesContext; | ||
import jakarta.inject.Named; | ||
import lombok.Getter; | ||
|
||
import java.io.Serializable; | ||
|
||
@SessionScoped | ||
@Named("timeZoneBean") | ||
public class TimeZoneBean implements Serializable { | ||
@Getter | ||
private String timezone = "America/New_York"; | ||
|
||
public void updateTimezone() { | ||
timezone = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("timezone"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:h="http://xmlns.jcp.org/jsf/html" | ||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets" | ||
xmlns:f="http://xmlns.jcp.org/jsf/core" | ||
xmlns:p="http://primefaces.org/ui" | ||
xmlns:my="http://xmlns.jcp.org/jsf/composite/mycomponents/graph" | ||
> | ||
<ui:composition> | ||
<h:form> | ||
<p:remoteCommand name="setTimezone" action="#{timeZoneBean.updateTimezone()}" update="#{listener}"/> | ||
<p:remoteCommand name="updateTimezone" update="#{listener}"/> | ||
</h:form> | ||
<script type="text/javascript"> | ||
setTimezone([{name: "timezone", value: Intl.DateTimeFormat().resolvedOptions().timeZone}]); | ||
updateTimezone(); | ||
</script> | ||
</ui:composition> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.