Traewelling / traewelling

Free check-in service to log your public transit journeys
https://traewelling.de
GNU Affero General Public License v3.0
225 stars 43 forks source link

Checkins with a delay are sorted wrong #1382

Open Oxbowatos opened 1 year ago

Oxbowatos commented 1 year ago

Describe the bug If e.g. I checkin in a train which derparting at 7am and I get on a train departing 6:30am but has 1 hour delay, the delayed checkin is sorted under the first checkin.

It also happens on the Global Dashboard and Home Dashboard that it's sorted wrong

To Reproduce Steps to reproduce the behavior:

  1. Checkin in a normal Train
  2. At your Stop search for a delayed Train/Bus/etc (where the sheduled departure time is under the sheduled departure time of your first Checkin)
  3. Look how the Checkins are sorted
  4. See that the Checkin with Delay is sorted under the Checkins without Delay

Expected behavior That the Page sorts the Checkins with the delayed departure time not only the sheduled departure time.

Screenshots If applicable, add screenshots to help explain your problem.

See how its sorted: (Deleted some fields for privacy reason) grafik

Desktop (please complete the following information): Any Browser

Smartphone (please complete the following information): Any Smartphone

MrKrisKrisu commented 11 months ago

This is our current query for the private dashboard: https://github.com/Traewelling/traewelling/blob/74d3a988a149219d8371a1b0ff95d0ddc160d133/app/Http/Controllers/Backend/User/DashboardController.php#L19-L37

We sort here only according to the planned departure of the Journey: https://github.com/Traewelling/traewelling/blob/74d3a988a149219d8371a1b0ff95d0ddc160d133/app/Http/Controllers/Backend/User/DashboardController.php#L27

In order for us to aggregate the data correctly directly we would need to do the following sorts in order:

  1. if isset DESC {join}.train_checkins.manual_departure
  2. DESC {join}.train_checkins.{join}.train_stopovers.{real_departure}.
  3. DESC {join}.train_checkins.{join}.train_stopovers.{planned_departure}.

Since our data structure is a bit complex to build a meaningful and performant query for it I would suggest to do the sorting only on the frontend level so that it looks properly sorted to the user.

MrKrisKrisu commented 11 months ago

ER-Diagram with the relevant tables: image