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 light rail ETA (route_list=null; end_service_status) #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

desmondlsl
Copy link
Contributor

Issues:

  1. platform_list[].route_list is null when there are no ETAs available. This behaviour is undocumented.

  2. As when platform_list[].end_service_status exists, platform_list[].route_list does not exist. This field is undocumented.
    How should end_service_status for only some platforms be handled? Would a light rail line stop at different platforms?

For both of the above scanerios, this library currently throws an error, affecting querying ETAs of trains going to arrive at other platforms of the same stop.

TypeError: Cannot read properties of undefined (reading 'filter')

This PR fixes the above 2 scanerios.


Sample response of route_list: null

{
    "platform_list": [
        {
            "route_list": null,
            "platform_id": 2
        },
        {
            "route_list": [
                {
                    "train_length": 1,
                    "arrival_departure": "D",
                    "dest_en": "Tuen Mun Ferry Pier",
                    "dest_ch": "屯門碼頭",
                    "time_en": "2 min",
                    "time_ch": "2 分鐘",
                    "route_no": "610",
                    "stop": 0
                },
                {
                    "train_length": 1,
                    "arrival_departure": "D",
                    "dest_en": "Tuen Mun Ferry Pier",
                    "dest_ch": "屯門碼頭",
                    "time_en": "18 min",
                    "time_ch": "18 分鐘",
                    "route_no": "610",
                    "stop": 0
                }
            ],
            "platform_id": 3
        },
        {
            "route_list": [
                {
                    "train_length": 1,
                    "arrival_departure": "D",
                    "dest_en": "Tuen Mun Ferry Pier",
                    "dest_ch": "屯門碼頭",
                    "time_en": "8 min",
                    "time_ch": "8 分鐘",
                    "route_no": "615",
                    "stop": 0
                }
            ],
            "platform_id": 4
        },
        {
            "route_list": [
                {
                    "train_length": 2,
                    "arrival_departure": "D",
                    "dest_en": "Tin Yat",
                    "dest_ch": "天逸",
                    "time_en": "5 min",
                    "time_ch": "5 分鐘",
                    "route_no": "761P",
                    "stop": 0
                },
                {
                    "train_length": 2,
                    "arrival_departure": "D",
                    "dest_en": "Tin Yat",
                    "dest_ch": "天逸",
                    "time_en": "19 min",
                    "time_ch": "19 分鐘",
                    "route_no": "761P",
                    "stop": 0
                }
            ],
            "platform_id": 5
        }
    ],
    "status": 1,
    "system_time": "2024-10-31 00:02:48"
}

Sample response of route_list is an array later.

{
    "platform_list": [
        {
            "route_list": [
                {
                    "train_length": 1,
                    "arrival_departure": "D",
                    "dest_en": "Tuen Mun Ferry Pier",
                    "dest_ch": "屯門碼頭",
                    "time_en": "19 min",
                    "time_ch": "19 分鐘",
                    "route_no": "614",
                    "stop": 0
                }
            ],
            "platform_id": 2
        },
        {
            "route_list": [
                {
                    "train_length": 1,
                    "arrival_departure": "D",
                    "dest_en": "Tuen Mun Ferry Pier",
                    "dest_ch": "屯門碼頭",
                    "time_en": "Departing",
                    "time_ch": "正在離開",
                    "route_no": "610",
                    "stop": 0
                },
                {
                    "train_length": 1,
                    "arrival_departure": "D",
                    "dest_en": "Tuen Mun Ferry Pier",
                    "dest_ch": "屯門碼頭",
                    "time_en": "17 min",
                    "time_ch": "17 分鐘",
                    "route_no": "610",
                    "stop": 0
                }
            ],
            "platform_id": 3
        },
        {
            "route_list": [
                {
                    "train_length": 1,
                    "arrival_departure": "D",
                    "dest_en": "Tuen Mun Ferry Pier",
                    "dest_ch": "屯門碼頭",
                    "time_en": "7 min",
                    "time_ch": "7 分鐘",
                    "route_no": "615",
                    "stop": 0
                }
            ],
            "platform_id": 4
        },
        {
            "route_list": [
                {
                    "train_length": 2,
                    "arrival_departure": "D",
                    "dest_en": "Tin Yat",
                    "dest_ch": "天逸",
                    "time_en": "4 min",
                    "time_ch": "4 分鐘",
                    "route_no": "761P",
                    "stop": 0
                },
                {
                    "train_length": 2,
                    "arrival_departure": "D",
                    "dest_en": "Tin Yat",
                    "dest_ch": "天逸",
                    "time_en": "18 min",
                    "time_ch": "18 分鐘",
                    "route_no": "761P",
                    "stop": 0
                }
            ],
            "platform_id": 5
        }
    ],
    "status": 1,
    "system_time": "2024-10-31 00:03:18"
}

Sample response with end_service_status

{
    "platform_list": [
        {
            "route_list": [
                {
                    "train_length": 1,
                    "arrival_departure": "D",
                    "dest_en": "Tuen Mun Ferry Pier",
                    "dest_ch": "屯門碼頭",
                    "time_en": "15 min",
                    "time_ch": "15 分鐘",
                    "route_no": "614",
                    "stop": 0
                }
            ],
            "platform_id": 2
        },
        {
            "route_list": [
                {
                    "train_length": 1,
                    "arrival_departure": "D",
                    "dest_en": "Tuen Mun Ferry Pier",
                    "dest_ch": "屯門碼頭",
                    "time_en": "8 min",
                    "time_ch": "8 分鐘",
                    "route_no": "610",
                    "stop": 0
                }
            ],
            "platform_id": 3
        },
        {
            "end_service_status": 1,
            "platform_id": 4
        },
        {
            "route_list": [
                {
                    "train_length": 2,
                    "arrival_departure": "D",
                    "dest_en": "Tin Yat",
                    "dest_ch": "天逸",
                    "time_en": "6 min",
                    "time_ch": "6 分鐘",
                    "route_no": "761P",
                    "stop": 0
                }
            ],
            "platform_id": 5
        }
    ],
    "status": 1,
    "system_time": "2024-10-31 00:29:40"
}
{
    "platform_list": [
        {
            "end_service_status": 1,
            "platform_id": 1
        },
        {
            "end_service_status": 1,
            "platform_id": 4
        },
        {
            "end_service_status": 1,
            "platform_id": 5
        },
        {
            "end_service_status": 1,
            "platform_id": 6
        }
    ],
    "status": 1,
    "system_time": "2024-10-31 00:56: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.

1 participant