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

editoast: add train_schedule object to search endpoint #9178

Merged
merged 1 commit into from
Oct 11, 2024

Conversation

EthanPERRUZZA
Copy link
Contributor

#9124

Bellow is a test using the below request :
Based on the openapi request : Returns all infra objects of some type according to a hierarchical query.

POST :
{{baseUrl}}/search?page=1&page_size=25
Body :

{
    "object": "trainschedule",
    "query": [
        "and",
        [
            "search",
            [
                "train_name"
            ],
            "10222"
        ],
        [
            "=",
            [
                "timetable_id"
            ],
            1
        ]
    ]
}

Answer :

[
    {
        "comfort": 0,
        "constraint_distribution": 0,
        "id": 1,
        "initial_speed": 0,
        "labels": [
            "all-stops",
            "H3C4"
        ],
        "margins": {
            "boundaries": [],
            "values": [
                "0%"
            ]
        },
        "options": {
            "use_electrical_profiles": true
        },
        "path": [
            {
                "deleted": false,
                "id": "0",
                "operational_point": "d9e37c1e-6667-11e3-89ff-01f464e0362d"
            },
            {
                "deleted": false,
                "id": "1",
                "operational_point": "d9a37fbe-6667-11e3-89ff-01f464e0362d"
            },
            {
                "deleted": false,
                "id": "2",
                "operational_point": "d97702c4-6667-11e3-89ff-01f464e0362d"
            }
        ],
        "power_restrictions": [],
        "rolling_stock_name": "69400US",
        "schedule": [
            {
                "arrival": "PT6720S",
                "at": "1",
                "locked": true,
                "reception_signal": "OPEN",
                "stop_for": "PT1680S"
            },
            {
                "arrival": "PT10200S",
                "at": "2",
                "locked": true,
                "reception_signal": "OPEN",
                "stop_for": "P0D"
            }
        ],
        "speed_limit_tag": "ME100",
        "start_time": "2024-09-17T10:03:00+00:00",
        "timetable_id": 1,
        "train_name": "102224"
    }
]

@EthanPERRUZZA EthanPERRUZZA self-assigned this Oct 3, 2024
@github-actions github-actions bot added the area:editoast Work on Editoast Service label Oct 3, 2024
@codecov-commenter
Copy link

codecov-commenter commented Oct 3, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 38.54%. Comparing base (b38f9e2) to head (6152bb0).
Report is 3 commits behind head on dev.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev    #9178      +/-   ##
============================================
+ Coverage     38.45%   38.54%   +0.08%     
  Complexity     2244     2244              
============================================
  Files          1288     1288              
  Lines         98429    98454      +25     
  Branches       3273     3273              
============================================
+ Hits          37855    37948      +93     
+ Misses        58637    58569      -68     
  Partials       1937     1937              
Flag Coverage Δ
core 74.87% <ø> (ø)
editoast 72.42% <100.00%> (+0.32%) ⬆️
front 10.13% <ø> (-0.01%) ⬇️
gateway 2.19% <ø> (ø)
osrdyne 2.43% <ø> (ø)
railjson_generator 87.49% <ø> (ø)
tests 86.71% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@EthanPERRUZZA EthanPERRUZZA force-pushed the eth/search_trainschedule branch 4 times, most recently from 8566369 to 6250bbe Compare October 3, 2024 13:37
@EthanPERRUZZA EthanPERRUZZA marked this pull request as ready for review October 3, 2024 13:56
@EthanPERRUZZA EthanPERRUZZA requested a review from a team as a code owner October 3, 2024 13:56
Copy link
Contributor

@leovalais leovalais left a comment

Choose a reason for hiding this comment

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

Nice job! Tested and it works great, a few comments on documentation though.

Side note: since the train_name column isn't indexed to support fuzzy matching, the search operator is likely much more inefficient than a plain =.

Copy link
Contributor

@woshilapin woshilapin left a comment

Choose a reason for hiding this comment

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

Thanks for giving an example in the PR description. I'd say it's perfect for actually adding that as a test case of the feature 😈 😜

@EthanPERRUZZA
Copy link
Contributor Author

Thanks for giving an example in the PR description. I'd say it's perfect for actually adding that as a test case of the feature 😈 😜

😭
I'll have a look but I'm not sure that it's even possible as you need to load data from a backup in the database to make the search. I'll try to look if there is tests for the other sarch objects.

I'm also unsure if it's necessary to test that feature as it's not meant to change or be broken by anything unless we change the database structure and/or the request result content.

@EthanPERRUZZA EthanPERRUZZA force-pushed the eth/search_trainschedule branch 2 times, most recently from f9c6093 to e45c644 Compare October 4, 2024 09:21
@leovalais
Copy link
Contributor

@woshilapin We didn't test the search endpoint because there's a bunch of things to setup and we didn't have the test infrastructure have today.

@EthanPERRUZZA for train schedules it should be simpler though, especially since there's no cache. You have in models::fixtures a test train schedule you can add to the DB to test your requests. You don't have to cleanup the DB after the test, this is done automatically.

Copy link
Contributor

@flomonster flomonster left a comment

Choose a reason for hiding this comment

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

LGTM. I agree with @leovalais we can add a test for this search object.

Here an example on how create a train schedule in a test.

Note

For your test, you don't need an infra or a scenario. You just need a timetable and a train schedule.

@EthanPERRUZZA EthanPERRUZZA force-pushed the eth/search_trainschedule branch from 0ca6f1e to 73e8366 Compare October 9, 2024 09:15
@EthanPERRUZZA EthanPERRUZZA force-pushed the eth/search_trainschedule branch 2 times, most recently from e45c644 to d1d8524 Compare October 9, 2024 09:30
Copy link
Contributor

@woshilapin woshilapin left a comment

Choose a reason for hiding this comment

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

Looks good, thank you the test. Maybe you can add another simple one to test no results?

Copy link
Contributor

@leovalais leovalais left a comment

Choose a reason for hiding this comment

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

Thanks for adding the test! Just a few more details:

Copy link
Contributor

@leovalais leovalais left a comment

Choose a reason for hiding this comment

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

Just a few nitpicks, otherwise LGTM thank you! You have to squash your commits before merging otherwise the CI won't pass.

@EthanPERRUZZA EthanPERRUZZA force-pushed the eth/search_trainschedule branch from 0839d57 to 6152bb0 Compare October 10, 2024 14:13
@EthanPERRUZZA EthanPERRUZZA added this pull request to the merge queue Oct 10, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 10, 2024
@EthanPERRUZZA EthanPERRUZZA added this pull request to the merge queue Oct 11, 2024
Merged via the queue into dev with commit 5c58af7 Oct 11, 2024
25 checks passed
@EthanPERRUZZA EthanPERRUZZA deleted the eth/search_trainschedule branch October 11, 2024 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:editoast Work on Editoast Service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants