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

fix: filter stop time updates without arrival/departure #294

Merged
merged 9 commits into from
Aug 4, 2023

Conversation

Whoops
Copy link
Collaborator

@Whoops Whoops commented Jul 25, 2023

Summary of changes

Asana Ticket: 🐛 API publishing bus predictions with no times or schedule relationship

This filters out StopTimeUpdates which are scheduled, but have no arrival/departure. These occur when the BusLoc feed contains stops which Swiftly either isn't yet predicting, or is no longer publishing predictions for because the bus is already well past that stop.

@Whoops Whoops temporarily deployed to dev-green July 25, 2023 21:22 — with GitHub Actions Inactive
@github-actions
Copy link

Coverage of commit d14b864

Summary coverage rate:
  lines......: 94.7% (1197 of 1264 lines)
  functions..: 83.5% (385 of 461 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/reporter/unskipped_null_stops.ex                  |14.3%      7|20.0%     5|    -      0

Download coverage report

@Whoops Whoops temporarily deployed to dev-green July 26, 2023 14:07 — with GitHub Actions Inactive
@Whoops Whoops temporarily deployed to dev-green July 26, 2023 16:56 — with GitHub Actions Inactive
@github-actions
Copy link

Coverage of commit 1be6052

Summary coverage rate:
  lines......: 94.7% (1197 of 1264 lines)
  functions..: 83.5% (385 of 461 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/reporter/unskipped_null_stops.ex                  |14.3%      7|20.0%     5|    -      0

Download coverage report

@Whoops Whoops temporarily deployed to dev-green July 26, 2023 17:01 — with GitHub Actions Inactive
@github-actions
Copy link

Coverage of commit 76d6f70

Summary coverage rate:
  lines......: 94.7% (1197 of 1264 lines)
  functions..: 83.5% (385 of 461 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/reporter/unskipped_null_stops.ex                  |14.3%      7|20.0%     5|    -      0

Download coverage report

@github-actions
Copy link

Coverage of commit 1b59e6f

Summary coverage rate:
  lines......: 94.3% (1197 of 1270 lines)
  functions..: 83.3% (385 of 462 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/filter/unscheduled_scheduled_stop.ex              | 0.0%      6| 0.0%     1|    -      0
  lib/concentrate/reporter/unskipped_null_stops.ex                  |14.3%      7|20.0%     5|    -      0

Download coverage report

@Whoops Whoops temporarily deployed to dev-green July 26, 2023 18:04 — with GitHub Actions Inactive
@github-actions
Copy link

Coverage of commit c9b7d72

Summary coverage rate:
  lines......: 94.3% (1197 of 1270 lines)
  functions..: 83.3% (385 of 462 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/filter/unscheduled_scheduled_stop.ex              | 0.0%      6| 0.0%     1|    -      0
  lib/concentrate/reporter/unskipped_null_stops.ex                  |14.3%      7|20.0%     5|    -      0

Download coverage report

@Whoops Whoops temporarily deployed to dev-green July 26, 2023 19:20 — with GitHub Actions Inactive
@github-actions
Copy link

Coverage of commit 84e1d3c

Summary coverage rate:
  lines......: 94.3% (1197 of 1270 lines)
  functions..: 83.3% (385 of 462 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/filter/unscheduled_scheduled_stop.ex              | 0.0%      6| 0.0%     1|    -      0
  lib/concentrate/reporter/unskipped_null_stops.ex                  |14.3%      7|20.0%     5|    -      0

Download coverage report

@Whoops Whoops changed the title Log warnings on unskipped stops with no arrival/departure fix: filter stop time updates without arrival/departure Jul 27, 2023
@Whoops Whoops marked this pull request as ready for review July 27, 2023 17:12
@Whoops Whoops requested a review from a team July 27, 2023 17:12
@github-actions
Copy link

Coverage of commit 85fd45b

Summary coverage rate:
  lines......: 95.2% (1202 of 1263 lines)
  functions..: 84.5% (386 of 457 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/filter/unscheduled_scheduled_stop.ex              |83.3%      6| 100%     1|    -      0

Download coverage report

@Whoops Whoops temporarily deployed to dev-green July 27, 2023 17:13 — with GitHub Actions Inactive
Copy link
Member

@paulswartz paulswartz 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 think you want to that at this stage. Commuter Rail predictions can exist without an arrival or departure time, but with a boarding_status.

Instead, I'd look at filtering these out of non-enhanced outputs, as those wouldn't include the boarding_status field.

@Whoops
Copy link
Collaborator Author

Whoops commented Jul 27, 2023

Instead, I'd look at filtering these out of non-enhanced outputs, as those wouldn't include the boarding_status field.

Ugh, and in fact they already are being filtered from non-enchanced feeds (https://github.com/mbta/concentrate/blob/master/lib/concentrate/encoder/trip_updates.ex#L28). But the predictions API uses the enhanced feed and so is publishing a bunch of nonsensical bus predictions. I'll need to come up with a new idea to deal with those. Especially since apparently similar predictions are valid in other contexts.

@paulswartz
Copy link
Member

Given the original report, it looks like the issue is starting with Busloc. That application should never be generating predictions without at least one of an arrival/departure time AFAIK.

@Whoops
Copy link
Collaborator Author

Whoops commented Jul 27, 2023

As far as I can tell, it'll never output an arrival/departure time. Some waivers it publishes as skipped, some as scheduled (https://github.com/mbta/busloc/blob/master/lib/busloc/waiver/encoder/trip_updates_enhanced.ex#L71). The last time we went down this rabbit-hole we were unable to get a clear answer as to the purpose of the scheduled updates.

@paulswartz
Copy link
Member

Right right, this is coming back to me now. Maybe filtering out STUs without a time OR boarding status would work?

@Whoops
Copy link
Collaborator Author

Whoops commented Jul 27, 2023

That seems reasonable. I'll make the change. Thanks!

@github-actions
Copy link

Coverage of commit 992e4dd

Summary coverage rate:
  lines......: 95.1% (1202 of 1264 lines)
  functions..: 84.2% (385 of 457 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/filter/unscheduled_scheduled_stop.ex              |85.7%      7| 100%     1|    -      0

Download coverage report

@Whoops Whoops requested a review from paulswartz July 27, 2023 18:25
def filter(%StopTimeUpdate{} = stu) do
scheduled? =
StopTimeUpdate.schedule_relationship(stu) == :SCHEDULED ||
StopTimeUpdate.schedule_relationship(stu) == nil
Copy link
Member

Choose a reason for hiding this comment

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

question: is it possible for this to be nil? I thought the parser converted it to the default value of :SCHEDULED?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It looks like your correct, I've removed the condition. I was working off the spec and the fact that concentrate will omit schedule_relationship in it's output if it's :SCHEDULED

@github-actions
Copy link

Coverage of commit 76778e9

Summary coverage rate:
  lines......: 95.1% (1198 of 1260 lines)
  functions..: 84.2% (385 of 457 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/filter/unscheduled_scheduled_stop.ex              |66.7%      3| 100%     1|    -      0

Download coverage report

Copy link
Member

@paulswartz paulswartz left a comment

Choose a reason for hiding this comment

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

🍰

code looks good! can you deploy again to make sure it's working okay?

@Whoops Whoops temporarily deployed to dev-green July 28, 2023 13:58 — with GitHub Actions Inactive
@Whoops
Copy link
Collaborator Author

Whoops commented Jul 28, 2023

code looks good! can you deploy again to make sure it's working okay?

Yep! I sent it to dev-green, I'll keep an eye on it for issues.

@Whoops Whoops merged commit e6f4a05 into master Aug 4, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants