Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lapCountResource): add lap count per source & team #131

Merged
merged 4 commits into from
Apr 14, 2024

Conversation

NuttyShrimp
Copy link
Member

End date should be the date of the postgres DB so in our normal settingg, the local time (UTC + 2)

closes #110

End date should be the date of the postgres DB so in our normal settingg, the local time (UTC + 2)
@NuttyShrimp NuttyShrimp requested a review from FKD13 March 29, 2024 17:07
@NuttyShrimp NuttyShrimp requested a review from FKD13 April 3, 2024 16:18
Copy link
Member

@FKD13 FKD13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 I don't know how nice the timestamp will be to use, guess we will find out :D

src/main/java/telraam/database/daos/LapDAO.java Outdated Show resolved Hide resolved
src/main/java/telraam/api/LapCountResource.java Outdated Show resolved Hide resolved
@NuttyShrimp NuttyShrimp requested a review from FKD13 April 4, 2024 22:31
Copy link
Member

@FKD13 FKD13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I only just now noticed the queries can be simplified, this does the same right?

@@ -29,6 +30,14 @@ public interface LapDAO extends DAO<Lap> {
@RegisterBeanMapper(Lap.class)
List<Lap> getAllBySourceSorted(@Bind("lapSourceId") Integer lapSourceId);

@SqlQuery("SELECT t.id as team_id, (SELECT COUNT(*) FROM lap WHERE lap_source_id = :lapSourceId AND timestamp <= :timestamp and team_id = t.id) as count FROM team t")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@SqlQuery("SELECT t.id as team_id, (SELECT COUNT(*) FROM lap WHERE lap_source_id = :lapSourceId AND timestamp <= :timestamp and team_id = t.id) as count FROM team t")
@SqlQuery("SELECT team_id, COUNT(*) FROM lap WHERE lap_source_id = :lapSourceId AND timestamp <= :timestamp GROUP BY team_id")

@RegisterBeanMapper(LapCount.class)
List<LapCount> getAllBeforeTime(@Bind("lapSourceId") Integer lapSourceId, @Bind("timestamp") Timestamp timestamp);

@SqlQuery("SELECT t.id as team_id, (SELECT COUNT(*) FROM lap WHERE lap_source_id = :lapSourceId AND timestamp <= :timestamp and team_id = t.id) as count FROM team t where id = :teamId")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@SqlQuery("SELECT t.id as team_id, (SELECT COUNT(*) FROM lap WHERE lap_source_id = :lapSourceId AND timestamp <= :timestamp and team_id = t.id) as count FROM team t where id = :teamId")
@SqlQuery("SELECT team_id, COUNT(*) FROM lap WHERE lap_source_id = :lapSourceId AND timestamp <= :timestamp and team_id = :teamId GROUP BY team_id")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with GROUP BY is that it doesn't return anything if a team has zero laps

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid remark, I assumed data to always be there.

@NuttyShrimp NuttyShrimp merged commit 29daae2 into development Apr 14, 2024
1 check passed
@NuttyShrimp NuttyShrimp deleted the lap-count-per-team branch April 14, 2024 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Retrieve lapCount by lapSourceId
2 participants