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

Group ETA on same routes with same ETA times (remote duplicate ones) #194

Merged
merged 5 commits into from
Aug 19, 2024

Conversation

chengkeith
Copy link
Contributor

@chengkeith chengkeith commented Jul 12, 2024

Description

This PR intends to solve issue #112. The issue of #112 will be more obvious when multiple bus stops are merged and more ETAs are shown in the list (due to PR #193).

Therefore, it is recommended that when merging PR #193, this PR (#194) is also merged, but these two PRs themselves have no dependencies of each other, just a recommendation.

It is also recommended to deploy to alpha site for testing first before merging to production.

Behaviour before and after the code changes are illustrated in below screenshot. Left side is current production build at hkbus.app, right side is my localhost version with latest code.

image

  • Route 90B (Rows 1 and 2)
    • ETAs are different (0, 19, 39 mins vs 0, 7, 19 mins)
    • Direction also different (Row 1 is departure route, Row 2 is arrival route)
    • Behavour: no merge
  • Route 171 (Row 3 to 5 on the left)
    • ETAs are same (3, 17, 31 mins)
    • Direction also same (From South Horizon towards Lai Chi Kok)
    • Behaviour: merge them (criteria about which route is chosen will be described below)
    • Note: Row 9 on the right is actually arrival route, also ETA times are different (15, 25 mins). This route will not be merged.
  • Route 595 (Row 6 to 9 on the left, Row 4 to 5 on the right)
    • ETAs with (3, 14, 29 mins) are departure route
    • ETAs with (5, 11, 15 mins) are arrival routes
    • Behaviour: merge departure route and show one row of ETA, then merge arrival route and show one row of ETA. Hence total two rows of route 595 on the right hand side

Criteria to decide which route is chosen to be displayed when merging

Routes are chosen based on score system. Generally speaking, the criteria is as follows:

  1. If one bus route is available according to current frequency timetable, prefer this route over the other routes that aren't running
  2. If one bus route has frequency timetable and/or fares table, prefer this route over the other routes that don't have (freq/fares table = null)
  3. If one bus route is normal route, others are special routes, then prefer to display the normal route (serviceType with smaller value wins)
  4. If one bus route is a circular route, the other is one-way (in screenshot above, 595 海怡半島<->海怡半島 vs 595 海怡半島->石排灣), prefer the circular route (bounds with "OI" or "IO" is preferred over just "O" or "I")
    At the end, the routes with best score wins and is chosen.

Summary by CodeRabbit

  • Enhancements
    • Improved the useStopEtas functionality for better filtering of stop lists and handling of duplicate routes.
    • Enhanced sorting of ETAs to display the earliest arrivals first.
    • Added logic to determine the best route based on heuristic scoring.
    • Introduced a new parameter to consider holidays in ETA calculations.

Copy link

coderabbitai bot commented Jul 12, 2024

Walkthrough

The enhancements to useStopEtas hook in src/hooks/useStopEtas.tsx include improved filtering logic to refine stop lists, better handling of duplicate routes with identical ETAs, and the implementation of heuristic scoring for optimal route selection. The ETAs are now sorted to prioritize the earliest arrivals. Additionally, a new parameter isTodayHoliday was introduced to the function.

Changes

File Path Change Summary
src/hooks/useStopEtas.tsx Enhanced filtering logic, improved duplicate route handling, heuristic scoring for routes, and ETA sorting. Added isTodayHoliday parameter.

Poem

The buses come, the stops align,
New routes emerge, in perfect time.
With holiday cheer, they sort and score,
ETAs now shine, more than before.
Hooray for code, in transit's dance,
A better flow, with every chance! 🐇🚍


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1212440 and 6d83fe4.

Files selected for processing (1)
  • src/hooks/useStopEtas.tsx (2 hunks)
Additional comments not posted (5)
src/hooks/useStopEtas.tsx (5)

Line range hint 11-13:
Initialization of isTodayHoliday looks good.

The isTodayHoliday variable is correctly initialized using the useContext hook.


Line range hint 34-38:
Usage of isTodayHoliday in routeKeys memoization looks good.

The isTodayHoliday variable is correctly used to filter routes based on their availability.


101-165: New logic for removing duplicate routes and selecting the best route looks good.

The new logic efficiently removes duplicate routes and selects the best route using heuristic scoring.


Line range hint 168-174:
Updated sorting logic looks good.

The sorting logic correctly prioritizes the earliest arrival times for display.


195-195: Usage of isTodayHoliday in fetchData callback looks good.

The isTodayHoliday variable is correctly used in the fetchData callback to filter routes.

@chunlaw chunlaw merged commit 3b0955e into hkbus:master Aug 19, 2024
2 checks passed
@chengkeith chengkeith deleted the feature-remove-duplicate-eta branch September 15, 2024 10:16
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.

2 participants