MarisiaS / SMM

0 stars 0 forks source link

BE- Heat display and update #76

Open MarisiaS opened 5 months ago

MarisiaS commented 5 months ago

This PR address issue #58

It depends on PR #75

Implementation

  1. backend/api/serializers/HeatDisplaySerializer.py

Created two serializer:

  1. backend/api/views/HeatView.py

Contains two classes:

  1. backend/api/urls.py

Added two endpoints:

Swagger

Steps to tests:

  1. GET api/seed_times/{event_id}/

Use event_id = 1 to retrieve all the athletes and their seed times. Copy the response.

  1. POST api/event_heat/{event_id}/

Use event_id = 1 and add the previously copied response to athletes in the request body. Delete the athlete_full_name for each entry. Execute. This action generates all the heats for the event.

image

  1. GET /api/event_heat/{event_id}/{heat_num}/
Result event_id = 1 and heat_num = 1 [ { "id": 1, "lane_num": 1, "athlete": 11, "athlete_full_name": "Sofia Avila", "seed_time": "NT", "heat_time": null }, { "id": 3, "lane_num": 2, "athlete": 12, "athlete_full_name": "Ellie Yuan", "seed_time": "00:00:41.840000", "heat_time": null }, { "id": 4, "lane_num": 3, "athlete": 8, "athlete_full_name": "Kyla Smith", "seed_time": "00:00:41.540000", "heat_time": null }, { "id": 2, "lane_num": 4, "athlete": 2, "athlete_full_name": "Ana Gomez", "seed_time": "00:00:45.100000", "heat_time": null }, { "id": null, "lane_num": 5, "athlete": null, "athlete_full_name": null, "seed_time": "", "heat_time": null } ]
Result event_id = 1 and heat_num = 2 [ { "id": 6, "lane_num": 1, "athlete": 10, "athlete_full_name": "Anna Anderson", "seed_time": "00:00:38.540000", "heat_time": null }, { "id": 8, "lane_num": 2, "athlete": 16, "athlete_full_name": "Ava Wilson", "seed_time": "00:00:37.810000", "heat_time": null }, { "id": 9, "lane_num": 3, "athlete": 6, "athlete_full_name": "Laura Sanchez", "seed_time": "00:00:31.360000", "heat_time": null }, { "id": 7, "lane_num": 4, "athlete": 15, "athlete_full_name": "Olivia Davis", "seed_time": "00:00:38.540000", "heat_time": null }, { "id": 5, "lane_num": 5, "athlete": 4, "athlete_full_name": "Elena Lopez", "seed_time": "00:00:39.210000", "heat_time": null } ]
Result event_id = 1 and heat_num = 3 { "error": "There is not a heat with that number" }
  1. GET /api/event_lane/{event_id}/{lane_num}/
Result event_id = 1 and lane_num = 1 [ { "id": 1, "num_heat": 1, "athlete": 11, "athlete_full_name": "Sofia Avila" }, { "id": 6, "num_heat": 2, "athlete": 10, "athlete_full_name": "Anna Anderson" } ]
Result event_id = 1 and lane_num = 2 [ { "id": 3, "num_heat": 1, "athlete": 12, "athlete_full_name": "Ellie Yuan" }, { "id": 8, "num_heat": 2, "athlete": 16, "athlete_full_name": "Ava Wilson" } ]
Result event_id = 1 and lane_num = 3 [ { "id": 4, "num_heat": 1, "athlete": 8, "athlete_full_name": "Kyla Smith" }, { "id": 9, "num_heat": 2, "athlete": 6, "athlete_full_name": "Laura Sanchez" } ]
Result event_id = 1 and lane_num = 4 [ { "id": 2, "num_heat": 1, "athlete": 2, "athlete_full_name": "Ana Gomez" }, { "id": 7, "num_heat": 2, "athlete": 15, "athlete_full_name": "Olivia Davis" } ]
Result event_id = 1 and lane_num = 5 [ { "id": null, "num_heat": 1, "athlete": null, "athlete_full_name": null }, { "id": 5, "num_heat": 2, "athlete": 4, "athlete_full_name": "Elena Lopez" } ]
Result event_id = 1 and lane_num = 6 { "error": "There is not a lane with that number" }
  1. PUT /api/event_lane/{event_id}/{lane_num}/

Data used:

Request body using event_id = 1 and lane_num = 1 [ { "num_heat": 1, "athlete": 11, "heat_time":"39.01" }, { "num_heat": 2, "athlete": 10, "heat_time":"NS" } ]
Request body using event_id = 1 and lane_num = 2 [ { "num_heat": 1, "athlete": 12, "heat_time":"DQ" }, { "num_heat": 2, "athlete": 16, "heat_time":"40.78" } ]
Request body using event_id = 1 and lane_num = 3 [ { "num_heat": 1, "athlete": 8, "heat_time":"32.12" }, { "num_heat": 2, "athlete": 6, "heat_time":"36.29" } ]
Request body using event_id = 1 and lane_num = 4 [ { "num_heat": 1, "athlete": 2, "heat_time":"31.45" }, { "num_heat": 2, "athlete": 15, "heat_time":"27.92" } ]
Request body using event_id = 1 and lane_num = 5 [ { "num_heat": 1, "athlete": null, "heat_time":"" }, { "num_heat": 2, "athlete": 4, "heat_time":"25.43" } ]

Heat on the database

image

TimeRecord on the database:

image

  1. GET /api/event_heat/{event_id}/{heat_num}/

Now the heat times are not null:

Event 1 Heat 1 [ { "id": 1, "lane_num": 1, "athlete": 11, "athlete_full_name": "Sofia Avila", "seed_time": "NT", "heat_time": "00:00:39.010000" }, { "id": 3, "lane_num": 2, "athlete": 12, "athlete_full_name": "Ellie Yuan", "seed_time": "00:00:41.840000", "heat_time": "DQ" }, { "id": 4, "lane_num": 3, "athlete": 8, "athlete_full_name": "Kyla Smith", "seed_time": "00:00:41.540000", "heat_time": "00:00:32.120000" }, { "id": 2, "lane_num": 4, "athlete": 2, "athlete_full_name": "Ana Gomez", "seed_time": "00:00:45.100000", "heat_time": "00:00:31.450000" }, { "id": null, "lane_num": 5, "athlete": null, "athlete_full_name": null, "seed_time": null, "heat_time": null } ]
Event 1 Heat 2 [ { "id": 6, "lane_num": 1, "athlete": 10, "athlete_full_name": "Anna Anderson", "seed_time": "00:00:38.540000", "heat_time": "NS" }, { "id": 8, "lane_num": 2, "athlete": 16, "athlete_full_name": "Ava Wilson", "seed_time": "00:00:37.810000", "heat_time": "00:00:40.780000" }, { "id": 9, "lane_num": 3, "athlete": 6, "athlete_full_name": "Laura Sanchez", "seed_time": "00:00:31.360000", "heat_time": "00:00:36.290000" }, { "id": 7, "lane_num": 4, "athlete": 15, "athlete_full_name": "Olivia Davis", "seed_time": "00:00:38.540000", "heat_time": "00:00:27.920000" }, { "id": 5, "lane_num": 5, "athlete": 4, "athlete_full_name": "Elena Lopez", "seed_time": "00:00:39.210000", "heat_time": "00:00:25.430000" } ]
MarisiaS commented 3 days ago

I think we need to have a separate endpoint to get the num of heats and the num of lines.